diff options
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 8da9f0481e..d69a998cb0 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 279c7eb887..ff0b7906a0 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 758c41f1f9..31692f8a39 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 5190dd2fd8..5182df4eb4 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) &&< |