aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBrian Gaeke <gaeke@uiuc.edu>2004-05-19 09:08:14 +0000
committerBrian Gaeke <gaeke@uiuc.edu>2004-05-19 09:08:14 +0000
commitc58a7f4b3ca69c0f3b827ec6ca2664603570d7d6 (patch)
tree4e849a681ead43f1c07b071dde08c47f8d227a91 /lib
parent6129af3fb14d1050f9fb4800c787e6f930b910d1 (diff)
downloadexternal_llvm-c58a7f4b3ca69c0f3b827ec6ca2664603570d7d6.zip
external_llvm-c58a7f4b3ca69c0f3b827ec6ca2664603570d7d6.tar.gz
external_llvm-c58a7f4b3ca69c0f3b827ec6ca2664603570d7d6.tar.bz2
Add CloneTraceInto(), which is based on (and has mostly the same
effects as) CloneFunctionInto(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13601 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Utils/CloneTrace.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/Transforms/Utils/CloneTrace.cpp b/lib/Transforms/Utils/CloneTrace.cpp
index 7cdb20e..94bfc38 100644
--- a/lib/Transforms/Utils/CloneTrace.cpp
+++ b/lib/Transforms/Utils/CloneTrace.cpp
@@ -15,9 +15,11 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/Analysis/Trace.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/iPHINode.h"
#include "llvm/Function.h"
+#include "ValueMapper.h"
using namespace llvm;
//Clones the trace (a vector of basic blocks)
@@ -84,3 +86,34 @@ llvm::CloneTrace(const std::vector<BasicBlock*> &origTrace) {
//return new vector of basic blocks
return clonedTrace;
}
+
+/// CloneTraceInto - Clone T into NewFunc. Original<->clone mapping is
+/// saved in ValueMap.
+///
+void llvm::CloneTraceInto(Function *NewFunc, Trace &T,
+ std::map<const Value*, Value*> &ValueMap,
+ const char *NameSuffix) {
+ assert(NameSuffix && "NameSuffix cannot be null!");
+
+ // Loop over all of the basic blocks in the trace, cloning them as
+ // appropriate.
+ //
+ for (Trace::const_iterator BI = T.begin(), BE = T.end(); BI != BE; ++BI) {
+ const BasicBlock *BB = *BI;
+
+ // Create a new basic block and copy instructions into it!
+ BasicBlock *CBB = CloneBasicBlock(BB, ValueMap, NameSuffix, NewFunc);
+ ValueMap[BB] = CBB; // Add basic block mapping.
+ }
+
+ // Loop over all of the instructions in the new function, fixing up operand
+ // references as we go. This uses ValueMap to do all the hard work.
+ //
+ for (Function::iterator BB =
+ cast<BasicBlock>(ValueMap[T.getEntryBasicBlock()]),
+ BE = NewFunc->end(); BB != BE; ++BB)
+ // Loop over all instructions, fixing each one as we find it...
+ for (BasicBlock::iterator II = BB->begin(); II != BB->end(); ++II)
+ RemapInstruction(II, ValueMap);
+}
+