[llvm-commits] [llvm] r118031 - in /llvm/trunk/utils/TableGen: AsmMatcherEmitter.cpp CodeGenTarget.cpp CodeGenTarget.h

Chris Lattner sabre at nondot.org
Tue Nov 2 11:10:06 PDT 2010


Author: lattner
Date: Tue Nov  2 13:10:06 2010
New Revision: 118031

URL: http://llvm.org/viewvc/llvm-project?rev=118031&view=rev
Log:
a bunch of random cleanup, move a helper to CGT where it belongs.

Modified:
    llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp
    llvm/trunk/utils/TableGen/CodeGenTarget.cpp
    llvm/trunk/utils/TableGen/CodeGenTarget.h

Modified: llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp?rev=118031&r1=118030&r2=118031&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp Tue Nov  2 13:10:06 2010
@@ -254,7 +254,9 @@
     /// The unique class instance this operand should match.
     ClassInfo *Class;
 
-    /// The original operand this corresponds to, if any.
+    /// The original operand this corresponds to.  This is unset for singleton
+    /// registers and tokens, because they don't have a list in the ins/outs
+    /// list.  If an operand is tied ($a=$b), this refers to source operand: $b.
     const CGIOperandList::OperandInfo *OperandInfo;
     
     explicit Operand(StringRef T) : Token(T), Class(0), OperandInfo(0) {}
@@ -601,17 +603,6 @@
 
 
 
