[llvm-commits] [llvm] r45633 - in /llvm/trunk/utils/TableGen: CodeGenDAGPatterns.h DAGISelEmitter.cpp DAGISelEmitter.h

Chris Lattner sabre at nondot.org
Sat Jan 5 14:30:18 PST 2008


Author: lattner
Date: Sat Jan  5 16:30:17 2008
New Revision: 45633

URL: http://llvm.org/viewvc/llvm-project?rev=45633&view=rev
Log:
fix a fixme by improving const correctness.

Modified:
    llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h
    llvm/trunk/utils/TableGen/DAGISelEmitter.cpp
    llvm/trunk/utils/TableGen/DAGISelEmitter.h

Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h?rev=45633&r1=45632&r2=45633&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h Sat Jan  5 16:30:17 2008
@@ -507,10 +507,9 @@
   pf_iterator pf_end() const { return PatternFragments.end(); }
 
   // Patterns to match information.
-  // FIXME: make a const_iterator.
-  typedef std::vector<PatternToMatch>::iterator ptm_iterator;
-  ptm_iterator ptm_begin() { return PatternsToMatch.begin(); }
-  ptm_iterator ptm_end() { return PatternsToMatch.end(); }
+  typedef std::vector<PatternToMatch>::const_iterator ptm_iterator;
+  ptm_iterator ptm_begin() const { return PatternsToMatch.begin(); }
+  ptm_iterator ptm_end() const { return PatternsToMatch.end(); }
   
   
   

Modified: llvm/trunk/utils/TableGen/DAGISelEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelEmitter.cpp?rev=45633&r1=45632&r2=45633&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/DAGISelEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/DAGISelEmitter.cpp Sat Jan  5 16:30:17 2008
@@ -139,8 +139,8 @@
   PatternSortingPredicate(CodegenDAGPatterns &cgp) : CGP(cgp) {}
   CodegenDAGPatterns &CGP;
 
