diff options
author | Chris Lattner <sabre@nondot.org> | 2002-06-25 16:13:24 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-06-25 16:13:24 +0000 |
commit | 7e70829632f82de15db187845666aaca6e04b792 (patch) | |
tree | 48dd2d804e7ebec9a3cbd8bf229cb2a2aa20dce5 /lib/VMCore | |
parent | 0b12b5f50ec77a8bd01b92d287c52d748619bb4b (diff) | |
download | external_llvm-7e70829632f82de15db187845666aaca6e04b792.zip external_llvm-7e70829632f82de15db187845666aaca6e04b792.tar.gz external_llvm-7e70829632f82de15db187845666aaca6e04b792.tar.bz2 |
MEGAPATCH checkin.
For details, See: docs/2002-06-25-MegaPatchInfo.txt
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2779 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/AsmWriter.cpp | 148 | ||||
-rw-r--r-- | lib/VMCore/BasicBlock.cpp | 78 | ||||
-rw-r--r-- | lib/VMCore/Constants.cpp | 1 | ||||
-rw-r--r-- | lib/VMCore/Dominators.cpp | 18 | ||||
-rw-r--r-- | lib/VMCore/Function.cpp | 44 | ||||
-rw-r--r-- | lib/VMCore/InstrTypes.cpp | 1 | ||||
-rw-r--r-- | lib/VMCore/Instruction.cpp | 3 | ||||
-rw-r--r-- | lib/VMCore/Module.cpp | 45 | ||||
-rw-r--r-- | lib/VMCore/Pass.cpp | 26 | ||||
-rw-r--r-- | lib/VMCore/PassManagerT.h | 38 | ||||
-rw-r--r-- | lib/VMCore/SlotCalculator.cpp | 28 | ||||
-rw-r--r-- | lib/VMCore/SymbolTable.cpp | 3 | ||||
-rw-r--r-- | lib/VMCore/SymbolTableListTraitsImpl.h | 88 | ||||
-rw-r--r-- | lib/VMCore/ValueHolderImpl.h | 222 | ||||
-rw-r--r-- | lib/VMCore/iBranch.cpp | 13 | ||||
-rw-r--r-- | lib/VMCore/iSwitch.cpp | 3 |
16 files changed, 324 insertions, 435 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index fe66575..9f826fb 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -13,16 +13,12 @@ #include "llvm/SlotCalculator.h" #include "llvm/DerivedTypes.h" #include "llvm/Module.h" -#include "llvm/Function.h" -#include "llvm/GlobalVariable.h" -#include "llvm/BasicBlock.h" #include "llvm/Constants.h" #include "llvm/iMemory.h" #include "llvm/iTerminators.h" #include "llvm/iPHINode.h" #include "llvm/iOther.h" #include "llvm/SymbolTable.h" -#include "llvm/Argument.h" #include "Support/StringExtras.h" #include "Support/STLExtras.h" #include <algorithm> @@ -317,7 +313,7 @@ static void WriteConstantInt(ostream &Out, const Constant *CV, bool PrintName, } else if (isa<ConstantPointerNull>(CV)) { Out << "null"; - } else if (ConstantPointerRef *PR = dyn_cast<ConstantPointerRef>(CV)) { + } else if (const ConstantPointerRef *PR = dyn_cast<ConstantPointerRef>(CV)) { const GlobalValue *V = PR->getValue(); if (V->hasName()) { Out << "%" << V->getName(); @@ -414,7 +410,7 @@ public: inline void write(const GlobalVariable *G) { printGlobal(G); } inline void write(const Function *F) { printFunction(F); } inline void write(const BasicBlock *BB) { printBasicBlock(BB); } - inline void write(const Instruction *I) { printInstruction(I); } + inline void write(const Instruction *I) { printInstruction(*I); } inline void write(const Constant *CPV) { printConstant(CPV); } inline void write(const Type *Ty) { printType(Ty); } @@ -428,7 +424,7 @@ private : void printFunction(const Function *F); void printArgument(const Argument *FA); void printBasicBlock(const BasicBlock *BB); - void printInstruction(const Instruction *I); + void printInstruction(const Instruction &I); // printType - Go to extreme measures to attempt to print out a short, // symbolic version of a type name. @@ -444,7 +440,7 @@ private : // printInfoComment - Print a little comment after the instruction indicating // which slot it occupies. - void printInfoComment(const Value *V); + void printInfoComment(const Value &V); }; @@ -452,7 +448,7 @@ private : // without considering any symbolic types that we may have equal to it. // ostream &AssemblyWriter::printTypeAtLeastOneLevel(const Type *Ty) { - if (FunctionType *FTy = dyn_cast<FunctionType>(Ty)) { + if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty)) { printType(FTy->getReturnType()) << " ("; for (FunctionType::ParamTypes::const_iterator I = FTy->getParamTypes().begin(), @@ -466,7 +462,7 @@ ostream &AssemblyWriter::printTypeAtLeastOneLevel(const Type *Ty) { Out << "..."; } Out << ")"; - } else if (StructType *STy = dyn_cast<StructType>(Ty)) { + } else if (const StructType *STy = dyn_cast<StructType>(Ty)) { Out << "{ "; for (StructType::ElementTypes::const_iterator I = STy->getElementTypes().begin(), @@ -476,12 +472,12 @@ ostream &AssemblyWriter::printTypeAtLeastOneLevel(const Type *Ty) { printType(*I); } Out << " }"; - } else if (PointerType *PTy = dyn_cast<PointerType>(Ty)) { + } else if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) { printType(PTy->getElementType()) << "*"; - } else if (ArrayType *ATy = dyn_cast<ArrayType>(Ty)) { + } else if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) { Out << "[" << ATy->getNumElements() << " x "; printType(ATy->getElementType()) << "]"; - } else if (OpaqueType *OTy = dyn_cast<OpaqueType>(Ty)) { + } else if (const OpaqueType *OTy = dyn_cast<OpaqueType>(Ty)) { Out << OTy->getDescription(); } else { assert(Ty->isPrimitiveType() && "Unknown derived type!"); @@ -503,13 +499,14 @@ void AssemblyWriter::printModule(const Module *M) { if (M->hasSymbolTable()) printSymbolTable(*M->getSymbolTable()); - for_each(M->gbegin(), M->gend(), - bind_obj(this, &AssemblyWriter::printGlobal)); + for (Module::const_giterator I = M->gbegin(), E = M->gend(); I != E; ++I) + printGlobal(I); Out << "\nimplementation ; Functions:\n"; // Output all of the functions... - for_each(M->begin(), M->end(), bind_obj(this,&AssemblyWriter::printFunction)); + for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) + printFunction(I); } void AssemblyWriter::printGlobal(const GlobalVariable *GV) { @@ -524,7 +521,7 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) { if (GV->hasInitializer()) writeOperand(GV->getInitializer(), false, false); - printInfoComment(GV); + printInfoComment(*GV); Out << "\n"; } @@ -566,50 +563,49 @@ void AssemblyWriter::printConstant(const Constant *CPV) { // Write the value out now... writeOperand(CPV, true, false); - printInfoComment(CPV); + printInfoComment(*CPV); Out << "\n"; } // printFunction - Print all aspects of a function. // -void AssemblyWriter::printFunction(const Function *M) { +void AssemblyWriter::printFunction(const Function *F) { // Print out the return type and name... - Out << "\n" << (M->isExternal() ? "declare " : "") - << (M->hasInternalLinkage() ? "internal " : ""); - printType(M->getReturnType()) << " %" << M->getName() << "("; - Table.incorporateFunction(M); + Out << "\n" << (F->isExternal() ? "declare " : "") + << (F->hasInternalLinkage() ? "internal " : ""); + printType(F->getReturnType()) << " %" << F->getName() << "("; + Table.incorporateFunction(F); // Loop over the arguments, printing them... - const FunctionType *MT = M->getFunctionType(); + const FunctionType *FT = F->getFunctionType(); - if (!M->isExternal()) { - for_each(M->getArgumentList().begin(), M->getArgumentList().end(), - bind_obj(this, &AssemblyWriter::printArgument)); + if (!F->isExternal()) { + for(Function::const_aiterator I = F->abegin(), E = F->aend(); I != E; ++I) + printArgument(I); } else { // Loop over the arguments, printing them... - const FunctionType *MT = M->getFunctionType(); - for (FunctionType::ParamTypes::const_iterator I = MT->getParamTypes().begin(), - E = MT->getParamTypes().end(); I != E; ++I) { - if (I != MT->getParamTypes().begin()) Out << ", "; + for (FunctionType::ParamTypes::const_iterator I = FT->getParamTypes().begin(), + E = FT->getParamTypes().end(); I != E; ++I) { + if (I != FT->getParamTypes().begin()) Out << ", "; printType(*I); } } // Finish printing arguments... - if (MT->isVarArg()) { - if (MT->getParamTypes().size()) Out << ", "; + if (FT->isVarArg()) { + if (FT->getParamTypes().size()) Out << ", "; Out << "..."; // Output varargs portion of signature! } Out << ")"; - if (M->isExternal()) { + if (F->isExternal()) { Out << "\n"; } else { Out << " {"; // Output all of its basic blocks... for the function - for_each(M->begin(), M->end(), - bind_obj(this, &AssemblyWriter::printBasicBlock)); + for (Function::const_iterator I = F->begin(), E = F->end(); I != E; ++I) + printBasicBlock(I); Out << "}\n"; } @@ -622,7 +618,7 @@ void AssemblyWriter::printFunction(const Function *M) { // void AssemblyWriter::printArgument(const Argument *Arg) { // Insert commas as we go... the first arg doesn't get a comma - if (Arg != Arg->getParent()->getArgumentList().front()) Out << ", "; + if (Arg != &Arg->getParent()->afront()) Out << ", "; // Output type... printType(Arg->getType()); @@ -653,72 +649,72 @@ void AssemblyWriter::printBasicBlock(const BasicBlock *BB) { Out << "\n"; // Output all of the instructions in the basic block... - for_each(BB->begin(), BB->end(), - bind_obj(this, &AssemblyWriter::printInstruction)); + for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) + printInstruction(*I); } // printInfoComment - Print a little comment after the instruction indicating // which slot it occupies. // -void AssemblyWriter::printInfoComment(const Value *V) { - if (V->getType() != Type::VoidTy) { +void AssemblyWriter::printInfoComment(const Value &V) { + if (V.getType() != Type::VoidTy) { Out << "\t\t; <"; - printType(V->getType()) << ">"; + printType(V.getType()) << ">"; - if (!V->hasName()) { - int Slot = Table.getValSlot(V); // Print out the def slot taken... + if (!V.hasName()) { + int Slot = Table.getValSlot(&V); // Print out the def slot taken... if (Slot >= 0) Out << ":" << Slot; else Out << ":<badref>"; } - Out << " [#uses=" << V->use_size() << "]"; // Output # uses + Out << " [#uses=" << V.use_size() << "]"; // Output # uses } } // printInstruction - This member is called for each Instruction in a methd. // -void AssemblyWriter::printInstruction(const Instruction *I) { +void AssemblyWriter::printInstruction(const Instruction &I) { Out << "\t"; // Print out name if it exists... - if (I && I->hasName()) - Out << "%" << I->getName() << " = "; + if (I.hasName()) + Out << "%" << I.getName() << " = "; // Print out the opcode... - Out << I->getOpcodeName(); + Out << I.getOpcodeName(); // Print out the type of the operands... - const Value *Operand = I->getNumOperands() ? I->getOperand(0) : 0; + const Value *Operand = I.getNumOperands() ? I.getOperand(0) : 0; // Special case conditional branches to swizzle the condition out to the front - if (isa<BranchInst>(I) && I->getNumOperands() > 1) { - writeOperand(I->getOperand(2), true); + if (isa<BranchInst>(I) && I.getNumOperands() > 1) { + writeOperand(I.getOperand(2), true); Out << ","; writeOperand(Operand, true); Out << ","; - writeOperand(I->getOperand(1), true); + writeOperand(I.getOperand(1), true); } else if (isa<SwitchInst>(I)) { // Special case switch statement to get formatting nice and correct... - writeOperand(Operand , true); Out << ","; - writeOperand(I->getOperand(1), true); Out << " ["; + writeOperand(Operand , true); Out << ","; + writeOperand(I.getOperand(1), true); Out << " ["; - for (unsigned op = 2, Eop = I->getNumOperands(); op < Eop; op += 2) { + for (unsigned op = 2, Eop = I.getNumOperands(); op < Eop; op += 2) { Out << "\n\t\t"; - writeOperand(I->getOperand(op ), true); Out << ","; - writeOperand(I->getOperand(op+1), true); + writeOperand(I.getOperand(op ), true); Out << ","; + writeOperand(I.getOperand(op+1), true); } Out << "\n\t]"; } else if (isa<PHINode>(I)) { Out << " "; - printType(I->getType()); + printType(I.getType()); Out << " "; - for (unsigned op = 0, Eop = I->getNumOperands(); op < Eop; op += 2) { + for (unsigned op = 0, Eop = I.getNumOperands(); op < Eop; op += 2) { if (op) Out << ", "; Out << "["; - writeOperand(I->getOperand(op ), false); Out << ","; - writeOperand(I->getOperand(op+1), false); Out << " ]"; + writeOperand(I.getOperand(op ), false); Out << ","; + writeOperand(I.getOperand(op+1), false); Out << " ]"; } } else if (isa<ReturnInst>(I) && !Operand) { Out << " void"; @@ -740,21 +736,21 @@ void AssemblyWriter::printInstruction(const Instruction *I) { writeOperand(Operand, true); } Out << "("; - if (I->getNumOperands() > 1) writeOperand(I->getOperand(1), true); - for (unsigned op = 2, Eop = I->getNumOperands(); op < Eop; ++op) { + if (I.getNumOperands() > 1) writeOperand(I.getOperand(1), true); + for (unsigned op = 2, Eop = I.getNumOperands(); op < Eop; ++op) { Out << ","; - writeOperand(I->getOperand(op), true); + writeOperand(I.getOperand(op), true); } Out << " )"; - } else if (const InvokeInst *II = dyn_cast<InvokeInst>(I)) { + } else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I)) { // TODO: Should try to print out short form of the Invoke instruction writeOperand(Operand, true); Out << "("; - if (I->getNumOperands() > 3) writeOperand(I->getOperand(3), true); - for (unsigned op = 4, Eop = I->getNumOperands(); op < Eop; ++op) { + if (I.getNumOperands() > 3) writeOperand(I.getOperand(3), true); + for (unsigned op = 4, Eop = I.getNumOperands(); op < Eop; ++op) { Out << ","; - writeOperand(I->getOperand(op), true); + writeOperand(I.getOperand(op), true); } Out << " )\n\t\t\tto"; @@ -762,7 +758,7 @@ void AssemblyWriter::printInstruction(const Instruction *I) { Out << " except"; writeOperand(II->getExceptionalDest(), true); - } else if (const AllocationInst *AI = dyn_cast<AllocationInst>(I)) { + } else if (const AllocationInst *AI = dyn_cast<AllocationInst>(&I)) { Out << " "; printType(AI->getType()->getElementType()); if (AI->isArrayAllocation()) { @@ -772,7 +768,7 @@ void AssemblyWriter::printInstruction(const Instruction *I) { } else if (isa<CastInst>(I)) { if (Operand) writeOperand(Operand, true); Out << " to "; - printType(I->getType()); + printType(I.getType()); } else if (Operand) { // Print the normal way... // PrintAllTypes - Instructions who have operands of all the same type @@ -781,8 +777,8 @@ void AssemblyWriter::printInstruction(const Instruction *I) { bool PrintAllTypes = false; const Type *TheType = Operand->getType(); - for (unsigned i = 1, E = I->getNumOperands(); i != E; ++i) { - Operand = I->getOperand(i); + for (unsigned i = 1, E = I.getNumOperands(); i != E; ++i) { + Operand = I.getOperand(i); if (Operand->getType() != TheType) { PrintAllTypes = true; // We have differing types! Print them all! break; @@ -794,12 +790,12 @@ void AssemblyWriter::printInstruction(const Instruction *I) { if (!PrintAllTypes) { Out << " "; - printType(I->getOperand(0)->getType()); + printType(I.getOperand(0)->getType()); } - for (unsigned i = 0, E = I->getNumOperands(); i != E; ++i) { + for (unsigned i = 0, E = I.getNumOperands(); i != E; ++i) { if (i) Out << ","; - writeOperand(I->getOperand(i), PrintAllTypes); + writeOperand(I.getOperand(i), PrintAllTypes); } } diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp index 512ddb5..39ffdea 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/lib/VMCore/BasicBlock.cpp @@ -4,29 +4,61 @@ // //===----------------------------------------------------------------------===// -#include "ValueHolderImpl.h" +#include "llvm/BasicBlock.h" #include "llvm/iTerminators.h" #include "llvm/Type.h" #include "llvm/Support/CFG.h" #include "llvm/Constant.h" #include "llvm/iPHINode.h" +#include "llvm/SymbolTable.h" #include "llvm/CodeGen/MachineInstr.h" +#include "SymbolTableListTraitsImpl.h" +#include <algorithm> -// Instantiate Templates - This ugliness is the price we have to pay -// for having a ValueHolderImpl.h file seperate from ValueHolder.h! :( +// DummyInst - An instance of this class is used to mark the end of the +// instruction list. This is not a real instruction. // -template class ValueHolder<Instruction, BasicBlock, Function>; +struct DummyInst : public Instruction { + DummyInst() : Instruction(Type::VoidTy, NumOtherOps) {} + + virtual Instruction *clone() const { assert(0 && "Cannot clone EOL");abort();} + virtual const char *getOpcodeName() const { return "*end-of-list-inst*"; } + + // Methods for support type inquiry through isa, cast, and dyn_cast... + static inline bool classof(const DummyInst *) { return true; } + static inline bool classof(const Instruction *I) { + return I->getOpcode() == NumOtherOps; + } + static inline bool classof(const Value *V) { + return isa<Instruction>(V) && classof(cast<Instruction>(V)); + } +}; + +Instruction *ilist_traits<Instruction>::createNode() { + return new DummyInst(); +} +iplist<Instruction> &ilist_traits<Instruction>::getList(BasicBlock *BB) { + return BB->getInstList(); +} + +// Explicit instantiation of SymbolTableListTraits since some of the methods +// are not in the public header file... +template SymbolTableListTraits<Instruction, BasicBlock, Function>; + BasicBlock::BasicBlock(const std::string &name, Function *Parent) - : Value(Type::LabelTy, Value::BasicBlockVal, name), InstList(this, 0), + : Value(Type::LabelTy, Value::BasicBlockVal, name), machineInstrVec(new MachineCodeForBasicBlock) { + // Initialize the instlist... + InstList.setItemParent(this); + if (Parent) - Parent->getBasicBlocks().push_back(this); + Parent->getBasicBlockList().push_back(this); } BasicBlock::~BasicBlock() { dropAllReferences(); - InstList.delete_all(); + InstList.clear(); delete machineInstrVec; } @@ -40,33 +72,19 @@ void BasicBlock::setName(const std::string &name, SymbolTable *ST) { if (P && hasName()) P->getSymbolTable()->insert(this); } -void BasicBlock::setParent(Function *parent) { - if (getParent() && hasName()) - getParent()->getSymbolTable()->remove(this); - - InstList.setParent(parent); - - if (getParent() && hasName()) - getParent()->getSymbolTableSure()->insert(this); -} - TerminatorInst *BasicBlock::getTerminator() { if (InstList.empty()) return 0; - Instruction *T = InstList.back(); - if (isa<TerminatorInst>(T)) return cast<TerminatorInst>(T); - return 0; + return dyn_cast<TerminatorInst>(&InstList.back()); } const TerminatorInst *const BasicBlock::getTerminator() const { if (InstList.empty()) return 0; - if (const TerminatorInst *TI = dyn_cast<TerminatorInst>(InstList.back())) - return TI; - return 0; + return dyn_cast<TerminatorInst>(&InstList.back()); } void BasicBlock::dropAllReferences() { - for_each(InstList.begin(), InstList.end(), - std::mem_fun(&Instruction::dropAllReferences)); + for(iterator I = begin(), E = end(); I != E; ++I) + I->dropAllReferences(); } // hasConstantReferences() - This predicate is true if there is a @@ -123,7 +141,7 @@ void BasicBlock::removePredecessor(BasicBlock *Pred) { if (max_idx <= 2) { // <= Two predecessors BEFORE I remove one? // Yup, loop through and nuke the PHI nodes - while (PHINode *PN = dyn_cast<PHINode>(front())) { + while (PHINode *PN = dyn_cast<PHINode>(&front())) { PN->removeIncomingValue(Pred); // Remove the predecessor first... assert(PN->getNumIncomingValues() == max_idx-1 && @@ -134,12 +152,12 @@ void BasicBlock::removePredecessor(BasicBlock *Pred) { PN->replaceAllUsesWith(PN->getOperand(0)); else // Otherwise there are no incoming values/edges, replace with dummy PN->replaceAllUsesWith(Constant::getNullValue(PN->getType())); - delete getInstList().remove(begin()); // Remove the PHI node + getInstList().pop_front(); // Remove the PHI node } } else { // Okay, now we know that we need to remove predecessor #pred_idx from all // PHI nodes. Iterate over each PHI node fixing them up - for (iterator II = begin(); PHINode *PN = dyn_cast<PHINode>(*II); ++II) + for (iterator II = begin(); PHINode *PN = dyn_cast<PHINode>(&*II); ++II) PN->removeIncomingValue(Pred); } } @@ -170,7 +188,7 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I) { 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. + } while (Inst != &*I); // Loop until we move the specified instruction. // Add a branch instruction to the newly formed basic block. InstList.push_back(new BranchInst(New)); @@ -186,7 +204,7 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I) { // incoming values... BasicBlock *Successor = *I; for (BasicBlock::iterator II = Successor->begin(); - PHINode *PN = dyn_cast<PHINode>(*II); ++II) { + PHINode *PN = dyn_cast<PHINode>(&*II); ++II) { int IDX = PN->getBasicBlockIndex(this); while (IDX != -1) { PN->setIncomingBlock((unsigned)IDX, New); diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 7487bb4..dcce830 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -8,7 +8,6 @@ #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/SymbolTable.h" -#include "llvm/GlobalValue.h" #include "llvm/Module.h" #include "llvm/SlotCalculator.h" #include "Support/StringExtras.h" diff --git a/lib/VMCore/Dominators.cpp b/lib/VMCore/Dominators.cpp index ca0b64a..caff1f1 100644 --- a/lib/VMCore/Dominators.cpp +++ b/lib/VMCore/Dominators.cpp @@ -21,7 +21,7 @@ using std::set; AnalysisID DominatorSet::ID(AnalysisID::create<DominatorSet>(), true); AnalysisID DominatorSet::PostDomID(AnalysisID::create<DominatorSet>(), true); -bool DominatorSet::runOnFunction(Function *F) { +bool DominatorSet::runOnFunction(Function &F) { Doms.clear(); // Reset from the last time we were run... if (isPostDominator()) @@ -40,17 +40,17 @@ bool DominatorSet::dominates(Instruction *A, Instruction *B) const { // Loop through the basic block until we find A or B. BasicBlock::iterator I = BBA->begin(); - for (; *I != A && *I != B; ++I) /*empty*/; + for (; &*I != A && &*I != B; ++I) /*empty*/; // A dominates B if it is found first in the basic block... - return *I == A; + return &*I == A; } // calcForwardDominatorSet - This method calculates the forward dominator sets // for the specified function. // -void DominatorSet::calcForwardDominatorSet(Function *M) { - Root = M->getEntryNode(); +void DominatorSet::calcForwardDominatorSet(Function &F) { + Root = &F.getEntryNode(); assert(pred_begin(Root) == pred_end(Root) && "Root node has predecessors in function!"); @@ -59,7 +59,7 @@ void DominatorSet::calcForwardDominatorSet(Function *M) { Changed = false; DomSetType WorkingSet; - df_iterator<Function*> It = df_begin(M), End = df_end(M); + df_iterator<Function*> It = df_begin(&F), End = df_end(&F); for ( ; It != End; ++It) { BasicBlock *BB = *It; pred_iterator PI = pred_begin(BB), PEnd = pred_end(BB); @@ -93,7 +93,7 @@ void DominatorSet::calcForwardDominatorSet(Function *M) { // only have a single exit node (return stmt), then calculates the post // dominance sets for the function. // -void DominatorSet::calcPostDominatorSet(Function *F) { +void DominatorSet::calcPostDominatorSet(Function &F) { // Since we require that the unify all exit nodes pass has been run, we know // that there can be at most one return instruction in the function left. // Get it. @@ -101,8 +101,8 @@ void DominatorSet::calcPostDominatorSet(Function *F) { Root = getAnalysis<UnifyFunctionExitNodes>().getExitNode(); if (Root == 0) { // No exit node for the function? Postdomsets are all empty - for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) - Doms[*FI] = DomSetType(); + for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) + Doms[FI] = DomSetType(); return; } diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index a91948f..f7d7953 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -12,7 +12,24 @@ #include "llvm/BasicBlock.h" #include "llvm/iOther.h" #include "llvm/Argument.h" -#include "ValueHolderImpl.h" +#include "SymbolTableListTraitsImpl.h" + +iplist<BasicBlock> &ilist_traits<BasicBlock>::getList(Function *F) { + return F->getBasicBlockList(); +} + +Argument *ilist_traits<Argument>::createNode() { + return new Argument(Type::IntTy); +} + +iplist<Argument> &ilist_traits<Argument>::getList(Function *F) { + return F->getArgumentList(); +} + +// Explicit instantiations of SymbolTableListTraits since some of the methods +// are not in the public header file... +template SymbolTableListTraits<Argument, Function, Function>; +template SymbolTableListTraits<BasicBlock, Function, Function>; //===----------------------------------------------------------------------===// // Argument Implementation @@ -28,36 +45,28 @@ void Argument::setName(const std::string &name, SymbolTable *ST) { if (P && hasName()) P->getSymbolTable()->insert(this); } - - //===----------------------------------------------------------------------===// // Function Implementation //===----------------------------------------------------------------------===// -// Instantiate Templates - This ugliness is the price we have to pay -// for having a ValueHolderImpl.h file seperate from ValueHolder.h! :( -// -template class ValueHolder<Argument , Function, Function>; -template class ValueHolder<BasicBlock, Function, Function>; - Function::Function(const FunctionType *Ty, bool isInternal, const std::string &name) - : GlobalValue(PointerType::get(Ty), Value::FunctionVal, isInternal, name), - BasicBlocks(this), ArgumentList(this, this) { + : GlobalValue(PointerType::get(Ty), Value::FunctionVal, isInternal, name) { + BasicBlocks.setItemParent(this); + BasicBlocks.setParent(this); + ArgumentList.setItemParent(this); + ArgumentList.setParent(this); ParentSymTab = SymTab = 0; } Function::~Function() { dropAllReferences(); // After this it is safe to delete instructions. - // TODO: Should remove from the end, not the beginning of vector! - iterator BI = begin(); - while ((BI = begin()) != end()) - delete BasicBlocks.remove(BI); + BasicBlocks.clear(); // Delete all basic blocks... // Delete all of the method arguments and unlink from symbol table... - ArgumentList.delete_all(); + ArgumentList.clear(); ArgumentList.setParent(0); delete SymTab; } @@ -118,7 +127,8 @@ bool Function::hasSymbolTable() const { // delete. // void Function::dropAllReferences() { - for_each(begin(), end(), std::mem_fun(&BasicBlock::dropAllReferences)); + for (iterator I = begin(), E = end(); I != E; ++I) + I->dropAllReferences(); } //===----------------------------------------------------------------------===// diff --git a/lib/VMCore/InstrTypes.cpp b/lib/VMCore/InstrTypes.cpp index 6fb1869..d167669 100644 --- a/lib/VMCore/InstrTypes.cpp +++ b/lib/VMCore/InstrTypes.cpp @@ -6,7 +6,6 @@ #include "llvm/iOther.h" #include "llvm/iPHINode.h" -#include "llvm/BasicBlock.h" #include "llvm/Function.h" #include "llvm/SymbolTable.h" #include "llvm/Type.h" diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp index 9cb493a..737af5b 100644 --- a/lib/VMCore/Instruction.cpp +++ b/lib/VMCore/Instruction.cpp @@ -4,10 +4,9 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Instruction.h" -#include "llvm/BasicBlock.h" #include "llvm/Function.h" #include "llvm/SymbolTable.h" +#include "llvm/Type.h" Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name) : User(ty, Value::InstructionVal, Name) { diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index 0d25691..b8cffdb 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -11,14 +11,29 @@ #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "Support/STLExtras.h" -#include "ValueHolderImpl.h" +#include "SymbolTableListTraitsImpl.h" +#include <algorithm> #include <map> -// Instantiate Templates - This ugliness is the price we have to pay -// for having a DefHolderImpl.h file seperate from DefHolder.h! :( -// -template class ValueHolder<GlobalVariable, Module, Module>; -template class ValueHolder<Function, Module, Module>; +Function *ilist_traits<Function>::createNode() { + return new Function(FunctionType::get(Type::VoidTy,std::vector<const Type*>(), + false), false); +} +GlobalVariable *ilist_traits<GlobalVariable>::createNode() { + return new GlobalVariable(Type::IntTy, false, false); +} + +iplist<Function> &ilist_traits<Function>::getList(Module *M) { + return M->getFunctionList(); +} +iplist<GlobalVariable> &ilist_traits<GlobalVariable>::getList(Module *M) { + return M->getGlobalList(); +} + +// Explicit instantiations of SymbolTableListTraits since some of the methods +// are not in the public header file... +template SymbolTableListTraits<GlobalVariable, Module, Module>; +template SymbolTableListTraits<Function, Module, Module>; // Define the GlobalValueRefMap as a struct that wraps a map so that we don't // have Module.h depend on <map> @@ -27,16 +42,20 @@ struct GlobalValueRefMap : public std::map<GlobalValue*, ConstantPointerRef*>{ }; -Module::Module() : GlobalList(this, this), FunctionList(this, this) { +Module::Module() { + FunctionList.setItemParent(this); + FunctionList.setParent(this); + GlobalList.setItemParent(this); + GlobalList.setParent(this); GVRefMap = 0; SymTab = 0; } Module::~Module() { dropAllReferences(); - GlobalList.delete_all(); + GlobalList.clear(); GlobalList.setParent(0); - FunctionList.delete_all(); + FunctionList.clear(); FunctionList.setParent(0); delete SymTab; } @@ -136,11 +155,11 @@ std::string Module::getTypeName(const Type *Ty) { // delete. // void Module::dropAllReferences() { - for_each(FunctionList.begin(), FunctionList.end(), - std::mem_fun(&Function::dropAllReferences)); + for(Module::iterator I = begin(), E = end(); I != E; ++I) + I->dropAllReferences(); - for_each(GlobalList.begin(), GlobalList.end(), - std::mem_fun(&GlobalVariable::dropAllReferences)); + for(Module::giterator I = gbegin(), E = gend(); I != E; ++I) + I->dropAllReferences(); // If there are any GlobalVariable references still out there, nuke them now. // Since all references are hereby dropped, nothing could possibly reference diff --git a/lib/VMCore/Pass.cpp b/lib/VMCore/Pass.cpp index b4f837d..ae659da 100644 --- a/lib/VMCore/Pass.cpp +++ b/lib/VMCore/Pass.cpp @@ -9,8 +9,6 @@ #include "llvm/PassManager.h" #include "PassManagerT.h" // PassManagerT implementation #include "llvm/Module.h" -#include "llvm/Function.h" -#include "llvm/BasicBlock.h" #include "Support/STLExtras.h" #include "Support/CommandLine.h" #include <typeinfo> @@ -75,7 +73,7 @@ void AnalysisUsage::preservesCFG() { PassManager::PassManager() : PM(new PassManagerT<Module>()) {} PassManager::~PassManager() { delete PM; } void PassManager::add(Pass *P) { PM->add(P); } -bool PassManager::run(Module *M) { return PM->run(M); } +bool PassManager::run(Module &M) { return PM->run(M); } //===----------------------------------------------------------------------===// @@ -220,11 +218,11 @@ const char *Pass::getPassName() const { return typeid(*this).name(); } // run - On a module, we run this pass by initializing, runOnFunction'ing once // for every function in the module, then by finalizing. // -bool FunctionPass::run(Module *M) { +bool FunctionPass::run(Module &M) { bool Changed = doInitialization(M); - for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) - if (!(*I)->isExternal()) // Passes are not run on external functions! + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) + if (!I->isExternal()) // Passes are not run on external functions! Changed |= runOnFunction(*I); return Changed | doFinalization(M); @@ -232,11 +230,11 @@ bool FunctionPass::run(Module *M) { // run - On a function, we simply initialize, run the function, then finalize. // -bool FunctionPass::run(Function *F) { - if (F->isExternal()) return false;// Passes are not run on external functions! +bool FunctionPass::run(Function &F) { + if (F.isExternal()) return false;// Passes are not run on external functions! - return doInitialization(F->getParent()) | runOnFunction(F) - | doFinalization(F->getParent()); + return doInitialization(*F.getParent()) | runOnFunction(F) + | doFinalization(*F.getParent()); } void FunctionPass::addToPassManager(PassManagerT<Module> *PM, @@ -256,9 +254,9 @@ void FunctionPass::addToPassManager(PassManagerT<Function> *PM, // To run this pass on a function, we simply call runOnBasicBlock once for each // function. // -bool BasicBlockPass::runOnFunction(Function *F) { +bool BasicBlockPass::runOnFunction(Function &F) { bool Changed = false; - for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) + for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) Changed |= runOnBasicBlock(*I); return Changed; } @@ -266,8 +264,8 @@ bool BasicBlockPass::runOnFunction(Function *F) { // To run directly on the basic block, we initialize, runOnBasicBlock, then // finalize. // -bool BasicBlockPass::run(BasicBlock *BB) { - Module *M = BB->getParent()->getParent(); +bool BasicBlockPass::run(BasicBlock &BB) { + Module &M = *BB.getParent()->getParent(); return doInitialization(M) | runOnBasicBlock(BB) | doFinalization(M); } diff --git a/lib/VMCore/PassManagerT.h b/lib/VMCore/PassManagerT.h index e61d994..845e5cd 100644 --- a/lib/VMCore/PassManagerT.h +++ b/lib/VMCore/PassManagerT.h @@ -424,7 +424,7 @@ template<> struct PassManagerTraits<BasicBlock> : public BasicBlockPass { // runPass - Specify how the pass should be run on the UnitType static bool runPass(PassClass *P, BasicBlock *M) { // todo, init and finalize - return P->runOnBasicBlock(M); + return P->runOnBasicBlock(*M); } // Dummy implementation of PassStarted/PassEnded @@ -437,9 +437,9 @@ template<> struct PassManagerTraits<BasicBlock> : public BasicBlockPass { virtual const char *getPassName() const { return "BasicBlock Pass Manager"; } // Implement the BasicBlockPass interface... - virtual bool doInitialization(Module *M); - virtual bool runOnBasicBlock(BasicBlock *BB); - virtual bool doFinalization(Module *M); + virtual bool doInitialization(Module &M); + virtual bool runOnBasicBlock(BasicBlock &BB); + virtual bool doFinalization(Module &M); virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); @@ -472,7 +472,7 @@ template<> struct PassManagerTraits<Function> : public FunctionPass { // runPass - Specify how the pass should be run on the UnitType static bool runPass(PassClass *P, Function *F) { - return P->runOnFunction(F); + return P->runOnFunction(*F); } // Dummy implementation of PassStarted/PassEnded @@ -485,9 +485,9 @@ template<> struct PassManagerTraits<Function> : public FunctionPass { virtual const char *getPassName() const { return "Function Pass Manager"; } // Implement the FunctionPass interface... - virtual bool doInitialization(Module *M); - virtual bool runOnFunction(Function *F); - virtual bool doFinalization(Module *M); + virtual bool doInitialization(Module &M); + virtual bool runOnFunction(Function &F); + virtual bool doFinalization(Module &M); virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); @@ -515,7 +515,7 @@ template<> struct PassManagerTraits<Module> : public Pass { typedef AnalysisResolver ParentClass; // runPass - Specify how the pass should be run on the UnitType - static bool runPass(PassClass *P, Module *M) { return P->run(M); } + static bool runPass(PassClass *P, Module *M) { return P->run(*M); } // getPMName() - Return the name of the unit the PassManager operates on for // debugging. @@ -539,9 +539,9 @@ template<> struct PassManagerTraits<Module> : public Pass { } // run - Implement the PassManager interface... - bool run(Module *M) { + bool run(Module &M) { TimeInfo = TimingInfo::create(); - bool Result = ((PassManagerT<Module>*)this)->runOnUnit(M); + bool Result = ((PassManagerT<Module>*)this)->runOnUnit(&M); if (TimeInfo) { delete TimeInfo; TimeInfo = 0; @@ -563,18 +563,18 @@ template<> struct PassManagerTraits<Module> : public Pass { // PassManagerTraits<BasicBlock> Implementations // -inline bool PassManagerTraits<BasicBlock>::doInitialization(Module *M) { +inline bool PassManagerTraits<BasicBlock>::doInitialization(Module &M) { bool Changed = false; for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i) ((PMType*)this)->Passes[i]->doInitialization(M); return Changed; } -inline bool PassManagerTraits<BasicBlock>::runOnBasicBlock(BasicBlock *BB) { - return ((PMType*)this)->runOnUnit(BB); +inline bool PassManagerTraits<BasicBlock>::runOnBasicBlock(BasicBlock &BB) { + return ((PMType*)this)->runOnUnit(&BB); } -inline bool PassManagerTraits<BasicBlock>::doFinalization(Module *M) { +inline bool PassManagerTraits<BasicBlock>::doFinalization(Module &M) { bool Changed = false; for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i) ((PMType*)this)->Passes[i]->doFinalization(M); @@ -584,18 +584,18 @@ inline bool PassManagerTraits<BasicBlock>::doFinalization(Module *M) { // PassManagerTraits<Function> Implementations // -inline bool PassManagerTraits<Function>::doInitialization(Module *M) { +inline bool PassManagerTraits<Function>::doInitialization(Module &M) { bool Changed = false; for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i) ((PMType*)this)->Passes[i]->doInitialization(M); return Changed; } -inline bool PassManagerTraits<Function>::runOnFunction(Function *F) { - return ((PMType*)this)->runOnUnit(F); +inline bool PassManagerTraits<Function>::runOnFunction(Function &F) { + return ((PMType*)this)->runOnUnit(&F); } -inline bool PassManagerTraits<Function>::doFinalization(Module *M) { +inline bool PassManagerTraits<Function>::doFinalization(Module &M) { bool Changed = false; for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i) ((PMType*)this)->Passes[i]->doFinalization(M); diff --git a/lib/VMCore/SlotCalculator.cpp b/lib/VMCore/SlotCalculator.cpp index 6dad926..6b83a11 100644 --- a/lib/VMCore/SlotCalculator.cpp +++ b/lib/VMCore/SlotCalculator.cpp @@ -11,15 +11,11 @@ #include "llvm/SlotCalculator.h" #include "llvm/Analysis/ConstantsScanner.h" -#include "llvm/Function.h" -#include "llvm/GlobalVariable.h" #include "llvm/Module.h" -#include "llvm/BasicBlock.h" #include "llvm/iOther.h" #include "llvm/Constant.h" #include "llvm/DerivedTypes.h" #include "llvm/SymbolTable.h" -#include "llvm/Argument.h" #include "Support/DepthFirstIterator.h" #include "Support/STLExtras.h" #include <algorithm> @@ -75,20 +71,22 @@ void SlotCalculator::processModule() { // for (Module::const_giterator I = TheModule->gbegin(), E = TheModule->gend(); I != E; ++I) { - if ((*I)->hasInitializer()) - insertValue((*I)->getInitializer()); + if (I->hasInitializer()) + insertValue(I->getInitializer()); } // Add all of the global variables to the value table... // - for_each(TheModule->gbegin(), TheModule->gend(), - bind_obj(this, &SlotCalculator::insertValue)); + for(Module::const_giterator I = TheModule->gbegin(), E = TheModule->gend(); + I != E; ++I) + insertValue(I); // Scavenge the types out of the functions, then add the functions themselves // to the value table... // - for_each(TheModule->begin(), TheModule->end(), // Insert functions... - bind_obj(this, &SlotCalculator::insertValue)); + for(Module::const_iterator I = TheModule->begin(), E = TheModule->end(); + I != E; ++I) + insertValue(I); // Insert constants that are named at module level into the slot pool so that // the module symbol table can refer to them... @@ -132,8 +130,8 @@ void SlotCalculator::incorporateFunction(const Function *M) { SC_DEBUG("Inserting function arguments\n"); // Iterate over function arguments, adding them to the value table... - for_each(M->getArgumentList().begin(), M->getArgumentList().end(), - bind_obj(this, &SlotCalculator::insertValue)); + for(Function::const_aiterator I = M->abegin(), E = M->aend(); I != E; ++I) + insertValue(I); // Iterate over all of the instructions in the function, looking for constant // values that are referenced. Add these to the value pools before any @@ -166,8 +164,10 @@ void SlotCalculator::incorporateFunction(const Function *M) { SC_DEBUG("Inserting Labels:\n"); // Iterate over basic blocks, adding them to the value table... - for_each(M->begin(), M->end(), - bind_obj(this, &SlotCalculator::insertValue)); + for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I) + insertValue(I); + /* for_each(M->begin(), M->end(), + bind_obj(this, &SlotCalculator::insertValue));*/ SC_DEBUG("Inserting Instructions:\n"); diff --git a/lib/VMCore/SymbolTable.cpp b/lib/VMCore/SymbolTable.cpp index dba5dcb..6d09c7d 100644 --- a/lib/VMCore/SymbolTable.cpp +++ b/lib/VMCore/SymbolTable.cpp @@ -5,10 +5,9 @@ //===----------------------------------------------------------------------===// #include "llvm/SymbolTable.h" -#include "llvm/InstrTypes.h" #include "llvm/DerivedTypes.h" #include "llvm/Module.h" -#include "llvm/Function.h" +#include "llvm/InstrTypes.h" #include "Support/StringExtras.h" #include <iostream> #include <algorithm> diff --git a/lib/VMCore/SymbolTableListTraitsImpl.h b/lib/VMCore/SymbolTableListTraitsImpl.h new file mode 100644 index 0000000..a9971c8 --- /dev/null +++ b/lib/VMCore/SymbolTableListTraitsImpl.h @@ -0,0 +1,88 @@ +//===-- llvm/SymbolTableListTraitsImpl.h - Implementation ------*- C++ -*--===// +// +// This file implements the stickier parts of the SymbolTableListTraits class, +// and is explicitly instantiated where needed to avoid defining all this code +// in a widely used header. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_SYMBOLTABLELISTTRAITS_IMPL_H +#define LLVM_SYMBOLTABLELISTTRAITS_IMPL_H + +#include "llvm/SymbolTableListTraits.h" +#include "llvm/SymbolTable.h" + +template<typename ValueSubClass, typename ItemParentClass,typename SymTabClass, + typename SubClass> +void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass> +::setParent(SymTabClass *STO) { + iplist<ValueSubClass> &List = SubClass::getList(ItemParent); + + // Remove all of the items from the old symtab.. + if (SymTabObject && !List.empty()) { + SymbolTable *SymTab = SymTabObject->getSymbolTable(); + for (iplist<ValueSubClass>::iterator I = List.begin(); I != List.end(); ++I) + if (I->hasName()) SymTab->remove(I); + } + + SymTabObject = STO; + + // Add all of the items to the new symtab... + if (SymTabObject && !List.empty()) { + SymbolTable *SymTab = SymTabObject->getSymbolTableSure(); + for (iplist<ValueSubClass>::iterator I = List.begin(); I != List.end(); ++I) + if (I->hasName()) SymTab->insert(I); + } +} + +template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass, + typename SubClass> +void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass> +::addNodeToList(ValueSubClass *V) { + assert(V->getParent() == 0 && "Value already in a container!!"); + V->setParent(ItemParent); + if (V->hasName() && SymTabObject) + SymTabObject->getSymbolTableSure()->insert(V); +} + +template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass, + typename SubClass> +void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass> +::removeNodeFromList(ValueSubClass *V) { + V->setParent(0); + if (V->hasName() && SymTabObject) + SymTabObject->getSymbolTable()->remove(V); +} + +template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass, + typename SubClass> +void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass> +::transferNodesFromList(iplist<ValueSubClass, ilist_traits<ValueSubClass> > &L2, + ilist_iterator<ValueSubClass> first, + ilist_iterator<ValueSubClass> last) { + // We only have to do work here if transfering instructions between BB's + ItemParentClass *NewIP = ItemParent, *OldIP = L2.ItemParent; + if (NewIP == OldIP) return; // No work to do at all... + + // We only have to update symbol table entries if we are transfering the + // instructions to a different symtab object... + SymTabClass *NewSTO = SymTabObject, *OldSTO = L2.SymTabObject; + if (NewSTO != OldSTO) { + for (; first != last; ++first) { + ValueSubClass &V = *first; + bool HasName = V.hasName(); + if (OldSTO && HasName) + OldSTO->getSymbolTable()->remove(&V); + V.setParent(NewIP); + if (NewSTO && HasName) + NewSTO->getSymbolTableSure()->insert(&V); + } + } else { + // Just transfering between blocks in the same function, simply update the + // parent fields in the instructions... + for (; first != last; ++first) + first->setParent(NewIP); + } +} + +#endif diff --git a/lib/VMCore/ValueHolderImpl.h b/lib/VMCore/ValueHolderImpl.h deleted file mode 100644 index 6c44771..0000000 --- a/lib/VMCore/ValueHolderImpl.h +++ /dev/null @@ -1,222 +0,0 @@ -//===-- llvm/ValueHolderImpl.h - Implement ValueHolder template --*- C++ -*--=// -// -// This file implements the ValueHolder class. This is kept out of line because -// it tends to pull in a lot of dependencies on other headers and most files -// don't need all that crud. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_VALUEHOLDER_IMPL_H -#define LLVM_VALUEHOLDER_IMPL_H - -#include "llvm/ValueHolder.h" -#include "llvm/SymbolTable.h" -#include <algorithm> - -template<class ValueSubclass, class ItemParentType, class SymTabType> -void ValueHolder<ValueSubclass,ItemParentType,SymTabType> -::setParent(SymTabType *P) { - if (Parent && !empty()) { // Remove all of the items from the old symtab.. - SymbolTable *SymTab = Parent->getSymbolTable(); - for (iterator I = begin(); I != end(); ++I) - if ((*I)->hasName()) SymTab->remove(*I); - } - - Parent = P; - - if (Parent && !empty()) { // Add all of the items to the new symtab... - SymbolTable *SymTab = Parent->getSymbolTableSure(); - for (iterator I = begin(); I != end(); ++I) - if ((*I)->hasName()) SymTab->insert(*I); - } -} - - -template<class ValueSubclass, class ItemParentType, class SymTabType> -void ValueHolder<ValueSubclass,ItemParentType,SymTabType> -::remove(ValueSubclass *D) { - iterator I(find(begin(), end(), D)); - assert(I != end() && "Value not in ValueHolder!!"); - remove(I); -} - -// ValueHolder::remove(iterator &) this removes the element at the location -// specified by the iterator, and leaves the iterator pointing to the element -// that used to follow the element deleted. -// -template<class ValueSubclass, class ItemParentType, class SymTabType> -ValueSubclass *ValueHolder<ValueSubclass,ItemParentType,SymTabType> -::remove(iterator &DI) { - assert(DI != ValueList.end() && - "Trying to remove the end of the value list!!!"); - - ValueSubclass *i = *DI; - DI = ValueList.erase(DI); - - i->setParent(0); // I don't own you anymore... byebye... - - // You don't get to be in the symbol table anymore... byebye - if (i->hasName() && Parent) - Parent->getSymbolTable()->remove(i); - - return i; -} - -template<class ValueSubclass, class ItemParentType, class SymTabType> -ValueSubclass *ValueHolder<ValueSubclass,ItemParentType,SymTabType> -::pop_back() { - assert(!ValueList.empty() && "Can't pop_back an empty valuelist!"); - ValueSubclass *i = ValueList.back(); - ValueList.pop_back(); - i->setParent(0); // I don't own you anymore... byebye... - - // You don't get to be in the symbol table anymore... byebye - if (i->hasName() && Parent) - Parent->getSymbolTable()->remove(i); - - return i; -} - - -template<class ValueSubclass, class ItemParentType, class SymTabType> -ValueSubclass *ValueHolder<ValueSubclass,ItemParentType,SymTabType> -::remove(const iterator &DI) { - assert(DI != ValueList.end() && - "Trying to remove the end of the value holder list!!!"); - - ValueSubclass *i = *DI; - ValueList.erase(DI); - - i->setParent(0); // I don't own you anymore... byebye... - - // You don't get to be in the symbol table anymore... byebye - if (i->hasName() && Parent) - Parent->getSymbolTable()->remove(i); - - return i; -} - - -template<class ValueSubclass, class ItemParentType, class SymTabType> -void ValueHolder<ValueSubclass,ItemParentType,SymTabType> -::remove(iterator S, iterator E) { - for (iterator I = S; I != E; ++I) { - ValueSubclass *i = *I; - i->setParent(0); // I don't own you anymore... byebye... - - // You don't get to be in the symbol table anymore... byebye - if (i->hasName() && Parent) - Parent->getSymbolTable()->remove(i); - } - - ValueList.erase(S, E); -} - - -template<class ValueSubclass, class ItemParentType, class SymTabType> -ValueSubclass *ValueHolder<ValueSubclass,ItemParentType,SymTabType> -::replaceWith(iterator &DI, ValueSubclass *NewVal) { - assert(DI != ValueList.end() && - "Trying to replace the end of the value holder list!!!"); - - // Remove the value from the current container... - ValueSubclass *Ret = *DI; - Ret->setParent(0); // I don't own you anymore... byebye... - - // You don't get to be in the symbol table anymore... byebye - if (Ret->hasName() && Parent) - Parent->getSymbolTable()->remove(Ret); - - // Insert the new value into the container... - assert(NewVal->getParent() == 0 && "Value already has parent!"); - NewVal->setParent(ItemParent); - - *DI = NewVal; - if (NewVal->hasName() && Parent) - Parent->getSymbolTableSure()->insert(NewVal); - - return Ret; -} - - -template<class ValueSubclass, class ItemParentType, class SymTabType> -void ValueHolder<ValueSubclass,ItemParentType,SymTabType> -::push_front(ValueSubclass *Inst) { - assert(Inst->getParent() == 0 && "Value already has parent!"); - Inst->setParent(ItemParent); - - //ValueList.push_front(Inst); - ValueList.insert(ValueList.begin(), Inst); - - if (Inst->hasName() && Parent) - Parent->getSymbolTableSure()->insert(Inst); -} - -template<class ValueSubclass, class ItemParentType, class SymTabType> -void ValueHolder<ValueSubclass,ItemParentType,SymTabType> -::push_back(ValueSubclass *Inst) { - assert(Inst->getParent() == 0 && "Value already has parent!"); - Inst->setParent(ItemParent); - - ValueList.push_back(Inst); - - if (Inst->hasName() && Parent) - Parent->getSymbolTableSure()->insert(Inst); -} - -// ValueHolder::insert - This method inserts the specified value *BEFORE* the -// indicated iterator position, and returns an interator to the newly inserted -// value. -// -template<class ValueSubclass, class ItemParentType, class SymTabType> -ValueHolder<ValueSubclass,ItemParentType,SymTabType>::iterator -ValueHolder<ValueSubclass,ItemParentType,SymTabType> -::insert(iterator Pos, ValueSubclass *Inst) { - assert(Inst->getParent() == 0 && "Value already has parent!"); - Inst->setParent(ItemParent); - - iterator I = ValueList.insert(Pos, Inst); - if (Inst->hasName() && Parent) - Parent->getSymbolTableSure()->insert(Inst); - return I; -} - -// ValueHolder::insert - This method inserts the specified _range_ of values -// before the 'Pos' iterator, and returns an iterator to the first newly -// inserted element. This currently only works for vector iterators... -// -// FIXME: This is not generic so that the code does not have to be around -// to be used... is this ok? -// -template<class ValueSubclass, class ItemParentType, class SymTabType> -ValueHolder<ValueSubclass,ItemParentType,SymTabType>::iterator -ValueHolder<ValueSubclass,ItemParentType,SymTabType> -::insert(iterator Pos, // Where to insert - iterator First, iterator Last) { // Vector to read insts from - - // Since the vector range insert operation doesn't return an updated iterator, - // we have to convert the iterator to and index and back to assure that it - // cannot get invalidated. Gross hack, but effective. - // - unsigned Offset = Pos-begin(); - - // Check to make sure that the values are not already in some valueholder... - for (iterator X = First; X != Last; ++X) { - assert((*X)->getParent() == 0 && - "Cannot insert into valueholder, value already has a parent!"); - (*X)->setParent(ItemParent); - } - - // Add all of the values to the value holder... - ValueList.insert(Pos, First, Last); - - // Insert all of the instructions in the symbol table... - if (Parent) - for (;First != Last; ++First) - if ((*First)->hasName()) - Parent->getSymbolTableSure()->insert(*First); - - return begin()+Offset; -} - -#endif diff --git a/lib/VMCore/iBranch.cpp b/lib/VMCore/iBranch.cpp index 7a352ee..fe5c060 100644 --- a/lib/VMCore/iBranch.cpp +++ b/lib/VMCore/iBranch.cpp @@ -7,10 +7,7 @@ #include "llvm/iTerminators.h" #include "llvm/BasicBlock.h" -#ifndef NDEBUG -#include "llvm/Type.h" // Only used for assertions... -#include <iostream> -#endif +#include "llvm/Type.h" BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond) : TerminatorInst(Instruction::Br) { @@ -24,14 +21,6 @@ BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond) assert(!!False == !!Cond && "Either both cond and false or neither can be specified!"); - -#ifndef NDEBUG - if (Cond != 0 && Cond->getType() != Type::BoolTy) { - std::cerr << "Bad Condition: "; - Cond->dump(); - std::cerr << "\n"; - } -#endif assert((Cond == 0 || Cond->getType() == Type::BoolTy) && "May only branch on boolean predicates!!!!"); } diff --git a/lib/VMCore/iSwitch.cpp b/lib/VMCore/iSwitch.cpp index cd3079a..402610c 100644 --- a/lib/VMCore/iSwitch.cpp +++ b/lib/VMCore/iSwitch.cpp @@ -6,9 +6,6 @@ #include "llvm/iTerminators.h" #include "llvm/BasicBlock.h" -#ifndef NDEBUG -#include "llvm/Type.h" -#endif SwitchInst::SwitchInst(Value *V, BasicBlock *DefDest) : TerminatorInst(Instruction::Switch) { |