Changes to fix up the inst_iterator to pass to boost iterator checks. This

patch was graciously contributed by Vladimir Prus.

llvm-svn: 13185
This commit is contained in:
Chris Lattner 2004-04-27 15:13:33 +00:00
parent 8bcc86b6ae
commit 2d3a7a6ff0
12 changed files with 58 additions and 46 deletions

View File

@ -33,15 +33,18 @@ class InstIterator {
typedef _BB_i_t BBIty; typedef _BB_i_t BBIty;
typedef _BI_t BIty; typedef _BI_t BIty;
typedef _II_t IIty; typedef _II_t IIty;
_BB_t &BBs; // BasicBlocksType _BB_t *BBs; // BasicBlocksType
_BB_i_t BB; // BasicBlocksType::iterator _BB_i_t BB; // BasicBlocksType::iterator
_BI_t BI; // BasicBlock::iterator _BI_t BI; // BasicBlock::iterator
public: public:
typedef std::bidirectional_iterator_tag iterator_category; typedef std::bidirectional_iterator_tag iterator_category;
typedef IIty value_type; typedef IIty value_type;
typedef unsigned difference_type; typedef signed difference_type;
typedef BIty pointer; typedef IIty* pointer;
typedef IIty reference; typedef IIty& reference;
// Default constructor
InstIterator() {}
// Copy constructor... // Copy constructor...
template<typename A, typename B, typename C, typename D> template<typename A, typename B, typename C, typename D>
@ -53,26 +56,26 @@ public:
: BBs(II.BBs), BB(II.BB), BI(II.BI) {} : BBs(II.BBs), BB(II.BB), BI(II.BI) {}
template<class M> InstIterator(M &m) template<class M> InstIterator(M &m)
: BBs(m.getBasicBlockList()), BB(BBs.begin()) { // begin ctor : BBs(&m.getBasicBlockList()), BB(BBs->begin()) { // begin ctor
if (BB != BBs.end()) { if (BB != BBs->end()) {
BI = BB->begin(); BI = BB->begin();
advanceToNextBB(); advanceToNextBB();
} }
} }
template<class M> InstIterator(M &m, bool) template<class M> 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... // Accessors to get at the underlying iterators...
inline BBIty &getBasicBlockIterator() { return BB; } inline BBIty &getBasicBlockIterator() { return BB; }
inline BIty &getInstructionIterator() { return BI; } inline BIty &getInstructionIterator() { return BI; }
inline IIty operator*() const { return BI; } inline reference operator*() const { return *BI; }
inline IIty operator->() const { return operator*(); } inline pointer operator->() const { return &operator*(); }
inline bool operator==(const InstIterator &y) const { 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 { inline bool operator!=(const InstIterator& y) const {
return !operator==(y); return !operator==(y);
@ -88,7 +91,7 @@ public:
} }
InstIterator& operator--() { InstIterator& operator--() {
while (BB == BBs.end() || BI == BB->begin()) { while (BB == BBs->end() || BI == BB->begin()) {
--BB; --BB;
BI = BB->end(); BI = BB->end();
} }
@ -99,7 +102,7 @@ public:
InstIterator tmp = *this; --*this; return tmp; InstIterator tmp = *this; --*this; return tmp;
} }
inline bool atEnd() const { return BB == BBs.end(); } inline bool atEnd() const { return BB == BBs->end(); }
private: private:
inline void advanceToNextBB() { inline void advanceToNextBB() {
@ -107,7 +110,7 @@ private:
// the end() of the current BasicBlock and there are successor BBs. // the end() of the current BasicBlock and there are successor BBs.
while (BI == BB->end()) { while (BI == BB->end()) {
++BB; ++BB;
if (BB == BBs.end()) break; if (BB == BBs->end()) break;
BI = BB->begin(); BI = BB->begin();
} }
} }
@ -116,11 +119,11 @@ private:
typedef InstIterator<iplist<BasicBlock>, typedef InstIterator<iplist<BasicBlock>,
Function::iterator, BasicBlock::iterator, Function::iterator, BasicBlock::iterator,
Instruction*> inst_iterator; Instruction> inst_iterator;
typedef InstIterator<const iplist<BasicBlock>, typedef InstIterator<const iplist<BasicBlock>,
Function::const_iterator, Function::const_iterator,
BasicBlock::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_begin(Function *F) { return inst_iterator(*F); }
inline inst_iterator inst_end(Function *F) { return inst_iterator(*F, true); } inline inst_iterator inst_end(Function *F) { return inst_iterator(*F, true); }

View File

@ -83,15 +83,15 @@ bool AAEval::runOnFunction(Function &F) {
Pointers.insert(I); Pointers.insert(I);
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) { for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
if (isa<PointerType>((*I)->getType())) // Add all pointer instructions if (isa<PointerType>(I->getType())) // Add all pointer instructions
Pointers.insert(*I); Pointers.insert(&*I);
for (User::op_iterator OI = (*I)->op_begin(); OI != (*I)->op_end(); ++OI) for (User::op_iterator OI = (*I).op_begin(); OI != (*I).op_end(); ++OI)
if (isa<PointerType>((*OI)->getType())) if (isa<PointerType>((*OI)->getType()))
Pointers.insert(*OI); Pointers.insert(*OI);
} }
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) { 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); if (CS.getInstruction()) CallSites.insert(CS);
} }

