From 60d8139d1b1db8b23c066623d65302dd3dcc4572 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 5 Jan 2008 22:30:17 +0000 Subject: [PATCH] fix a fixme by improving const correctness. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45633 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/CodeGenDAGPatterns.h | 7 +++-- utils/TableGen/DAGISelEmitter.cpp | 41 +++++++++++++++-------------- utils/TableGen/DAGISelEmitter.h | 4 +-- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/utils/TableGen/CodeGenDAGPatterns.h b/utils/TableGen/CodeGenDAGPatterns.h index 6a1be8cdc2a..d386963810c 100644 --- a/utils/TableGen/CodeGenDAGPatterns.h +++ b/utils/TableGen/CodeGenDAGPatterns.h @@ -507,10 +507,9 @@ public: pf_iterator pf_end() const { return PatternFragments.end(); } // Patterns to match information. - // FIXME: make a const_iterator. - typedef std::vector::iterator ptm_iterator; - ptm_iterator ptm_begin() { return PatternsToMatch.begin(); } - ptm_iterator ptm_end() { return PatternsToMatch.end(); } + typedef std::vector::const_iterator ptm_iterator; + ptm_iterator ptm_begin() const { return PatternsToMatch.begin(); } + ptm_iterator ptm_end() const { return PatternsToMatch.end(); } diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp index 830d0efc37f..8632bc5ce8d 100644 --- a/utils/TableGen/DAGISelEmitter.cpp +++ b/utils/TableGen/DAGISelEmitter.cpp @@ -139,8 +139,8 @@ struct PatternSortingPredicate { 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 @@ private: /// 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 > &GeneratedCode, std::set &GeneratedDecl, std::vector &TargetOpcodes, @@ -1252,7 +1252,7 @@ void DAGISelEmitter::GenerateCodeForPattern(PatternToMatch &Pattern, /// 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 > > > &Patterns) { bool ErasedPatterns = false; @@ -1269,13 +1269,13 @@ static bool EraseCodeLine(std::vector > > > &Patterns, unsigned Indent, std::ostream &OS) { typedef std::pair CodeLine; typedef std::vector CodeList; - typedef std::vector > PatternList; + typedef std::vector > PatternList; if (Patterns.empty()) return; @@ -1295,7 +1295,7 @@ void DAGISelEmitter::EmitPatterns(std::vectorprint(OS); OS << "\n" << std::string(Indent, ' ') << "// Emits: "; @@ -1320,7 +1320,7 @@ void DAGISelEmitter::EmitPatterns(std::vectorprint(OS); OS << "\n" << std::string(Indent, ' ') << "// Emits: "; @@ -1408,12 +1408,12 @@ void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) { if (!InstNS.empty()) InstNS += "::"; // Group the patterns by their top-level opcodes. - std::map > PatternsByOpcode; + std::map > PatternsByOpcode; // All unique target node emission functions. std::map 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 @@ void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) { // 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 >::iterator + for (std::map >::iterator PBOI = PatternsByOpcode.begin(), E = PatternsByOpcode.end(); PBOI != E; ++PBOI) { const std::string &OpName = PBOI->first; - std::vector &PatternsOfOp = PBOI->second; + std::vector &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 @@ void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) { PatternSortingPredicate(*CGP)); // Split them into groups by type. - std::map > PatternsByType; + std::map >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 >::iterator TI = + std::map >::iterator TI = PatternsByType.find(VT); if (TI != PatternsByType.end()) TI->second.push_back(Pat); else { - std::vector PVec; + std::vector PVec; PVec.push_back(Pat); PatternsByType.insert(std::make_pair(VT, PVec)); } } - for (std::map >::iterator + for (std::map >::iterator II = PatternsByType.begin(), EE = PatternsByType.end(); II != EE; ++II) { MVT::ValueType OpVT = II->first; - std::vector &Patterns = II->second; + std::vector &Patterns = II->second; typedef std::vector > CodeList; typedef std::vector >::iterator CodeListI; - std::vector > CodeForPatterns; + std::vector > CodeForPatterns; std::vector > PatternOpcodes; std::vector > PatternVTs; std::vector > PatternDecls; @@ -1757,7 +1758,7 @@ void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) { // Loop over all of the case statements, emiting a call to each method we // emitted above. - for (std::map >::iterator + for (std::map >::iterator PBOI = PatternsByOpcode.begin(), E = PatternsByOpcode.end(); PBOI != E; ++PBOI) { const std::string &OpName = PBOI->first; diff --git a/utils/TableGen/DAGISelEmitter.h b/utils/TableGen/DAGISelEmitter.h index 8fb5d6f2497..278af7812d7 100644 --- a/utils/TableGen/DAGISelEmitter.h +++ b/utils/TableGen/DAGISelEmitter.h @@ -33,12 +33,12 @@ public: private: - void GenerateCodeForPattern(PatternToMatch &Pattern, + void GenerateCodeForPattern(const PatternToMatch &Pattern, std::vector > &GeneratedCode, std::set &GeneratedDecl, std::vector &TargetOpcodes, std::vector &TargetVTs); - void EmitPatterns(std::vector > > > &Patterns, unsigned Indent, std::ostream &OS); void EmitInstructionSelector(std::ostream &OS); -- 2.34.1