From 6ffe551f657c948d6a473a198ecbd1188bf9ce45 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 27 Apr 2004 15:13:33 +0000 Subject: [PATCH] Changes to fix up the inst_iterator to pass to boost iterator checks. This patch was graciously contributed by Vladimir Prus. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13185 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/InstIterator.h | 33 ++++++++++--------- lib/Analysis/AliasAnalysisEvaluator.cpp | 8 ++--- lib/Analysis/AliasSetTracker.cpp | 2 +- lib/Analysis/IPA/FindUnsafePointerTypes.cpp | 6 ++-- lib/Analysis/IPA/FindUsedTypes.cpp | 6 ++-- lib/Analysis/ScalarEvolution.cpp | 12 +++---- lib/Bytecode/Writer/SlotCalculator.cpp | 4 +-- lib/Target/CBackend/CBackend.cpp | 10 +++--- lib/Target/CBackend/Writer.cpp | 10 +++--- lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp | 8 ++--- lib/Transforms/Scalar/ConstantProp.cpp | 5 ++- lib/Transforms/Scalar/DCE.cpp | 5 ++- .../Scalar/InstructionCombining.cpp | 5 ++- lib/VMCore/SlotCalculator.cpp | 4 +-- 14 files changed, 65 insertions(+), 53 deletions(-) diff --git a/include/llvm/Support/InstIterator.h b/include/llvm/Support/InstIterator.h index 31c8b660d67..cdb78e9042d 100644 --- a/include/llvm/Support/InstIterator.h +++ b/include/llvm/Support/InstIterator.h @@ -33,15 +33,18 @@ class InstIterator { typedef _BB_i_t BBIty; typedef _BI_t BIty; typedef _II_t IIty; - _BB_t &BBs; // BasicBlocksType + _BB_t *BBs; // BasicBlocksType _BB_i_t BB; // BasicBlocksType::iterator _BI_t BI; // BasicBlock::iterator public: typedef std::bidirectional_iterator_tag iterator_category; typedef IIty value_type; - typedef unsigned difference_type; - typedef BIty pointer; - typedef IIty reference; + typedef signed difference_type; + typedef IIty* pointer; + typedef IIty& reference; + + // Default constructor + InstIterator() {} // Copy constructor... template @@ -53,26 +56,26 @@ public: : BBs(II.BBs), BB(II.BB), BI(II.BI) {} template InstIterator(M &m) - : BBs(m.getBasicBlockList()), BB(BBs.begin()) { // begin ctor - if (BB != BBs.end()) { + : BBs(&m.getBasicBlockList()), BB(BBs->begin()) { // begin ctor + if (BB != BBs->end()) { BI = BB->begin(); advanceToNextBB(); } } template InstIterator(M &m, bool) - : BBs(m.getBasicBlockList()), BB(BBs.end()) { // end ctor + : BBs(&m.getBasicBlockList()), BB(BBs->end()) { // end ctor } // Accessors to get at the underlying iterators... inline BBIty &getBasicBlockIterator() { return BB; } inline BIty &getInstructionIterator() { return BI; } - inline IIty operator*() const { return BI; } - inline IIty operator->() const { return operator*(); } + inline reference operator*() const { return *BI; } + inline pointer operator->() const { return &operator*(); } inline bool operator==(const InstIterator &y) const { - return BB == y.BB && (BB == BBs.end() || BI == y.BI); + return BB == y.BB && (BB == BBs->end() || BI == y.BI); } inline bool operator!=(const InstIterator& y) const { return !operator==(y); @@ -88,7 +91,7 @@ public: } InstIterator& operator--() { - while (BB == BBs.end() || BI == BB->begin()) { + while (BB == BBs->end() || BI == BB->begin()) { --BB; BI = BB->end(); } @@ -99,7 +102,7 @@ public: InstIterator tmp = *this; --*this; return tmp; } - inline bool atEnd() const { return BB == BBs.end(); } + inline bool atEnd() const { return BB == BBs->end(); } private: inline void advanceToNextBB() { @@ -107,7 +110,7 @@ private: // the end() of the current BasicBlock and there are successor BBs. while (BI == BB->end()) { ++BB; - if (BB == BBs.end()) break; + if (BB == BBs->end()) break; BI = BB->begin(); } } @@ -116,11 +119,11 @@ private: typedef InstIterator, Function::iterator, BasicBlock::iterator, - Instruction*> inst_iterator; + Instruction> inst_iterator; typedef InstIterator, Function::const_iterator, BasicBlock::const_iterator, - const Instruction*> const_inst_iterator; + const Instruction> const_inst_iterator; inline inst_iterator inst_begin(Function *F) { return inst_iterator(*F); } inline inst_iterator inst_end(Function *F) { return inst_iterator(*F, true); } diff --git a/lib/Analysis/AliasAnalysisEvaluator.cpp b/lib/Analysis/AliasAnalysisEvaluator.cpp index 19d44dd9c85..ef7b5015f19 100644 --- a/lib/Analysis/AliasAnalysisEvaluator.cpp +++ b/lib/Analysis/AliasAnalysisEvaluator.cpp @@ -83,15 +83,15 @@ bool AAEval::runOnFunction(Function &F) { Pointers.insert(I); for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) { - if (isa((*I)->getType())) // Add all pointer instructions - Pointers.insert(*I); - for (User::op_iterator OI = (*I)->op_begin(); OI != (*I)->op_end(); ++OI) + if (isa(I->getType())) // Add all pointer instructions + Pointers.insert(&*I); + for (User::op_iterator OI = (*I).op_begin(); OI != (*I).op_end(); ++OI) if (isa((*OI)->getType())) Pointers.insert(*OI); } for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) { - CallSite CS = CallSite::get(*I); + CallSite CS = CallSite::get(&*I); if (CS.getInstruction()) CallSites.insert(CS); } diff --git a/lib/Analysis/AliasSetTracker.cpp b/lib/Analysis/AliasSetTracker.cpp index 303d7987b79..82b6edec935 100644 --- a/lib/Analysis/AliasSetTracker.cpp +++ b/lib/Analysis/AliasSetTracker.cpp @@ -366,7 +366,7 @@ namespace { Tracker = new AliasSetTracker(getAnalysis()); for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) - Tracker->add(*I); + Tracker->add(&*I); return false; } diff --git a/lib/Analysis/IPA/FindUnsafePointerTypes.cpp b/lib/Analysis/IPA/FindUnsafePointerTypes.cpp index 45f5b72ecf9..67ab52d8a8a 100644 --- a/lib/Analysis/IPA/FindUnsafePointerTypes.cpp +++ b/lib/Analysis/IPA/FindUnsafePointerTypes.cpp @@ -42,8 +42,8 @@ static cl::opt PrintFailures("printunsafeptrinst", cl::Hidden, cl::desc("Print Unsafe Pointer Access Instructions")); -static inline bool isSafeInstruction(const Instruction *I) { - switch (I->getOpcode()) { +static inline bool isSafeInstruction(const Instruction &I) { + switch (I.getOpcode()) { case Instruction::Alloca: case Instruction::Malloc: case Instruction::Free: @@ -72,7 +72,7 @@ bool FindUnsafePointerTypes::run(Module &Mod) { if (PrintFailures) { CachedWriter CW(F->getParent(), std::cerr); CW << "FindUnsafePointerTypes: Type '" << ITy - << "' marked unsafe in '" << F->getName() << "' by:\n" << **I; + << "' marked unsafe in '" << F->getName() << "' by:\n" << *I; } } } diff --git a/lib/Analysis/IPA/FindUsedTypes.cpp b/lib/Analysis/IPA/FindUsedTypes.cpp index e930499e2e2..870f5716a36 100644 --- a/lib/Analysis/IPA/FindUsedTypes.cpp +++ b/lib/Analysis/IPA/FindUsedTypes.cpp @@ -79,11 +79,11 @@ bool FindUsedTypes::run(Module &m) { // for (const_inst_iterator II = inst_begin(F), IE = inst_end(F); II != IE; ++II) { - const Instruction *I = *II; - const Type *Ty = I->getType(); + const Instruction &I = *II; + const Type *Ty = I.getType(); IncorporateType(Ty); // Incorporate the type of the instruction - for (User::const_op_iterator OI = I->op_begin(), OE = I->op_end(); + for (User::const_op_iterator OI = I.op_begin(), OE = I.op_end(); OI != OE; ++OI) IncorporateValue(*OI); // Insert inst operand types as well } diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 68cad3c0e23..ae3aa411f2b 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -2175,22 +2175,22 @@ void ScalarEvolution::print(std::ostream &OS) const { OS << "Classifying expressions for: " << F.getName() << "\n"; for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) - if ((*I)->getType()->isInteger()) { - OS << **I; + if (I->getType()->isInteger()) { + OS << *I; OS << " --> "; - SCEVHandle SV = getSCEV(*I); + SCEVHandle SV = getSCEV(&*I); SV->print(OS); OS << "\t\t"; - if ((*I)->getType()->isIntegral()) { + if ((*I).getType()->isIntegral()) { ConstantRange Bounds = SV->getValueRange(); if (!Bounds.isFullSet()) OS << "Bounds: " << Bounds << " "; } - if (const Loop *L = LI.getLoopFor((*I)->getParent())) { + if (const Loop *L = LI.getLoopFor((*I).getParent())) { OS << "Exits: "; - SCEVHandle ExitValue = getSCEVAtScope(*I, L->getParentLoop()); + SCEVHandle ExitValue = getSCEVAtScope(&*I, L->getParentLoop()); if (isa(ExitValue)) { OS << "<>"; } else { diff --git a/lib/Bytecode/Writer/SlotCalculator.cpp b/lib/Bytecode/Writer/SlotCalculator.cpp index d462bdd1e9f..35490532795 100644 --- a/lib/Bytecode/Writer/SlotCalculator.cpp +++ b/lib/Bytecode/Writer/SlotCalculator.cpp @@ -186,7 +186,7 @@ void SlotCalculator::processModule() { if (isa(I->getOperand(op))) getOrCreateSlot(I->getOperand(op)); getOrCreateSlot(I->getType()); - if (const VANextInst *VAN = dyn_cast(*I)) + if (const VANextInst *VAN = dyn_cast(&*I)) getOrCreateSlot(VAN->getArgType()); } processSymbolTableConstants(&F->getSymbolTable()); @@ -448,7 +448,7 @@ void SlotCalculator::buildCompactionTable(const Function *F) { if (isa(I->getOperand(op)) || isa(I->getOperand(op))) getOrCreateCompactionTableSlot(I->getOperand(op)); - if (const VANextInst *VAN = dyn_cast(*I)) + if (const VANextInst *VAN = dyn_cast(&*I)) getOrCreateCompactionTableSlot(VAN->getArgType()); } diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index 807f8ab92f1..09ee36c85bb 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -955,19 +955,19 @@ void CWriter::printFunction(Function &F) { // print local variable information for the function for (inst_iterator I = inst_begin(&F), E = inst_end(&F); I != E; ++I) - if (const AllocaInst *AI = isDirectAlloca(*I)) { + if (const AllocaInst *AI = isDirectAlloca(&*I)) { Out << " "; printType(Out, AI->getAllocatedType(), Mang->getValueName(AI)); Out << "; /* Address exposed local */\n"; - } else if ((*I)->getType() != Type::VoidTy && !isInlinableInst(**I)) { + } else if (I->getType() != Type::VoidTy && !isInlinableInst(*I)) { Out << " "; - printType(Out, (*I)->getType(), Mang->getValueName(*I)); + printType(Out, I->getType(), Mang->getValueName(&*I)); Out << ";\n"; if (isa(*I)) { // Print out PHI node temporaries as well... Out << " "; - printType(Out, (*I)->getType(), - Mang->getValueName(*I)+"__PHI_TEMPORARY"); + printType(Out, I->getType(), + Mang->getValueName(&*I)+"__PHI_TEMPORARY"); Out << ";\n"; } } diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp index 807f8ab92f1..09ee36c85bb 100644 --- a/lib/Target/CBackend/Writer.cpp +++ b/lib/Target/CBackend/Writer.cpp @@ -955,19 +955,19 @@ void CWriter::printFunction(Function &F) { // print local variable information for the function for (inst_iterator I = inst_begin(&F), E = inst_end(&F); I != E; ++I) - if (const AllocaInst *AI = isDirectAlloca(*I)) { + if (const AllocaInst *AI = isDirectAlloca(&*I)) { Out << " "; printType(Out, AI->getAllocatedType(), Mang->getValueName(AI)); Out << "; /* Address exposed local */\n"; - } else if ((*I)->getType() != Type::VoidTy && !isInlinableInst(**I)) { + } else if (I->getType() != Type::VoidTy && !isInlinableInst(*I)) { Out << " "; - printType(Out, (*I)->getType(), Mang->getValueName(*I)); + printType(Out, I->getType(), Mang->getValueName(&*I)); Out << ";\n"; if (isa(*I)) { // Print out PHI node temporaries as well... Out << " "; - printType(Out, (*I)->getType(), - Mang->getValueName(*I)+"__PHI_TEMPORARY"); + printType(Out, I->getType(), + Mang->getValueName(&*I)+"__PHI_TEMPORARY"); Out << ";\n"; } } diff --git a/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp b/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp index 28fc75a8f6c..0f4c4bde932 100644 --- a/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp +++ b/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp @@ -1167,9 +1167,9 @@ void PhyRegAlloc::saveState () { unsigned Insn = 0; // Instructions themselves encoded as operand # -1 for (const_inst_iterator II=inst_begin (Fn), IE=inst_end (Fn); II!=IE; ++II){ - saveStateForValue (state, (*II), Insn, -1); - for (unsigned i = 0; i < (*II)->getNumOperands (); ++i) { - const Value *V = (*II)->getOperand (i); + saveStateForValue (state, (&*II), Insn, -1); + for (unsigned i = 0; i < (*II).getNumOperands (); ++i) { + const Value *V = (*II).getOperand (i); // Don't worry about it unless it's something whose reg. we'll need. if (!isa (V) && !isa (V)) continue; @@ -1201,7 +1201,7 @@ void PhyRegAlloc::verifySavedState () { } int Insn = 0; for (const_inst_iterator II=inst_begin (Fn), IE=inst_end (Fn); II!=IE; ++II) { - const Instruction *I = *II; + const Instruction *I = &*II; MachineCodeForInstruction &Instrs = MachineCodeForInstruction::get (I); std::cerr << "Instruction: " << *I << "MachineCodeForInstruction:\n"; diff --git a/lib/Transforms/Scalar/ConstantProp.cpp b/lib/Transforms/Scalar/ConstantProp.cpp index f1f7a442221..8be02476b9c 100644 --- a/lib/Transforms/Scalar/ConstantProp.cpp +++ b/lib/Transforms/Scalar/ConstantProp.cpp @@ -49,7 +49,10 @@ Pass *llvm::createConstantPropagationPass() { bool ConstantPropagation::runOnFunction(Function &F) { // Initialize the worklist to all of the instructions ready to process... - std::set WorkList(inst_begin(F), inst_end(F)); + std::set WorkList; + for(inst_iterator i = inst_begin(F), e = inst_end(F); i != e; ++i) { + WorkList.insert(&*i); + } bool Changed = false; while (!WorkList.empty()) { diff --git a/lib/Transforms/Scalar/DCE.cpp b/lib/Transforms/Scalar/DCE.cpp index 36e662ac2fb..64dfa8c82ae 100644 --- a/lib/Transforms/Scalar/DCE.cpp +++ b/lib/Transforms/Scalar/DCE.cpp @@ -76,7 +76,10 @@ namespace { bool DCE::runOnFunction(Function &F) { // Start out with all of the instructions in the worklist... - std::vector WorkList(inst_begin(F), inst_end(F)); + std::vector WorkList; + for (inst_iterator i = inst_begin(F), e = inst_end(F); i != e; ++i) { + WorkList.push_back(&*i); + } std::set DeadInsts; // Loop over the worklist finding instructions that are dead. If they are diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index e2607c0c1a8..92b7f1a39bc 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2934,7 +2934,10 @@ bool InstCombiner::runOnFunction(Function &F) { bool Changed = false; TD = &getAnalysis(); - WorkList.insert(WorkList.end(), inst_begin(F), inst_end(F)); + for (inst_iterator i = inst_begin(F), e = inst_end(F); i != e; ++i) { + WorkList.push_back(&*i); + } + while (!WorkList.empty()) { Instruction *I = WorkList.back(); // Get an instruction from the worklist diff --git a/lib/VMCore/SlotCalculator.cpp b/lib/VMCore/SlotCalculator.cpp index d462bdd1e9f..35490532795 100644 --- a/lib/VMCore/SlotCalculator.cpp +++ b/lib/VMCore/SlotCalculator.cpp @@ -186,7 +186,7 @@ void SlotCalculator::processModule() { if (isa(I->getOperand(op))) getOrCreateSlot(I->getOperand(op)); getOrCreateSlot(I->getType()); - if (const VANextInst *VAN = dyn_cast(*I)) + if (const VANextInst *VAN = dyn_cast(&*I)) getOrCreateSlot(VAN->getArgType()); } processSymbolTableConstants(&F->getSymbolTable()); @@ -448,7 +448,7 @@ void SlotCalculator::buildCompactionTable(const Function *F) { if (isa(I->getOperand(op)) || isa(I->getOperand(op))) getOrCreateCompactionTableSlot(I->getOperand(op)); - if (const VANextInst *VAN = dyn_cast(*I)) + if (const VANextInst *VAN = dyn_cast(&*I)) getOrCreateCompactionTableSlot(VAN->getArgType()); }