[llvm-branch-commits] [llvm-branch] r119208 - /llvm/branches/Apple/whitney/utils/TableGen/AsmMatcherEmitter.cpp

Daniel Dunbar daniel at zuster.org
Mon Nov 15 13:43:40 PST 2010


Author: ddunbar
Date: Mon Nov 15 15:43:40 2010
New Revision: 119208

URL: http://llvm.org/viewvc/llvm-project?rev=119208&view=rev
Log:
Merge r117844:
--
Author: Chris Lattner <clattner at apple.com>
Date:   Sat Oct 30 20:07:57 2010 +0000

    simplify code that creates SubtargetFeatureInfo, ensuring that features
    that are only used by MnemonicAliases will be found.

Modified:
    llvm/branches/Apple/whitney/utils/TableGen/AsmMatcherEmitter.cpp

Modified: llvm/branches/Apple/whitney/utils/TableGen/AsmMatcherEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/utils/TableGen/AsmMatcherEmitter.cpp?rev=119208&r1=119207&r2=119208&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/utils/TableGen/AsmMatcherEmitter.cpp (original)
+++ llvm/branches/Apple/whitney/utils/TableGen/AsmMatcherEmitter.cpp Mon Nov 15 15:43:40 2010
@@ -535,8 +535,12 @@
   /// \brief An unique index assigned to represent this feature.
   unsigned Index;
 
+  SubtargetFeatureInfo(Record *D, unsigned Idx) : TheDef(D), Index(Idx) {}
+  
   /// \brief The name of the enumerated constant identifying this feature.
-  std::string EnumName;
+  std::string getEnumName() const {
+    return "Feature_" + TheDef->getName();
+  }
 };
 
 class AsmMatcherInfo {
@@ -584,17 +588,7 @@
   /// given operand.
   SubtargetFeatureInfo *getSubtargetFeature(Record *Def) {
     assert(Def->isSubClassOf("Predicate") && "Invalid predicate type!");
-
-    SubtargetFeatureInfo *&Entry = SubtargetFeatures[Def];
-    if (!Entry) {
-      Entry = new SubtargetFeatureInfo();
-      Entry->TheDef = Def;
-      Entry->Index = SubtargetFeatures.size() - 1;
-      Entry->EnumName = "Feature_" + Def->getName();
-      assert(Entry->Index < 32 && "Too many subtarget features!");
-    }
-
-    return Entry;
+    return SubtargetFeatures[Def];
   }
 
   /// BuildRegisterClasses - Build the ClassInfo* instances for register
@@ -900,8 +894,8 @@
   }
 }
 
-AsmMatcherInfo::AsmMatcherInfo(Record *_AsmParser)
-  : AsmParser(_AsmParser),
+AsmMatcherInfo::AsmMatcherInfo(Record *asmParser)
+  : AsmParser(asmParser),
     CommentDelimiter(AsmParser->getValueAsString("CommentDelimiter")),
     RegisterPrefix(AsmParser->getValueAsString("RegisterPrefix"))
 {
@@ -914,6 +908,26 @@
 
   const std::vector<const CodeGenInstruction*> &InstrList =
     Target.getInstructionsByEnumValue();
+  
+  
+  // Build information about all of the AssemblerPredicates.
+  std::vector<Record*> AllPredicates =
+    Records.getAllDerivedDefinitions("Predicate");
+  for (unsigned i = 0, e = AllPredicates.size(); i != e; ++i) {
+    Record *Pred = AllPredicates[i];
+    // Ignore predicates that are not intended for the assembler.
+    if (!Pred->getValueAsBit("AssemblerMatcherPredicate"))
+      continue;
+    
+    if (Pred->getName().empty()) {
+      PrintError(Pred->getLoc(), "Predicate has no name!");
+      throw std::string("ERROR: Predicate defs must be named");
+    }
+    
+    unsigned FeatureNo = SubtargetFeatures.size();
+    SubtargetFeatures[Pred] = new SubtargetFeatureInfo(Pred, FeatureNo);
+    assert(FeatureNo < 32 && "Too many subtarget features!");
+  }
 
   for (unsigned i = 0, e = InstrList.size(); i != e; ++i) {
     const CodeGenInstruction &CGI = *InstrList[i];
@@ -1472,7 +1486,7 @@
          it = Info.SubtargetFeatures.begin(),
          ie = Info.SubtargetFeatures.end(); it != ie; ++it) {
     SubtargetFeatureInfo &SFI = *it->second;
-    OS << "  " << SFI.EnumName << " = (1 << " << SFI.Index << "),\n";
+    OS << "  " << SFI.getEnumName() << " = (1 << " << SFI.Index << "),\n";
   }
   OS << "  Feature_None = 0\n";
   OS << "};\n\n";
@@ -1496,7 +1510,7 @@
     SubtargetFeatureInfo &SFI = *it->second;
     OS << "  if (" << SFI.TheDef->getValueAsString("CondString")
        << ")\n";
-    OS << "    Features |= " << SFI.EnumName << ";\n";
+    OS << "    Features |= " << SFI.getEnumName() << ";\n";
   }
   OS << "  return Features;\n";
   OS << "}\n\n";
@@ -1529,7 +1543,7 @@
 
 /// EmitMnemonicAliases - If the target has any MnemonicAlias<> definitions,
 /// emit a function for them and return true, otherwise return false.
-static bool EmitMnemonicAliases(raw_ostream &OS) {
+static bool EmitMnemonicAliases(raw_ostream &OS, const AsmMatcherInfo &Info) {
   std::vector<Record*> Aliases =
     Records.getAllDerivedDefinitions("MnemonicAlias");
   if (Aliases.empty()) return false;
@@ -1688,7 +1702,7 @@
   OS << "#undef GET_MATCHER_IMPLEMENTATION\n\n";
 
   // Generate the function that remaps for mnemonic aliases.
-  bool HasMnemonicAliases = EmitMnemonicAliases(OS);
+  bool HasMnemonicAliases = EmitMnemonicAliases(OS, Info);
   
   // Generate the unified function to convert operands into an MCInst.
   EmitConvertToMCInst(Target, Info.Instructions, OS);
@@ -1773,7 +1787,7 @@
     if (!II.RequiredFeatures.empty()) {
       for (unsigned i = 0, e = II.RequiredFeatures.size(); i != e; ++i) {
         if (i) OS << "|";
-        OS << II.RequiredFeatures[i]->EnumName;
+        OS << II.RequiredFeatures[i]->getEnumName();
       }
     } else
       OS << "0";





More information about the llvm-branch-commits mailing list