Changes in directory llvm/lib/Transforms/Utils:
CloneFunction.cpp updated: 1.25 -> 1.26 --- Log message: Allow the code cloning interfaces to capture some important info about the code being cloned if the client wants. --- Diffs of the changes: (+35 -11) CloneFunction.cpp | 46 +++++++++++++++++++++++++++++++++++----------- 1 files changed, 35 insertions(+), 11 deletions(-) Index: llvm/lib/Transforms/Utils/CloneFunction.cpp diff -u llvm/lib/Transforms/Utils/CloneFunction.cpp:1.25 llvm/lib/Transforms/Utils/CloneFunction.cpp:1.26 --- llvm/lib/Transforms/Utils/CloneFunction.cpp:1.25 Thu Apr 21 18:45:33 2005 +++ llvm/lib/Transforms/Utils/CloneFunction.cpp Fri Jan 13 12:39:17 2006 @@ -14,8 +14,9 @@ //===----------------------------------------------------------------------===// #include "llvm/Transforms/Utils/Cloning.h" -#include "llvm/Instructions.h" +#include "llvm/Constants.h" #include "llvm/DerivedTypes.h" +#include "llvm/Instructions.h" #include "llvm/Function.h" #include "ValueMapper.h" using namespace llvm; @@ -23,11 +24,14 @@ // CloneBasicBlock - See comments in Cloning.h BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB, std::map<const Value*, Value*> &ValueMap, - const char *NameSuffix, Function *F) { + const char *NameSuffix, Function *F, + ClonedCodeInfo *CodeInfo) { BasicBlock *NewBB = new BasicBlock("", F); if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix); - // Loop over all instructions copying them over... + bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false; + + // Loop over all instructions, and copy them over. for (BasicBlock::const_iterator II = BB->begin(), IE = BB->end(); II != IE; ++II) { Instruction *NewInst = II->clone(); @@ -35,6 +39,22 @@ NewInst->setName(II->getName()+NameSuffix); NewBB->getInstList().push_back(NewInst); ValueMap[II] = NewInst; // Add instruction map to value. + + hasCalls |= isa<CallInst>(II); + if (const AllocaInst *AI = dyn_cast<AllocaInst>(II)) { + if (isa<ConstantInt>(AI->getArraySize())) + hasStaticAllocas = true; + else + hasDynamicAllocas = true; + } + } + + if (CodeInfo) { + CodeInfo->ContainsCalls |= hasCalls; + CodeInfo->ContainsUnwinds |= isa<UnwindInst>(BB->getTerminator()); + CodeInfo->ContainsDynamicAllocas |= hasDynamicAllocas; + CodeInfo->ContainsDynamicAllocas |= hasStaticAllocas && + BB != &BB->getParent()->front(); } return NewBB; } @@ -45,12 +65,12 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc, std::map<const Value*, Value*> &ValueMap, std::vector<ReturnInst*> &Returns, - const char *NameSuffix) { + const char *NameSuffix, ClonedCodeInfo *CodeInfo) { assert(NameSuffix && "NameSuffix cannot be null!"); #ifndef NDEBUG - for (Function::const_arg_iterator I = OldFunc->arg_begin(), E = OldFunc->arg_end(); - I != E; ++I) + for (Function::const_arg_iterator I = OldFunc->arg_begin(), + E = OldFunc->arg_end(); I != E; ++I) assert(ValueMap.count(I) && "No mapping from source argument specified!"); #endif @@ -63,7 +83,8 @@ const BasicBlock &BB = *BI; // Create a new basic block and copy instructions into it! - BasicBlock *CBB = CloneBasicBlock(&BB, ValueMap, NameSuffix, NewFunc); + BasicBlock *CBB = CloneBasicBlock(&BB, ValueMap, NameSuffix, NewFunc, + CodeInfo); ValueMap[&BB] = CBB; // Add basic block mapping. if (ReturnInst *RI = dyn_cast<ReturnInst>(CBB->getTerminator())) @@ -89,13 +110,15 @@ /// the function from their old to new values. /// Function *llvm::CloneFunction(const Function *F, - std::map<const Value*, Value*> &ValueMap) { + std::map<const Value*, Value*> &ValueMap, + ClonedCodeInfo *CodeInfo) { std::vector<const Type*> ArgTypes; // The user might be deleting arguments to the function by specifying them in // the ValueMap. If so, we need to not add the arguments to the arg ty vector // - for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I) + for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end(); + I != E; ++I) if (ValueMap.count(I) == 0) // Haven't mapped the argument to anything yet? ArgTypes.push_back(I->getType()); @@ -108,14 +131,15 @@ // Loop over the arguments, copying the names of the mapped arguments over... Function::arg_iterator DestI = NewF->arg_begin(); - for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I) + for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end(); + I != E; ++I) if (ValueMap.count(I) == 0) { // Is this argument preserved? DestI->setName(I->getName()); // Copy the name over... ValueMap[I] = DestI++; // Add mapping to ValueMap } std::vector<ReturnInst*> Returns; // Ignore returns cloned... - CloneFunctionInto(NewF, F, ValueMap, Returns); + CloneFunctionInto(NewF, F, ValueMap, Returns, "", CodeInfo); return NewF; } _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits