[llvm-commits] CVS: reopt/lib/LightWtProfiling/ValueAllocState.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Mon May 31 00:54:02 PDT 2004
Changes in directory reopt/lib/LightWtProfiling:
ValueAllocState.cpp updated: 1.1 -> 1.2
---
Log message:
Refactor the calculation of InstructionKey & OperandKey into
getValueAllocStateKeys(). Make it understand that the first PHI node
in a trace should have a special key.
---
Diffs of the changes: (+37 -30)
Index: reopt/lib/LightWtProfiling/ValueAllocState.cpp
diff -u reopt/lib/LightWtProfiling/ValueAllocState.cpp:1.1 reopt/lib/LightWtProfiling/ValueAllocState.cpp:1.2
--- reopt/lib/LightWtProfiling/ValueAllocState.cpp:1.1 Sun May 30 04:01:28 2004
+++ reopt/lib/LightWtProfiling/ValueAllocState.cpp Mon May 31 00:51:44 2004
@@ -17,6 +17,7 @@
#include "reopt/MappingInfo.h"
#include "llvm/Module.h"
#include "llvm/Argument.h"
+#include "llvm/iPHINode.h"
#include "llvm/Support/InstIterator.h"
#include "Support/Debug.h"
#include "../../../../lib/Target/SparcV9/RegAlloc/AllocInfo.h"
@@ -85,26 +86,42 @@
abort ();
}
+static BasicBlock *TraceEntryBB = 0;
+
+/// getValueAllocStateKeys - Fill in InstructionKey and OperandKey with the
+/// indices used to look up saved register allocation state for V in F.
+///
+static void getValueAllocStateKeys (Function *F, Value *V, int &InstructionKey,
+ int &OperandKey, bool preferLiveIn) {
+ if (Argument *Arg = dyn_cast<Argument> (V)) {
+ InstructionKey = -1;
+ OperandKey = getNumberOfFunctionArg (F, Arg);
+ } else if (Instruction *Inst = dyn_cast<Instruction> (V)) {
+ InstructionKey = getSavedStateIndexOfInstruction (F, Inst);
+ if (isa<PHINode> (Inst) && preferLiveIn
+ && Inst->getParent() == TraceEntryBB)
+ OperandKey = -2; // look for PhiCpRes
+ else
+ OperandKey = -1;
+ } else {
+ std::cerr << "getValueAllocStateKeys: can't look up state for " << *V;
+ abort();
+ }
+}
+
/// Returns the register number or stack position where V can be found in the
/// machine code for the function F, which it finds by searching the global
/// variable _llvm_regAllocState written out by PhyRegAlloc.cpp during a
/// previous invocation of llc.
///
-static AllocInfo getValueAllocStateFromModule (Function *F, Value *V) {
+static AllocInfo getValueAllocStateFromModule (Function *F, Value *V,
+ bool preferLiveIn) {
unsigned FI = getLLVMFunctionPositionInfo (F);
FunctionAllocState *FAllocState = _llvm_regAllocState.functions[FI];
assert (FAllocState->numTuples > 0
&& "Reg. alloc state for function is empty");
int InstructionKey = -1, OperandKey = -1;
- if (Argument *A = dyn_cast<Argument> (V)) {
- // Find the alloc state of an argument.
- OperandKey = getNumberOfFunctionArg (F, A);
- } else {
- // Figure out the indices (FI, VI, VO) that can be used to look up V, which
- // is an operand of some instruction in F, in _llvm_regAllocState:
- Instruction *Instr = cast<Instruction> (V);
- InstructionKey = getSavedStateIndexOfInstruction (F, Instr);
- }
+ getValueAllocStateKeys (F, V, InstructionKey, OperandKey, preferLiveIn);
// Reconstruct the AllocInfo for V by searching
// _llvm_regAllocState.functions[FI] for a tuple that starts with
// (InstructionKey, OperandKey, ...):
@@ -121,7 +138,7 @@
}
// By this time we had better have found it, otherwise we are about to do bad
// things.
- std::cerr << "ERROR: UnpackTraceFunction: No saved AllocInfo found for "
+ std::cerr << "ERROR: No saved AllocInfo found for "
<< F->getName () << "()'s value " << *V
<< " in getValueAllocStateFromModule()\n";
abort ();
@@ -131,26 +148,13 @@
/// machine code for the function F, which it finds by searching the global
/// variable ExportedFnAllocState exported by PhyRegAlloc.cpp.
///
-static AllocInfo getValueAllocStateFromGlobal (Function *F, Value *V) {
+static AllocInfo getValueAllocStateFromGlobal (Function *F, Value *V,
+ bool preferLiveIn) {
// Get the saved PhyRegAlloc state for F out of ExportedFnAllocState:
std::vector<AllocInfo> &FState = ExportedFnAllocState[F];
assert (FState.size () > 0 && "Reg. alloc state for function is empty");
int InstructionKey = -1, OperandKey = -1;
- if (Argument *A = dyn_cast<Argument> (V)) {
- // Find the alloc state of an argument.
- OperandKey = getNumberOfFunctionArg (F, A);
- } else {
- if (! isa<Instruction> (V)) {
- std::cerr
- << "ERROR: Don't know how to look up alloc state for this Value:\n\t"
- << *V << "\n";
- abort ();
- }
- // Figure out the indices (VI, VO) that can be used to look up V,
- // which is some instruction producing a value in F, in FState:
- Instruction *Instr = cast<Instruction> (V);
- InstructionKey = getSavedStateIndexOfInstruction (F, Instr);
- }
+ getValueAllocStateKeys (F, V, InstructionKey, OperandKey, preferLiveIn);
// Reconstruct the AllocInfo for V by searching
// FState for a tuple that starts with (InstructionKey, OperandKey, ...):
for (unsigned i = 0, s = FState.size (); i < s; ++i) {
@@ -164,7 +168,7 @@
}
// By this time we had better have found it, otherwise we are about to do bad
// things.
- std::cerr << "ERROR: UnpackTraceFunction: No saved AllocInfo found for "
+ std::cerr << "ERROR: No saved AllocInfo found for "
<< F->getName () << "()'s value " << *V
<< " in getValueAllocStateFromGlobal()\n";
abort ();
@@ -175,9 +179,12 @@
///
std::pair<AllocInfo, AllocInfo>
GetValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn) {
- return std::make_pair (getValueAllocStateFromModule (TF->MatrixFn, V),
+ TraceEntryBB = TF->T.getEntryBasicBlock();
+ return std::make_pair
+ (getValueAllocStateFromModule (TF->MatrixFn, V, preferLiveIn),
getValueAllocStateFromGlobal (TF->TraceFn,
- TF->getCorrespondingValue (V, preferLiveIn)));
+ TF->getCorrespondingValue (V, preferLiveIn),
+ preferLiveIn));
}
} // end namespace llvm
More information about the llvm-commits
mailing list