-/// 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) {
-    const CodeGenRegister &Reg = Target.getRegisters()[i];
-    if (Name == Reg.TheDef->getValueAsString("AsmName"))
-      return Reg.TheDef;
-  }
-  
-  return 0;
-}
-
 bool MatchableInfo::Validate(StringRef CommentDelimiter, bool Hack) const {
   // Reject matchables with no .s string.
   if (AsmString.empty())
@@ -676,14 +667,16 @@
     return 0;
   
   StringRef RegName = Tok.substr(Info.RegisterPrefix.size());
-  if (Record *Rec = getRegisterRecord(Info.Target, RegName))
-    return Rec;
+  if (const CodeGenRegister *Reg = Info.Target.getRegisterByName(RegName))
+    return Reg->TheDef;
   
   // If there is no register prefix (i.e. "%" in "%eax"), then this may
   // be some random non-register token, just ignore it.
   if (Info.RegisterPrefix.empty())
     return 0;
     
+  // Otherwise, we have something invalid prefixed with the register prefix,
+  // such as %foo.
   std::string Err = "unable to find register for '" + RegName.str() +
   "' (which matches register prefix)";
   throw TGError(TheDef->getLoc(), Err);
@@ -730,38 +723,31 @@
 AsmMatcherInfo::getOperandClass(StringRef Token,
                                 const CGIOperandList::OperandInfo &OI) {
   if (OI.Rec->isSubClassOf("RegisterClass")) {
-    ClassInfo *CI = RegisterClassClasses[OI.Rec];
-
-    if (!CI)
-      throw TGError(OI.Rec->getLoc(), "register class has no class info!");
-
-    return CI;
+    if (ClassInfo *CI = RegisterClassClasses[OI.Rec])
+      return CI;
+    throw TGError(OI.Rec->getLoc(), "register class has no class info!");
   }
 
   assert(OI.Rec->isSubClassOf("Operand") && "Unexpected operand!");
   Record *MatchClass = OI.Rec->getValueAsDef("ParserMatchClass");
-  ClassInfo *CI = AsmOperandClasses[MatchClass];
-
-  if (!CI)
-    throw TGError(OI.Rec->getLoc(), "operand has no match class!");
+  if (ClassInfo *CI = AsmOperandClasses[MatchClass])
+    return CI;
 
-  return CI;
+  throw TGError(OI.Rec->getLoc(), "operand has no match class!");
 }
 
 void AsmMatcherInfo::
 BuildRegisterClasses(SmallPtrSet<Record*, 16> &SingletonRegisters) {
-  std::vector<CodeGenRegisterClass> RegisterClasses;
-  std::vector<CodeGenRegister> Registers;
-
-  RegisterClasses = Target.getRegisterClasses();
-  Registers = Target.getRegisters();
+  const std::vector<CodeGenRegister> &Registers = Target.getRegisters();
+  const std::vector<CodeGenRegisterClass> &RegClassList =
+    Target.getRegisterClasses();
 
   // The register sets used for matching.
   std::set< std::set<Record*> > RegisterSets;
 
   // Gather the defined sets.
-  for (std::vector<CodeGenRegisterClass>::iterator it = RegisterClasses.begin(),
-         ie = RegisterClasses.end(); it != ie; ++it)
+  for (std::vector<CodeGenRegisterClass>::const_iterator it =
+       RegClassList.begin(), ie = RegClassList.end(); it != ie; ++it)
     RegisterSets.insert(std::set<Record*>(it->Elements.begin(),
                                           it->Elements.end()));
 
@@ -776,9 +762,9 @@
   // a unique register set class), and build the mapping of registers to the set
   // they should classify to.
   std::map<Record*, std::set<Record*> > RegisterMap;
-  for (std::vector<CodeGenRegister>::iterator it = Registers.begin(),
+  for (std::vector<CodeGenRegister>::const_iterator it = Registers.begin(),
          ie = Registers.end(); it != ie; ++it) {
-    CodeGenRegister &CGR = *it;
+    const CodeGenRegister &CGR = *it;
     // Compute the intersection of all sets containing this register.
     std::set<Record*> ContainingSet;
 
@@ -789,14 +775,14 @@
 
       if (ContainingSet.empty()) {
         ContainingSet = *it;
-      } else {
-        std::set<Record*> Tmp;
-        std::swap(Tmp, ContainingSet);
-        std::insert_iterator< std::set<Record*> > II(ContainingSet,
-                                                     ContainingSet.begin());
-        std::set_intersection(Tmp.begin(), Tmp.end(), it->begin(), it->end(),
-                              II);
+        continue;
       }
+      
+      std::set<Record*> Tmp;
+      std::swap(Tmp, ContainingSet);
+      std::insert_iterator< std::set<Record*> > II(ContainingSet,
+                                                   ContainingSet.begin());
+      std::set_intersection(Tmp.begin(), Tmp.end(), it->begin(), it->end(), II);
     }
 
     if (!ContainingSet.empty()) {
@@ -835,8 +821,8 @@
   }
 
   // Name the register classes which correspond to a user defined RegisterClass.
-  for (std::vector<CodeGenRegisterClass>::iterator it = RegisterClasses.begin(),
-         ie = RegisterClasses.end(); it != ie; ++it) {
+  for (std::vector<CodeGenRegisterClass>::const_iterator
+       it = RegClassList.begin(), ie = RegClassList.end(); it != ie; ++it) {
     ClassInfo *CI = RegisterSetClasses[std::set<Record*>(it->Elements.begin(),
                                                          it->Elements.end())];
     if (CI->ValueName.empty()) {
@@ -852,13 +838,13 @@
   // Populate the map for individual registers.
   for (std::map<Record*, std::set<Record*> >::iterator it = RegisterMap.begin(),
          ie = RegisterMap.end(); it != ie; ++it)
-    this->RegisterClasses[it->first] = RegisterSetClasses[it->second];
+    RegisterClasses[it->first] = RegisterSetClasses[it->second];
 
   // Name the register classes which correspond to singleton registers.
   for (SmallPtrSet<Record*, 16>::iterator it = SingletonRegisters.begin(),
          ie = SingletonRegisters.end(); it != ie; ++it) {
     Record *Rec = *it;
-    ClassInfo *CI = this->RegisterClasses[Rec];
+    ClassInfo *CI = RegisterClasses[Rec];
     assert(CI && "Missing singleton register class info!");
 
     if (CI->ValueName.empty()) {
@@ -1135,9 +1121,9 @@
       const CGIOperandList::OperandInfo &OpInfo = II.OperandList[i];
       for (unsigned j = 0, e = OpInfo.Constraints.size(); j != e; ++j) {
         const CGIOperandList::ConstraintInfo &CI = OpInfo.Constraints[j];
-        if (CI.isTied())
-          TiedOperands.push_back(std::make_pair(OpInfo.MIOperandNo + j,
-                                                CI.getTiedOperand()));
+        if (!CI.isTied()) continue;
+        TiedOperands.push_back(std::make_pair(OpInfo.MIOperandNo,
+                                              CI.getTiedOperand()));
       }
     }
 
@@ -1147,8 +1133,7 @@
     unsigned NumMIOperands = 0;
     for (unsigned i = 0, e = II.OperandList.size(); i != e; ++i) {
       const CGIOperandList::OperandInfo &OI = II.OperandList[i];
-      NumMIOperands = std::max(NumMIOperands,
-                               OI.MIOperandNo + OI.MINumOperands);
+      NumMIOperands = std::max(NumMIOperands, OI.MIOperandNo+OI.MINumOperands);
     }
 
     // Build the conversion function signature.

Modified: llvm/trunk/utils/TableGen/CodeGenTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenTarget.cpp?rev=118031&r1=118030&r2=118031&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenTarget.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenTarget.cpp Tue Nov  2 13:10:06 2010
@@ -190,6 +190,19 @@
   RegisterClasses.assign(RegClasses.begin(), RegClasses.end());
 }
 
+/// getRegisterByName - If there is a register with the specific AsmName,
+/// return it.
+const CodeGenRegister *CodeGenTarget::getRegisterByName(StringRef Name) const {
+  const std::vector<CodeGenRegister> &Regs = getRegisters();
+  for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
+    const CodeGenRegister &Reg = Regs[i];
+    if (Reg.TheDef->getValueAsString("AsmName") == Name)
+      return &Reg;
+  }
+  
+  return 0;
+}
+
 std::vector<MVT::SimpleValueType> CodeGenTarget::
 getRegisterVTs(Record *R) const {
   std::vector<MVT::SimpleValueType> Result;

Modified: llvm/trunk/utils/TableGen/CodeGenTarget.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenTarget.h?rev=118031&r1=118030&r2=118031&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenTarget.h (original)
+++ llvm/trunk/utils/TableGen/CodeGenTarget.h Tue Nov  2 13:10:06 2010
@@ -101,6 +101,10 @@
     if (Registers.empty()) ReadRegisters();
     return Registers;
   }
+  
+  /// getRegisterByName - If there is a register with the specific AsmName,
+  /// return it.
+  const CodeGenRegister *getRegisterByName(StringRef Name) const;
 
   const std::vector<Record*> &getSubRegIndices() const {
     if (SubRegIndices.empty()) ReadSubRegIndices();





More information about the llvm-commits mailing list