diff options
author | Chris Lattner <sabre@nondot.org> | 2002-06-25 16:13:21 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-06-25 16:13:21 +0000 |
commit | 0b12b5f50ec77a8bd01b92d287c52d748619bb4b (patch) | |
tree | 5764db59facb124b023f1de96f0e45d37657c82e /lib/Transforms | |
parent | 18961504fc2b299578dba817900a0696cf3ccc4d (diff) | |
download | external_llvm-0b12b5f50ec77a8bd01b92d287c52d748619bb4b.zip external_llvm-0b12b5f50ec77a8bd01b92d287c52d748619bb4b.tar.gz external_llvm-0b12b5f50ec77a8bd01b92d287c52d748619bb4b.tar.bz2 |
MEGAPATCH checkin.
For details, See: docs/2002-06-25-MegaPatchInfo.txt
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2778 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/IPO/GlobalDCE.cpp | 19 | ||||
-rw-r--r-- | lib/Transforms/IPO/Internalize.cpp | 14 | ||||
-rw-r--r-- | lib/Transforms/IPO/MutateStructTypes.cpp | 167 | ||||
-rw-r--r-- | lib/Transforms/IPO/OldPoolAllocate.cpp | 264 | ||||
-rw-r--r-- | lib/Transforms/IPO/SimpleStructMutation.cpp | 6 | ||||
-rw-r--r-- | lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp | 65 | ||||
-rw-r--r-- | lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp | 24 |
7 files changed, 272 insertions, 287 deletions
diff --git a/lib/Transforms/IPO/GlobalDCE.cpp b/lib/Transforms/IPO/GlobalDCE.cpp index 8da9f04..d69a998 100644 --- a/lib/Transforms/IPO/GlobalDCE.cpp +++ b/lib/Transforms/IPO/GlobalDCE.cpp @@ -15,7 +15,7 @@ static Statistic<> NumRemoved("globaldce\t- Number of global values removed"); -static bool RemoveUnreachableFunctions(Module *M, CallGraph &CallGraph) { +static bool RemoveUnreachableFunctions(Module &M, CallGraph &CallGraph) { // Calculate which functions are reachable from the external functions in the // call graph. // @@ -27,10 +27,10 @@ static bool RemoveUnreachableFunctions(Module *M, CallGraph &CallGraph) { // The second pass removes the functions that need to be removed. // std::vector<CallGraphNode*> FunctionsToDelete; // Track unused functions - for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) { - CallGraphNode *N = CallGraph[*I]; + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) { + CallGraphNode *N = CallGraph[I]; if (!ReachableNodes.count(N)) { // Not reachable?? - (*I)->dropAllReferences(); + I->dropAllReferences(); N->removeAllCalledMethods(); FunctionsToDelete.push_back(N); ++NumRemoved; @@ -50,17 +50,16 @@ static bool RemoveUnreachableFunctions(Module *M, CallGraph &CallGraph) { return true; } -static bool RemoveUnreachableGlobalVariables(Module *M) { +static bool RemoveUnreachableGlobalVariables(Module &M) { bool Changed = false; // Eliminate all global variables that are unused, and that are internal, or // do not have an initializer. // - for (Module::giterator I = M->gbegin(); I != M->gend(); ) - if (!(*I)->use_empty() || - ((*I)->hasExternalLinkage() && (*I)->hasInitializer())) + for (Module::giterator I = M.gbegin(); I != M.gend(); ) + if (!I->use_empty() || (I->hasExternalLinkage() && I->hasInitializer())) ++I; // Cannot eliminate global variable else { - delete M->getGlobalList().remove(I); + I = M.getGlobalList().erase(I); ++NumRemoved; Changed = true; } @@ -74,7 +73,7 @@ namespace { // run - Do the GlobalDCE pass on the specified module, optionally updating // the specified callgraph to reflect the changes. // - bool run(Module *M) { + bool run(Module &M) { return RemoveUnreachableFunctions(M, getAnalysis<CallGraph>()) | RemoveUnreachableGlobalVariables(M); } diff --git a/lib/Transforms/IPO/Internalize.cpp b/lib/Transforms/IPO/Internalize.cpp index 279c7eb..ff0b790 100644 --- a/lib/Transforms/IPO/Internalize.cpp +++ b/lib/Transforms/IPO/Internalize.cpp @@ -17,10 +17,10 @@ static Statistic<> NumChanged("internalize\t- Number of functions internal'd"); class InternalizePass : public Pass { const char *getPassName() const { return "Internalize Functions"; } - virtual bool run(Module *M) { + virtual bool run(Module &M) { bool FoundMain = false; // Look for a function named main... - for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) - if ((*I)->getName() == "main" && !(*I)->isExternal()) { + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) + if (I->getName() == "main" && !I->isExternal()) { FoundMain = true; break; } @@ -30,10 +30,10 @@ class InternalizePass : public Pass { bool Changed = false; // Found a main function, mark all functions not named main as internal. - for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) - if ((*I)->getName() != "main" && // Leave the main function external - !(*I)->isExternal()) { // Function must be defined here - (*I)->setInternalLinkage(true); + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) + if (I->getName() != "main" && // Leave the main function external + !I->isExternal()) { // Function must be defined here + I->setInternalLinkage(true); Changed = true; ++NumChanged; } diff --git a/lib/Transforms/IPO/MutateStructTypes.cpp b/lib/Transforms/IPO/MutateStructTypes.cpp index 758c41f..31692f8 100644 --- a/lib/Transforms/IPO/MutateStructTypes.cpp +++ b/lib/Transforms/IPO/MutateStructTypes.cpp @@ -95,7 +95,7 @@ const Type *MutateStructTypes::ConvertType(const Type *Ty) { assert(DestTy && "Type didn't get created!?!?"); // Refine our little placeholder value into a real type... - cast<DerivedType>(PlaceHolder.get())->refineAbstractTypeTo(DestTy); + ((DerivedType*)PlaceHolder.get())->refineAbstractTypeTo(DestTy); TypeMap.insert(std::make_pair(Ty, PlaceHolder.get())); return PlaceHolder.get(); @@ -139,9 +139,9 @@ Value *MutateStructTypes::ConvertValue(const Value *V) { // Ignore null values and simple constants.. if (V == 0) return 0; - if (Constant *CPV = dyn_cast<Constant>(V)) { + if (const Constant *CPV = dyn_cast<Constant>(V)) { if (V->getType()->isPrimitiveType()) - return CPV; + return (Value*)CPV; if (isa<ConstantPointerNull>(CPV)) return ConstantPointerNull::get( @@ -150,11 +150,11 @@ Value *MutateStructTypes::ConvertValue(const Value *V) { } // Check to see if this is an out of function reference first... - if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) { + if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) { // Check to see if the value is in the map... map<const GlobalValue*, GlobalValue*>::iterator I = GlobalMap.find(GV); if (I == GlobalMap.end()) - return GV; // Not mapped, just return value itself + return (Value*)GV; // Not mapped, just return value itself return I->second; } @@ -221,7 +221,7 @@ void MutateStructTypes::setTransforms(const TransformsType &XForm) { // types... // const Type *OldTypeStub = TypeMap.find(OldTy)->second.get(); - cast<DerivedType>(OldTypeStub)->refineAbstractTypeTo(NSTy); + ((DerivedType*)OldTypeStub)->refineAbstractTypeTo(NSTy); // Add the transformation to the Transforms map. Transforms.insert(std::make_pair(OldTy, @@ -239,52 +239,46 @@ void MutateStructTypes::clearTransforms() { "Local Value Map should always be empty between transformations!"); } -// doInitialization - This loops over global constants defined in the +// processGlobals - This loops over global constants defined in the // module, converting them to their new type. // -void MutateStructTypes::processGlobals(Module *M) { +void MutateStructTypes::processGlobals(Module &M) { // Loop through the functions in the module and create a new version of the - // function to contained the transformed code. Don't use an iterator, because - // we will be adding values to the end of the vector, and it could be - // reallocated. Also, we don't want to process the values that we add. + // function to contained the transformed code. Also, be careful to not + // process the values that we add. // - unsigned NumFunctions = M->size(); - for (unsigned i = 0; i < NumFunctions; ++i) { - Function *Meth = M->begin()[i]; - - if (!Meth->isExternal()) { + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) + if (!I->isExternal()) { const FunctionType *NewMTy = - cast<FunctionType>(ConvertType(Meth->getFunctionType())); + cast<FunctionType>(ConvertType(I->getFunctionType())); // Create a new function to put stuff into... - Function *NewMeth = new Function(NewMTy, Meth->hasInternalLinkage(), - Meth->getName()); - if (Meth->hasName()) - Meth->setName("OLD."+Meth->getName()); + Function *NewMeth = new Function(NewMTy, I->hasInternalLinkage(), + I->getName()); + if (I->hasName()) + I->setName("OLD."+I->getName()); // Insert the new function into the function list... to be filled in later - M->getFunctionList().push_back(NewMeth); + M.getFunctionList().push_back(NewMeth); // Keep track of the association... - GlobalMap[Meth] = NewMeth; + GlobalMap[I] = NewMeth; } - } // TODO: HANDLE GLOBAL VARIABLES // Remap the symbol table to refer to the types in a nice way // - if (M->hasSymbolTable()) { - SymbolTable *ST = M->getSymbolTable(); + if (SymbolTable *ST = M.getSymbolTable()) { SymbolTable::iterator I = ST->find(Type::TypeTy); if (I != ST->end()) { // Get the type plane for Type's SymbolTable::VarMap &Plane = I->second; for (SymbolTable::type_iterator TI = Plane.begin(), TE = Plane.end(); TI != TE; ++TI) { - // This is gross, I'm reaching right into a symbol table and mucking - // around with it's internals... but oh well. + // FIXME: This is gross, I'm reaching right into a symbol table and + // mucking around with it's internals... but oh well. // - TI->second = cast<Type>(ConvertType(cast<Type>(TI->second))); + TI->second = (Value*)cast<Type>(ConvertType(cast<Type>(TI->second))); } } } @@ -293,20 +287,20 @@ void MutateStructTypes::processGlobals(Module *M) { // removeDeadGlobals - For this pass, all this does is remove the old versions // of the functions and global variables that we no longer need. -void MutateStructTypes::removeDeadGlobals(Module *M) { +void MutateStructTypes::removeDeadGlobals(Module &M) { // Prepare for deletion of globals by dropping their interdependencies... - for(Module::iterator I = M->begin(); I != M->end(); ++I) { - if (GlobalMap.find(*I) != GlobalMap.end()) - (*I)->Function::dropAllReferences(); + for(Module::iterator I = M.begin(); I != M.end(); ++I) { + if (GlobalMap.find(I) != GlobalMap.end()) + I->dropAllReferences(); } // Run through and delete the functions and global variables... #if 0 // TODO: HANDLE GLOBAL VARIABLES - M->getGlobalList().delete_span(M->gbegin(), M->gbegin()+NumGVars/2); + M->getGlobalList().delete_span(M.gbegin(), M.gbegin()+NumGVars/2); #endif - for(Module::iterator I = M->begin(); I != M->end();) { - if (GlobalMap.find(*I) != GlobalMap.end()) - delete M->getFunctionList().remove(I); + for(Module::iterator I = M.begin(); I != M.end();) { + if (GlobalMap.find(I) != GlobalMap.end()) + I = M.getFunctionList().erase(I); else ++I; } @@ -326,46 +320,43 @@ void MutateStructTypes::transformFunction(Function *m) { Function *NewMeth = cast<Function>(GMI->second); // Okay, first order of business, create the arguments... - for (unsigned i = 0, e = M->getArgumentList().size(); i != e; ++i) { - const Argument *OFA = M->getArgumentList()[i]; - Argument *NFA = new Argument(ConvertType(OFA->getType()), OFA->getName()); + for (Function::aiterator I = m->abegin(), E = m->aend(); I != E; ++I) { + Argument *NFA = new Argument(ConvertType(I->getType()), I->getName()); NewMeth->getArgumentList().push_back(NFA); - LocalValueMap[OFA] = NFA; // Keep track of value mapping + LocalValueMap[I] = NFA; // Keep track of value mapping } // Loop over all of the basic blocks copying instructions over... - for (Function::const_iterator BBI = M->begin(), BBE = M->end(); BBI != BBE; - ++BBI) { - + for (Function::const_iterator BB = M->begin(), BBE = M->end(); BB != BBE; + ++BB) { // Create a new basic block and establish a mapping between the old and new - const BasicBlock *BB = *BBI; BasicBlock *NewBB = cast<BasicBlock>(ConvertValue(BB)); - NewMeth->getBasicBlocks().push_back(NewBB); // Add block to function + NewMeth->getBasicBlockList().push_back(NewBB); // Add block to function // Copy over all of the instructions in the basic block... for (BasicBlock::const_iterator II = BB->begin(), IE = BB->end(); II != IE; ++II) { - const Instruction *I = *II; // Get the current instruction... + const Instruction &I = *II; // Get the current instruction... Instruction *NewI = 0; - switch (I->getOpcode()) { + switch (I.getOpcode()) { // Terminator Instructions case Instruction::Ret: NewI = new ReturnInst( - ConvertValue(cast<ReturnInst>(I)->getReturnValue())); + ConvertValue(cast<ReturnInst>(I).getReturnValue())); break; case Instruction::Br: { - const BranchInst *BI = cast<BranchInst>(I); - if (BI->isConditional()) { + const BranchInst &BI = cast<BranchInst>(I); + if (BI.isConditional()) { NewI = - new BranchInst(cast<BasicBlock>(ConvertValue(BI->getSuccessor(0))), - cast<BasicBlock>(ConvertValue(BI->getSuccessor(1))), - ConvertValue(BI->getCondition())); + new BranchInst(cast<BasicBlock>(ConvertValue(BI.getSuccessor(0))), + cast<BasicBlock>(ConvertValue(BI.getSuccessor(1))), + ConvertValue(BI.getCondition())); } else { NewI = - new BranchInst(cast<BasicBlock>(ConvertValue(BI->getSuccessor(0)))); + new BranchInst(cast<BasicBlock>(ConvertValue(BI.getSuccessor(0)))); } break; } @@ -375,8 +366,8 @@ void MutateStructTypes::transformFunction(Function *m) { // Unary Instructions case Instruction::Not: - NewI = UnaryOperator::create((Instruction::UnaryOps)I->getOpcode(), - ConvertValue(I->getOperand(0))); + NewI = UnaryOperator::create((Instruction::UnaryOps)I.getOpcode(), + ConvertValue(I.getOperand(0))); break; // Binary Instructions @@ -397,41 +388,41 @@ void MutateStructTypes::transformFunction(Function *m) { case Instruction::SetGE: case Instruction::SetLT: case Instruction::SetGT: - NewI = BinaryOperator::create((Instruction::BinaryOps)I->getOpcode(), - ConvertValue(I->getOperand(0)), - ConvertValue(I->getOperand(1))); + NewI = BinaryOperator::create((Instruction::BinaryOps)I.getOpcode(), + ConvertValue(I.getOperand(0)), + ConvertValue(I.getOperand(1))); break; case Instruction::Shr: case Instruction::Shl: - NewI = new ShiftInst(cast<ShiftInst>(I)->getOpcode(), - ConvertValue(I->getOperand(0)), - ConvertValue(I->getOperand(1))); + NewI = new ShiftInst(cast<ShiftInst>(I).getOpcode(), + ConvertValue(I.getOperand(0)), + ConvertValue(I.getOperand(1))); break; // Memory Instructions case Instruction::Alloca: NewI = - new AllocaInst(ConvertType(I->getType()), - I->getNumOperands()?ConvertValue(I->getOperand(0)):0); + new AllocaInst(ConvertType(I.getType()), + I.getNumOperands() ? ConvertValue(I.getOperand(0)) :0); break; case Instruction::Malloc: NewI = - new MallocInst(ConvertType(I->getType()), - I->getNumOperands()?ConvertValue(I->getOperand(0)):0); + new MallocInst(ConvertType(I.getType()), + I.getNumOperands() ? ConvertValue(I.getOperand(0)) :0); break; case Instruction::Free: - NewI = new FreeInst(ConvertValue(I->getOperand(0))); + NewI = new FreeInst(ConvertValue(I.getOperand(0))); break; case Instruction::Load: case Instruction::Store: case Instruction::GetElementPtr: { - const MemAccessInst *MAI = cast<MemAccessInst>(I); - vector<Value*> Indices(MAI->idx_begin(), MAI->idx_end()); - const Value *Ptr = MAI->getPointerOperand(); + const MemAccessInst &MAI = cast<MemAccessInst>(I); + vector<Value*> Indices(MAI.idx_begin(), MAI.idx_end()); + const Value *Ptr = MAI.getPointerOperand(); Value *NewPtr = ConvertValue(Ptr); if (!Indices.empty()) { const Type *PTy = cast<PointerType>(Ptr->getType())->getElementType(); @@ -441,7 +432,7 @@ void MutateStructTypes::transformFunction(Function *m) { if (isa<LoadInst>(I)) { NewI = new LoadInst(NewPtr, Indices); } else if (isa<StoreInst>(I)) { - NewI = new StoreInst(ConvertValue(I->getOperand(0)), NewPtr, Indices); + NewI = new StoreInst(ConvertValue(I.getOperand(0)), NewPtr, Indices); } else if (isa<GetElementPtrInst>(I)) { NewI = new GetElementPtrInst(NewPtr, Indices); } else { @@ -452,23 +443,23 @@ void MutateStructTypes::transformFunction(Function *m) { // Miscellaneous Instructions case Instruction::PHINode: { - const PHINode *OldPN = cast<PHINode>(I); - PHINode *PN = new PHINode(ConvertType(I->getType())); - for (unsigned i = 0; i < OldPN->getNumIncomingValues(); ++i) - PN->addIncoming(ConvertValue(OldPN->getIncomingValue(i)), - cast<BasicBlock>(ConvertValue(OldPN->getIncomingBlock(i)))); + const PHINode &OldPN = cast<PHINode>(I); + PHINode *PN = new PHINode(ConvertType(OldPN.getType())); + for (unsigned i = 0; i < OldPN.getNumIncomingValues(); ++i) + PN->addIncoming(ConvertValue(OldPN.getIncomingValue(i)), + cast<BasicBlock>(ConvertValue(OldPN.getIncomingBlock(i)))); NewI = PN; break; } case Instruction::Cast: - NewI = new CastInst(ConvertValue(I->getOperand(0)), - ConvertType(I->getType())); + NewI = new CastInst(ConvertValue(I.getOperand(0)), + ConvertType(I.getType())); break; case Instruction::Call: { - Value *Meth = ConvertValue(I->getOperand(0)); + Value *Meth = ConvertValue(I.getOperand(0)); vector<Value*> Operands; - for (unsigned i = 1; i < I->getNumOperands(); ++i) - Operands.push_back(ConvertValue(I->getOperand(i))); + for (unsigned i = 1; i < I.getNumOperands(); ++i) + Operands.push_back(ConvertValue(I.getOperand(i))); NewI = new CallInst(Meth, Operands); break; } @@ -478,11 +469,11 @@ void MutateStructTypes::transformFunction(Function *m) { break; } - NewI->setName(I->getName()); + NewI->setName(I.getName()); NewBB->getInstList().push_back(NewI); // Check to see if we had to make a placeholder for this value... - map<const Value*,Value*>::iterator LVMI = LocalValueMap.find(I); + map<const Value*,Value*>::iterator LVMI = LocalValueMap.find(&I); if (LVMI != LocalValueMap.end()) { // Yup, make sure it's a placeholder... Instruction *I = cast<Instruction>(LVMI->second); @@ -495,7 +486,7 @@ void MutateStructTypes::transformFunction(Function *m) { // Keep track of the fact the the local implementation of this instruction // is NewI. - LocalValueMap[I] = NewI; + LocalValueMap[&I] = NewI; } } @@ -503,11 +494,11 @@ void MutateStructTypes::transformFunction(Function *m) { } -bool MutateStructTypes::run(Module *M) { +bool MutateStructTypes::run(Module &M) { processGlobals(M); - for_each(M->begin(), M->end(), - bind_obj(this, &MutateStructTypes::transformFunction)); + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) + transformFunction(I); removeDeadGlobals(M); return true; diff --git a/lib/Transforms/IPO/OldPoolAllocate.cpp b/lib/Transforms/IPO/OldPoolAllocate.cpp index 5190dd2..5182df4 100644 --- a/lib/Transforms/IPO/OldPoolAllocate.cpp +++ b/lib/Transforms/IPO/OldPoolAllocate.cpp @@ -13,8 +13,6 @@ #include "llvm/Transforms/Utils/CloneFunction.h" #include "llvm/Analysis/DataStructureGraph.h" #include "llvm/Module.h" -#include "llvm/Function.h" -#include "llvm/BasicBlock.h" #include "llvm/iMemory.h" #include "llvm/iTerminators.h" #include "llvm/iPHINode.h" @@ -23,7 +21,6 @@ #include "llvm/Constants.h" #include "llvm/Target/TargetData.h" #include "llvm/Support/InstVisitor.h" -#include "llvm/Argument.h" #include "Support/DepthFirstIterator.h" #include "Support/STLExtras.h" #include <algorithm> @@ -62,9 +59,9 @@ const Type *POINTERTYPE; static TargetData TargetData("test"); static const Type *getPointerTransformedType(const Type *Ty) { - if (PointerType *PT = dyn_cast<PointerType>(Ty)) { + if (const PointerType *PT = dyn_cast<PointerType>(Ty)) { return POINTERTYPE; - } else if (StructType *STy = dyn_cast<StructType>(Ty)) { + } else if (const StructType *STy = dyn_cast<StructType>(Ty)) { vector<const Type *> NewElTypes; NewElTypes.reserve(STy->getElementTypes().size()); for (StructType::ElementTypes::const_iterator @@ -72,7 +69,7 @@ static const Type *getPointerTransformedType(const Type *Ty) { E = STy->getElementTypes().end(); I != E; ++I) NewElTypes.push_back(getPointerTransformedType(*I)); return StructType::get(NewElTypes); - } else if (ArrayType *ATy = dyn_cast<ArrayType>(Ty)) { + } else if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) { return ArrayType::get(getPointerTransformedType(ATy->getElementType()), ATy->getNumElements()); } else { @@ -233,7 +230,7 @@ namespace { return Result; } - bool run(Module *M); + bool run(Module &M); // getAnalysisUsage - This function requires data structure information // to be able to see what is pool allocatable. @@ -273,7 +270,7 @@ namespace { // specified module and update the Pool* instance variables to point to // them. // - void addPoolPrototypes(Module *M); + void addPoolPrototypes(Module &M); // CreatePools - Insert instructions into the function we are processing to @@ -410,12 +407,13 @@ class NewInstructionCreator : public InstVisitor<NewInstructionCreator> { return 0; } - BasicBlock::iterator ReplaceInstWith(Instruction *I, Instruction *New) { - BasicBlock *BB = I->getParent(); - BasicBlock::iterator RI = find(BB->begin(), BB->end(), I); - BB->getInstList().replaceWith(RI, New); - XFormMap[I] = New; - return RI; + BasicBlock::iterator ReplaceInstWith(Instruction &I, Instruction *New) { + BasicBlock *BB = I.getParent(); + BasicBlock::iterator RI = &I; + BB->getInstList().remove(RI); + BB->getInstList().insert(RI, New); + XFormMap[&I] = New; + return New; } Instruction *createPoolBaseInstruction(Value *PtrVal) { @@ -471,36 +469,36 @@ public: // NewInstructionCreator instance... //===--------------------------------------------------------------------===// - void visitGetElementPtrInst(GetElementPtrInst *I) { + void visitGetElementPtrInst(GetElementPtrInst &I) { assert(0 && "Cannot transform get element ptr instructions yet!"); } // Replace the load instruction with a new one. - void visitLoadInst(LoadInst *I) { + void visitLoadInst(LoadInst &I) { vector<Instruction *> BeforeInsts; // Cast our index to be a UIntTy so we can use it to index into the pool... CastInst *Index = new CastInst(Constant::getNullValue(POINTERTYPE), - Type::UIntTy, I->getOperand(0)->getName()); + Type::UIntTy, I.getOperand(0)->getName()); BeforeInsts.push_back(Index); - ReferencesToUpdate.push_back(RefToUpdate(Index, 0, I->getOperand(0))); + ReferencesToUpdate.push_back(RefToUpdate(Index, 0, I.getOperand(0))); // Include the pool base instruction... - Instruction *PoolBase = createPoolBaseInstruction(I->getOperand(0)); + Instruction *PoolBase = createPoolBaseInstruction(I.getOperand(0)); BeforeInsts.push_back(PoolBase); Instruction *IdxInst = - BinaryOperator::create(Instruction::Add, *I->idx_begin(), Index, - I->getName()+".idx"); + BinaryOperator::create(Instruction::Add, *I.idx_begin(), Index, + I.getName()+".idx"); BeforeInsts.push_back(IdxInst); - vector<Value*> Indices(I->idx_begin(), I->idx_end()); + vector<Value*> Indices(I.idx_begin(), I.idx_end()); Indices[0] = IdxInst; Instruction *Address = new GetElementPtrInst(PoolBase, Indices, - I->getName()+".addr"); + I.getName()+".addr"); BeforeInsts.push_back(Address); - Instruction *NewLoad = new LoadInst(Address, I->getName()); + Instruction *NewLoad = new LoadInst(Address, I.getName()); // Replace the load instruction with the new load instruction... BasicBlock::iterator II = ReplaceInstWith(I, NewLoad); @@ -512,57 +510,58 @@ public: // If not yielding a pool allocated pointer, use the new load value as the // value in the program instead of the old load value... // - if (!getScalar(I)) - I->replaceAllUsesWith(NewLoad); + if (!getScalar(&I)) + I.replaceAllUsesWith(NewLoad); } // Replace the store instruction with a new one. In the store instruction, // the value stored could be a pointer type, meaning that the new store may // have to change one or both of it's operands. // - void visitStoreInst(StoreInst *I) { - assert(getScalar(I->getOperand(1)) && + void visitStoreInst(StoreInst &I) { + assert(getScalar(I.getOperand(1)) && "Store inst found only storing pool allocated pointer. " "Not imp yet!"); - Value *Val = I->getOperand(0); // The value to store... + Value *Val = I.getOperand(0); // The value to store... // Check to see if the value we are storing is a data structure pointer... - //if (const ScalarInfo *ValScalar = getScalar(I->getOperand(0))) - if (isa<PointerType>(I->getOperand(0)->getType())) + //if (const ScalarInfo *ValScalar = getScalar(I.getOperand(0))) + if (isa<PointerType>(I.getOperand(0)->getType())) Val = Constant::getNullValue(POINTERTYPE); // Yes, store a dummy - Instruction *PoolBase = createPoolBaseInstruction(I->getOperand(1)); + Instruction *PoolBase = createPoolBaseInstruction(I.getOperand(1)); // Cast our index to be a UIntTy so we can use it to index into the pool... CastInst *Index = new CastInst(Constant::getNullValue(POINTERTYPE), - Type::UIntTy, I->getOperand(1)->getName()); - ReferencesToUpdate.push_back(RefToUpdate(Index, 0, I->getOperand(1))); + Type::UIntTy, I.getOperand(1)->getName()); + ReferencesToUpdate.push_back(RefToUpdate(Index, 0, I.getOperand(1))); // Instructions to add after the Index... vector<Instruction*> AfterInsts; Instruction *IdxInst = - BinaryOperator::create(Instruction::Add, *I->idx_begin(), Index, "idx"); + BinaryOperator::create(Instruction::Add, *I.idx_begin(), Index, "idx"); AfterInsts.push_back(IdxInst); - vector<Value*> Indices(I->idx_begin(), I->idx_end()); + vector<Value*> Indices(I.idx_begin(), I.idx_end()); Indices[0] = IdxInst; Instruction *Address = new GetElementPtrInst(PoolBase, Indices, - I->getName()+"storeaddr"); + I.getName()+"storeaddr"); AfterInsts.push_back(Address); Instruction *NewStore = new StoreInst(Val, Address); AfterInsts.push_back(NewStore); - if (Val != I->getOperand(0)) // Value stored was a pointer? - ReferencesToUpdate.push_back(RefToUpdate(NewStore, 0, I->getOperand(0))); + if (Val != I.getOperand(0)) // Value stored was a pointer? + ReferencesToUpdate.push_back(RefToUpdate(NewStore, 0, I.getOperand(0))); // Replace the store instruction with the cast instruction... BasicBlock::iterator II = ReplaceInstWith(I, Index); // Add the pool base calculator instruction before the index... - II = Index->getParent()->getInstList().insert(II, PoolBase)+2; + II = ++Index->getParent()->getInstList().insert(II, PoolBase); + ++II; // Add the instructions that go after the index... Index->getParent()->getInstList().insert(II, AfterInsts.begin(), @@ -571,42 +570,42 @@ public: // Create call to poolalloc for every malloc instruction - void visitMallocInst(MallocInst *I) { - const ScalarInfo &SCI = getScalarRef(I); + void visitMallocInst(MallocInst &I) { + const ScalarInfo &SCI = getScalarRef(&I); vector<Value*> Args; CallInst *Call; - if (!I->isArrayAllocation()) { + if (!I.isArrayAllocation()) { Args.push_back(SCI.Pool.Handle); - Call = new CallInst(PoolAllocator.PoolAlloc, Args, I->getName()); + Call = new CallInst(PoolAllocator.PoolAlloc, Args, I.getName()); } else { - Args.push_back(I->getArraySize()); + Args.push_back(I.getArraySize()); Args.push_back(SCI.Pool.Handle); - Call = new CallInst(PoolAllocator.PoolAllocArray, Args, I->getName()); + Call = new CallInst(PoolAllocator.PoolAllocArray, Args, I.getName()); } ReplaceInstWith(I, Call); } // Convert a call to poolfree for every free instruction... - void visitFreeInst(FreeInst *I) { + void visitFreeInst(FreeInst &I) { // Create a new call to poolfree before the free instruction vector<Value*> Args; Args.push_back(Constant::getNullValue(POINTERTYPE)); - Args.push_back(getScalarRef(I->getOperand(0)).Pool.Handle); + Args.push_back(getScalarRef(I.getOperand(0)).Pool.Handle); Instruction *NewCall = new CallInst(PoolAllocator.PoolFree, Args); ReplaceInstWith(I, NewCall); - ReferencesToUpdate.push_back(RefToUpdate(NewCall, 1, I->getOperand(0))); + ReferencesToUpdate.push_back(RefToUpdate(NewCall, 1, I.getOperand(0))); } // visitCallInst - Create a new call instruction with the extra arguments for // all of the memory pools that the call needs. // - void visitCallInst(CallInst *I) { - TransformFunctionInfo &TI = CallMap[I]; + void visitCallInst(CallInst &I) { + TransformFunctionInfo &TI = CallMap[&I]; // Start with all of the old arguments... - vector<Value*> Args(I->op_begin()+1, I->op_end()); + vector<Value*> Args(I.op_begin()+1, I.op_end()); for (unsigned i = 0, e = TI.ArgInfo.size(); i != e; ++i) { // Replace all of the pointer arguments with our new pointer typed values. @@ -618,7 +617,7 @@ public: } Function *NF = PoolAllocator.getTransformedFunction(TI); - Instruction *NewCall = new CallInst(NF, Args, I->getName()); + Instruction *NewCall = new CallInst(NF, Args, I.getName()); ReplaceInstWith(I, NewCall); // Keep track of the mapping of operands so that we can resolve them to real @@ -627,7 +626,7 @@ public: for (unsigned i = 0, e = TI.ArgInfo.size(); i != e; ++i) if (TI.ArgInfo[i].ArgNo != -1) ReferencesToUpdate.push_back(RefToUpdate(NewCall, TI.ArgInfo[i].ArgNo+1, - I->getOperand(TI.ArgInfo[i].ArgNo+1))); + I.getOperand(TI.ArgInfo[i].ArgNo+1))); else RetVal = 0; // If returning a pointer, don't change retval... @@ -635,47 +634,47 @@ public: // instead of the old call... // if (RetVal) - I->replaceAllUsesWith(RetVal); + I.replaceAllUsesWith(RetVal); } // visitPHINode - Create a new PHI node of POINTERTYPE for all of the old Phi // nodes... // - void visitPHINode(PHINode *PN) { + void visitPHINode(PHINode &PN) { Value *DummyVal = Constant::getNullValue(POINTERTYPE); - PHINode *NewPhi = new PHINode(POINTERTYPE, PN->getName()); - for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { - NewPhi->addIncoming(DummyVal, PN->getIncomingBlock(i)); + PHINode *NewPhi = new PHINode(POINTERTYPE, PN.getName()); + for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) { + NewPhi->addIncoming(DummyVal, PN.getIncomingBlock(i)); ReferencesToUpdate.push_back(RefToUpdate(NewPhi, i*2, - PN->getIncomingValue(i))); + PN.getIncomingValue(i))); } ReplaceInstWith(PN, NewPhi); } // visitReturnInst - Replace ret instruction with a new return... - void visitReturnInst(ReturnInst *I) { + void visitReturnInst(ReturnInst &I) { Instruction *Ret = new ReturnInst(Constant::getNullValue(POINTERTYPE)); ReplaceInstWith(I, Ret); - ReferencesToUpdate.push_back(RefToUpdate(Ret, 0, I->getOperand(0))); + ReferencesToUpdate.push_back(RefToUpdate(Ret, 0, I.getOperand(0))); } // visitSetCondInst - Replace a conditional test instruction with a new one - void visitSetCondInst(SetCondInst *SCI) { - BinaryOperator *I = (BinaryOperator*)SCI; + void visitSetCondInst(SetCondInst &SCI) { + BinaryOperator &I = (BinaryOperator&)SCI; Value *DummyVal = Constant::getNullValue(POINTERTYPE); - BinaryOperator *New = BinaryOperator::create(I->getOpcode(), DummyVal, - DummyVal, I->getName()); + BinaryOperator *New = BinaryOperator::create(I.getOpcode(), DummyVal, + DummyVal, I.getName()); ReplaceInstWith(I, New); - ReferencesToUpdate.push_back(RefToUpdate(New, 0, I->getOperand(0))); - ReferencesToUpdate.push_back(RefToUpdate(New, 1, I->getOperand(1))); + ReferencesToUpdate.push_back(RefToUpdate(New, 0, I.getOperand(0))); + ReferencesToUpdate.push_back(RefToUpdate(New, 1, I.getOperand(1))); // Make sure branches refer to the new condition... - I->replaceAllUsesWith(New); + I.replaceAllUsesWith(New); } - void visitInstruction(Instruction *I) { + void visitInstruction(Instruction &I) { cerr << "Unknown instruction to FunctionBodyTransformer:\n" << I; } }; @@ -729,8 +728,8 @@ public: } #ifdef DEBUG_POOLBASE_LOAD_ELIMINATOR - void visitFunction(Function *F) { - cerr << "Pool Load Elim '" << F->getName() << "'\t"; + void visitFunction(Function &F) { + cerr << "Pool Load Elim '" << F.getName() << "'\t"; } ~PoolBaseLoadEliminator() { unsigned Total = Eliminated+Remaining; @@ -745,7 +744,7 @@ public: // local transformation, we reset all of our state when we enter a new basic // block. // - void visitBasicBlock(BasicBlock *) { + void visitBasicBlock(BasicBlock &) { PoolDescMap.clear(); // Forget state. } @@ -754,25 +753,25 @@ public: // indicating that we have a value available to recycle next time we see the // poolbase of this instruction being loaded. // - void visitLoadInst(LoadInst *LI) { - Value *LoadAddr = LI->getPointerOperand(); + void visitLoadInst(LoadInst &LI) { + Value *LoadAddr = LI.getPointerOperand(); map<Value*, LoadInst*>::iterator VIt = PoolDescMap.find(LoadAddr); if (VIt != PoolDescMap.end()) { // We already have a value for this load? - LI->replaceAllUsesWith(VIt->second); // Make the current load dead + LI.replaceAllUsesWith(VIt->second); // Make the current load dead ++Eliminated; } else { // This load might not be a load of a pool pointer, check to see if it is - if (LI->getNumOperands() == 4 && // load pool, uint 0, ubyte 0, ubyte 0 + if (LI.getNumOperands() == 4 && // load pool, uint 0, ubyte 0, ubyte 0 find(PoolDescValues.begin(), PoolDescValues.end(), LoadAddr) != PoolDescValues.end()) { assert("Make sure it's a load of the pool base, not a chaining field" && - LI->getOperand(1) == Constant::getNullValue(Type::UIntTy) && - LI->getOperand(2) == Constant::getNullValue(Type::UByteTy) && - LI->getOperand(3) == Constant::getNullValue(Type::UByteTy)); + LI.getOperand(1) == Constant::getNullValue(Type::UIntTy) && + LI.getOperand(2) == Constant::getNullValue(Type::UByteTy) && + LI.getOperand(3) == Constant::getNullValue(Type::UByteTy)); // If it is a load of a pool base, keep track of it for future reference - PoolDescMap.insert(make_pair(LoadAddr, LI)); + PoolDescMap.insert(make_pair(LoadAddr, &LI)); ++Remaining; } } @@ -784,7 +783,7 @@ public: // function might call one of these functions, so be conservative. Through // more analysis, this could be improved in the future. // - void visitCallInst(CallInst *) { + void visitCallInst(CallInst &) { PoolDescMap.clear(); } }; @@ -845,8 +844,9 @@ static void CalculateNodeMapping(Function *F, TransformFunctionInfo &TFI, NodeMapping); } else { // Figure out which node argument # ArgNo points to in the called graph. - Value *Arg = F->getArgumentList()[TFI.ArgInfo[i].ArgNo]; - addNodeMapping(TFI.ArgInfo[i].Node, CalledGraph.getValueMap()[Arg], + Function::aiterator AI = F->abegin(); + std::advance(AI, TFI.ArgInfo[i].ArgNo); + addNodeMapping(TFI.ArgInfo[i].Node, CalledGraph.getValueMap()[AI], NodeMapping); } LastArgNo = TFI.ArgInfo[i].ArgNo; @@ -923,9 +923,9 @@ void TransformFunctionInfo::ensureDependantArgumentsIncluded(DataStructure *DS, Done = false; } - for (unsigned i = 0, e = Func->getArgumentList().size(); i != e; ++i) { - Argument *Arg = Func->getArgumentList()[i]; - if (isa<PointerType>(Arg->getType())) { + unsigned i = 0; + for (Function::aiterator I = Func->abegin(), E = Func->aend(); I!=E; ++I,++i){ + if (isa<PointerType>(I->getType())) { if (PtrNo < ArgInfo.size() && ArgInfo[PtrNo++].ArgNo == (int)i) { // We DO transform this arg... skip all possible entries for argument while (PtrNo < ArgInfo.size() && ArgInfo[PtrNo].ArgNo == (int)i) @@ -989,9 +989,10 @@ void TransformFunctionInfo::ensureDependantArgumentsIncluded(DataStructure *DS, if (i == 0) // Only process retvals once (performance opt) markReachableNodes(CalledDS.getRetNodes(), ReachableNodes); } else { // If it's an argument value... - Argument *Arg = Func->getArgumentList()[ArgInfo[i].ArgNo]; - if (isa<PointerType>(Arg->getType())) - markReachableNodes(CalledDS.getValueMap()[Arg], ReachableNodes); + Function::aiterator AI = Func->abegin(); + std::advance(AI, ArgInfo[i].ArgNo); + if (isa<PointerType>(AI->getType())) + markReachableNodes(CalledDS.getValueMap()[AI], ReachableNodes); } } @@ -1035,9 +1036,9 @@ void TransformFunctionInfo::ensureDependantArgumentsIncluded(DataStructure *DS, } } - for (unsigned i = 0, e = Func->getArgumentList().size(); i != e; ++i) { - Argument *Arg = Func->getArgumentList()[i]; - if (isa<PointerType>(Arg->getType())) { + i = 0; + for (Function::aiterator I = Func->abegin(), E = Func->aend(); I!=E; ++I, ++i) + if (isa<PointerType>(I->getType())) { if (PtrNo < ArgInfo.size() && ArgInfo[PtrNo++].ArgNo == (int)i) { // We DO transform this arg... skip all possible entries for argument while (PtrNo < ArgInfo.size() && ArgInfo[PtrNo].ArgNo == (int)i) @@ -1045,13 +1046,13 @@ void TransformFunctionInfo::ensureDependantArgumentsIncluded(DataStructure *DS, } else { // This should generalize to any number of nodes, just see if any are // reachable. - assert(CalledDS.getValueMap()[Arg].size() == 1 && + assert(CalledDS.getValueMap()[I].size() == 1 && "Only handle case where pointing to one node so far!"); // If the arg is not marked as being passed in, but it NEEDS to // be transformed, then make it known now. // - DSNode *N = CalledDS.getValueMap()[Arg][0].Node; + DSNode *N = CalledDS.getValueMap()[I][0].Node; if (ReachableNodes.count(N)) { #ifdef DEBUG_TRANSFORM_PROGRESS cerr << "ensure dependant arguments adds for arg #" << i << "\n"; @@ -1063,7 +1064,6 @@ void TransformFunctionInfo::ensureDependantArgumentsIncluded(DataStructure *DS, } } } - } } @@ -1222,7 +1222,7 @@ void PoolAllocate::transformFunctionBody(Function *F, FunctionDSGraph &IPFGraph, if (PoolDescs.count(RetNode.Node)) { // Loop over all of the basic blocks, adding return instructions... for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) - if (ReturnInst *RI = dyn_cast<ReturnInst>((*I)->getTerminator())) + if (ReturnInst *RI = dyn_cast<ReturnInst>(I->getTerminator())) InstToFix.push_back(RI); } } @@ -1246,7 +1246,7 @@ void PoolAllocate::transformFunctionBody(Function *F, FunctionDSGraph &IPFGraph, #ifdef DEBUG_TRANSFORM_PROGRESS for (unsigned i = 0, e = InstToFix.size(); i != e; ++i) { cerr << "Fixing: " << InstToFix[i]; - NIC.visit(InstToFix[i]); + NIC.visit(*InstToFix[i]); } #else NIC.visit(InstToFix.begin(), InstToFix.end()); @@ -1264,16 +1264,15 @@ void PoolAllocate::transformFunctionBody(Function *F, FunctionDSGraph &IPFGraph, // FunctionType::ParamTypes::const_iterator TI = F->getFunctionType()->getParamTypes().begin(); - for (Function::ArgumentListType::iterator I = F->getArgumentList().begin(), - E = F->getArgumentList().end(); I != E; ++I, ++TI) { - Argument *Arg = *I; - if (Arg->getType() != *TI) { - assert(isa<PointerType>(Arg->getType()) && *TI == POINTERTYPE); - Argument *NewArg = new Argument(*TI, Arg->getName()); - XFormMap[Arg] = NewArg; // Map old arg into new arg... + for (Function::aiterator I = F->abegin(), E = F->aend(); I != E; ++I, ++TI) { + if (I->getType() != *TI) { + assert(isa<PointerType>(I->getType()) && *TI == POINTERTYPE); + Argument *NewArg = new Argument(*TI, I->getName()); + XFormMap[I] = NewArg; // Map old arg into new arg... // Replace the old argument and then delete it... - delete F->getArgumentList().replaceWith(I, NewArg); + I = F->getArgumentList().erase(I); + I = F->getArgumentList().insert(I, NewArg); } } @@ -1366,9 +1365,9 @@ void PoolAllocate::transformFunction(TransformFunctionInfo &TFI, // Add arguments to the function... starting with all of the old arguments vector<Value*> ArgMap; - for (unsigned i = 0, e = TFI.Func->getArgumentList().size(); i != e; ++i) { - const Argument *OFA = TFI.Func->getArgumentList()[i]; - Argument *NFA = new Argument(OFA->getType(), OFA->getName()); + for (Function::const_aiterator I = TFI.Func->abegin(), E = TFI.Func->aend(); + I != E; ++I) { + Argument *NFA = new Argument(I->getType(), I->getName()); NewFunc->getArgumentList().push_back(NFA); ArgMap.push_back(NFA); // Keep track of the arguments } @@ -1457,11 +1456,13 @@ void PoolAllocate::transformFunction(TransformFunctionInfo &TFI, #ifdef DEBUG_TRANSFORM_PROGRESS cerr << "Should be argument #: " << ArgNo << "[i = " << a << "]\n"; #endif - assert(ArgNo < NewFunc->getArgumentList().size() && + assert(ArgNo < NewFunc->asize() && "Call already has pool arguments added??"); // Map the pool argument into the called function... - CalleeValue = NewFunc->getArgumentList()[ArgNo]; + Function::aiterator AI = NewFunc->abegin(); + std::advance(AI, ArgNo); + CalleeValue = AI; break; // Found value, quit loop } @@ -1501,12 +1502,12 @@ void PoolAllocate::transformFunction(TransformFunctionInfo &TFI, static unsigned countPointerTypes(const Type *Ty) { if (isa<PointerType>(Ty)) { return 1; - } else if (StructType *STy = dyn_cast<StructType>(Ty)) { + } else if (const StructType *STy = dyn_cast<StructType>(Ty)) { unsigned Num = 0; for (unsigned i = 0, e = STy->getElementTypes().size(); i != e; ++i) Num += countPointerTypes(STy->getElementTypes()[i]); return Num; - } else if (ArrayType *ATy = dyn_cast<ArrayType>(Ty)) { + } else if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) { return countPointerTypes(ATy->getElementType()); } else { assert(Ty->isPrimitiveType() && "Unknown derived type!"); @@ -1524,8 +1525,8 @@ void PoolAllocate::CreatePools(Function *F, const vector<AllocDSNode*> &Allocs, // Find all of the return nodes in the function... vector<BasicBlock*> ReturnNodes; for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) - if (isa<ReturnInst>((*I)->getTerminator())) - ReturnNodes.push_back(*I); + if (isa<ReturnInst>(I->getTerminator())) + ReturnNodes.push_back(I); #ifdef DEBUG_CREATE_POOLS cerr << "Allocs that we are pool allocating:\n"; @@ -1595,11 +1596,10 @@ void PoolAllocate::CreatePools(Function *F, const vector<AllocDSNode*> &Allocs, // The actual struct type could change each time through the loop, so it's // NOT loop invariant. - StructType *PoolTy = cast<StructType>(PoolTyH.get()); + const StructType *PoolTy = cast<StructType>(PoolTyH.get()); // Get the opaque type... - DerivedType *ElTy = - cast<DerivedType>(PoolTy->getElementTypes()[p+1].get()); + DerivedType *ElTy = (DerivedType*)(PoolTy->getElementTypes()[p+1].get()); #ifdef DEBUG_CREATE_POOLS cerr << "Refining " << ElTy << " of " << PoolTy << " to " @@ -1653,7 +1653,7 @@ void PoolAllocate::CreatePools(Function *F, const vector<AllocDSNode*> &Allocs, // Insert it before the return instruction... BasicBlock *RetNode = ReturnNodes[EN]; - RetNode->getInstList().insert(RetNode->end()-1, Destroy); + RetNode->getInstList().insert(RetNode->end()--, Destroy); } } @@ -1683,7 +1683,7 @@ void PoolAllocate::CreatePools(Function *F, const vector<AllocDSNode*> &Allocs, } // Insert the entry node code into the entry block... - F->getEntryNode()->getInstList().insert(F->getEntryNode()->begin()+1, + F->getEntryNode().getInstList().insert(++F->getEntryNode().begin(), EntryNodeInsts.begin(), EntryNodeInsts.end()); } @@ -1692,45 +1692,43 @@ void PoolAllocate::CreatePools(Function *F, const vector<AllocDSNode*> &Allocs, // addPoolPrototypes - Add prototypes for the pool functions to the specified // module and update the Pool* instance variables to point to them. // -void PoolAllocate::addPoolPrototypes(Module *M) { +void PoolAllocate::addPoolPrototypes(Module &M) { // Get poolinit function... vector<const Type*> Args; Args.push_back(Type::UIntTy); // Num bytes per element FunctionType *PoolInitTy = FunctionType::get(Type::VoidTy, Args, true); - PoolInit = M->getOrInsertFunction("poolinit", PoolInitTy); + PoolInit = M.getOrInsertFunction("poolinit", PoolInitTy); // Get pooldestroy function... Args.pop_back(); // Only takes a pool... FunctionType *PoolDestroyTy = FunctionType::get(Type::VoidTy, Args, true); - PoolDestroy = M->getOrInsertFunction("pooldestroy", PoolDestroyTy); + PoolDestroy = M.getOrInsertFunction("pooldestroy", PoolDestroyTy); // Get the poolalloc function... FunctionType *PoolAllocTy = FunctionType::get(POINTERTYPE, Args, true); - PoolAlloc = M->getOrInsertFunction("poolalloc", PoolAllocTy); + PoolAlloc = M.getOrInsertFunction("poolalloc", PoolAllocTy); // Get the poolfree function... Args.push_back(POINTERTYPE); // Pointer to free FunctionType *PoolFreeTy = FunctionType::get(Type::VoidTy, Args, true); - PoolFree = M->getOrInsertFunction("poolfree", PoolFreeTy); + PoolFree = M.getOrInsertFunction("poolfree", PoolFreeTy); Args[0] = Type::UIntTy; // Number of slots to allocate FunctionType *PoolAllocArrayTy = FunctionType::get(POINTERTYPE, Args, true); - PoolAllocArray = M->getOrInsertFunction("poolallocarray", PoolAllocArrayTy); + PoolAllocArray = M.getOrInsertFunction("poolallocarray", PoolAllocArrayTy); } -bool PoolAllocate::run(Module *M) { +bool PoolAllocate::run(Module &M) { addPoolPrototypes(M); - CurModule = M; + CurModule = &M; DS = &getAnalysis<DataStructure>(); bool Changed = false; - // We cannot use an iterator here because it will get invalidated when we add - // functions to the module later... - for (unsigned i = 0; i != M->size(); ++i) - if (!M->getFunctionList()[i]->isExternal()) { - Changed |= processFunction(M->getFunctionList()[i]); + for (Module::iterator I = M.begin(); I != M.end(); ++I) + if (!I->isExternal()) { + Changed |= processFunction(I); if (Changed) { cerr << "Only processing one function\n"; break; diff --git a/lib/Transforms/IPO/SimpleStructMutation.cpp b/lib/Transforms/IPO/SimpleStructMutation.cpp index 908b5b1..7f18f31 100644 --- a/lib/Transforms/IPO/SimpleStructMutation.cpp +++ b/lib/Transforms/IPO/SimpleStructMutation.cpp @@ -32,7 +32,7 @@ namespace { const char *getPassName() const { return "Simple Struct Mutation"; } - virtual bool run(Module *M) { + virtual bool run(Module &M) { setTransforms(getTransforms(M, CurrentXForm)); bool Changed = MutateStructTypes::run(M); clearTransforms(); @@ -49,7 +49,7 @@ namespace { } private: - TransformsType getTransforms(Module *M, enum Transform); + TransformsType getTransforms(Module &M, enum Transform); }; } // end anonymous namespace @@ -124,7 +124,7 @@ static inline void GetTransformation(const StructType *ST, SimpleStructMutation::TransformsType - SimpleStructMutation::getTransforms(Module *M, enum Transform XForm) { + SimpleStructMutation::getTransforms(Module &, enum Transform XForm) { // We need to know which types to modify, and which types we CAN'T modify // TODO: Do symbol tables as well diff --git a/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp b/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp index f8d7616..1c09705 100644 --- a/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp +++ b/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp @@ -34,7 +34,7 @@ void getEdgeCode::getCode(Instruction *rInst, case 1:{ Value *val=ConstantSInt::get(Type::IntTy,inc); Instruction *stInst=new StoreInst(val, rInst); - here=instList.insert(here,stInst)+1; + here=++instList.insert(here,stInst); break; } @@ -42,7 +42,7 @@ void getEdgeCode::getCode(Instruction *rInst, case 2:{ Value *val=ConstantSInt::get(Type::IntTy,0); Instruction *stInst=new StoreInst(val, rInst); - here=instList.insert(here,stInst)+1; + here=++instList.insert(here,stInst); break; } @@ -54,9 +54,9 @@ void getEdgeCode::getCode(Instruction *rInst, create(Instruction::Add, ldInst, val,"ti2"); Instruction *stInst=new StoreInst(addIn, rInst); - here=instList.insert(here,ldInst)+1; - here=instList.insert(here,addIn)+1; - here=instList.insert(here,stInst)+1; + here=++instList.insert(here,ldInst); + here=++instList.insert(here,addIn); + here=++instList.insert(here,stInst); break; } @@ -74,9 +74,9 @@ void getEdgeCode::getCode(Instruction *rInst, StoreInst(addIn, countInst, vector<Value *> (1, ConstantUInt::get(Type::UIntTy,inc))); - here=instList.insert(here,ldInst)+1; - here=instList.insert(here,addIn)+1; - here=instList.insert(here,stInst)+1; + here=++instList.insert(here,ldInst); + here=++instList.insert(here,addIn); + here=++instList.insert(here,stInst); break; } @@ -102,12 +102,12 @@ void getEdgeCode::getCode(Instruction *rInst, StoreInst(addIn, countInst, vector<Value *>(1,castInst)); - here=instList.insert(here,ldIndex)+1; - here=instList.insert(here,addIndex)+1; - here=instList.insert(here,castInst)+1; - here=instList.insert(here,ldInst)+1; - here=instList.insert(here,addIn)+1; - here=instList.insert(here,stInst)+1; + here=++instList.insert(here,ldIndex); + here=++instList.insert(here,addIndex); + here=++instList.insert(here,castInst); + here=++instList.insert(here,ldInst); + here=++instList.insert(here,addIn); + here=++instList.insert(here,stInst); break; } @@ -129,11 +129,11 @@ void getEdgeCode::getCode(Instruction *rInst, Instruction *stInst=new StoreInst(addIn, countInst, vector<Value *>(1,castInst2)); - here=instList.insert(here,ldIndex)+1; - here=instList.insert(here,castInst2)+1; - here=instList.insert(here,ldInst)+1; - here=instList.insert(here,addIn)+1; - here=instList.insert(here,stInst)+1; + here=++instList.insert(here,ldIndex); + here=++instList.insert(here,castInst2); + here=++instList.insert(here,ldInst); + here=++instList.insert(here,addIn); + here=++instList.insert(here,stInst); break; } @@ -175,8 +175,8 @@ void insertInTopBB(BasicBlock *front, //now push all instructions in front of the BB BasicBlock::InstListType& instList=front->getInstList(); BasicBlock::iterator here=instList.begin(); - here=front->getInstList().insert(here, rVar)+1; - here=front->getInstList().insert(here,countVar)+1; + here=++front->getInstList().insert(here, rVar); + here=++front->getInstList().insert(here,countVar); //Initialize Count[...] with 0 for(int i=0;i<k; i++){ @@ -184,10 +184,10 @@ void insertInTopBB(BasicBlock *front, StoreInst(ConstantInt::get(Type::IntTy, 0), countVar, std::vector<Value *> (1,ConstantUInt::get(Type::UIntTy, i))); - here=front->getInstList().insert(here,stInstrC)+1; + here=++front->getInstList().insert(here,stInstrC); } - here=front->getInstList().insert(here,stInstr)+1; + here=++front->getInstList().insert(here,stInstr); } @@ -226,27 +226,24 @@ void insertBB(Edge ed, Value *cond=BI->getCondition(); BasicBlock *fB, *tB; - if(BI->getSuccessor(0)==BB2){ + if (BI->getSuccessor(0) == BB2){ tB=newBB; fB=BI->getSuccessor(1); - } - else{ + } else { fB=newBB; tB=BI->getSuccessor(0); } - delete BB1->getInstList().pop_back(); - Instruction *newBI=new BranchInst(tB,fB,cond); - Instruction *newBI2=new BranchInst(BB2); - BB1->getInstList().push_back(newBI); - newBB->getInstList().push_back(newBI2); + BB1->getInstList().pop_back(); + BB1->getInstList().push_back(new BranchInst(tB,fB,cond)); + newBB->getInstList().push_back(new BranchInst(BB2)); } //now iterate over BB2, and set its Phi nodes right - for(BasicBlock::iterator BB2Inst=BB2->begin(), BBend=BB2->end(); - BB2Inst!=BBend; ++BB2Inst){ + for(BasicBlock::iterator BB2Inst = BB2->begin(), BBend = BB2->end(); + BB2Inst != BBend; ++BB2Inst){ - if(PHINode *phiInst=dyn_cast<PHINode>(*BB2Inst)){ + if(PHINode *phiInst=dyn_cast<PHINode>(&*BB2Inst)){ DEBUG(cerr<<"YYYYYYYYYYYYYYYYY\n"); int bbIndex=phiInst->getBasicBlockIndex(BB1); diff --git a/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp b/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp index dcab136..42ef33c 100644 --- a/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp +++ b/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp @@ -37,7 +37,7 @@ using std::vector; struct ProfilePaths : public FunctionPass { const char *getPassName() const { return "ProfilePaths"; } - bool runOnFunction(Function *F); + bool runOnFunction(Function &F); // Before this pass, make sure that there is only one // entry and only one exit node for the function in the CFG of the function @@ -64,7 +64,7 @@ static Node *findBB(std::set<Node *> &st, BasicBlock *BB){ } //Per function pass for inserting counters and trigger code -bool ProfilePaths::runOnFunction(Function *M){ +bool ProfilePaths::runOnFunction(Function &F){ // Transform the cfg s.t. we have just one exit node BasicBlock *ExitNode = getAnalysis<UnifyFunctionExitNodes>().getExitNode(); @@ -78,20 +78,20 @@ bool ProfilePaths::runOnFunction(Function *M){ // That is, no two nodes must hav same BB* // First enter just nodes: later enter edges - for (Function::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){ - Node *nd=new Node(*BB); + for (Function::iterator BB = F.begin(), BE = F.end(); BB != BE; ++BB) { + Node *nd=new Node(BB); nodes.insert(nd); - if(*BB==ExitNode) + if(&*BB == ExitNode) exitNode=nd; - if(*BB==M->front()) + if(&*BB==F.begin()) startNode=nd; } // now do it againto insert edges - for (Function::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){ - Node *nd=findBB(nodes, *BB); + for (Function::iterator BB = F.begin(), BE = F.end(); BB != BE; ++BB){ + Node *nd=findBB(nodes, BB); assert(nd && "No node for this edge!"); - for(BasicBlock::succ_iterator s=succ_begin(*BB), se=succ_end(*BB); + for(BasicBlock::succ_iterator s=succ_begin(BB), se=succ_end(BB); s!=se; ++s){ Node *nd2=findBB(nodes,*s); assert(nd2 && "No node for this edge!"); @@ -104,10 +104,10 @@ bool ProfilePaths::runOnFunction(Function *M){ DEBUG(printGraph(g)); - BasicBlock *fr=M->front(); + BasicBlock *fr=&F.front(); // If only one BB, don't instrument - if (M->getBasicBlocks().size() == 1) { + if (++F.begin() == F.end()) { // The graph is made acyclic: this is done // by removing back edges for now, and adding them later on vector<Edge> be; @@ -148,7 +148,7 @@ bool ProfilePaths::runOnFunction(Function *M){ // insert initialization code in first (entry) BB // this includes initializing r and count - insertInTopBB(M->getEntryNode(),numPaths, rVar, countVar); + insertInTopBB(&F.getEntryNode(),numPaths, rVar, countVar); // now process the graph: get path numbers, // get increments along different paths, |