diff options
author | Chris Lattner <sabre@nondot.org> | 2001-06-27 23:41:11 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-06-27 23:41:11 +0000 |
commit | 7fc9fe34390c66ca58646d09a87f7dbaacb6c1f8 (patch) | |
tree | fd083cad8506b9f54d19b8429dfae825f264c35b | |
parent | 138a124f09de272b2ab93cfd6e2a8a283d18029b (diff) |
Miscellaneous cleanups:
* Convert post to pre-increment for for loops
* Use generic programming more
* Use new Value::cast* instructions
* Use new Module, Method, & BasicBlock forwarding methods
* Use new facilities in STLExtras.h
* Use new Instruction::isPHINode() method
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96 91177308-0d34-0410-b5e6-96231b3b80d8
28 files changed, 230 insertions, 207 deletions
diff --git a/include/llvm/CFG.h b/include/llvm/CFG.h index e313e16fa6..5f207b5cfe 100644 --- a/include/llvm/CFG.h +++ b/include/llvm/CFG.h @@ -48,12 +48,15 @@ public: typedef PredIterator<_Ptr,_USE_iterator> _Self; typedef bidirectional_iterator_tag iterator_category; + typedef _Ptr &reference; + typedef unsigned difference_type; + typedef _Ptr value_type; typedef _Ptr pointer; inline void advancePastConstPool() { // Loop to ignore constant pool references while (It != BB->use_end() && - (((*It)->getValueType() != Value::InstructionVal) || + ((!(*It)->isInstruction()) || !(((Instruction*)(*It))->isTerminator()))) ++It; } @@ -67,8 +70,7 @@ public: inline bool operator!=(const _Self& x) const { return !operator==(x); } inline pointer operator*() const { - assert ((*It)->getValueType() == Value::InstructionVal); - return ((Instruction *)(*It))->getParent(); + return (*It)->castInstructionAsserting()->getParent(); } inline pointer *operator->() const { return &(operator*()); } @@ -113,6 +115,9 @@ public: typedef SuccIterator<_Term, _BB> _Self; // TODO: This can be random access iterator, need operator+ and stuff tho typedef bidirectional_iterator_tag iterator_category; + typedef _BB &reference; + typedef unsigned difference_type; + typedef _BB value_type; typedef _BB pointer; inline SuccIterator(_Term T) : Term(T), idx(0) {} // begin iterator @@ -242,11 +247,11 @@ public: }; inline df_iterator df_begin(Method *M, bool Reverse = false) { - return df_iterator(M->getBasicBlocks().front(), Reverse); + return df_iterator(M->front(), Reverse); } inline df_const_iterator df_begin(const Method *M, bool Reverse = false) { - return df_const_iterator(M->getBasicBlocks().front(), Reverse); + return df_const_iterator(M->front(), Reverse); } inline df_iterator df_end(Method*) { return df_iterator(); @@ -334,10 +339,10 @@ public: }; inline po_iterator po_begin( Method *M) { - return po_iterator(M->getBasicBlocks().front()); + return po_iterator(M->front()); } inline po_const_iterator po_begin(const Method *M) { - return po_const_iterator(M->getBasicBlocks().front()); + return po_const_iterator(M->front()); } inline po_iterator po_end ( Method *M) { return po_iterator(); @@ -371,7 +376,7 @@ class ReversePostOrderTraversal { } public: inline ReversePostOrderTraversal(Method *M) { - Initialize(M->getBasicBlocks().front()); + Initialize(M->front()); } inline ReversePostOrderTraversal(BasicBlock *BB) { Initialize(BB); diff --git a/lib/Analysis/IntervalPartition.cpp b/lib/Analysis/IntervalPartition.cpp index f820d7ad16..32936fd43d 100644 --- a/lib/Analysis/IntervalPartition.cpp +++ b/lib/Analysis/IntervalPartition.cpp @@ -6,6 +6,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Analysis/IntervalIterator.h" +#include "llvm/Tools/STLExtras.h" using namespace cfg; @@ -49,22 +50,24 @@ void IntervalPartition::updatePredecessors(cfg::Interval *Int) { // specified method... // IntervalPartition::IntervalPartition(Method *M) { - assert(M->getBasicBlocks().front() && "Cannot operate on prototypes!"); + assert(M->front() && "Cannot operate on prototypes!"); // Pass false to intervals_begin because we take ownership of it's memory method_interval_iterator I = intervals_begin(M, false); - method_interval_iterator End = intervals_end(M); - assert(I != End && "No intervals in method!?!?!"); + assert(I != intervals_end(M) && "No intervals in method!?!?!"); addIntervalToPartition(RootInterval = *I); - for (++I; I != End; ++I) - addIntervalToPartition(*I); + ++I; // After the first one... + + // Add the rest of the intervals to the partition... + for_each(I, intervals_end(M), + bind_obj(this, &IntervalPartition::addIntervalToPartition)); // Now that we know all of the successor information, propogate this to the // predecessors for each block... - for(iterator It = begin(), E = end(); It != E; ++It) - updatePredecessors(*It); + for_each(begin(), end(), + bind_obj(this, &IntervalPartition::updatePredecessors)); } @@ -78,16 +81,18 @@ IntervalPartition::IntervalPartition(IntervalPartition &IP, bool) { // Pass false to intervals_begin because we take ownership of it's memory interval_part_interval_iterator I = intervals_begin(IP, false); - interval_part_interval_iterator End = intervals_end(IP); - assert(I != End && "No intervals in interval partition!?!?!"); + assert(I != intervals_end(IP) && "No intervals in interval partition!?!?!"); addIntervalToPartition(RootInterval = *I); - for (++I; I != End; ++I) - addIntervalToPartition(*I); + ++I; // After the first one... + + // Add the rest of the intervals to the partition... + for_each(I, intervals_end(IP), + bind_obj(this, &IntervalPartition::addIntervalToPartition)); // Now that we know all of the successor information, propogate this to the // predecessors for each block... - for(iterator I = begin(), E = end(); I != E; ++I) - updatePredecessors(*I); + for_each(begin(), end(), + bind_obj(this, &IntervalPartition::updatePredecessors)); } diff --git a/lib/Analysis/ModuleAnalyzer.cpp b/lib/Analysis/ModuleAnalyzer.cpp index 1c3464e48c..0f028d12dd 100644 --- a/lib/Analysis/ModuleAnalyzer.cpp +++ b/lib/Analysis/ModuleAnalyzer.cpp @@ -13,6 +13,7 @@ #include "llvm/BasicBlock.h" #include "llvm/DerivedTypes.h" #include "llvm/ConstPoolVals.h" +#include "llvm/Tools/STLExtras.h" #include <map> // processModule - Driver function to call all of my subclasses virtual methods. @@ -87,7 +88,7 @@ bool ModuleAnalyzer::processConstPool(const ConstantPool &CP, bool isMethod) { if (processConstPoolPlane(CP, Plane, isMethod)) return true; for (ConstantPool::PlaneType::const_iterator CI = Plane.begin(); - CI != Plane.end(); CI++) { + CI != Plane.end(); ++CI) { if ((*CI)->getType() == Type::TypeTy) if (handleType(TypeSet, ((const ConstPoolType*)(*CI))->getValue())) return true; @@ -98,11 +99,9 @@ bool ModuleAnalyzer::processConstPool(const ConstantPool &CP, bool isMethod) { } if (!isMethod) { - assert(CP.getParent()->getValueType() == Value::ModuleVal); - const Module *M = (const Module*)CP.getParent(); + const Module *M = CP.getParent()->castModuleAsserting(); // Process the method types after the constant pool... - for (Module::MethodListType::const_iterator I = M->getMethodList().begin(); - I != M->getMethodList().end(); I++) { + for (Module::const_iterator I = M->begin(); I != M->end(); ++I) { if (handleType(TypeSet, (*I)->getType())) return true; if (visitMethod(*I)) return true; } @@ -111,34 +110,28 @@ bool ModuleAnalyzer::processConstPool(const ConstantPool &CP, bool isMethod) { } bool ModuleAnalyzer::processMethods(const Module *M) { - for (Module::MethodListType::const_iterator I = M->getMethodList().begin(); - I != M->getMethodList().end(); I++) - if (processMethod(*I)) return true; - - return false; + return apply_until(M->begin(), M->end(), + bind_obj(this, &ModuleAnalyzer::processMethod)); } bool ModuleAnalyzer::processMethod(const Method *M) { // Loop over the arguments, processing them... - const Method::ArgumentListType &ArgList = M->getArgumentList(); - for (Method::ArgumentListType::const_iterator AI = ArgList.begin(); - AI != ArgList.end(); AI++) - if (processMethodArgument(*AI)) return true; + if (apply_until(M->getArgumentList().begin(), M->getArgumentList().end(), + bind_obj(this, &ModuleAnalyzer::processMethodArgument))) + return true; // Loop over the constant pool, adding the constants to the table... processConstPool(M->getConstantPool(), true); // Loop over all the basic blocks, in order... - Method::BasicBlocksType::const_iterator BBI = M->getBasicBlocks().begin(); - for (; BBI != M->getBasicBlocks().end(); BBI++) - if (processBasicBlock(*BBI)) return true; - return false; + return apply_until(M->begin(), M->end(), + bind_obj(this, &ModuleAnalyzer::processBasicBlock)); } bool ModuleAnalyzer::processBasicBlock(const BasicBlock *BB) { // Process all of the instructions in the basic block - BasicBlock::InstListType::const_iterator Inst = BB->getInstList().begin(); - for (; Inst != BB->getInstList().end(); Inst++) { + BasicBlock::const_iterator Inst = BB->begin(); + for (; Inst != BB->end(); Inst++) { if (preProcessInstruction(*Inst) || processInstruction(*Inst)) return true; } return false; diff --git a/lib/AsmParser/llvmAsmParser.cpp b/lib/AsmParser/llvmAsmParser.cpp index 98417c4426..9f18db0f88 100644 --- a/lib/AsmParser/llvmAsmParser.cpp +++ b/lib/AsmParser/llvmAsmParser.cpp @@ -1569,7 +1569,7 @@ case 74: { MethodType::ParamTypes ParamTypeList; if (yyvsp[-1].MethodArgList) - for (list<MethodArgument*>::iterator I = yyvsp[-1].MethodArgList->begin(); I != yyvsp[-1].MethodArgList->end(); I++) + for (list<MethodArgument*>::iterator I = yyvsp[-1].MethodArgList->begin(); I != yyvsp[-1].MethodArgList->end(); ++I) ParamTypeList.push_back((*I)->getType()); const MethodType *MT = MethodType::getMethodType(yyvsp[-4].TypeVal, ParamTypeList); @@ -1585,7 +1585,7 @@ case 74: if (yyvsp[-1].MethodArgList) { // Is null if empty... Method::ArgumentListType &ArgList = M->getArgumentList(); - for (list<MethodArgument*>::iterator I = yyvsp[-1].MethodArgList->begin(); I != yyvsp[-1].MethodArgList->end(); I++) { + for (list<MethodArgument*>::iterator I = yyvsp[-1].MethodArgList->begin(); I != yyvsp[-1].MethodArgList->end(); ++I) { InsertValue(*I); ArgList.push_back(*I); } @@ -1658,9 +1658,9 @@ case 85: { Value *D = getVal(Type::TypeTy, yyvsp[0].ValIDVal, true); if (D == 0) ThrowException("Invalid user defined type: " + yyvsp[0].ValIDVal.getName()); - assert (D->getValueType() == Value::ConstantVal && - "Internal error! User defined type not in const pool!"); - ConstPoolType *CPT = (ConstPoolType*)D; + + // User defined type not in const pool! + ConstPoolType *CPT = (ConstPoolType*)D->castConstantAsserting(); yyval.TypeVal = CPT->getValue(); ; break;} @@ -1805,7 +1805,7 @@ case 105: list<pair<ConstPoolVal*, BasicBlock*> >::iterator I = yyvsp[-1].JumpTable->begin(), end = yyvsp[-1].JumpTable->end(); - for (; I != end; I++) + for (; I != end; ++I) S->dest_push_back(I->first, I->second); ; break;} @@ -1916,7 +1916,7 @@ case 118: const MethodType *Ty = (const MethodType*)yyvsp[-4].TypeVal; Value *V = getVal(Ty, yyvsp[-3].ValIDVal); - if (V->getValueType() != Value::MethodVal || V->getType() != Ty) + if (!V->isMethod() || V->getType() != Ty) ThrowException("Cannot call: " + yyvsp[-3].ValIDVal.getName() + "!"); // Create or access a new type that corresponds to the function call... diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 3f71274c8e..6fa817fbfa 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -643,7 +643,7 @@ ArgList : ArgListH { MethodHeaderH : TypesV STRINGCONSTANT '(' ArgList ')' { MethodType::ParamTypes ParamTypeList; if ($4) - for (list<MethodArgument*>::iterator I = $4->begin(); I != $4->end(); I++) + for (list<MethodArgument*>::iterator I = $4->begin(); I != $4->end(); ++I) ParamTypeList.push_back((*I)->getType()); const MethodType *MT = MethodType::getMethodType($1, ParamTypeList); @@ -659,7 +659,7 @@ MethodHeaderH : TypesV STRINGCONSTANT '(' ArgList ')' { if ($4) { // Is null if empty... Method::ArgumentListType &ArgList = M->getArgumentList(); - for (list<MethodArgument*>::iterator I = $4->begin(); I != $4->end(); I++) { + for (list<MethodArgument*>::iterator I = $4->begin(); I != $4->end(); ++I) { InsertValue(*I); ArgList.push_back(*I); } @@ -713,9 +713,9 @@ ValueRef : INTVAL { // Is it an integer reference...? Types : ValueRef { Value *D = getVal(Type::TypeTy, $1, true); if (D == 0) ThrowException("Invalid user defined type: " + $1.getName()); - assert (D->getValueType() == Value::ConstantVal && - "Internal error! User defined type not in const pool!"); - ConstPoolType *CPT = (ConstPoolType*)D; + + // User defined type not in const pool! + ConstPoolType *CPT = (ConstPoolType*)D->castConstantAsserting(); $$ = CPT->getValue(); } | TypesV '(' TypeList ')' { // Method derived type? @@ -811,7 +811,7 @@ BBTerminatorInst : RET Types ValueRef { // Return with a result... list<pair<ConstPoolVal*, BasicBlock*> >::iterator I = $8->begin(), end = $8->end(); - for (; I != end; I++) + for (; I != end; ++I) S->dest_push_back(I->first, I->second); } @@ -894,7 +894,7 @@ InstVal : BinaryOps Types ValueRef ',' ValueRef { const MethodType *Ty = (const MethodType*)$2; Value *V = getVal(Ty, $3); - if (V->getValueType() != Value::MethodVal || V->getType() != Ty) + if (!V->isMethod() || V->getType() != Ty) ThrowException("Cannot call: " + $3.getName() + "!"); // Create or access a new type that corresponds to the function call... diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp index b85bd887ef..dd47d1c2cf 100644 --- a/lib/Bytecode/Reader/ConstantReader.cpp +++ b/lib/Bytecode/Reader/ConstantReader.cpp @@ -156,7 +156,7 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf, unsigned Slot; if (read_vbr(Buf, EndBuf, Slot)) return true; Value *V = getValue(AT->getElementType(), Slot, false); - if (!V || V->getValueType() != Value::ConstantVal) + if (!V || !V->isConstant()) return true; Elements.push_back((ConstPoolVal*)V); } @@ -173,7 +173,7 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf, unsigned Slot; if (read_vbr(Buf, EndBuf, Slot)) return true; Value *V = getValue(ET[i], Slot, false); - if (!V || V->getValueType() != Value::ConstantVal) + if (!V || !V->isConstant()) return true; Elements.push_back((ConstPoolVal*)V); } diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index c3f4c907fe..e8bf17e604 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -46,11 +46,8 @@ const Type *BytecodeParser::getType(unsigned ID) { const Value *D = getValue(Type::TypeTy, ID, false); if (D == 0) return 0; - assert(D->getType() == Type::TypeTy && - D->getValueType() == Value::ConstantVal); - - - return ((const ConstPoolType*)D)->getValue();; + assert(D->getType() == Type::TypeTy); + return ((const ConstPoolType*)D->castConstantAsserting())->getValue(); } bool BytecodeParser::insertValue(Value *Def, vector<ValueList> &ValueTab) { @@ -63,7 +60,7 @@ bool BytecodeParser::insertValue(Value *Def, vector<ValueList> &ValueTab) { //cerr << "insertValue Values[" << type << "][" << ValueTab[type].size() // << "] = " << Def << endl; - if (type == Type::TypeTyID && Def->getValueType() == Value::ConstantVal) { + if (type == Type::TypeTyID && Def->isConstant()) { const Type *Ty = ((const ConstPoolType*)Def)->getValue(); unsigned ValueOffset = FirstDerivedTyID; @@ -123,7 +120,7 @@ Value *BytecodeParser::getValue(const Type *Ty, unsigned oNum, bool Create) { bool BytecodeParser::postResolveValues(ValueTable &ValTab) { bool Error = false; - for (unsigned ty = 0; ty < ValTab.size(); ty++) { + for (unsigned ty = 0; ty < ValTab.size(); ++ty) { ValueList &DL = ValTab[ty]; unsigned Size; while ((Size = DL.size())) { @@ -180,7 +177,7 @@ bool BytecodeParser::ParseSymbolTable(const uchar *&Buf, const uchar *EndBuf) { const Type *Ty = getType(Typ); if (Ty == 0) return true; - for (unsigned i = 0; i < NumEntries; i++) { + for (unsigned i = 0; i < NumEntries; ++i) { // Symtab entry: [def slot #][name] unsigned slot; if (read_vbr(Buf, EndBuf, slot)) return true; @@ -211,7 +208,7 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf, const MethodType::ParamTypes &Params = MTy->getParamTypes(); for (MethodType::ParamTypes::const_iterator It = Params.begin(); - It != Params.end(); It++) { + It != Params.end(); ++It) { MethodArgument *MA = new MethodArgument(*It); if (insertValue(MA, Values)) { delete M; return true; } M->getArgumentList().push_back(MA); @@ -267,7 +264,7 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf, Value *MethPHolder = getValue(MTy, MethSlot, false); assert(MethPHolder && "Something is broken no placeholder found!"); - assert(MethPHolder->getValueType() == Value::MethodVal && "Not a method?"); + assert(MethPHolder->isMethod() && "Not a method?"); unsigned type; // Type slot assert(!getTypeSlot(MTy, type) && "How can meth type not exist?"); diff --git a/lib/Bytecode/Writer/SlotCalculator.cpp b/lib/Bytecode/Writer/SlotCalculator.cpp index 01fae37e53..f7eada1418 100644 --- a/lib/Bytecode/Writer/SlotCalculator.cpp +++ b/lib/Bytecode/Writer/SlotCalculator.cpp @@ -176,12 +176,11 @@ void SlotCalculator::insertVal(const Value *D) { // Insert node into table and NodeMap... NodeMap[D] = Table[Ty].size(); - if (Typ == Type::TypeTy && // If it's a type constant, add the Type also - D->getValueType() != Value::TypeVal) { - assert(D->getValueType() == Value::ConstantVal && - "All Type instances should be constant types!"); - - const ConstPoolType *CPT = (const ConstPoolType*)D; + if (Typ == Type::TypeTy && !D->isType()) { + // If it's a type constant, add the Type also + + // All Type instances should be constant types! + const ConstPoolType *CPT = (const ConstPoolType*)D->castConstantAsserting(); int Slot = getValSlot(CPT->getValue()); if (Slot == -1) { // Only add if it's not already here! diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp index d03c945471..2be490dbed 100644 --- a/lib/Bytecode/Writer/Writer.cpp +++ b/lib/Bytecode/Writer/Writer.cpp @@ -67,7 +67,7 @@ bool BytecodeWriter::processConstPool(const ConstantPool &CP, bool isMethod) { unsigned NumConstants = 0; for (unsigned vn = ValNo; vn < Plane.size(); vn++) - if (Plane[vn]->getValueType() == Value::ConstantVal) + if (Plane[vn]->isConstant()) NumConstants++; if (NumConstants == 0) continue; // Skip empty type planes... @@ -85,21 +85,19 @@ bool BytecodeWriter::processConstPool(const ConstantPool &CP, bool isMethod) { for (; ValNo < Plane.size(); ValNo++) { const Value *V = Plane[ValNo]; - if (V->getValueType() == Value::ConstantVal) { + if (const ConstPoolVal *CPV = V->castConstant()) { //cerr << "Serializing value: <" << V->getType() << ">: " // << ((const ConstPoolVal*)V)->getStrValue() << ":" // << Out.size() << "\n"; - outputConstant((const ConstPoolVal*)V); + outputConstant(CPV); } } } delete CPool; // End bytecode block section! - if (!isMethod) { // The ModuleInfoBlock follows directly after the c-pool - assert(CP.getParent()->getValueType() == Value::ModuleVal); - outputModuleInfoBlock((const Module*)CP.getParent()); - } + if (!isMethod) // The ModuleInfoBlock follows directly after the c-pool + outputModuleInfoBlock(CP.getParent()->castModuleAsserting()); return false; } @@ -108,13 +106,11 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) { BytecodeBlock ModuleInfoBlock(BytecodeFormat::ModuleGlobalInfo, Out); // Output the types of the methods in this class - Module::MethodListType::const_iterator I = M->getMethodList().begin(); - while (I != M->getMethodList().end()) { + for (Module::const_iterator I = M->begin(), End = M->end(); I != End; ++I) { int Slot = Table.getValSlot((*I)->getType()); assert(Slot != -1 && "Module const pool is broken!"); assert(Slot >= Type::FirstDerivedTyID && "Derived type not in range!"); output_vbr((unsigned)Slot, Out); - I++; } output_vbr((unsigned)Table.getValSlot(Type::VoidTy), Out); align32(Out); @@ -144,7 +140,7 @@ bool BytecodeWriter::processBasicBlock(const BasicBlock *BB) { void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) { BytecodeBlock MethodBlock(BytecodeFormat::SymbolTable, Out); - for (SymbolTable::const_iterator TI = MST.begin(); TI != MST.end(); TI++) { + for (SymbolTable::const_iterator TI = MST.begin(); TI != MST.end(); ++TI) { SymbolTable::type_const_iterator I = MST.type_begin(TI->first); SymbolTable::type_const_iterator End = MST.type_end(TI->first); int Slot; @@ -158,7 +154,7 @@ void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) { assert(Slot != -1 && "Type in symtab, but not in table!"); output_vbr((unsigned)Slot, Out); - for (; I != End; I++) { + for (; I != End; ++I) { // Symtab entry: [def slot #][name] Slot = Table.getValSlot(I->second); assert (Slot != -1 && "Value in symtab but not in method!!"); diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp index 0a191a508f..e5bc171beb 100644 --- a/lib/Transforms/IPO/InlineSimple.cpp +++ b/lib/Transforms/IPO/InlineSimple.cpp @@ -36,9 +36,9 @@ static inline void RemapInstruction(Instruction *I, map<const Value *, Value*> &ValueMap) { - for (unsigned op = 0; const Value *Op = I->getOperand(op); op++) { + for (unsigned op = 0; const Value *Op = I->getOperand(op); ++op) { Value *V = ValueMap[Op]; - if (!V && Op->getValueType() == Value::MethodVal) + if (!V && Op->isMethod()) continue; // Methods don't get relocated if (!V) { @@ -60,7 +60,7 @@ static inline void RemapInstruction(Instruction *I, // exists in the instruction stream. Similiarly this will inline a recursive // method by one level. // -bool InlineMethod(BasicBlock::InstListType::iterator CIIt) { +bool InlineMethod(BasicBlock::iterator CIIt) { assert((*CIIt)->getInstType() == Instruction::Call && "InlineMethod only works on CallInst nodes!"); assert((*CIIt)->getParent() && "Instruction not embedded in basic block!"); @@ -124,9 +124,8 @@ bool InlineMethod(BasicBlock::InstListType::iterator CIIt) { // Loop over all of the basic blocks in the method, inlining them as // appropriate. Keep track of the first basic block of the method... // - for (Method::BasicBlocksType::const_iterator BI = - CalledMeth->getBasicBlocks().begin(); - BI != CalledMeth->getBasicBlocks().end(); BI++) { + for (Method::const_iterator BI = CalledMeth->begin(); + BI != CalledMeth->end(); ++BI) { const BasicBlock *BB = *BI; assert(BB->getTerminator() && "BasicBlock doesn't have terminator!?!?"); @@ -143,8 +142,8 @@ bool InlineMethod(BasicBlock::InstListType::iterator CIIt) { // Loop over all instructions copying them over... Instruction *NewInst; - for (BasicBlock::InstListType::const_iterator II = BB->getInstList().begin(); - II != (BB->getInstList().end()-1); II++) { + for (BasicBlock::const_iterator II = BB->begin(); + II != (BB->end()-1); ++II) { IBB->getInstList().push_back((NewInst = (*II)->clone())); ValueMap[*II] = NewInst; // Add instruction map to value. } @@ -193,16 +192,14 @@ bool InlineMethod(BasicBlock::InstListType::iterator CIIt) { // Loop over all of the instructions in the method, fixing up operand // references as we go. This uses ValueMap to do all the hard work. // - for (Method::BasicBlocksType::const_iterator BI = - CalledMeth->getBasicBlocks().begin(); - BI != CalledMeth->getBasicBlocks().end(); BI++) { + for (Method::const_iterator BI = CalledMeth->begin(); + BI != CalledMeth->end(); ++BI) { const BasicBlock *BB = *BI; BasicBlock *NBB = (BasicBlock*)ValueMap[BB]; // Loop over all instructions, fixing each one as we find it... // - for (BasicBlock::InstListType::iterator II = NBB->getInstList().begin(); - II != NBB->getInstList().end(); II++) + for (BasicBlock::iterator II = NBB->begin(); II != NBB->end(); II++) RemapInstruction(*II, ValueMap); } @@ -214,7 +211,7 @@ bool InlineMethod(BasicBlock::InstListType::iterator CIIt) { TerminatorInst *Br = OrigBB->getTerminator(); assert(Br && Br->getInstType() == Instruction::Br && "splitBasicBlock broken!"); - Br->setOperand(0, ValueMap[CalledMeth->getBasicBlocks().front()]); + Br->setOperand(0, ValueMap[CalledMeth->front()]); // Since we are now done with the CallInst, we can finally delete it. delete CI; @@ -225,10 +222,9 @@ bool InlineMethod(CallInst *CI) { assert(CI->getParent() && "CallInst not embeded in BasicBlock!"); BasicBlock *PBB = CI->getParent(); - BasicBlock::InstListType::iterator CallIt = find(PBB->getInstList().begin(), - PBB->getInstList().end(), - CI); - assert(CallIt != PBB->getInstList().end() && + BasicBlock::iterator CallIt = find(PBB->begin(), PBB->end(), CI); + + assert(CallIt != PBB->end() && "CallInst has parent that doesn't contain CallInst?!?"); return InlineMethod(CallIt); } @@ -241,10 +237,10 @@ static inline bool ShouldInlineMethod(const CallInst *CI, const Method *M) { if (CI->getParent()->getParent() == M) return false; // Don't inline something too big. This is a really crappy heuristic - if (M->getBasicBlocks().size() > 3) return false; + if (M->size() > 3) return false; // Don't inline into something too big. This is a **really** crappy heuristic - if (CI->getParent()->getParent()->getBasicBlocks().size() > 10) return false; + if (CI->getParent()->getParent()->size() > 10) return false; // Go ahead and try just about anything else. return true; @@ -252,8 +248,7 @@ static inline bool ShouldInlineMethod(const CallInst *CI, const Method *M) { static inline bool DoMethodInlining(BasicBlock *BB) { - for (BasicBlock::InstListType::iterator I = BB->getInstList().begin(); - I != BB->getInstList().end(); I++) { + for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) { if ((*I)->getInstType() == Instruction::Call) { // Check to see if we should inline this method CallInst *CI = (CallInst*)*I; @@ -266,15 +261,14 @@ static inline bool DoMethodInlining(BasicBlock *BB) { } bool DoMethodInlining(Method *M) { - Method::BasicBlocksType &BBs = M->getBasicBlocks(); bool Changed = false; // Loop through now and inline instructions a basic block at a time... - for (Method::BasicBlocksType::iterator I = BBs.begin(); I != BBs.end(); ) + for (Method::iterator I = M->begin(); I != M->end(); ) if (DoMethodInlining(*I)) { Changed = true; // Iterator is now invalidated by new basic blocks inserted - I = BBs.begin(); + I = M->begin(); } else { ++I; } diff --git a/lib/Transforms/Scalar/DCE.cpp b/lib/Transforms/Scalar/DCE.cpp index 14ee8d5a6c..5bc3c5b089 100644 --- a/lib/Transforms/Scalar/DCE.cpp +++ b/lib/Transforms/Scalar/DCE.cpp @@ -61,7 +61,7 @@ static bool RemoveUnusedDefs(ValueHolder<ValueSubclass, ItemParentType> &Vals, delete Vals.remove(DI); Changed = true; } else { - DI++; + ++DI; } } return Changed; @@ -79,8 +79,8 @@ static bool RemoveSingularPHIs(BasicBlock *BB) { if (PI == pred_end(BB) || ++PI != pred_end(BB)) return false; // More than one predecessor... - Instruction *I = BB->getInstList().front(); - if (I->getInstType() != Instruction::PHINode) return false; // No PHI nodes + Instruction *I = BB->front(); + if (!I->isPHINode()) return false; // No PHI nodes //cerr << "Killing PHIs from " << BB; //cerr << "Pred #0 = " << *pred_begin(BB); @@ -93,10 +93,10 @@ static bool RemoveSingularPHIs(BasicBlock *BB) { Value *V = PN->getOperand(0); PN->replaceAllUsesWith(V); // Replace PHI node with its single value. - delete BB->getInstList().remove(BB->getInstList().begin()); + delete BB->getInstList().remove(BB->begin()); - I = BB->getInstList().front(); - } while (I->getInstType() == Instruction::PHINode); + I = BB->front(); + } while (I->isPHINode()); return true; // Yes, we nuked at least one phi node } @@ -154,8 +154,8 @@ static void RemovePredecessorFromBlock(BasicBlock *BB, BasicBlock *Pred) { // Okay, now we know that we need to remove predecessor #pred_idx from all // PHI nodes. Iterate over each PHI node fixing them up - BasicBlock::InstListType::iterator II(BB->getInstList().begin()); - for (; (*II)->getInstType() == Instruction::PHINode; ++II) { + BasicBlock::iterator II(BB->begin()); + for (; (*II)->isPHINode(); ++II) { PHINode *PN = (PHINode*)*II; PN->removeIncomingValue(BB); @@ -177,25 +177,36 @@ static void RemovePredecessorFromBlock(BasicBlock *BB, BasicBlock *Pred) { // Assumption: BB is the single predecessor of Succ. |