View File

@ -366,7 +366,7 @@ namespace {
Tracker = new AliasSetTracker(getAnalysis<AliasAnalysis>()); Tracker = new AliasSetTracker(getAnalysis<AliasAnalysis>());
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
Tracker->add(*I); Tracker->add(&*I);
return false; return false;
} }

View File

@ -42,8 +42,8 @@ static cl::opt<bool>
PrintFailures("printunsafeptrinst", cl::Hidden, PrintFailures("printunsafeptrinst", cl::Hidden,
cl::desc("Print Unsafe Pointer Access Instructions")); cl::desc("Print Unsafe Pointer Access Instructions"));
static inline bool isSafeInstruction(const Instruction *I) { static inline bool isSafeInstruction(const Instruction &I) {
switch (I->getOpcode()) { switch (I.getOpcode()) {
case Instruction::Alloca: case Instruction::Alloca:
case Instruction::Malloc: case Instruction::Malloc:
case Instruction::Free: case Instruction::Free:
@ -72,7 +72,7 @@ bool FindUnsafePointerTypes::run(Module &Mod) {
if (PrintFailures) { if (PrintFailures) {
CachedWriter CW(F->getParent(), std::cerr); CachedWriter CW(F->getParent(), std::cerr);
CW << "FindUnsafePointerTypes: Type '" << ITy CW << "FindUnsafePointerTypes: Type '" << ITy
<< "' marked unsafe in '" << F->getName() << "' by:\n" << **I; << "' marked unsafe in '" << F->getName() << "' by:\n" << *I;
} }
} }
} }

View File

@ -79,11 +79,11 @@ bool FindUsedTypes::run(Module &m) {
// //
for (const_inst_iterator II = inst_begin(F), IE = inst_end(F); for (const_inst_iterator II = inst_begin(F), IE = inst_end(F);
II != IE; ++II) { II != IE; ++II) {
const Instruction *I = *II; const Instruction &I = *II;
const Type *Ty = I->getType(); const Type *Ty = I.getType();
IncorporateType(Ty); // Incorporate the type of the instruction 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) OI != OE; ++OI)
IncorporateValue(*OI); // Insert inst operand types as well IncorporateValue(*OI); // Insert inst operand types as well
} }

View File

@ -2175,22 +2175,22 @@ void ScalarEvolution::print(std::ostream &OS) const {
OS << "Classifying expressions for: " << F.getName() << "\n"; OS << "Classifying expressions for: " << F.getName() << "\n";
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
if ((*I)->getType()->isInteger()) { if (I->getType()->isInteger()) {
OS << **I; OS << *I;
OS << " --> "; OS << " --> ";
SCEVHandle SV = getSCEV(*I); SCEVHandle SV = getSCEV(&*I);
SV->print(OS); SV->print(OS);
OS << "\t\t"; OS << "\t\t";
if ((*I)->getType()->isIntegral()) { if ((*I).getType()->isIntegral()) {
ConstantRange Bounds = SV->getValueRange(); ConstantRange Bounds = SV->getValueRange();
if (!Bounds.isFullSet()) if (!Bounds.isFullSet())
OS << "Bounds: " << Bounds << " "; OS << "Bounds: " << Bounds << " ";
} }
if (const Loop *L = LI.getLoopFor((*I)->getParent())) { if (const Loop *L = LI.getLoopFor((*I).getParent())) {
OS << "Exits: "; OS << "Exits: ";
SCEVHandle ExitValue = getSCEVAtScope(*I, L->getParentLoop()); SCEVHandle ExitValue = getSCEVAtScope(&*I, L->getParentLoop());
if (isa<SCEVCouldNotCompute>(ExitValue)) { if (isa<SCEVCouldNotCompute>(ExitValue)) {
OS << "<<Unknown>>"; OS << "<<Unknown>>";
} else { } else {

View File

@ -955,19 +955,19 @@ void CWriter::printFunction(Function &F) {
// print local variable information for the function // print local variable information for the function
for (inst_iterator I = inst_begin(&F), E = inst_end(&F); I != E; ++I) 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 << " "; Out << " ";
printType(Out, AI->getAllocatedType(), Mang->getValueName(AI)); printType(Out, AI->getAllocatedType(), Mang->getValueName(AI));
Out << "; /* Address exposed local */\n"; Out << "; /* Address exposed local */\n";
} else if ((*I)->getType() != Type::VoidTy && !isInlinableInst(**I)) { } else if (I->getType() != Type::VoidTy && !isInlinableInst(*I)) {
Out << " "; Out << " ";
printType(Out, (*I)->getType(), Mang->getValueName(*I)); printType(Out, I->getType(), Mang->getValueName(&*I));
Out << ";\n"; Out << ";\n";
if (isa<PHINode>(*I)) { // Print out PHI node temporaries as well... if (isa<PHINode>(*I)) { // Print out PHI node temporaries as well...
Out << " "; Out << " ";
printType(Out, (*I)->getType(), printType(Out, I->getType(),
Mang->getValueName(*I)+"__PHI_TEMPORARY"); Mang->getValueName(&*I)+"__PHI_TEMPORARY");
Out << ";\n"; Out << ";\n";
} }
} }

View File

@ -1167,9 +1167,9 @@ void PhyRegAlloc::saveState () {
unsigned Insn = 0; unsigned Insn = 0;
// Instructions themselves encoded as operand # -1 // Instructions themselves encoded as operand # -1
for (const_inst_iterator II=inst_begin (Fn), IE=inst_end (Fn); II!=IE; ++II){ for (const_inst_iterator II=inst_begin (Fn), IE=inst_end (Fn); II!=IE; ++II){
saveStateForValue (state, (*II), Insn, -1); saveStateForValue (state, (&*II), Insn, -1);
for (unsigned i = 0; i < (*II)->getNumOperands (); ++i) { for (unsigned i = 0; i < (*II).getNumOperands (); ++i) {
const Value *V = (*II)->getOperand (i); const Value *V = (*II).getOperand (i);
// Don't worry about it unless it's something whose reg. we'll need. // Don't worry about it unless it's something whose reg. we'll need.
if (!isa<Argument> (V) && !isa<Instruction> (V)) if (!isa<Argument> (V) && !isa<Instruction> (V))
continue; continue;
@ -1201,7 +1201,7 @@ void PhyRegAlloc::verifySavedState () {
} }
int Insn = 0; int Insn = 0;
for (const_inst_iterator II=inst_begin (Fn), IE=inst_end (Fn); II!=IE; ++II) { 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); MachineCodeForInstruction &Instrs = MachineCodeForInstruction::get (I);
std::cerr << "Instruction: " << *I std::cerr << "Instruction: " << *I
<< "MachineCodeForInstruction:\n"; << "MachineCodeForInstruction:\n";

View File

@ -49,7 +49,10 @@ Pass *llvm::createConstantPropagationPass() {
bool ConstantPropagation::runOnFunction(Function &F) { bool ConstantPropagation::runOnFunction(Function &F) {
// Initialize the worklist to all of the instructions ready to process... // Initialize the worklist to all of the instructions ready to process...
std::set<Instruction*> WorkList(inst_begin(F), inst_end(F)); std::set<Instruction*> WorkList;
for(inst_iterator i = inst_begin(F), e = inst_end(F); i != e; ++i) {
WorkList.insert(&*i);
}
bool Changed = false; bool Changed = false;
while (!WorkList.empty()) { while (!WorkList.empty()) {

View File

@ -76,7 +76,10 @@ namespace {
bool DCE::runOnFunction(Function &F) { bool DCE::runOnFunction(Function &F) {
// Start out with all of the instructions in the worklist... // Start out with all of the instructions in the worklist...
std::vector<Instruction*> WorkList(inst_begin(F), inst_end(F)); std::vector<Instruction*> WorkList;
for (inst_iterator i = inst_begin(F), e = inst_end(F); i != e; ++i) {
WorkList.push_back(&*i);
}
std::set<Instruction*> DeadInsts; std::set<Instruction*> DeadInsts;
// Loop over the worklist finding instructions that are dead. If they are // Loop over the worklist finding instructions that are dead. If they are

View File

@ -2934,7 +2934,10 @@ bool InstCombiner::runOnFunction(Function &F) {
bool Changed = false; bool Changed = false;
TD = &getAnalysis<TargetData>(); TD = &getAnalysis<TargetData>();
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()) { while (!WorkList.empty()) {
Instruction *I = WorkList.back(); // Get an instruction from the worklist Instruction *I = WorkList.back(); // Get an instruction from the worklist

View File

@ -186,7 +186,7 @@ void SlotCalculator::processModule() {
if (isa<Constant>(I->getOperand(op))) if (isa<Constant>(I->getOperand(op)))
getOrCreateSlot(I->getOperand(op)); getOrCreateSlot(I->getOperand(op));
getOrCreateSlot(I->getType()); getOrCreateSlot(I->getType());
if (const VANextInst *VAN = dyn_cast<VANextInst>(*I)) if (const VANextInst *VAN = dyn_cast<VANextInst>(&*I))
getOrCreateSlot(VAN->getArgType()); getOrCreateSlot(VAN->getArgType());
} }
processSymbolTableConstants(&F->getSymbolTable()); processSymbolTableConstants(&F->getSymbolTable());
@ -448,7 +448,7 @@ void SlotCalculator::buildCompactionTable(const Function *F) {
if (isa<Constant>(I->getOperand(op)) || if (isa<Constant>(I->getOperand(op)) ||
isa<GlobalValue>(I->getOperand(op))) isa<GlobalValue>(I->getOperand(op)))
getOrCreateCompactionTableSlot(I->getOperand(op)); getOrCreateCompactionTableSlot(I->getOperand(op));
if (const VANextInst *VAN = dyn_cast<VANextInst>(*I)) if (const VANextInst *VAN = dyn_cast<VANextInst>(&*I))
getOrCreateCompactionTableSlot(VAN->getArgType()); getOrCreateCompactionTableSlot(VAN->getArgType());
} }