From dcd8040d115803e427dc1caf9feb44a894eef927 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 19 Nov 2002 21:54:07 +0000 Subject: Rework inline pass to use cloning infrastructure to do the dirty work git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4766 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/CloneFunction.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'lib/Transforms/Utils/CloneFunction.cpp') diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp index 0a2c41f785..94a4750a2d 100644 --- a/lib/Transforms/Utils/CloneFunction.cpp +++ b/lib/Transforms/Utils/CloneFunction.cpp @@ -4,6 +4,7 @@ // FIXME: document #include "llvm/Transforms/Utils/Cloning.h" +#include "llvm/iTerminators.h" #include "llvm/Function.h" #include @@ -35,9 +36,10 @@ static inline void RemapInstruction(Instruction *I, // ArgMap values. // void CloneFunctionInto(Function *NewFunc, const Function *OldFunc, - const std::vector &ArgMap) { - assert(OldFunc->aempty() || !NewFunc->aempty() && - "Synthesization of arguments is not implemented yet!"); + const std::vector &ArgMap, + std::vector &Returns, + const char *NameSuffix) { + assert(NameSuffix && "NameSuffix cannot be null!"); assert(OldFunc->asize() == ArgMap.size() && "Improper number of argument values to map specified!"); @@ -55,25 +57,30 @@ void CloneFunctionInto(Function *NewFunc, const Function *OldFunc, // Loop over all of the basic blocks in the function, cloning them as - // appropriate. + // appropriate. Note that we save BE this way in order to handle cloning of + // recursive functions into themselves. // for (Function::const_iterator BI = OldFunc->begin(), BE = OldFunc->end(); BI != BE; ++BI) { const BasicBlock &BB = *BI; - assert(BB.getTerminator() && "BasicBlock doesn't have terminator!?!?"); // Create a new basic block to copy instructions into! - BasicBlock *CBB = new BasicBlock(BB.getName(), NewFunc); + BasicBlock *CBB = new BasicBlock("", NewFunc); + if (BB.hasName()) CBB->setName(BB.getName()+NameSuffix); ValueMap[&BB] = CBB; // Add basic block mapping. // Loop over all instructions copying them over... for (BasicBlock::const_iterator II = BB.begin(), IE = BB.end(); II != IE; ++II) { Instruction *NewInst = II->clone(); - NewInst->setName(II->getName()); // Name is not cloned... + if (II->hasName()) + NewInst->setName(II->getName()+NameSuffix); // Name is not cloned... CBB->getInstList().push_back(NewInst); ValueMap[II] = NewInst; // Add instruction map to value. } + + if (ReturnInst *RI = dyn_cast(CBB->getTerminator())) + Returns.push_back(RI); } // Loop over all of the instructions in the function, fixing up operand -- cgit v1.2.3