Give full control of subtarget features over to table generated code.
authorJim Laskey <jlaskey@mac.com>
Wed, 26 Oct 2005 17:30:34 +0000 (17:30 +0000)
committerJim Laskey <jlaskey@mac.com>
Wed, 26 Oct 2005 17:30:34 +0000 (17:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24013 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Alpha/AlphaSubtarget.cpp
lib/Target/Alpha/AlphaSubtarget.h
lib/Target/PowerPC/PPCSubtarget.cpp
lib/Target/PowerPC/PPCSubtarget.h
utils/TableGen/SubtargetEmitter.cpp
utils/TableGen/SubtargetEmitter.h

index cc3a6b11f9359eafcc6328a81f2b489959420f41..22f0c698235a14a000caee829d64de2fd6970031 100644 (file)
@@ -19,10 +19,7 @@ using namespace llvm;
 AlphaSubtarget::AlphaSubtarget(const Module &M, const std::string &FS)
   : HasF2I(false), HasCT(false) {
   std::string CPU = "generic";
-  SubtargetFeatures Features(FS);
-  Features.setCPUIfNone(CPU);
-  uint32_t Bits =Features.getBits(SubTypeKV, SubTypeKVSize,
-                                  FeatureKV, FeatureKVSize);
-  HasF2I = (Bits & FeatureFIX) != 0;
-  HasCT  = (Bits & FeatureCIX) != 0;
+
+  // Parse features string.
+  ParseSubtargetFeatures(FS, CPU);
 }
index 8eadec00d05786dfe4574088c7e59b33ab839c79..d5847f3bf3534b1e0812ea455e3f1d31c53a8ac8 100644 (file)
@@ -33,6 +33,10 @@ public:
   /// of the specified module.
   ///
   AlphaSubtarget(const Module &M, const std::string &FS);
+  
+  /// ParseSubtargetFeatures - Parses features string setting specified 
+  /// subtarget options.  Definition of function is usto generated by tblgen.
+  void ParseSubtargetFeatures(const std::string &FS, const std::string &CPU);
 
   bool hasF2I() const { return HasF2I; }
   bool hasCT() const { return HasCT; }
index 1995e1ceb077461a7189b4161a437930f834da64..94af54c35916769119207637933491eb6081ef94 100644 (file)
@@ -68,22 +68,25 @@ static const char *GetCurrentPowerPCCPU() {
 }
 #endif
 
+
 PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS)
-  : StackAlignment(16), IsGigaProcessor(false), IsAIX(false), IsDarwin(false) {
+  : StackAlignment(16)
+  , IsGigaProcessor(false)
+  , Is64Bit(false)
+  , Has64BitRegs(false)
+  , HasAltivec(false)
+  , HasFSQRT(false)
+  , IsAIX(false)
+  , IsDarwin(false) {
 
   // Determine default and user specified characteristics
   std::string CPU = "generic";
 #if defined(__APPLE__)
   CPU = GetCurrentPowerPCCPU();
 #endif
-  SubtargetFeatures Features(FS);
-  Features.setCPUIfNone(CPU);
-  uint32_t Bits =  Features.getBits(SubTypeKV, SubTypeKVSize,
-                                    FeatureKV, FeatureKVSize);
-  IsGigaProcessor = (Bits & FeatureGPUL ) != 0;
-  Is64Bit         = (Bits & Feature64Bit) != 0;
-  HasFSQRT        = (Bits & FeatureFSqrt) != 0;
-  Has64BitRegs    = (Bits & Feature64BitRegs) != 0;
+
+  // Parse features string.
+  ParseSubtargetFeatures(FS, CPU);
 
   // Set the boolean corresponding to the current target triple, or the default
   // if one cannot be determined, to true.
index 9d0edf54ffb3022a163bb58412ac631e3d186fb4..5e94612da7ae91e53dd81a424fe721f42a7e1f33 100644 (file)
@@ -31,6 +31,7 @@ protected:
   bool IsGigaProcessor;
   bool Is64Bit;
   bool Has64BitRegs;
+  bool HasAltivec;
   bool HasFSQRT;
   bool IsAIX;
   bool IsDarwin;
@@ -39,6 +40,10 @@ public:
   /// of the specified module.
   ///
   PPCSubtarget(const Module &M, const std::string &FS);
+  
+  /// ParseSubtargetFeatures - Parses features string setting specified 
+  /// subtarget options.  Definition of function is usto generated by tblgen.
+  void ParseSubtargetFeatures(const std::string &FS, const std::string &CPU);
 
   /// getStackAlignment - Returns the minimum alignment known to hold of the
   /// stack frame on entry to the function and which must be maintained by every
@@ -46,11 +51,12 @@ public:
   unsigned getStackAlignment() const { return StackAlignment; }
 
   bool hasFSQRT() const { return HasFSQRT; }
+  bool has64BitRegs() const { return Has64BitRegs; }
+  bool hasAltivec() const { return HasAltivec; }
   
   bool isAIX() const { return IsAIX; }
   bool isDarwin() const { return IsDarwin; }
   bool is64Bit() const { return Is64Bit; }
-  bool has64BitRegs() const { return Has64BitRegs; }
   bool isGigaProcessor() const { return IsGigaProcessor; }
 };
 } // End llvm namespace
index 0957fba9d3915a33d2f6f8bb678c59e41f16e707..5739a6af54282dd45b70694ef659d8878ee1abc9 100644 (file)
@@ -45,24 +45,28 @@ struct LessRecordFieldName {
 };
 
 //
-// FeatureEnumeration - Emit an enumeration of all the subtarget features.
+// Enumeration - Emit the specified class as an enumeration.
 //
-void SubtargetEmitter::FeatureEnumeration(std::ostream &OS) {
-  RecordList Features = Records.getAllDerivedDefinitions("SubtargetFeature");
-  sort(Features.begin(), Features.end(), LessRecord());
+void SubtargetEmitter::Enumeration(std::ostream &OS,
+                                   const char *ClassName,
+                                   bool isBits) {
+  RecordList Defs = Records.getAllDerivedDefinitions(ClassName);
+  sort(Defs.begin(), Defs.end(), LessRecord());
 
   int i = 0;
   
   OS << "enum {\n";
   
-  for (RecordListIter RI = Features.begin(), E = Features.end(); RI != E;){
+  for (RecordListIter RI = Defs.begin(), E = Defs.end(); RI != E;) {
     Record *R = *RI++;
     std::string Instance = R->getName();
     OS << "  "
-       << Instance
-       << " = "
-       << " 1 << " << i++
-       << ((RI != E) ? ",\n" : "\n");
+       << Instance;
+    if (isBits) {
+      OS << " = "
+         << " 1 << " << i++;
+    }
+    OS << ((RI != E) ? ",\n" : "\n");
   }
   
   OS << "};\n";
@@ -76,8 +80,7 @@ void SubtargetEmitter::FeatureKeyValues(std::ostream &OS) {
   RecordList Features = Records.getAllDerivedDefinitions("SubtargetFeature");
   sort(Features.begin(), Features.end(), LessRecord());
 
-  OS << "\n"
-     << "// Sorted (by key) array of values for CPU features.\n"
+  OS << "// Sorted (by key) array of values for CPU features.\n"
      << "static llvm::SubtargetFeatureKV FeatureKV[] = {\n";
   for (RecordListIter RI = Features.begin(), E = Features.end(); RI != E;) {
     Record *R = *RI++;
@@ -105,8 +108,7 @@ void SubtargetEmitter::CPUKeyValues(std::ostream &OS) {
   RecordList Processors = Records.getAllDerivedDefinitions("Processor");
   sort(Processors.begin(), Processors.end(), LessRecordFieldName());
 
-  OS << "\n"
-     << "// Sorted (by key) array of values for CPU subtype.\n"
+  OS << "// Sorted (by key) array of values for CPU subtype.\n"
      << "static const llvm::SubtargetFeatureKV SubTypeKV[] = {\n";
   for (RecordListIter RI = Processors.begin(), E = Processors.end();
        RI != E;) {
@@ -145,15 +147,61 @@ void SubtargetEmitter::CPUKeyValues(std::ostream &OS) {
   OS<<"};\n";
 }
 
+//
+// ParseFeaturesFunction - Produces a subtarget specific function for parsing
+// the subtarget features string.
+//
+void SubtargetEmitter::ParseFeaturesFunction(std::ostream &OS) {
+  RecordList Features = Records.getAllDerivedDefinitions("SubtargetFeature");
+  sort(Features.begin(), Features.end(), LessRecord());
+
+  OS << "// ParseSubtargetFeatures - Parses features string setting specified\n" 
+        "// subtarget options.\n" 
+        "void llvm::";
+  OS << Target;
+  OS << "Subtarget::ParseSubtargetFeatures(const std::string &FS,\n"
+        "                                  const std::string &CPU) {\n"
+        "  SubtargetFeatures Features(FS);\n"
+        "  Features.setCPUIfNone(CPU);\n"
+        "  uint32_t Bits =  Features.getBits(SubTypeKV, SubTypeKVSize,\n"
+        "                                    FeatureKV, FeatureKVSize);\n";
+        
+  for (RecordListIter RI = Features.begin(), E = Features.end(); RI != E;) {
+    Record *R = *RI++;
+    std::string Instance = R->getName();
+    std::string Name = R->getValueAsString("Name");
+    std::string Type = R->getValueAsString("Type");
+    std::string Attribute = R->getValueAsString("Attribute");
+    
+    OS << "  " << Attribute << " = (Bits & " << Instance << ") != 0;\n";
+  }
+  OS << "}\n";
+}
+
 // 
 // SubtargetEmitter::run - Main subtarget enumeration emitter.
 //
 void SubtargetEmitter::run(std::ostream &OS) {
+  std::vector<Record*> Targets = Records.getAllDerivedDefinitions("Target");
+  if (Targets.size() == 0)
+    throw std::string("ERROR: No 'Target' subclasses defined!");
+  if (Targets.size() != 1)
+    throw std::string("ERROR: Multiple subclasses of Target defined!");
+  Target = Targets[0]->getName();
+
   EmitSourceFileHeader("Subtarget Enumeration Source Fragment", OS);
 
   OS << "#include \"llvm/Target/SubtargetFeature.h\"\n\n";
   
-  FeatureEnumeration(OS);
+  Enumeration(OS, "FuncUnit", true);
+  OS<<"\n";
+  Enumeration(OS, "InstrItinClass", false);
+  OS<<"\n";
+  Enumeration(OS, "SubtargetFeature", true);
+  OS<<"\n";
   FeatureKeyValues(OS);
+  OS<<"\n";
   CPUKeyValues(OS);
+  OS<<"\n";
+  ParseFeaturesFunction(OS);
 }
index bb81df372de3ec0561fdf676ce47875952730a9c..7e2a7cb0a3742cb381bc15f2457e3120ff646bce 100644 (file)
@@ -20,10 +20,12 @@ namespace llvm {
 
 class SubtargetEmitter : public TableGenBackend {
   RecordKeeper &Records;
+  std::string Target;
   
-  void FeatureEnumeration(std::ostream &OS);
+  void Enumeration(std::ostream &OS, const char *ClassName, bool isBits);
   void FeatureKeyValues(std::ostream &OS);
   void CPUKeyValues(std::ostream &OS);
+  void SubtargetEmitter::ParseFeaturesFunction(std::ostream &OS);
   
 public:
   SubtargetEmitter(RecordKeeper &R) : Records(R) {}