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

Daniel Dunbar daniel at zuster.org
Mon Nov 15 13:44:51 PST 2010


Author: ddunbar
Date: Mon Nov 15 15:44:51 2010
New Revision: 119231

URL: http://llvm.org/viewvc/llvm-project?rev=119231&view=rev
Log:
Merge r117898:
--
Author: Chris Lattner <clattner at apple.com>
Date:   Mon Nov 1 04:53:48 2010 +0000

    refactor initialization of InstructionInfo to be sharable between
    instructions and InstAliases.  Start creating InstructionInfo's
    for Aliases.

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=119231&r1=119230&r2=119231&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/utils/TableGen/AsmMatcherEmitter.cpp (original)
+++ llvm/branches/Apple/whitney/utils/TableGen/AsmMatcherEmitter.cpp Mon Nov 15 15:44:51 2010
@@ -356,14 +356,18 @@
   std::string ConversionFnKind;
   
   InstructionInfo(const CodeGenInstruction &CGI)
-    : TheDef(CGI.TheDef), OperandList(CGI.Operands) {
-    InstrName = TheDef->getName();
-    // TODO: Eventually support asmparser for Variant != 0.
-    AsmString = CGI.FlattenAsmStringVariants(CGI.AsmString, 0);
-    
-    TokenizeAsmString(AsmString, Tokens);
+    : TheDef(CGI.TheDef), OperandList(CGI.Operands), AsmString(CGI.AsmString) {
   }
 
+  InstructionInfo(const CodeGenInstAlias *Alias)
+    : TheDef(Alias->TheDef), OperandList(Alias->Operands),
+      AsmString(Alias->AsmString) {
+    
+  }
+  
+  void Initialize(const AsmMatcherInfo &Info,
+                  SmallPtrSet<Record*, 16> &SingletonRegisters);
+  
   /// isAssemblerInstruction - Return true if this matchable is a valid thing to
   /// match against.
   bool isAssemblerInstruction(StringRef CommentDelimiter) const;
@@ -545,6 +549,30 @@
   }
 }
 
+void InstructionInfo::Initialize(const AsmMatcherInfo &Info,
+                                 SmallPtrSet<Record*, 16> &SingletonRegisters) {
+  InstrName = TheDef->getName();
+  
+  // TODO: Eventually support asmparser for Variant != 0.
+  AsmString = CodeGenInstruction::FlattenAsmStringVariants(AsmString, 0);
+  
+  TokenizeAsmString(AsmString, Tokens);
+  
+  // Compute the require features.
+  std::vector<Record*> Predicates =TheDef->getValueAsListOfDefs("Predicates");
+  for (unsigned i = 0, e = Predicates.size(); i != e; ++i)
+    if (SubtargetFeatureInfo *Feature =
+        Info.getSubtargetFeature(Predicates[i]))
+      RequiredFeatures.push_back(Feature);
+  
+  // Collect singleton registers, if used.
+  for (unsigned i = 0, e = Tokens.size(); i != e; ++i) {
+    if (Record *Reg = getSingletonRegisterForToken(i, Info))
+      SingletonRegisters.insert(Reg);
+  }
+}
+
+
 /// getRegisterRecord - Get the register record for \arg name, or 0.
 static Record *getRegisterRecord(CodeGenTarget &Target, StringRef Name) {
   for (unsigned i = 0, e = Target.getRegisters().size(); i != e; ++i) {
@@ -557,8 +585,6 @@
 }
 
 bool InstructionInfo::isAssemblerInstruction(StringRef CommentDelimiter) const {
-  StringRef Name = InstrName;
-  
   // Reject instructions with no .s string.
   if (AsmString.empty())
     throw TGError(TheDef->getLoc(), "instruction with empty asm string");
@@ -594,7 +620,7 @@
     // bunch of instructions.  It is unclear what the right answer is for this.
     if (Tokens[i][0] == '$' && !OperandNames.insert(Tokens[i]).second) {
       DEBUG({
-        errs() << "warning: '" << Name << "': "
+        errs() << "warning: '" << InstrName << "': "
         << "ignoring instruction with tied operand '"
         << Tokens[i].str() << "'\n";
       });
@@ -869,10 +895,10 @@
 
 AsmMatcherInfo::AsmMatcherInfo(Record *asmParser, CodeGenTarget &target)
   : AsmParser(asmParser), Target(target),
-    RegisterPrefix(AsmParser->getValueAsString("RegisterPrefix"))
-{
+    RegisterPrefix(AsmParser->getValueAsString("RegisterPrefix")) {
 }
 
+
 void AsmMatcherInfo::BuildInfo() {
   // Build information about all of the AssemblerPredicates.
   std::vector<Record*> AllPredicates =
@@ -911,6 +937,8 @@
     
     OwningPtr<InstructionInfo> II(new InstructionInfo(CGI));
 
+    II->Initialize(*this, SingletonRegisters);
+    
     // Ignore instructions which shouldn't be matched and diagnose invalid
     // instruction definitions with an error.
     if (!II->isAssemblerInstruction(CommentDelimiter))
@@ -923,30 +951,21 @@
         StringRef(II->InstrName).endswith("_Int"))
       continue;
     
-    // Collect singleton registers, if used.
-    for (unsigned i = 0, e = II->Tokens.size(); i != e; ++i) {
-      if (Record *Reg = II->getSingletonRegisterForToken(i, *this))
-        SingletonRegisters.insert(Reg);
-    }
-
-    // Compute the require features.
-    std::vector<Record*> Predicates =
-      CGI.TheDef->getValueAsListOfDefs("Predicates");
-    for (unsigned i = 0, e = Predicates.size(); i != e; ++i)
-      if (SubtargetFeatureInfo *Feature = getSubtargetFeature(Predicates[i]))
-        II->RequiredFeatures.push_back(Feature);
-
-    Instructions.push_back(II.take());
+     Instructions.push_back(II.take());
   }
   
-  // Parse all of the InstAlias definitions.
+  // Parse all of the InstAlias definitions and stick them in the list of
+  // matchables.
   std::vector<Record*> AllInstAliases =
     Records.getAllDerivedDefinitions("InstAlias");
   for (unsigned i = 0, e = AllInstAliases.size(); i != e; ++i) {
     CodeGenInstAlias *Alias = new CodeGenInstAlias(AllInstAliases[i]);
 
+    OwningPtr<InstructionInfo> II(new InstructionInfo(Alias));
+    
+    II->Initialize(*this, SingletonRegisters);
     
-    (void)Alias;
+    //Instructions.push_back(II.take());
   }
 
   // Build info for the register classes.





More information about the llvm-branch-commits mailing list