[llvm-commits] CVS: reopt/lib/LightWtProfiling/TraceToFunction.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Sat May 15 19:02:02 PDT 2004
Changes in directory reopt/lib/LightWtProfiling:
TraceToFunction.cpp updated: 1.31 -> 1.32
---
Log message:
Use a better class name for TraceToFunction, and add comments.
Stub out an interface for finding FLI blocks.
Apply a few minor simplifications.
Expand some tabs.
---
Diffs of the changes: (+48 -30)
Index: reopt/lib/LightWtProfiling/TraceToFunction.cpp
diff -u reopt/lib/LightWtProfiling/TraceToFunction.cpp:1.31 reopt/lib/LightWtProfiling/TraceToFunction.cpp:1.32
--- reopt/lib/LightWtProfiling/TraceToFunction.cpp:1.31 Fri May 14 12:58:20 2004
+++ reopt/lib/LightWtProfiling/TraceToFunction.cpp Sat May 15 19:00:52 2004
@@ -45,7 +45,10 @@
typedef std::vector<const Type *> TypeVector;
typedef std::map<BranchInst *, unsigned int> BranchNumberMap;
-class TraceToFunction {
+/// TraceFunctionBuilder - a Method Object which encapsulates the algorithm
+/// for building TraceFunctions given Traces.
+///
+class TraceFunctionBuilder {
BranchNumberMap BranchNumber;
TraceFunction *TF;
virtual TypeVector createFunctionArgTypeVector (PointerType *ST,
@@ -55,9 +58,14 @@
BasicBlock *dstB, ValueMap &O2CMap,
LiveVariableSet &So);
public:
- TraceToFunction () { }
- virtual ~TraceToFunction () { }
- virtual TraceFunction *traceToFunction (Trace &T);
+ TraceFunctionBuilder () { }
+ virtual ~TraceFunctionBuilder () { }
+
+ /// buildTraceFunction - Given a Trace object, returns a pointer to a new
+ /// TraceFunction containing the same code as the Trace, along with some.
+ /// auxiliary data structures.
+ ///
+ virtual TraceFunction *buildTraceFunction (Trace &T);
};
static bool dominates (Trace &T, const BasicBlock *B1,
@@ -203,7 +211,7 @@
/// mapping between live-ins and parameters in
/// TF->LiveInToParameterMap.
///
-TypeVector TraceToFunction::createFunctionArgTypeVector (PointerType *PST,
+TypeVector TraceFunctionBuilder::createFunctionArgTypeVector (PointerType *PST,
LiveVariableSet S) {
TypeVector P;
P.push_back (PST);
@@ -374,7 +382,7 @@
/// consistent and that the live-outs So get stored in F's first
/// argument.
///
-void TraceToFunction::fillInFunctionBody (Trace &T, Function *F,
+void TraceFunctionBuilder::fillInFunctionBody (Trace &T, Function *F,
LiveVariableSet &So) {
ValueMap &O2CMap = TF->O2CMap;
// First copy the basic blocks from the trace.
@@ -395,13 +403,21 @@
fixupPhisAndCalls (FI, O2CMap);
}
+/// isFirstLevelInstrumentationBlock - returns true iff BB is a basic block
+/// inserted by the first-level instrumentation (-instloops) pass.
+///
+static bool isFirstLevelInstrumentationBlock (BasicBlock *BB) {
+ // not yet implemented
+ return false;
+}
+
/// fixupFunctionBodyBB - Given srcB in T and its clone dstB in F, and
/// the map O2CMap detailing the correspondences between values in T
/// and values in F, fix up dstB so that its contents are internally
/// consistent, and so that it stores its live-out values So in F's first
/// argument. (This is where all the magic gets done...)
///
-void TraceToFunction::fixupFunctionBodyBB (Trace &T, Function *F,
+void TraceFunctionBuilder::fixupFunctionBodyBB (Trace &T, Function *F,
BasicBlock *srcB, BasicBlock *dstB,
ValueMap &O2CMap,
LiveVariableSet &So) {
@@ -496,8 +512,7 @@
});
assert(isa<BasicBlock> (V2)
&& "Clone of basic block on trace is not a basic block?");
- BasicBlock *BIsuccInF = cast<BasicBlock> (V2);
- BIinF->setSuccessor (i, BIsuccInF);
+ BIinF->setSuccessor (i, cast<BasicBlock> (V2));
}
}
}
@@ -518,10 +533,10 @@
TF->MatrixFn->getParent ());
std::cerr << " in instruction:\n " << I << " is argument "
<< TF->LiveInToParameterMap[V] << " in new function\n");
- assert (V->getType () ==
- getFunctionArg (F, TF->LiveInToParameterMap[V])->getType ()
- && "Live-in Value's type doesn't match corresponding arg type");
- I.setOperand(i, getFunctionArg (F, TF->LiveInToParameterMap[V]));
+ assert (V->getType () ==
+ getFunctionArg (F, TF->LiveInToParameterMap[V])->getType ()
+ && "Live-in Value's type doesn't match corresponding arg type");
+ I.setOperand(i, getFunctionArg (F, TF->LiveInToParameterMap[V]));
}
// If the instruction I has an operand which is in the
// trace, that operand will have been cloned into the
@@ -529,23 +544,24 @@
// outside the function. Replace any reference to an operand
// which has had a clone made with a reference to its clone.
else if (O2CMap.find (V) != O2CMap.end () && O2CMap[V]) {
- DEBUG(std::cerr << *V << " in instruction " << I
- << " is value " << O2CMap[V] << " in new function\n");
- assert (V->getType () == O2CMap[V]->getType ()
- && "Value's type doesn't match clone's type");
- I.setOperand(i, O2CMap[V]);
+ DEBUG(std::cerr << *V << " in instruction " << I
+ << " is value " << O2CMap[V] << " in new function\n");
+ assert (V->getType () == O2CMap[V]->getType ()
+ && "Value's type doesn't match clone's type");
+ I.setOperand(i, O2CMap[V]);
}
}
+
// Make sure that our operand fixups did not try to branch into a
// BB outside the trace function or a non-cloned BB.
DEBUG(if (BranchInst *BrI = dyn_cast<BranchInst> (&I)) {
for (unsigned i = 0; i < BrI->getNumSuccessors (); ++i) {
BasicBlock *succ = BrI->getSuccessor (i);
- assert (succ->getParent () == F
- && "Branch out of function missed by copyTraceToFunction");
- assert (O2CMap.find (succ) == O2CMap.end ()
- && "Branch's clone found as key in original-->clone map; "
- "no one told me today was opposite day!");
+ assert (succ->getParent () == F
+ && "Branch out of function missed by fixupFunctionBodyBB");
+ assert (O2CMap.find (succ) == O2CMap.end ()
+ && "Branch's clone found as key in original-->clone map; "
+ "no one told me today was opposite day!");
}
});
}
@@ -555,7 +571,7 @@
/// Only called when debugging.
///
static void cloneMapDump (TraceFunction *TF, std::ostream &OS) {
- OS << "\n; TraceToFunction Original-->Clone map follows:\n";
+ OS << "\n; TraceFunctionBuilder Original-->Clone map follows:\n";
for (ValueMap::const_iterator i = TF->O2CMap.begin(), e = TF->O2CMap.end();
i != e; ++i) {
const std::pair<const Value *, Value *> &elem = *i;
@@ -568,13 +584,13 @@
OS << "\n";
}
-TraceFunction *TraceToFunction::traceToFunction (Trace &T) {
+TraceFunction *TraceFunctionBuilder::buildTraceFunction (Trace &T) {
// Create a TraceFunction object to hold the trace function along with
// its auxiliary data structures.
TF = new TraceFunction (T);
std::string CurrentFnName = T.getFunction ()->getName ();
- DEBUG(std::cerr << "In traceToFunction() for " << CurrentFnName << "\n");
+ DEBUG(std::cerr << "In buildTraceFunction() for " << CurrentFnName << "\n");
DEBUG(T.dump ());
// Get some information about the trace's relationship to its parent
@@ -598,11 +614,13 @@
return TF;
}
-/// runTraceToFunction - Entry point for TraceToFunction transformation.
-
+/// TraceFunction::get - Given a Trace, returns a TraceFunction, which is
+/// a Function containing the code from the Trace along with some supporting
+/// data structures.
+///
TraceFunction *TraceFunction::get (Trace &T) {
- TraceToFunction TTF;
- return TTF.traceToFunction (T);
+ TraceFunctionBuilder TTF;
+ return TTF.buildTraceFunction (T);
}
} // end namespace llvm
More information about the llvm-commits
mailing list