Allow itineraries to be passed through the Target Machine.
authorJim Laskey <jlaskey@mac.com>
Tue, 1 Nov 2005 20:06:59 +0000 (20:06 +0000)
committerJim Laskey <jlaskey@mac.com>
Tue, 1 Nov 2005 20:06:59 +0000 (20:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24139 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetInstrInfo.h
include/llvm/Target/TargetInstrItineraries.h
include/llvm/Target/TargetMachine.h
lib/Target/PowerPC/PPCSubtarget.cpp
lib/Target/PowerPC/PPCSubtarget.h
lib/Target/PowerPC/PPCTargetMachine.cpp
lib/Target/PowerPC/PPCTargetMachine.h
utils/TableGen/InstrInfoEmitter.cpp
utils/TableGen/SubtargetEmitter.cpp
utils/TableGen/SubtargetEmitter.h

index 7b9cda2a9488a16945103188fddf6c608d28918e..8659ef9e39cfb1579c21a38265fb7a8d1cec80e1 100644 (file)
@@ -146,7 +146,6 @@ public:
     return get(Opcode).numOperands;
   }
 
-
   InstrSchedClass getSchedClass(MachineOpCode Opcode) const {
     return get(Opcode).schedClass;
   }
index 3a622c7732f5b0f1a0a1d4f858e2146482d921f1..3be5b9513a221e7cd4f700f4f056d6be1effa60f 100644 (file)
@@ -16,6 +16,8 @@
 #ifndef LLVM_TARGET_TARGETINSTRITINERARIES_H
 #define LLVM_TARGET_TARGETINSTRITINERARIES_H
 
+#include "llvm/Support/Debug.h"
+
 namespace llvm {
 
 //===----------------------------------------------------------------------===//
@@ -41,6 +43,56 @@ struct InstrItinerary {
 };
 
 
+
+//===----------------------------------------------------------------------===//
+// Instruction itinerary Data - Itinerary data supplied by a subtarget to be
+// used by a target.
+//
+class InstrItineraryData {
+  InstrStage     *Stages;         // Array of stages selected
+  unsigned        NStages;        // Number of stages
+  InstrItinerary *Itineratries;   // Array of itineraries selected
+  unsigned        NItineraries;   // Number of itineraries (actually classes)
+
+public:
+
+  //
+  // Ctors.
+  //
+  InstrItineraryData()
+  : Stages(NULL), NStages(0), Itineratries(NULL), NItineraries(0)
+  {}
+  InstrItineraryData(InstrStage *S, unsigned NS, InstrItinerary *I, unsigned NI)
+  : Stages(S), NStages(NS), Itineratries(I), NItineraries(NI)
+  {}
+  
+  //
+  // isEmpty - Returns true if there are no itineraries.
+  //
+  inline bool isEmpty() const { return NItineraries == 0; }
+  
+  //
+  // begin - Return the first stage of the itinerary.
+  // 
+  inline InstrStage *begin(unsigned ItinClassIndx) const {
+    assert(ItinClassIndx < NItineraries && "Itinerary index out of range");
+    unsigned StageIdx = Itineratries[ItinClassIndx].First;
+    assert(StageIdx < NStages && "Stage index out of range");
+    return Stages + StageIdx;
+  }
+
+  //
+  // end - Return the last+1 stage of the itinerary.
+  // 
+  inline InstrStage *end(unsigned ItinClassIndx) const {
+    assert(ItinClassIndx < NItineraries && "Itinerary index out of range");
+    unsigned StageIdx = Itineratries[ItinClassIndx].Last;
+    assert(StageIdx < NStages && "Stage index out of range");
+    return Stages + StageIdx;
+  }
+};
+
+
 } // End llvm namespace
 
 #endif
index 9c026cc4f6c71924c866c0dfbc1865fdffb0fe38..aae7d901fbebf93f4becb4ccc17da8d7548072ed 100644 (file)
@@ -15,6 +15,7 @@
 #define LLVM_TARGET_TARGETMACHINE_H
 
 #include "llvm/Target/TargetData.h"