-  bool operator()(PatternToMatch *LHS,
-                  PatternToMatch *RHS) {
+  bool operator()(const PatternToMatch *LHS,
+                  const PatternToMatch *RHS) {
     unsigned LHSSize = getPatternSize(LHS->getSrcPattern(), CGP);
     unsigned RHSSize = getPatternSize(RHS->getSrcPattern(), CGP);
     LHSSize += LHS->getAddedComplexity();
@@ -1194,7 +1194,7 @@
 /// EmitCodeForPattern - Given a pattern to match, emit code to the specified
 /// stream to match the pattern, and generate the code for the match if it
 /// succeeds.  Returns true if the pattern is not guaranteed to match.
-void DAGISelEmitter::GenerateCodeForPattern(PatternToMatch &Pattern,
+void DAGISelEmitter::GenerateCodeForPattern(const PatternToMatch &Pattern,
                   std::vector<std::pair<unsigned, std::string> > &GeneratedCode,
                                            std::set<std::string> &GeneratedDecl,
                                         std::vector<std::string> &TargetOpcodes,
@@ -1252,7 +1252,7 @@
 /// EraseCodeLine - Erase one code line from all of the patterns.  If removing
 /// a line causes any of them to be empty, remove them and return true when
 /// done.
-static bool EraseCodeLine(std::vector<std::pair<PatternToMatch*, 
+static bool EraseCodeLine(std::vector<std::pair<const PatternToMatch*, 
                           std::vector<std::pair<unsigned, std::string> > > >
                           &Patterns) {
   bool ErasedPatterns = false;
@@ -1269,13 +1269,13 @@
 
 /// EmitPatterns - Emit code for at least one pattern, but try to group common
 /// code together between the patterns.
-void DAGISelEmitter::EmitPatterns(std::vector<std::pair<PatternToMatch*, 
+void DAGISelEmitter::EmitPatterns(std::vector<std::pair<const PatternToMatch*, 
                               std::vector<std::pair<unsigned, std::string> > > >
                                   &Patterns, unsigned Indent,
                                   std::ostream &OS) {
   typedef std::pair<unsigned, std::string> CodeLine;
   typedef std::vector<CodeLine> CodeList;
-  typedef std::vector<std::pair<PatternToMatch*, CodeList> > PatternList;
+  typedef std::vector<std::pair<const PatternToMatch*, CodeList> > PatternList;
   
   if (Patterns.empty()) return;
   
@@ -1295,7 +1295,7 @@
     
     // FIXME: Emit braces?
     if (Shared.size() == 1) {
-      PatternToMatch &Pattern = *Shared.back().first;
+      const PatternToMatch &Pattern = *Shared.back().first;
       OS << "\n" << std::string(Indent, ' ') << "// Pattern: ";
       Pattern.getSrcPattern()->print(OS);
       OS << "\n" << std::string(Indent, ' ') << "// Emits: ";
@@ -1320,7 +1320,7 @@
     }
     
     if (Other.size() == 1) {
-      PatternToMatch &Pattern = *Other.back().first;
+      const PatternToMatch &Pattern = *Other.back().first;
       OS << "\n" << std::string(Indent, ' ') << "// Pattern: ";
       Pattern.getSrcPattern()->print(OS);
       OS << "\n" << std::string(Indent, ' ') << "// Emits: ";
@@ -1408,12 +1408,12 @@
   if (!InstNS.empty()) InstNS += "::";
   
   // Group the patterns by their top-level opcodes.
-  std::map<std::string, std::vector<PatternToMatch*> > PatternsByOpcode;
+  std::map<std::string, std::vector<const PatternToMatch*> > PatternsByOpcode;
   // All unique target node emission functions.
   std::map<std::string, unsigned> EmitFunctions;
   for (CodegenDAGPatterns::ptm_iterator I = CGP->ptm_begin(),
        E = CGP->ptm_end(); I != E; ++I) {
-    PatternToMatch &Pattern = *I;
+    const PatternToMatch &Pattern = *I;
 
     TreePatternNode *Node = Pattern.getSrcPattern();
     if (!Node->isLeaf()) {
@@ -1449,11 +1449,11 @@
   // Emit one Select_* method for each top-level opcode.  We do this instead of
   // emitting one giant switch statement to support compilers where this will
   // result in the recursive functions taking less stack space.
-  for (std::map<std::string, std::vector<PatternToMatch*> >::iterator
+  for (std::map<std::string, std::vector<const PatternToMatch*> >::iterator
          PBOI = PatternsByOpcode.begin(), E = PatternsByOpcode.end();
        PBOI != E; ++PBOI) {
     const std::string &OpName = PBOI->first;
-    std::vector<PatternToMatch*> &PatternsOfOp = PBOI->second;
+    std::vector<const PatternToMatch*> &PatternsOfOp = PBOI->second;
     assert(!PatternsOfOp.empty() && "No patterns but map has entry?");
 
     // We want to emit all of the matching code now.  However, we want to emit
@@ -1463,31 +1463,32 @@
                      PatternSortingPredicate(*CGP));
 
     // Split them into groups by type.
-    std::map<MVT::ValueType, std::vector<PatternToMatch*> > PatternsByType;
+    std::map<MVT::ValueType, std::vector<const PatternToMatch*> >PatternsByType;
     for (unsigned i = 0, e = PatternsOfOp.size(); i != e; ++i) {
-      PatternToMatch *Pat = PatternsOfOp[i];
+      const PatternToMatch *Pat = PatternsOfOp[i];
       TreePatternNode *SrcPat = Pat->getSrcPattern();
       MVT::ValueType VT = SrcPat->getTypeNum(0);
-      std::map<MVT::ValueType, std::vector<PatternToMatch*> >::iterator TI = 
+      std::map<MVT::ValueType, 
+               std::vector<const PatternToMatch*> >::iterator TI = 
         PatternsByType.find(VT);
       if (TI != PatternsByType.end())
         TI->second.push_back(Pat);
       else {
-        std::vector<PatternToMatch*> PVec;
+        std::vector<const PatternToMatch*> PVec;
         PVec.push_back(Pat);
         PatternsByType.insert(std::make_pair(VT, PVec));
       }
     }
 
-    for (std::map<MVT::ValueType, std::vector<PatternToMatch*> >::iterator
+    for (std::map<MVT::ValueType, std::vector<const PatternToMatch*> >::iterator
            II = PatternsByType.begin(), EE = PatternsByType.end(); II != EE;
          ++II) {
       MVT::ValueType OpVT = II->first;
-      std::vector<PatternToMatch*> &Patterns = II->second;
+      std::vector<const PatternToMatch*> &Patterns = II->second;
       typedef std::vector<std::pair<unsigned,std::string> > CodeList;
       typedef std::vector<std::pair<unsigned,std::string> >::iterator CodeListI;
     
-      std::vector<std::pair<PatternToMatch*, CodeList> > CodeForPatterns;
+      std::vector<std::pair<const PatternToMatch*, CodeList> > CodeForPatterns;
       std::vector<std::vector<std::string> > PatternOpcodes;
       std::vector<std::vector<std::string> > PatternVTs;
       std::vector<std::set<std::string> > PatternDecls;
@@ -1757,7 +1758,7 @@
     
   // Loop over all of the case statements, emiting a call to each method we
   // emitted above.
-  for (std::map<std::string, std::vector<PatternToMatch*> >::iterator
+  for (std::map<std::string, std::vector<const PatternToMatch*> >::iterator
          PBOI = PatternsByOpcode.begin(), E = PatternsByOpcode.end();
        PBOI != E; ++PBOI) {
     const std::string &OpName = PBOI->first;

Modified: llvm/trunk/utils/TableGen/DAGISelEmitter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelEmitter.h?rev=45633&r1=45632&r2=45633&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/DAGISelEmitter.h (original)
+++ llvm/trunk/utils/TableGen/DAGISelEmitter.h Sat Jan  5 16:30:17 2008
@@ -33,12 +33,12 @@
   
   
 private:
-  void GenerateCodeForPattern(PatternToMatch &Pattern,
+  void GenerateCodeForPattern(const PatternToMatch &Pattern,
                   std::vector<std::pair<unsigned, std::string> > &GeneratedCode,
                               std::set<std::string> &GeneratedDecl,
                               std::vector<std::string> &TargetOpcodes,
                               std::vector<std::string> &TargetVTs);
-  void EmitPatterns(std::vector<std::pair<PatternToMatch*, 
+  void EmitPatterns(std::vector<std::pair<const PatternToMatch*, 
                   std::vector<std::pair<unsigned, std::string> > > > &Patterns, 
                     unsigned Indent, std::ostream &OS);
   void EmitInstructionSelector(std::ostream &OS);





More information about the llvm-commits mailing list