[llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Wed Jun 23 16:43:01 PDT 2004
Changes in directory reopt/lib/TraceToFunction:
TraceToFunction.cpp updated: 1.67 -> 1.68
---
Log message:
Don't produce duplicate [ %liveIn, %entryfixup ] entries in trace entry block
phi nodes.
---
Diffs of the changes: (+43 -28)
Index: reopt/lib/TraceToFunction/TraceToFunction.cpp
diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.67 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.68
--- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.67 Tue Jun 15 04:46:02 2004
+++ reopt/lib/TraceToFunction/TraceToFunction.cpp Wed Jun 23 16:41:34 2004
@@ -64,6 +64,7 @@
TypeVector createFunctionArgTypeVector (PointerType *ST,
const LiveVariableSet &S);
void fillInFunctionBody (Trace &T, Function *F, LiveVariableSet &So);
+ int findOffTracePhiSource (const PHINode *newPN);
void fixupFunctionBodyBB (Trace &T, Function *F, BasicBlock *srcB,
BasicBlock *dstB, ValueMap &O2CMap,
LiveVariableSet &So);
@@ -596,6 +597,22 @@
return i->second.second;
}
+int TraceFunctionBuilder::findOffTracePhiSource (const PHINode *newPN) {
+ for (unsigned i = 0; i < newPN->getNumIncomingValues (); ++i) {
+ BasicBlock *phiSource = newPN->getIncomingBlock (i);
+ ValueMap::iterator MapIt = TF->O2CMap.find (phiSource);
+ if (MapIt != TF->O2CMap.end ()) { phiSource = cast<BasicBlock> (MapIt->second); }
+ if (newPN->getParent ()->getParent () != phiSource->getParent ()) {
+ DEBUG (std::cerr << "findOffTracePhiSource: " << newPN->getName ()
+ << "'s source #" << i << " looks like an off-trace source: [ %"
+ << newPN->getIncomingValue (i)->getName () << ", %"
+ << newPN->getIncomingBlock (i)->getName () << " ]\n");
+ return i;
+ }
+ }
+ return -1;
+}
+
/// 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
@@ -609,7 +626,7 @@
LiveVariableSet &So) {
assert (T.contains (srcB) && "Source BB is not on the trace");
assert (dstB->getParent () == F && "Clone is not in the function");
-
+
// Additional special handling for trace's entry basic block:
// The old entry BB's clone will start with a phi, one of whose args
// comes from off-trace (that's the trace entry point.) We can't
@@ -625,38 +642,36 @@
// their value from the argument which carries the live-in value.
for (BasicBlock::iterator BI = srcB->begin ();
PHINode *oldPN = dyn_cast<PHINode> (BI); ++BI) {
- DEBUG (std::cerr << "fixupFunctionBodyBB: Changing name of trace"
- << " entry block Phi node:\n" << O2CMap[oldPN] << " to "
- << O2CMap[oldPN]->getName() << ".phifixup\n";
- O2CMap[oldPN]->setName (O2CMap[oldPN]->getName () + ".phifixup"));
assert (TF->LiveInSet.find (oldPN) != TF->LiveInSet.end ()
&& "Phi nodes in trace entry BB must be live-in");
- unsigned argNum = TF->LiveInToParameterMap [oldPN];
- Argument *phiLiveIn = getFunctionArg (F, argNum);
- for (unsigned i = 0; i < oldPN->getNumIncomingValues (); ++i) {
- // Fold Phi sources which come from FLI blocks
- BasicBlock *phiSource = oldPN->getIncomingBlock (i);
- if (BasicBlock *realSource = getFLIEdgeSource (phiSource))
- phiSource = realSource;
- if (!T.contains (phiSource)) {
- Value *V = O2CMap[oldPN];
- assert (V && isa<PHINode> (V)
- && "Clone of PHINode from trace entry BB missing or mangled");
- PHINode *newPN = cast<PHINode> (V);
- DEBUG (std::cerr << "fixupFunctionBodyBB: Changing incoming block "
- << i << " of trace entry block Phi node:\n" << *newPN << " from "
- << newPN->getIncomingBlock (i)->getName () << " to entry-fixup "
- << "block, and incoming value to argument " << argNum << " (";
- WriteAsOperand (std::cerr, phiLiveIn, true, true,
- TF->TraceFn->getParent ());
- std::cerr << ")\n");
- newPN->setIncomingBlock (i, EntryFixup);
- newPN->setIncomingValue (i, phiLiveIn);
- }
+ Argument *phiLiveIn = getFunctionArg (F,
+ TF->LiveInToParameterMap [oldPN]);
+
+ Value *V = O2CMap[oldPN];
+ assert (V && isa<PHINode> (V)
+ && "Clone of PHINode from trace entry BB missing or mangled");
+ PHINode *newPN = cast<PHINode> (V);
+
+ DEBUG (std::cerr << "fixupFunctionBodyBB: Changing name of trace"
+ << " entry block Phi node:\n" << newPN << " to "
+ << newPN->getName() << ".phifixup\n";
+ newPN->setName (newPN->getName () + ".phifixup"));
+
+ // Remove all the off-trace sources; then, if we found an off-trace
+ // source, add an entryfixup source.
+ bool foundOffTracePhiSource = false;
+ for (int i = findOffTracePhiSource (newPN); i != -1;
+ i = findOffTracePhiSource (newPN)) {
+ foundOffTracePhiSource = true;
+ DEBUG (std::cerr << "fixupFunctionBodyBB: deleting " << newPN->getName ()
+ << "'s off-trace source #" << i << "\n");
+ newPN->removeIncomingValue (i);
}
+ if (foundOffTracePhiSource)
+ newPN->addIncoming (phiLiveIn, EntryFixup);
}
}
-
+
// If srcB contains a trace-exiting branch B, fix up B's clone in
// dstB to point to a new basic block in F that contains a return
// statement. Each return statement in F corresponds to a unique
More information about the llvm-commits
mailing list