+#include "llvm/Target/TargetInstrItineraries.h"
 #include <cassert>
 
 namespace llvm {
@@ -122,6 +123,13 @@ public:
   /// otherwise return null.
   ///
   virtual TargetJITInfo *getJITInfo() { return 0; }
+  
+  /// getInstrItineraryData - Returns instruction itinerary data for the target
+  /// or specific subtarget.
+  ///
+  virtual const InstrItineraryData getInstrItineraryData() const {  
+    return InstrItineraryData();
+  }
 
   // These are deprecated interfaces.
   virtual const TargetSchedInfo        *getSchedInfo() const { return 0; }
index 94af54c35916769119207637933491eb6081ef94..442017d8cd2afa76ab3785e154951f47006bcbac 100644 (file)
@@ -71,6 +71,7 @@ static const char *GetCurrentPowerPCCPU() {
 
 PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS)
   : StackAlignment(16)
+  , InstrItins()
   , IsGigaProcessor(false)
   , Is64Bit(false)
   , Has64BitRegs(false)
index a457751886fde64b689fb928aaf02dbdae4af107..3f1454ce527cbc957be698537176e33026f7932c 100644 (file)
@@ -14,6 +14,7 @@
 #ifndef POWERPCSUBTARGET_H
 #define POWERPCSUBTARGET_H
 
+#include "llvm/Target/TargetInstrItineraries.h"
 #include "llvm/Target/TargetSubtarget.h"
 
 #include <string>
@@ -26,6 +27,9 @@ protected:
   /// stackAlignment - The minimum alignment known to hold of the stack frame on
   /// entry to the function and which must be maintained by every function.
   unsigned StackAlignment;
+  
+  /// Selected instruction itineraries (one entry per itinerary class.)
+  InstrItineraryData InstrItins;
 
   /// Used by the ISel to turn in optimizations for POWER4-derived architectures
   bool IsGigaProcessor;
@@ -49,6 +53,11 @@ public:
   /// stack frame on entry to the function and which must be maintained by every
   /// function for this subtarget.
   unsigned getStackAlignment() const { return StackAlignment; }
+  
+  /// getInstrItins - Return the instruction itineraies based on subtarget 
+  /// selection.
+  const InstrItineraryData getInstrItineraryData() const { return InstrItins; }
+  
 
   bool hasFSQRT() const { return HasFSQRT; }
   bool has64BitRegs() const { return Has64BitRegs; }
index bd31e97aed77db8cc427f49ac318347144bf6377..9a88750b398eba927e7a2b58c57426cc8e502046 100644 (file)
@@ -64,7 +64,8 @@ unsigned PPCTargetMachine::getModuleMatchQuality(const Module &M) {
 PPCTargetMachine::PPCTargetMachine(const Module &M, IntrinsicLowering *IL,
                                    const std::string &FS)
 : TargetMachine("PowerPC", IL, false, 4, 4, 4, 4, 4, 4, 2, 1, 1),
-  Subtarget(M, FS), FrameInfo(*this, false), JITInfo(*this) {
+  Subtarget(M, FS), FrameInfo(*this, false), JITInfo(*this),
+  InstrItins(Subtarget.getInstrItineraryData()) {
   if (TargetDefault == PPCTarget) {
     if (Subtarget.isAIX()) PPCTarget = TargetAIX;
     if (Subtarget.isDarwin()) PPCTarget = TargetDarwin;
index 5ba4f3229013c98c5dcd37b1aebb9f26cfad6a43..1295a599107e4b656c4e8396a9e24626d58966f5 100644 (file)
@@ -27,10 +27,11 @@ class GlobalValue;
 class IntrinsicLowering;
 
 class PPCTargetMachine : public TargetMachine {
-  PPCInstrInfo    InstrInfo;
-  PPCSubtarget    Subtarget;
-  PPCFrameInfo    FrameInfo;
-  PPCJITInfo      JITInfo;
+  PPCInstrInfo           InstrInfo;
+  PPCSubtarget           Subtarget;
+  PPCFrameInfo           FrameInfo;
+  PPCJITInfo             JITInfo;
+  InstrItineraryData     InstrItins;
 public:
   PPCTargetMachine(const Module &M, IntrinsicLowering *IL,
                    const std::string &FS);
@@ -42,6 +43,10 @@ public:
   virtual const MRegisterInfo    *getRegisterInfo() const {
     return &InstrInfo.getRegisterInfo();
   }
+  virtual const InstrItineraryData getInstrItineraryData() const {  
+    return InstrItins;
+  }
+  
 
   static unsigned getJITMatchQuality();
 
index c911ad3ed6e94796dab26547b4fb63a1341cc5e6..3f7d5dbadc12bc1ab713a6a5b3edfa314be207f5 100644 (file)
@@ -247,7 +247,7 @@ void InstrInfoEmitter::GatherItinClasses() {
 
   for (unsigned i = 0, N = DefList.size(); i < N; i++) {
     Record *Def = DefList[i];
-    ItinClassMap[Def->getName()] = i + 1;
+    ItinClassMap[Def->getName()] = i;
   }
 }  
   
index 9eb1f67297a722a67ce0bf6808ffe1ef6ccd4d9b..0ec780390cf55532b4147a58c69e94a62366ab32 100644 (file)
@@ -178,8 +178,8 @@ void SubtargetEmitter::CPUKeyValues(std::ostream &OS) {
 // CollectAllItinClasses - Gathers and enumerates all the itinerary classes.
 // Returns itinerary class count.
 //
-unsigned SubtargetEmitter::CollectAllItinClasses(std::map<std::string, unsigned>
-                                                              &ItinClassesMap) {
+unsigned SubtargetEmitter::CollectAllItinClasses(std::ostream &OS,
+                              std::map<std::string, unsigned> &ItinClassesMap) {
   // Gather and sort all itinerary classes
   std::vector<Record*> ItinClassList =
                             Records.getAllDerivedDefinitions("InstrItinClass");
@@ -196,6 +196,11 @@ unsigned SubtargetEmitter::CollectAllItinClasses(std::map<std::string, unsigned>
     ItinClassesMap[Name] = i;
   }
   
+  // Emit size of table
+  OS<<"\nenum {\n";
+  OS<<"  ItinClassesSize = " << N << "\n";
+  OS<<"};\n";
+
   // Return itinerary class count
   return N;
 }
@@ -313,6 +318,11 @@ void SubtargetEmitter::EmitStageData(std::ostream &OS,
   
   // End stages table
   OS << "};\n";
+  
+  // Emit size of table
+  OS<<"\nenum {\n";
+  OS<<"  StagesSize = sizeof(Stages)/sizeof(llvm::InstrStage)\n";
+  OS<<"};\n";
 }
 
 //
@@ -421,13 +431,18 @@ void SubtargetEmitter::EmitData(std::ostream &OS) {
   std::vector<std::vector<InstrItinerary> > ProcList;
   
   // Enumerate all the itinerary classes
-  unsigned NItinClasses = CollectAllItinClasses(ItinClassesMap);
-  // Emit the stage data
-  EmitStageData(OS, NItinClasses, ItinClassesMap, ProcList);
-  // Emit the processor itinerary data
-  EmitProcessorData(OS, ProcList);
-  // Emit the processor lookup data
-  EmitProcessorLookup(OS);
+  unsigned NItinClasses = CollectAllItinClasses(OS, ItinClassesMap);
+  // Make sure the rest is worth the effort
+  HasItineraries = NItinClasses != 0;
+  
+  if (HasItineraries) {
+    // Emit the stage data
+    EmitStageData(OS, NItinClasses, ItinClassesMap, ProcList);
+    // Emit the processor itinerary data
+    EmitProcessorData(OS, ProcList);
+    // Emit the processor lookup data
+    EmitProcessorLookup(OS);
+  }
 }
 
 //
@@ -460,9 +475,15 @@ void SubtargetEmitter::ParseFeaturesFunction(std::ostream &OS) {
     
     OS << "  " << Attribute << " = (Bits & " << Instance << ") != 0;\n";
   }
-  OS << "\n"
-     << "  InstrItinerary *Itin = (InstrItinerary *)"
-                        "Features.getInfo(SubTypeInfoKV, SubTypeInfoKVSize);\n";
+  
+  if (HasItineraries) {
+    OS << "\n"
+       << "  InstrItinerary *Itinerary = (InstrItinerary *)"
+                        "Features.getInfo(SubTypeInfoKV, SubTypeInfoKVSize);\n"
+          "  InstrItins = InstrItineraryData(Stages, StagesSize, "
+                                             "Itinerary, ItinClassesSize);\n";
+  }
+  
   OS << "}\n";
 }
 
index f882f1d53cfc53050f6d9b6fae217caaa71d57dc..69feeb2d0f53e707f8d204c189636654c504939a 100644 (file)
@@ -27,12 +27,13 @@ class SubtargetEmitter : public TableGenBackend {
   
   RecordKeeper &Records;
   std::string Target;
+  bool HasItineraries;
   
   void Enumeration(std::ostream &OS, const char *ClassName, bool isBits);
   void FeatureKeyValues(std::ostream &OS);
   void CPUKeyValues(std::ostream &OS);
-  unsigned CollectAllItinClasses(std::map<std::string, unsigned>
-                                                               &ItinClassesMap);
+  unsigned CollectAllItinClasses(std::ostream &OS,
+                               std::map<std::string, unsigned> &ItinClassesMap);
   void FormItineraryString(Record *ItinData, std::string &ItinString,
                            unsigned &NStages);
   void EmitStageData(std::ostream &OS, unsigned NItinClasses,
@@ -45,7 +46,7 @@ class SubtargetEmitter : public TableGenBackend {
   void ParseFeaturesFunction(std::ostream &OS);
   
 public:
-  SubtargetEmitter(RecordKeeper &R) : Records(R) {}
+  SubtargetEmitter(RecordKeeper &R) : Records(R), HasItineraries(false) {}
 
   // run - Output the subtarget enumerations, returning true on failure.
   void run(std::ostream &o);