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 /lib | |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Analysis/IntervalPartition.cpp | 31 | ||||
-rw-r--r-- | lib/Analysis/ModuleAnalyzer.cpp | 33 | ||||
-rw-r--r-- | lib/AsmParser/llvmAsmParser.cpp | 14 | ||||
-rw-r--r-- | lib/AsmParser/llvmAsmParser.y | 14 | ||||
-rw-r--r-- | lib/Bytecode/Reader/ConstantReader.cpp | 4 | ||||
-rw-r--r-- | lib/Bytecode/Reader/Reader.cpp | 17 | ||||
-rw-r--r-- | lib/Bytecode/Writer/SlotCalculator.cpp | 11 | ||||
-rw-r--r-- | lib/Bytecode/Writer/Writer.cpp | 20 | ||||
-rw-r--r-- | lib/Transforms/IPO/InlineSimple.cpp | 44 | ||||
-rw-r--r-- | lib/Transforms/Scalar/DCE.cpp | 88 | ||||
-rw-r--r-- | lib/Transforms/Scalar/SymbolStripping.cpp | 2 | ||||
-rw-r--r-- | lib/VMCore/AsmWriter.cpp | 11 | ||||
-rw-r--r-- | lib/VMCore/BasicBlock.cpp | 6 | ||||
-rw-r--r-- | lib/VMCore/ConstantPool.cpp | 10 | ||||
-rw-r--r-- | lib/VMCore/Function.cpp | 7 | ||||
-rw-r--r-- | lib/VMCore/InstrTypes.cpp | 3 | ||||
-rw-r--r-- | lib/VMCore/Module.cpp | 2 | ||||
-rw-r--r-- | lib/VMCore/SlotCalculator.cpp | 11 | ||||
-rw-r--r-- | lib/VMCore/SymbolTable.cpp | 4 | ||||
-rw-r--r-- | lib/VMCore/Type.cpp | 16 | ||||
-rw-r--r-- | lib/VMCore/Value.cpp | 6 | ||||
-rw-r--r-- | lib/VMCore/Verifier.cpp | 12 | ||||
-rw-r--r-- | lib/VMCore/iCall.cpp | 5 |
23 files changed, 178 insertions, 193 deletions
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. // static void PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) { - assert(BB && Succ && *pred_begin(Succ) == BB && "BB is only pred of Succ" && - ++pred_begin(Succ) == pred_end(Succ)); + assert(Succ->front()->isPHINode() && "Only works on PHId BBs!"); // If there is more than one predecessor, and there are PHI nodes in // the successor, then we need to add incoming edges for the PHI nodes - pred_iterator PI(pred_begin(BB)); - for (; PI != pred_end(BB); ++PI) { - // TODO: - } + // + const vector<BasicBlock*> BBPreds(pred_begin(BB), pred_end(BB)); + + BasicBlock::iterator I = Succ->begin(); + do { // Loop over all of the PHI nodes in the successor BB + PHINode *PN = (PHINode*)*I; + Value *OldVal = PN->removeIncomingValue(BB); + assert(OldVal && "No entry in PHI for Pred BB!"); + + for (vector<BasicBlock*>::const_iterator PredI = BBPreds.begin(), + End = BBPreds.end(); PredI != End; ++PredI) { + // Add an incoming value for each of the new incoming values... + PN->addIncoming(OldVal, *PredI); + } + + ++I; + } while ((*I)->isPHINode()); } static bool DoDCEPass(Method *M) { - Method::BasicBlocksType &BBs = M->getBasicBlocks(); - Method::BasicBlocksType::iterator BBIt, BBEnd = BBs.end(); - if (BBs.begin() == BBEnd) return false; // Nothing to do + Method::iterator BBIt, BBEnd = M->end(); + if (M->begin() == BBEnd) return false; // Nothing to do bool Changed = false; // Loop through now and remove instructions that have no uses... - for (BBIt = BBs.begin(); BBIt != BBEnd; BBIt++) { + for (BBIt = M->begin(); BBIt != BBEnd; ++BBIt) { Changed |= RemoveUnusedDefs((*BBIt)->getInstList(), BasicBlockDCE()); Changed |= RemoveSingularPHIs(*BBIt); } @@ -203,11 +214,11 @@ static bool DoDCEPass(Method *M) { // Loop over all of the basic blocks (except the first one) and remove them // if they are unneeded... // - for (BBIt = BBs.begin(), ++BBIt; BBIt != BBs.end(); ++BBIt) { + for (BBIt = M->begin(), ++BBIt; BBIt != M->end(); ++BBIt) { BasicBlock *BB = *BBIt; assert(BB->getTerminator() && "Degenerate basic block encountered!"); -#if 0 +#if 0 // This is know to basically work? // Remove basic blocks that have no predecessors... which are unreachable. if (pred_begin(BB) == pred_end(BB) && !BB->hasConstantPoolReferences() && 0) { @@ -215,43 +226,46 @@ static bool DoDCEPass(Method *M) { // Loop through all of our successors and make sure they know that one // of their predecessors is going away. - for (succ_iterator SI = succ_begin(BB), EI = succ_end(BB); SI != EI; ++SI) - RemovePredecessorFromBlock(*SI, BB); + for_each(succ_begin(BB), succ_end(BB), + bind_2nd(RemovePredecessorFromBlock, BB)); - while (!BB->getInstList().empty()) { - Instruction *I = BB->getInstList().front(); + while (!BB->empty()) { + Instruction *I = BB->front(); // If this instruction is used, replace uses with an arbitrary // constant value. Because control flow can't get here, we don't care // what we replace the value with. if (!I->use_empty()) ReplaceUsesWithConstant(I); // Remove the instruction from the basic block - delete BB->getInstList().remove(BB->getInstList().begin()); + delete BB->getInstList().remove(BB->begin()); } - delete BBs.remove(BBIt); + delete M->getBasicBlocks().remove(BBIt); --BBIt; // remove puts use on the next block, we want the previous one Changed = true; continue; } +#endif +#if 0 // This has problems // Check to see if this block has no instructions and only a single // successor. If so, replace block references with successor. succ_iterator SI(succ_begin(BB)); if (SI != succ_end(BB) && ++SI == succ_end(BB)) { // One succ? - Instruction *I = BB->getInstList().front(); + Instruction *I = BB->front(); if (I->isTerminator()) { // Terminator is |