[llvm-commits] CVS: reopt/lib/LightWtProfiling/TraceToFunction.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Sat Oct 11 11:44:00 PDT 2003
Changes in directory reopt/lib/LightWtProfiling:
TraceToFunction.cpp updated: 1.4 -> 1.5
---
Log message:
Rewrite getTraceLive{Out,In}Set() in terms of DefinedInTraceBeforeUse(),
which is defined in terms of Trace::dominates().
I'm not sure if this stuff is working yet, but I'm going nuts trying
to keep track of the 39834 different modified versions of this file
I have.
Arr.
---
Diffs of the changes: (+83 -26)
Index: reopt/lib/LightWtProfiling/TraceToFunction.cpp
diff -u reopt/lib/LightWtProfiling/TraceToFunction.cpp:1.4 reopt/lib/LightWtProfiling/TraceToFunction.cpp:1.5
--- reopt/lib/LightWtProfiling/TraceToFunction.cpp:1.4 Sat Sep 13 16:12:11 2003
+++ reopt/lib/LightWtProfiling/TraceToFunction.cpp Sat Oct 11 11:43:17 2003
@@ -14,6 +14,7 @@
#include "llvm/iMemory.h"
#include "llvm/iOther.h"
#include "llvm/Constants.h"
+#include "llvm/Support/CFG.h" // for succ_iterator, etc.
#include "Support/StringExtras.h" // for utostr()
#include "Support/Debug.h" // for DEBUG()
#include <cassert>
@@ -40,8 +41,73 @@
virtual Function *traceToFunction (Trace &T);
};
-/// getTraceLiveInSet - Return the set of variables which are used in
-/// the trace but which are not defined in the trace.
+bool Trace::dominates (const BasicBlock *B1, const BasicBlock *B2,
+ const BasicBlock *start) {
+ if (start == B1) {
+ return true; // Seen B1 on this path, if we see B2 later it's OK.
+ } else if (start == B2) {
+ return false; // Seen B2, w/o seeing B1 earlier on this path. Not OK.
+ } else {
+ // If any successors are on the trace, AND not the entry BB, check them too.
+ // (Stop at entry BB because we don't want to loop if the CFG loops.)
+ for (succ_const_iterator i = succ_begin (start), e = succ_end (start);
+ i != e; ++i) {
+ const BasicBlock *succ = *i;
+ if (contains (succ) && (getEntryBasicBlock () != succ)
+ && (!dominates (B1, B2, succ)))
+ return false;
+ }
+ return true; // Dominates on all successors ==> dominates here too
+ }
+}
+
+bool Trace::dominates (const BasicBlock *B1, const BasicBlock *B2) {
+ return dominates (B1, B2, getEntryBasicBlock ());
+}
+
+static bool DefinedInTraceBeforeUse (Value *V, Trace &T) {
+ Instruction *Inst = dyn_cast<Instruction> (V);
+ if (!Inst)
+ return false;
+ BasicBlock *Block = Inst->getParent ();
+ if (!T.contains (Block)) // Is V defined in trace?
+ return false;
+ for (Value::use_iterator ui = V->use_begin (), ue = V->use_end ();
+ ui != ue; ++ui) {
+ Instruction *UInst = dyn_cast<Instruction> (*ui);
+ if (!UInst) // Non-Instruction Users scare me, mommy
+ return false;
+ BasicBlock *UBlock = UInst->getParent ();
+ if (Block == UBlock) {
+ // Start at Block->begin() traversing next pointers; if UInst
+ // appears BEFORE Inst in Block's InstList, return false
+ for (BasicBlock::const_iterator bi = Block->begin (), be = Block->end ();
+ bi != be; ++bi) {
+ const Instruction *BlockInst = bi;
+ if (BlockInst == UInst)
+ return false;
+ else if (BlockInst == Inst)
+ break;
+ }
+ } else {
+ if (!T.contains (UBlock))
+ return false;
+ else {
+ // If UBlock appears BEFORE Block on some path from the first
+ // basic block of the trace to an exit BB of the trace, return
+ // false.
+ if (!T.dominates (Block, UBlock))
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+/// getTraceLiveInSet - Return 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.
///
static LiveVariableSet getTraceLiveInSet (Trace &T) {
LiveVariableSet S;
@@ -54,10 +120,8 @@
for (unsigned i = 0; i < I.getNumOperands (); ++i) {
Value *V = I.getOperand (i);
// V is used in the trace by instruction I.
- if (Instruction *VI = dyn_cast<Instruction> (V))
- // V is defined by an instruction; not a constant or global.
- if (!T.contains (VI->getParent ()))
- // V is defined by an instruction outside the trace.
+ if (!(isa<Constant> (V) || isa<GlobalVariable> (V)))
+ if (DefinedInTraceBeforeUse (V, T))
S.insert (V);
}
}
@@ -65,30 +129,23 @@
return S;
}
-/// getTraceLiveOutSet - Return the set of variables which are defined
-/// by an instruction inside the trace, and used in an instruction
-/// outside the trace (but within that trace's function.)
+/// getTraceLiveOutSet - Any variable defined within the trace is
+/// potentially live-out, EXCEPT if its only uses are in the trace AND
+/// come after the def.
///
static LiveVariableSet getTraceLiveOutSet (Trace &T) {
LiveVariableSet S;
Function &F = *T.getFunction();
- for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) {
- BasicBlock &B = *FI;
- if (!T.contains (&B)) {
- for (BasicBlock::iterator BI = B.begin(), BE = B.end(); BI != BE; ++BI) {
- Instruction &I = *BI;
- // I is an instruction in the trace's function, but outside the trace.
- // Check its operands for uses of values defined in the trace.
- for (unsigned i = 0; i < I.getNumOperands (); ++i) {
- Value *V = I.getOperand (i);
- // V is used outside the trace by instruction I.
- if (Instruction *VI = dyn_cast<Instruction> (V))
- // V is defined by an instruction; not a constant or global.
- if (T.contains (VI->getParent ()))
- // V is defined by an instruction inside the trace.
- S.insert (V);
- }
- }
+ 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.
+ // (Does it define a value? FIXME)
+ if (!DefinedInTraceBeforeUse (V, T))
+ S.insert (&I);
}
}
return S;
More information about the llvm-commits
mailing list