make inst_begin/inst_end iterate over InstructionsByEnumValue.
authorChris Lattner <sabre@nondot.org>
Fri, 19 Mar 2010 00:40:22 +0000 (00:40 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 19 Mar 2010 00:40:22 +0000 (00:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98912 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/AsmWriterEmitter.cpp
utils/TableGen/CodeGenTarget.cpp
utils/TableGen/CodeGenTarget.h
utils/TableGen/InstrEnumEmitter.cpp
utils/TableGen/InstrInfoEmitter.cpp

index 9378343cec78843c5ab575faea7012f43ca92f26..ab1e239a95f25ea14146a3e8463985e836440c71 100644 (file)
@@ -254,10 +254,10 @@ void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) {
 
   for (CodeGenTarget::inst_iterator I = Target.inst_begin(),
          E = Target.inst_end(); I != E; ++I)
-    if (!I->second.AsmString.empty() &&
-        I->second.TheDef->getName() != "PHI")
+    if (!(*I)->AsmString.empty() &&
+        (*I)->TheDef->getName() != "PHI")
       Instructions.push_back(
-        AsmWriterInst(I->second
+        AsmWriterInst(**I
                       AsmWriter->getValueAsInt("Variant"),
                       AsmWriter->getValueAsInt("FirstOperandColumn"),
                       AsmWriter->getValueAsInt("OperandSpacing")));
index 36a9d1ef923190ee50b2fe82c2ae8217ab1a75b8..0dbc70cf90a493cef0475ece7d7fa723786ed506 100644 (file)
@@ -123,7 +123,7 @@ std::string CodeGenTarget::getInstNamespace() const {
   std::string InstNS;
 
   for (inst_iterator i = inst_begin(), e = inst_end(); i != e; ++i) {
-    InstNS = i->second.Namespace;
+    InstNS = (*i)->Namespace;
 
     // Make sure not to pick up "TargetInstrInfo" by accidentally getting
     // the namespace off the PHI instruction or something.
@@ -300,7 +300,7 @@ GetInstByName(const char *Name,
 
 /// getInstructionsByEnumValue - Return all of the instructions defined by the
 /// target, ordered by their enum value.
-void CodeGenTarget::ComputeInstrsByEnum() {
+void CodeGenTarget::ComputeInstrsByEnum() const {
   const std::map<std::string, CodeGenInstruction> &Insts = getInstructions();
   const CodeGenInstruction *PHI = GetInstByName("PHI", Insts);
   const CodeGenInstruction *INLINEASM = GetInstByName("INLINEASM", Insts);
@@ -333,19 +333,19 @@ void CodeGenTarget::ComputeInstrsByEnum() {
   InstrsByEnum.push_back(COPY_TO_REGCLASS);
   InstrsByEnum.push_back(DBG_VALUE);
   for (inst_iterator II = inst_begin(), E = inst_end(); II != E; ++II)
-    if (&II->second != PHI &&
-        &II->second != INLINEASM &&
-        &II->second != DBG_LABEL &&
-        &II->second != EH_LABEL &&
-        &II->second != GC_LABEL &&
-        &II->second != KILL &&
-        &II->second != EXTRACT_SUBREG &&
-        &II->second != INSERT_SUBREG &&
-        &II->second != IMPLICIT_DEF &&
-        &II->second != SUBREG_TO_REG &&
-        &II->second != COPY_TO_REGCLASS &&
-        &II->second != DBG_VALUE)
-      InstrsByEnum.push_back(&II->second);
+    if (*II != PHI &&
+        *II != INLINEASM &&
+        *II != DBG_LABEL &&
+        *II != EH_LABEL &&
+        *II != GC_LABEL &&
+        *II != KILL &&
+        *II != EXTRACT_SUBREG &&
+        *II != INSERT_SUBREG &&
+        *II != IMPLICIT_DEF &&
+        *II != SUBREG_TO_REG &&
+        *II != COPY_TO_REGCLASS &&
+        *II != DBG_VALUE)
+      InstrsByEnum.push_back(*II);
 }
 
 
index ac6574d69abd4c56373e3d75ca08a817421f82f2..a0e631e1093faa52a0dfdb5b0ad34eb7b18a432d 100644 (file)
@@ -71,7 +71,7 @@ class CodeGenTarget {
   void ReadInstructions() const;
   void ReadLegalValueTypes() const;
   
-  std::vector<const CodeGenInstruction*> InstrsByEnum;
+  mutable std::vector<const CodeGenInstruction*> InstrsByEnum;
 public:
   CodeGenTarget();
 
@@ -205,25 +205,25 @@ public:
   
   CodeGenInstruction &getInstruction(const Record *InstRec) const;  
 
-  typedef std::map<std::string,
-                   CodeGenInstruction>::const_iterator inst_iterator;
-  inst_iterator inst_begin() const { return getInstructions().begin(); }
-  inst_iterator inst_end() const { return Instructions.end(); }
-
   /// getInstructionsByEnumValue - Return all of the instructions defined by the
   /// target, ordered by their enum value.
-  const std::vector<const CodeGenInstruction*> &getInstructionsByEnumValue() {
+  const std::vector<const CodeGenInstruction*> &
+  getInstructionsByEnumValue() const {
     if (InstrsByEnum.empty()) ComputeInstrsByEnum();
     return InstrsByEnum;
   }
 
-
+  typedef std::vector<const CodeGenInstruction*>::const_iterator inst_iterator;
+  inst_iterator inst_begin() const{return getInstructionsByEnumValue().begin();}
+  inst_iterator inst_end() const { return getInstructionsByEnumValue().end(); }
+  
+  
   /// isLittleEndianEncoding - are instruction bit patterns defined as  [0..n]?
   ///
   bool isLittleEndianEncoding() const;
   
 private:
-  void ComputeInstrsByEnum();
+  void ComputeInstrsByEnum() const;
 };
 
 /// ComplexPattern - ComplexPattern info, corresponding to the ComplexPattern
index 4162107bce99d6ce3266e21afbee8370463becd4..06c95f27b65e69206cea46a988cb88e2a995bba4 100644 (file)
@@ -29,8 +29,8 @@ void InstrEnumEmitter::run(raw_ostream &OS) {
   std::string Namespace;
   for (CodeGenTarget::inst_iterator II = Target.inst_begin(), 
        E = Target.inst_end(); II != E; ++II) {
-    if (II->second.Namespace != "TargetOpcode") {
-      Namespace = II->second.Namespace;
+    if ((*II)->Namespace != "TargetOpcode") {
+      Namespace = (*II)->Namespace;
       break;
     }
   }
index 83602bb65c477fb9fb269bf875063db1d48aaf89..72c4e73ca1b7e69961924bbd0cb08f26e0898ad6 100644 (file)
@@ -149,7 +149,7 @@ void InstrInfoEmitter::EmitOperandInfo(raw_ostream &OS,
   const CodeGenTarget &Target = CDP.getTargetInfo();
   for (CodeGenTarget::inst_iterator II = Target.inst_begin(),
        E = Target.inst_end(); II != E; ++II) {
-    std::vector<std::string> OperandInfo = GetOperandInfo(II->second);
+    std::vector<std::string> OperandInfo = GetOperandInfo(**II);
     unsigned &N = OperandInfoIDs[OperandInfo];
     if (N != 0) continue;
     
@@ -214,7 +214,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
   // Emit all of the instruction's implicit uses and defs.
   for (CodeGenTarget::inst_iterator II = Target.inst_begin(),
          E = Target.inst_end(); II != E; ++II) {
-    Record *Inst = II->second.TheDef;
+    Record *Inst = (*II)->TheDef;
     std::vector<Record*> Uses = Inst->getValueAsListOfDefs("Uses");
     if (!Uses.empty()) {
       unsigned &IL = EmittedLists[Uses];