[llvm-commits] CVS: reopt/lib/LightWtProfiling/TraceToFunction.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Wed Mar 10 13:04:01 PST 2004
Changes in directory reopt/lib/LightWtProfiling:
TraceToFunction.cpp updated: 1.24 -> 1.25
---
Log message:
Move ValueToIntMap and LiveInToParameterMap into TraceFunction.h.
Fix up some comments.
Don't let O2CMap contain things which were deleted.
Remove a DEBUG printout which wasn't working anyway.
When debugging, print out O2CMap just before returning from TraceToFunction.
---
Diffs of the changes: (+33 -20)
Index: reopt/lib/LightWtProfiling/TraceToFunction.cpp
diff -u reopt/lib/LightWtProfiling/TraceToFunction.cpp:1.24 reopt/lib/LightWtProfiling/TraceToFunction.cpp:1.25
--- reopt/lib/LightWtProfiling/TraceToFunction.cpp:1.24 Tue Mar 9 13:18:26 2004
+++ reopt/lib/LightWtProfiling/TraceToFunction.cpp Wed Mar 10 13:03:43 2004
@@ -47,11 +47,9 @@
namespace llvm {
typedef std::vector<const Type *> TypeVector;
-typedef std::map<Value *, unsigned int> ValueToIntMap;
typedef std::map<BranchInst *, unsigned int> BranchNumberMap;
class TraceToFunction {
- ValueToIntMap LiveInToParameterMap;
BranchNumberMap BranchNumber;
TraceFunction *TF;
virtual TypeVector createFunctionArgTypeVector (PointerType *ST,
@@ -206,23 +204,23 @@
/// create a parameter list containing a parameter for each of the
/// variables in S as well as a pointer-to-structure type PST to fill
/// in which contains the live-outs. As a side effect, fill in the
-/// mapping between live-ins and parameters in the global map named
-/// LiveInToParameterMap.
+/// mapping between live-ins and parameters in
+/// TF->LiveInToParameterMap.
///
TypeVector TraceToFunction::createFunctionArgTypeVector (PointerType *PST,
LiveVariableSet S) {
TypeVector P;
P.push_back (PST);
- LiveInToParameterMap.clear ();
+ TF->LiveInToParameterMap.clear ();
for (LiveVariableSet::iterator I = S.begin (), E = S.end (); I != E; ++I) {
Value *V = *I;
P.push_back (V->getType ());
- LiveInToParameterMap[V] = P.size () - 1;
+ TF->LiveInToParameterMap[V] = P.size () - 1;
}
// Print out mapping of instructions to arg numbers.
- DEBUG(for (ValueToIntMap::iterator I = LiveInToParameterMap.begin (),
- E = LiveInToParameterMap.end (); I != E; ++I)
+ DEBUG(for (ValueToIntMap::iterator I = TF->LiveInToParameterMap.begin (),
+ E = TF->LiveInToParameterMap.end (); I != E; ++I)
std::cerr << I->first << " is parameter " << I->second << "\n");
return P;
}
@@ -291,7 +289,7 @@
}
}
-static void fixupPhisAndCalls (BasicBlock *dstB) {
+static void fixupPhisAndCalls (BasicBlock *dstB, ValueMap &O2CMap) {
std::vector<Instruction *> goners;
Function *F = dstB->getParent ();
// Fix up Phi nodes:
@@ -370,6 +368,12 @@
assert (goners.back ()->use_size () == 0
&& "Whoops, I was going to delete something which still has uses");
dstB->getInstList ().erase (goners.back ());
+ for (ValueMap::iterator i = O2CMap.begin(), e = O2CMap.end(); i != e; ++i) {
+ if (i->second == goners.back ()) {
+ O2CMap.erase (i);
+ break;
+ }
+ }
goners.pop_back ();
}
}
@@ -397,7 +401,7 @@
fixupFunctionBodyBB (T, F, srcB, dstB, O2CMap, So);
}
for (Function::iterator FI = F->begin (), FE = F->end (); FI != FE; ++FI)
- fixupPhisAndCalls (FI);
+ fixupPhisAndCalls (FI, O2CMap);
}
/// fixupFunctionBodyBB - Given srcB in T and its clone dstB in F, and
@@ -515,20 +519,15 @@
// set of the trace, then we must replace that operand with
// the corresponding argument of F. We can find out which
// operands to replace by looking them up in
- // LiveInToParameterMap.
- if (LiveInToParameterMap.find (V) != LiveInToParameterMap.end ()) {
+ // TF->LiveInToParameterMap.
+ if (TF->LiveInToParameterMap.find (V) != TF->LiveInToParameterMap.end ()) {
DEBUG(std::cerr << *V << " in instruction " << I
- << " is argument " << LiveInToParameterMap[V]
+ << " is argument " << TF->LiveInToParameterMap[V]
<< " in new function\n");
- DEBUG(std::cerr << " -- V's type is " << V->getType () << "\n");
- DEBUG(std::cerr << " -- Argument " << LiveInToParameterMap[V]
- << "'s type is "
- << getFunctionArg (F, LiveInToParameterMap[V])->getType ()
- << "\n");
assert (V->getType () ==
- getFunctionArg (F, LiveInToParameterMap[V])->getType ()
+ getFunctionArg (F, TF->LiveInToParameterMap[V])->getType ()
&& "Live-in Value's type doesn't match corresponding arg type");
- I.setOperand(i, getFunctionArg (F, LiveInToParameterMap[V]));
+ 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
@@ -558,6 +557,18 @@
}
}
+/// Dump out the O2CMap for the given TraceFunction to stderr.
+/// Only called when debugging.
+///
+static void cloneMapDump (TraceFunction *TF) {
+ for (ValueMap::const_iterator i = TF->O2CMap.begin(), e = TF->O2CMap.end();
+ i != e; ++i) {
+ const std::pair<const Value *, Value *> &elem = *i;
+ std::cerr << "Original value: " << i->first << "\nmaps to: "
+ << i->second << "\n";
+ }
+}
+
TraceFunction *TraceToFunction::traceToFunction (Trace &T) {
// Create a TraceFunction object to hold the trace function along with
// its auxiliary data structures.
@@ -582,6 +593,8 @@
T.getModule ());
DEBUG(giveNamesToFunctionArgs (TF->LiveInSet, TF->TraceFn));
fillInFunctionBody (T, TF->TraceFn, TF->LiveOutSet);
+
+ DEBUG(cloneMapDump(TF));
return TF;
}
More information about the llvm-commits
mailing list