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/VMCore | |
parent | 138a124f09de272b2ab93cfd6e2a8a283d18029b (diff) | |
download | external_llvm-7fc9fe34390c66ca58646d09a87f7dbaacb6c1f8.zip external_llvm-7fc9fe34390c66ca58646d09a87f7dbaacb6c1f8.tar.gz external_llvm-7fc9fe34390c66ca58646d09a87f7dbaacb6c1f8.tar.bz2 |
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/VMCore')
-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 |
12 files changed, 40 insertions, 53 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 97affcc..c68cd79 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -178,7 +178,7 @@ bool AssemblyWriter::processInstruction(const Instruction *I) { writeOperand(I->getOperand(op+1), true); } Out << "\n\t]"; - } else if (I->getInstType() == Instruction::PHINode) { + } else if (I->isPHINode()) { Out << " " << Operand->getType(); Out << " ["; writeOperand(Operand, false); Out << ","; @@ -262,7 +262,7 @@ void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType, } else { int Slot = Table.getValSlot(Operand); - if (Operand->getValueType() == Value::ConstantVal) { + if (Operand->isConstant()) { Out << " " << ((ConstPoolVal*)Operand)->getStrValue(); } else { if (Slot >= 0) Out << " %" << Slot; @@ -313,12 +313,11 @@ void WriteToAssembly(const ConstPoolVal *CPV, ostream &o) { // A Constant pool value may have a parent that is either a method or a // module. Untangle this now... // - if (CPV->getParent() == 0 || - CPV->getParent()->getValueType() == Value::MethodVal) { + if (CPV->getParent() == 0 || CPV->getParent()->isMethod()) { SlotTable = new SlotCalculator((Method*)CPV->getParent(), true); } else { - assert(CPV->getParent()->getValueType() == Value::ModuleVal); - SlotTable = new SlotCalculator((Module*)CPV->getParent(), true); + SlotTable = + new SlotCalculator(CPV->getParent()->castModuleAsserting(), true); } AssemblyWriter W(o, *SlotTable); diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp index f60bd46..36ad93d 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/lib/VMCore/BasicBlock.cpp @@ -73,7 +73,7 @@ void BasicBlock::dropAllReferences() { // bool BasicBlock::hasConstantPoolReferences() const { for (use_const_iterator I = use_begin(), E = use_end(); I != E; ++I) - if ((*I)->getValueType() == ConstantVal) + if ((*I)->isConstant()) return true; return false; @@ -91,7 +91,7 @@ bool BasicBlock::hasConstantPoolReferences() const { // cause a degenerate basic block to be formed, having a terminator inside of // the basic block). // -BasicBlock *BasicBlock::splitBasicBlock(InstListType::iterator I) { +BasicBlock *BasicBlock::splitBasicBlock(iterator I) { assert(getTerminator() && "Can't use splitBasicBlock on degenerate BB!"); assert(I != InstList.end() && "Trying to get me to create degenerate basic block!"); @@ -102,7 +102,7 @@ BasicBlock *BasicBlock::splitBasicBlock(InstListType::iterator I) { // to the new basic block... Instruction *Inst = 0; do { - InstListType::iterator EndIt = InstList.end(); + iterator EndIt = end(); Inst = InstList.remove(--EndIt); // Remove from end New->InstList.push_front(Inst); // Add to front } while (Inst != *I); // Loop until we move the specified instruction. diff --git a/lib/VMCore/ConstantPool.cpp b/lib/VMCore/ConstantPool.cpp index d624c8d..77ed50a 100644 --- a/lib/VMCore/ConstantPool.cpp +++ b/lib/VMCore/ConstantPool.cpp @@ -85,9 +85,8 @@ void ConstantPool::delete_all() { void ConstantPool::dropAllReferences() { for (unsigned i = 0; i < Planes.size(); i++) - for (PlaneType::iterator I = Planes[i]->begin(); - I != Planes[i]->end(); I++) - (*I)->dropAllReferences(); + for_each(Planes[i]->begin(), Planes[i]->end(), + mem_fun(&ConstPoolVal::dropAllReferences)); } struct EqualsConstant { @@ -280,10 +279,7 @@ ConstPoolStruct::ConstPoolStruct(const ConstPoolStruct &CPS) // getStrValue implementations string ConstPoolBool::getStrValue() const { - if (Val) - return "true"; - else - return "false"; + return Val ? "true" : "false"; } string ConstPoolSInt::getStrValue() const { diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index 550c4f0..aa0d08b 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -29,8 +29,8 @@ Method::~Method() { dropAllReferences(); // After this it is safe to delete instructions. // TODO: Should remove from the end, not the beginning of vector! - BasicBlocksType::iterator BI = BasicBlocks.begin(); - while ((BI = BasicBlocks.begin()) != BasicBlocks.end()) + iterator BI = begin(); + while ((BI = begin()) != end()) delete BasicBlocks.remove(BI); // Delete all of the method arguments and unlink from symbol table... @@ -70,6 +70,5 @@ const MethodType *Method::getMethodType() const { // delete. // void Method::dropAllReferences() { - for_each(BasicBlocks.begin(), BasicBlocks.end(), - std::mem_fun(&BasicBlock::dropAllReferences)); + for_each(begin(), end(), std::mem_fun(&BasicBlock::dropAllReferences)); } diff --git a/lib/VMCore/InstrTypes.cpp b/lib/VMCore/InstrTypes.cpp index 142019b..baafe0b 100644 --- a/lib/VMCore/InstrTypes.cpp +++ b/lib/VMCore/InstrTypes.cpp @@ -68,8 +68,7 @@ bool PHINode::setOperand(unsigned i, Value *Val) { if (i >= IncomingValues.size()*2) return false; if (i & 1) { - assert(Val->getValueType() == BasicBlockVal && "Not a BB!"); - IncomingValues[i/2].second = (BasicBlock*)Val; + IncomingValues[i/2].second = Val->castBasicBlockAsserting(); } else { IncomingValues[i/2].first = Val; } diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index 4f2eee4..7fa2802 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -37,6 +37,6 @@ Module::~Module() { // void Module::dropAllReferences() { MethodListType::iterator MI = MethodList.begin(); - for (; MI != MethodList.end(); MI++) + for (; MI != MethodList.end(); ++MI) (*MI)->dropAllReferences(); } diff --git a/lib/VMCore/SlotCalculator.cpp b/lib/VMCore/SlotCalculator.cpp index 01fae37..f7eada1 100644 --- a/lib/VMCore/SlotCalculator.cpp +++ b/lib/VMCore/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/VMCore/SymbolTable.cpp b/lib/VMCore/SymbolTable.cpp index 214f41f..07e4b87 100644 --- a/lib/VMCore/SymbolTable.cpp +++ b/lib/VMCore/SymbolTable.cpp @@ -15,9 +15,9 @@ SymbolTable::~SymbolTable() { #ifndef NDEBUG // Only do this in -g mode... bool Good = true; - for (iterator i = begin(); i != end(); i++) { + for (iterator i = begin(); i != end(); ++i) { if (i->second.begin() != i->second.end()) { - for (type_iterator I = i->second.begin(); I != i->second.end(); I++) + for (type_iterator I = i->second.begin(); I != i->second.end(); ++I) cerr << "Value still in symbol table! Type = " << i->first->getName() << " Name = " << I->first << endl; Good = false; diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp index cf16309..5ae2cf9 100644 --- a/lib/VMCore/Type.cpp +++ b/lib/VMCore/Type.cpp @@ -157,13 +157,13 @@ PointerType::PointerType(const Type *E) const MethodType *MethodType::getMethodType(const Type *ReturnType, const vector<const Type*> &Params) { static vector<const MethodType*> ExistingMethodTypesCache; - for (unsigned i = 0; i < ExistingMethodTypesCache.size(); i++) { + for (unsigned i = 0; i < ExistingMethodTypesCache.size(); ++i) { const MethodType *T = ExistingMethodTypesCache[i]; if (T->getReturnType() == ReturnType) { const ParamTypes &EParams = T->getParamTypes(); ParamTypes::const_iterator I = Params.begin(); ParamTypes::const_iterator J = EParams.begin(); - for (; I != Params.end() && J != EParams.end(); I++, J++) + for (; I != Params.end() && J != EParams.end(); ++I, ++J) if (*I != *J) break; // These types aren't equal! if (I == Params.end() && J == EParams.end()) { @@ -189,7 +189,7 @@ const MethodType *MethodType::getMethodType(const Type *ReturnType, // Calculate the string name for the new type... string Name = ReturnType->getName() + " ("; for (ParamTypes::const_iterator I = Params.begin(); - I != Params.end(); I++) { + I != Params.end(); ++I) { if (I != Params.begin()) Name += ", "; Name += (*I)->getName(); @@ -211,7 +211,7 @@ const ArrayType *ArrayType::getArrayType(const Type *ElementType, static vector<const ArrayType*> ExistingTypesCache; // Search cache for value... - for (unsigned i = 0; i < ExistingTypesCache.size(); i++) { + for (unsigned i = 0; i < ExistingTypesCache.size(); ++i) { const ArrayType *T = ExistingTypesCache[i]; if (T->getElementType() == ElementType && @@ -237,13 +237,13 @@ const ArrayType *ArrayType::getArrayType(const Type *ElementType, const StructType *StructType::getStructType(const ElementTypes &ETypes) { static vector<const StructType*> ExistingStructTypesCache; - for (unsigned i = 0; i < ExistingStructTypesCache.size(); i++) { + for (unsigned i = 0; i < ExistingStructTypesCache.size(); ++i) { const StructType *T = ExistingStructTypesCache[i]; const ElementTypes &Elements = T->getElementTypes(); ElementTypes::const_iterator I = ETypes.begin(); ElementTypes::const_iterator J = Elements.begin(); - for (; I != ETypes.end() && J != Elements.end(); I++, J++) + for (; I != ETypes.end() && J != Elements.end(); ++I, ++J) if (*I != *J) break; // These types aren't equal! if (I == ETypes.end() && J == Elements.end()) { @@ -269,7 +269,7 @@ const StructType *StructType::getStructType(const ElementTypes &ETypes) { // Calculate the string name for the new type... string Name = "{ "; for (ElementTypes::const_iterator I = ETypes.begin(); - I != ETypes.end(); I++) { + I != ETypes.end(); ++I) { if (I != ETypes.begin()) Name += ", "; Name += (*I)->getName(); @@ -290,7 +290,7 @@ const PointerType *PointerType::getPointerType(const Type *ValueType) { static vector<const PointerType*> ExistingTypesCache; // Search cache for value... - for (unsigned i = 0; i < ExistingTypesCache.size(); i++) { + for (unsigned i = 0; i < ExistingTypesCache.size(); ++i) { const PointerType *T = ExistingTypesCache[i]; if (T->getValueType() == ValueType) diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index ee642f6..79d8e0a 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -34,7 +34,7 @@ Value::~Value() { // a <badref> // if (Uses.begin() != Uses.end()) { - for (use_const_iterator I = Uses.begin(); I != Uses.end(); I++) + for (use_const_iterator I = Uses.begin(); I != Uses.end(); ++I) cerr << "Use still stuck around after Def is destroyed:" << *I << endl; } #endif @@ -88,7 +88,7 @@ User::User(const Type *Ty, ValueTy vty, const string &name) void User::replaceUsesOfWith(Value *From, Value *To) { if (From == To) return; // Duh what? - for (unsigned OpNum = 0; Value *D = getOperand(OpNum); OpNum++) { + for (unsigned OpNum = 0; Value *D = getOperand(OpNum); ++OpNum) { if (D == From) { // Okay, this operand is pointing to our fake def. // The side effects of this setOperand call include linking to // "To", adding "this" to the uses list of To, and @@ -140,7 +140,7 @@ bool SymTabValue::hasSymbolTable() const { if (!SymTab) return false; for (SymbolTable::const_iterator I = SymTab->begin(); - I != SymTab->end(); I++) { + I != SymTab->end(); ++I) { if (I->second.begin() != I->second.end()) return true; // Found nonempty type plane! } diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index 820fa5c..5b6654d 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -71,10 +71,9 @@ static bool verify(const BasicBlock *BB, vector<string> &ErrorMsgs) { bool verify(const Method *M, vector<string> &ErrorMsgs) { bool Bad = false; - for (Method::BasicBlocksType::const_iterator BBIt = M->getBasicBlocks().begin(); - BBIt != M->getBasicBlocks().end(); BBIt++) { + for (Method::const_iterator BBIt = M->begin(); + BBIt != M->end(); ++BBIt) Bad |= verify(*BBIt, ErrorMsgs); - } return Bad; } @@ -84,11 +83,8 @@ bool verify(const Module *C, vector<string> &ErrorMsgs) { assert(Type::FirstDerivedTyID-1 < sizeof(long)*8 && "Resize ValidTypes table to handle more than 32 primitive types!"); - for (Module::MethodListType::const_iterator MI = C->getMethodList().begin(); - MI != C->getMethodList().end(); MI++) { - const Method *M = *MI; - Bad |= verify(M, ErrorMsgs); - } + for (Module::const_iterator MI = C->begin(); MI != C->end(); ++MI) + Bad |= verify(*MI, ErrorMsgs); return Bad; } diff --git a/lib/VMCore/iCall.cpp b/lib/VMCore/iCall.cpp index 9ff6bb6..7632798 100644 --- a/lib/VMCore/iCall.cpp +++ b/lib/VMCore/iCall.cpp @@ -14,7 +14,7 @@ CallInst::CallInst(Method *m, vector<Value*> ¶ms, const MethodType* MT = M->getMethodType(); const MethodType::ParamTypes &PL = MT->getParamTypes(); - assert(params.size() == PL.size()); + assert(params.size() == PL.size() && "Calling a function with bad signature"); #ifndef NDEBUG MethodType::ParamTypes::const_iterator It = PL.begin(); #endif @@ -38,8 +38,7 @@ void CallInst::dropAllReferences() { bool CallInst::setOperand(unsigned i, Value *Val) { if (i > Params.size()) return false; if (i == 0) { - assert(Val->getValueType() == Value::MethodVal); - M = (Method*)Val; + M = Val->castMethodAsserting(); } else { // TODO: assert = method arg type Params[i-1] = Val; |