[llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Tue Aug 3 22:28:14 PDT 2004
Changes in directory reopt/lib/TraceToFunction:
TraceToFunction.cpp updated: 1.82 -> 1.83
---
Log message:
Split findAlternateEntryPoints() out from buildFLIMap(). Make it smarter --
fixing the Olden/tsp and Stanford/Puzzle infinite loop bug.
In addTraceLiveInsToSet(), and in many other places, only allow Arguments and
Instructions as trace live-in/out variables. Add an assertion to insert() to
check this.
Get rid of the (disabled) code that calls hasUseDominatedByEdge(). There is a
place for this check, but it is _not_ here.
Don't dump the DominatorSet every time in debug mode. It gets boring, let me
tell you.
---
Diffs of the changes: (+35 -27)
Index: reopt/lib/TraceToFunction/TraceToFunction.cpp
diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.82 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.83
--- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.82 Thu Jul 29 23:04:44 2004
+++ reopt/lib/TraceToFunction/TraceToFunction.cpp Wed Aug 4 00:28:02 2004
@@ -78,6 +78,7 @@
void buildFLIMap (Trace &T, FLIMapTy &FLIMap);
// Main methods of TraceFunctionBuilder transformation
+ void findAlternateEntryPoints (Trace &T, std::vector<BasicBlock *> &b);
TypeVector createFunctionArgTypeVector (const LiveVariableVector &LiveIns,
const LiveVariableVector &LiveOuts);
void giveNamesToFunctionArgs (const LiveVariableVector &LiveIns,
@@ -201,6 +202,8 @@
}
static void insert (LiveVariableSet &Set, LiveVariableVector &Vector, Value *V){
+ assert ((isa<Argument> (V) || isa<Instruction> (V))
+ && "Weird: live variable not defined by instr");
Set.insert (V);
if (std::find (Vector.begin (), Vector.end (), V) == Vector.end ())
Vector.push_back (V);
@@ -225,8 +228,7 @@
if (std::find (StartingFrom, T.end (), InB) != T.end ()) {
Value *V = PN->getIncomingValue (i);
// neglect incoming phi values from off-trace
- if (!(isa<Constant> (V) || isa<GlobalValue> (V)
- || isa<BasicBlock>(V))) {
+ if (isa<Argument> (V) || isa<Instruction> (V)) {
DEBUG (std::cerr << "TLV: considering Phi source which is on-trace: " << InB->getName () << " with value " << V->getName () << "\n");
if (!DefinedInTraceBeforeUse (V, T, StartingFrom, true))
insert (S, LVV, V);
@@ -239,8 +241,7 @@
}
for (unsigned i = 0; i < Inst->getNumOperands (); ++i) {
Value *V = Inst->getOperand (i); // V is used in the trace by Inst.
- if (!(isa<Constant> (V) || isa<GlobalValue> (V)
- || isa<BasicBlock>(V)))
+ if (isa<Argument> (V) || isa<Instruction> (V))
if (!DefinedInTraceBeforeUse (V, T, StartingFrom, true))
insert (S, LVV, V);
}
@@ -599,14 +600,6 @@
DEBUG (std::cerr << "buildFLIMap: identified FLI block " << i->getName()
<< " on edge <" << edge.first->getName () << ", "
<< edge.second->getName () << ">\n");
- if (T.contains (edge.second) && edge.second != T.getEntryBasicBlock ()) {
- DEBUG (std::cerr << "buildFLIMap: " << edge.second->getName()
- << " is a back-edge target that's internal to the trace\n");
- if (std::find (AlternateEntryPointsV.begin (),
- AlternateEntryPointsV.end (), edge.second)
- == AlternateEntryPointsV.end ())
- AlternateEntryPointsV.push_back (edge.second);
- }
// 1. remove the block from the trace if it is in there
BasicBlock *bb = i;
Trace::iterator TI = std::find (T.begin (), T.end (), bb);
@@ -620,6 +613,24 @@
}
}
+// Fill in b with all the (possible) alternate entry points into T.
+void TraceFunctionBuilder::findAlternateEntryPoints (Trace &T,
+ std::vector<BasicBlock *> &b) {
+ for (Trace::iterator TI = T.begin (), TE = T.end(); TI != TE; ++TI) {
+ BasicBlock *Blk = *TI;
+ if (Blk == T.getEntryBasicBlock ())
+ continue;
+ for (Value::use_iterator ui = Blk->use_begin (), ue = Blk->use_end ();
+ ui != ue; ++ui) {
+ assert (isa<Instruction> (*ui)
+ && "can't deal with non-Instruction Users of BasicBlocks");
+ if (!T.contains (cast<Instruction> (*ui)->getParent ()))
+ if (std::find (b.begin (), b.end (), Blk) == b.end ())
+ b.push_back (Blk);
+ }
+ }
+}
+
BasicBlock *TraceFunctionBuilder::getFLIEdgeSource (BasicBlock *BB) const {
FLIMapTy::const_iterator i = FLIMap.find (BB);
if (i == FLIMap.end ()) return 0;
@@ -784,17 +795,17 @@
// Add the getelementptr/store instruction pairs here that
// correspond to each live-out variable.
for (LiveVariableVector::iterator SI = So.begin (), SE = So.end ();
- SI != SE; ++SI)
- if (dominates (T, cast<Instruction> ((*SI))->getParent (),
-#if 0 // WARNING: hasUseDominatedByEdge isn't working right yet!
- BI->getParent ())
- && hasUseDominatedByEdge (cast<Instruction> (*SI), srcB,
- successor))
-#else
- BI->getParent ()))
-#endif
- FB->getInstList ().push_back
- (new StoreInst (O2CMap[*SI], TF->LiveOutToArgMap[*SI]));
+ SI != SE; ++SI) {
+ Value *V = *SI;
+ bool storeIt = true;
+ if (Instruction *Inst = dyn_cast<Instruction> (V))
+ storeIt = dominates (T, Inst->getParent (), BI->getParent ());
+ else // it's an Argument, so it must dominate the store.
+ assert (isa<Argument> (V) && "not instruction, not argument??");
+ if (storeIt)
+ FB->getInstList ().push_back (new StoreInst (O2CMap[V],
+ TF->LiveOutToArgMap[V]));
+ }
// Make FB contain a return instruction that returns the
// number of the taken exit-branch. Add it to the end of FB:
ReturnInst *RI = new ReturnInst (ConstantUInt::get (Type::UIntTy,
@@ -864,11 +875,7 @@
bool TraceFunctionBuilder::runOnFunction (Function &F) {
if (T.getFunction () != &F) { return false; }
-
DS = &getAnalysis<DominatorSet>();
- DEBUG (std::cerr << "Dominator set information:\n";
- DS->print (std::cerr);
- std::cerr << "End dominator set information.\n");
// Create a TraceFunction object to hold the trace function along with
// its auxiliary data structures.
@@ -883,6 +890,7 @@
// Get some information about the trace's relationship to its parent
// function.
+ findAlternateEntryPoints (T, AlternateEntryPointsV);
buildTraceLiveInSet (LiveInSet, TF->LiveInVector, T);
buildTraceLiveOutSet (LiveOutSet, TF->LiveOutVector, T);
TypeVector P = createFunctionArgTypeVector (TF->LiveInVector,
More information about the llvm-commits
mailing list