[llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp
Brian Gaeke
gaeke at persephone.cs.uiuc.edu
Mon Jun 14 15:55:02 PDT 2004
Changes in directory reopt/lib/TraceToFunction:
TraceToFunction.cpp updated: 1.63 -> 1.64
---
Log message:
Start adding support for calculating live-outs starting somewhere
other than the entry BasicBlock of the Trace. DefinedInTraceBeforeUse()
still doesn't really support it yet, though.
---
Diffs of the changes: (+47 -37)
Index: reopt/lib/TraceToFunction/TraceToFunction.cpp
diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.63 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.64
--- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.63 Mon Jun 14 02:29:06 2004
+++ reopt/lib/TraceToFunction/TraceToFunction.cpp Mon Jun 14 15:50:12 2004
@@ -98,7 +98,9 @@
}
}
-static bool DefinedInTraceBeforeUse (Value *V, Trace &T) {
+static bool DefinedInTraceBeforeUse (Value *V, Trace &T, Trace::iterator Start) {
+ assert (Start == T.begin ()
+ && "FIXME: Can only start at beginning of trace for now");
Instruction *Inst = dyn_cast<Instruction> (V);
if (!Inst)
return false;
@@ -140,57 +142,65 @@
return true;
}
-/// getTraceLiveInSet - Initialize TF->LiveInSet with the live-in set of the
-/// trace. Any variable which is used in the trace is potentially live-in,
-/// EXCEPT if it's a constant or a global, OR it is defined before being used
-/// in the trace.
-///
-void TraceFunctionBuilder::getTraceLiveInSet (LiveVariableSet &S, Trace &T) {
- for (Trace::iterator TI = T.begin (), TE = T.end (); TI != TE; ++TI) {
- BasicBlock *B = *TI;
- // B is a basic block in the trace.
- for (BasicBlock::iterator BI = B->begin (), BE = B->end (); BI != BE; ++BI){
- Instruction &I = *BI;
- // I is an instruction in B, which is in the trace.
- for (unsigned i = 0; i < I.getNumOperands (); ++i) {
- Value *V = I.getOperand (i);
- // V is used in the trace by instruction I.
+/// addTraceLiveInsToSet - helper fn. for getTraceLiveInSet and
+/// getTraceLiveOutSet. Adds the live-ins of T to S, assuming that
+/// the trace starts at StartingFrom and ends at T.end().
+static void addTraceLiveInsToSet (LiveVariableSet &S, Trace &T,
+ Trace::iterator StartingFrom) {
+ for (Trace::iterator TI = StartingFrom, TE = T.end (); TI != TE; ++TI)
+ for (BasicBlock::iterator Inst = (*TI)->begin (), BE = (*TI)->end ();
+ Inst != BE; ++Inst)
+ 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 (!DefinedInTraceBeforeUse (V, T))
+ if (!DefinedInTraceBeforeUse (V, T, StartingFrom))
S.insert (V);
}
- }
- }
- // Add phis from entry BB
- for (BasicBlock::iterator Inst = T.getEntryBasicBlock ()->begin ();
+ // Add phis from first BB
+ for (BasicBlock::iterator Inst = (*StartingFrom)->begin ();
PHINode *PN = dyn_cast<PHINode> (Inst); ++Inst)
S.insert (PN);
}
+/// getTraceLiveInSet - Initialize TF->LiveInSet with the live-in set of the
+/// trace. Any variable which is used in the trace is potentially live-in,
+/// EXCEPT if it's a constant or a global, OR it is defined before being used
+/// in the trace.
+///
+void TraceFunctionBuilder::getTraceLiveInSet (LiveVariableSet &S, Trace &T) {
+ addTraceLiveInsToSet (S, T, T.begin ());
+}
+
/// getTraceLiveOutSet - Initializes S with the live-out set of trace T.
/// Any variable defined within the trace is
/// potentially live-out, EXCEPT if its only uses are in the trace AND
-/// come after the def.
+/// come after the def. This method must also take into account side entrances
+/// to the NON-traced version of the code caused by early exits that end up
+/// taking back-edge branches.
///
void TraceFunctionBuilder::getTraceLiveOutSet (LiveVariableSet &S, Trace &T) {
- Function &F = *T.getFunction();
- for (Trace::iterator TI = T.begin (), TE = T.end (); TI != TE; ++TI) {
- BasicBlock *B = *TI;
- // B is a basic block in the trace.
- for (BasicBlock::iterator BI = B->begin (), BE = B->end (); BI != BE; ++BI){
- Instruction &I = *BI;
- Value *V = &I;
- // I is an instruction in B, which is in the trace.
- if (!(V->getType () == Type::VoidTy
- || V->getType () == Type::LabelTy)) // No void or label Values
- if (!DefinedInTraceBeforeUse (V, T))
- S.insert (&I);
+ // Iterate over the instructions in the trace, adding live-out values to S.
+ for (Trace::iterator TI = T.begin (), TE = T.end (); TI != TE; ++TI)
+ for (BasicBlock::iterator Inst = (*TI)->begin (), BE = (*TI)->end ();
+ Inst != BE; ++Inst) {
+ // Only consider those which produce values (not void or labels).
+ if (!(Inst->getType () == Type::VoidTy
+ || Inst->getType () == Type::LabelTy))
+ if (!DefinedInTraceBeforeUse (Inst, T, StartingFrom))
+ S.insert (Inst);
}
- }
+
+ // If there are alternate entry points into the trace, their live-INs are
+ // live-OUT from the main trace.
if (!AlternateEntryPoints.empty ()) {
- assert (AlternateEntryPoints.empty ()
- && "Alternate entry points not handled yet");
+ for (std::set<BasicBlock *>::iterator i = AlternateEntryPoints.begin (),
+ e = AlternateEntryPoints.end (); i != e; ++i) {
+ // Find the position of the block in the trace.
+ Trace::iterator StartingFrom = std::find (T.begin (), T.end (), *i);
+ assert (StartingFrom != T.end () && "AlternateEntryPoint not on trace?!");
+ addTraceLiveInsToSet (S, T, StartingFrom);
+ }
}
}
More information about the llvm-commits
mailing list