[llvm-commits] CVS: reopt/lib/LightWtProfiling/ValueAllocState.cpp UnpackTraceFunction.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Sun May 30 04:03:05 PDT 2004
Changes in directory reopt/lib/LightWtProfiling:
ValueAllocState.cpp added (r1.1)
UnpackTraceFunction.cpp updated: 1.75 -> 1.76
---
Log message:
Move getValueAllocState and all its helper functions and private data
structures to ValueAllocState.cpp, a new file. Capitalize its name and
make it non-static.
---
Diffs of the changes: (+188 -160)
Index: reopt/lib/LightWtProfiling/ValueAllocState.cpp
diff -c /dev/null reopt/lib/LightWtProfiling/ValueAllocState.cpp:1.1
*** /dev/null Sun May 30 04:01:39 2004
--- reopt/lib/LightWtProfiling/ValueAllocState.cpp Sun May 30 04:01:28 2004
***************
*** 0 ****
--- 1,183 ----
+ //===- ValueAllocState.cpp - Access saved state of PhyRegAlloc ----*- C++ -*-=//
+ //
+ // The LLVM Compiler Infrastructure
+ //
+ // This file was developed by the LLVM research group and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // Routines for accessing the global mapping between registers and LLVM Values
+ // created by the traditional SparcV9 graph-coloring register allocator. The
+ // main entry point for this code is the GetValueAllocState() global function.
+ //
+ //===----------------------------------------------------------------------===//
+
+ #include "reopt/TraceToFunction.h"
+ #include "reopt/MappingInfo.h"
+ #include "llvm/Module.h"
+ #include "llvm/Argument.h"
+ #include "llvm/Support/InstIterator.h"
+ #include "Support/Debug.h"
+ #include "../../../../lib/Target/SparcV9/RegAlloc/AllocInfo.h"
+ #include "../../../../lib/Target/SparcV9/RegAlloc/PhyRegAlloc.h"
+
+ namespace llvm {
+
+ /// Data structures describing the register allocator state
+ /// that gets saved by -save-ra-state.
+ ///
+ extern "C" {
+ struct OperandAllocState {
+ int Instruction;
+ int Operand;
+ unsigned AllocState;
+ int Placement;
+ };
+ struct FunctionAllocState {
+ unsigned numTuples;
+ struct OperandAllocState tuples[0]; // variable length
+ };
+ struct ModuleAllocState {
+ unsigned numFunctions;
+ struct FunctionAllocState *functions[0]; // variable length
+ };
+ /// This global is filled in by PhyRegAlloc's -save-ra-state option
+ /// in LLC output:
+ ///
+ extern struct ModuleAllocState _llvm_regAllocState;
+ };
+
+ /// This global is filled in by PhyRegAlloc's -save-ra-state option in JIT
+ /// output:
+ ///
+ extern PhyRegAlloc::SavedStateMapTy ExportedFnAllocState;
+
+ /// Returns the index of the given Instruction in the given Function.
+ ///
+ static unsigned getSavedStateIndexOfInstruction (const Function *F,
+ const Instruction *I) {
+ unsigned Key = 0;
+ for (const_inst_iterator II=inst_begin (F), IE=inst_end (F); II!=IE; ++II) {
+ if (&*II == I)
+ return Key;
+ ++Key;
+ }
+ // By this time we had better have found it, otherwise we are about to do bad
+ // things.
+ std::cerr << "ERROR: UnpackTraceFunction: Cannot find index of Value "
+ << F->getName() << "() in its parent Function using inst_iterator, "
+ << "in getSavedStateIndexOfInstruction()\n";
+ abort ();
+ }
+
+ /// Returns the index of the given Argument in the given Function's
+ /// argument list.
+ ///
+ static int getNumberOfFunctionArg (const Function *F, const Argument *Arg)
+ {
+ int ArgNum = 0;
+ for (Function::const_aiterator i = F->abegin (), e = F->aend (); i != e; ++i){
+ if (Arg == &*i) return ArgNum;
+ ++ArgNum;
+ }
+ std::cerr << "ERROR: getNumberOfFunctionArg couldn't find arg\n";
+ 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) {
+ 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);
+ }
+ // Reconstruct the AllocInfo for V by searching
+ // _llvm_regAllocState.functions[FI] for a tuple that starts with
+ // (InstructionKey, OperandKey, ...):
+ for (unsigned i = 0; i < FAllocState->numTuples; ++i) {
+ OperandAllocState &T = FAllocState->tuples[i];
+ if (T.Instruction == InstructionKey && T.Operand == OperandKey) {
+ AllocInfo AI (T.Instruction, T.Operand,
+ (AllocInfo::AllocStateTy) T.AllocState, T.Placement);
+ DEBUG (std::cerr << "Alloc state saved in module for " << F->getName ()
+ << ":" << V->getName () << " (key = " << InstructionKey << ","
+ << OperandKey << ") is " << AI << "\n");
+ return AI;
+ }
+ }
+ // 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 "
+ << F->getName () << "()'s value " << *V
+ << " in getValueAllocStateFromModule()\n";
+ 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 ExportedFnAllocState exported by PhyRegAlloc.cpp.
+ ///
+ static AllocInfo getValueAllocStateFromGlobal (Function *F, Value *V) {
+ // 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);
+ }
+ // 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) {
+ AllocInfo &T = FState[i];
+ if (T.Instruction == InstructionKey && T.Operand == OperandKey) {
+ DEBUG (std::cerr << "Alloc state saved in global for " << F->getName ()
+ << ":" << V->getName () << " (key = " << InstructionKey << ","
+ << OperandKey << ") is " << T << "\n");
+ return T;
+ }
+ }
+ // 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 "
+ << F->getName () << "()'s value " << *V
+ << " in getValueAllocStateFromGlobal()\n";
+ abort ();
+ }
+
+ /// GetValueAllocState - Returns a pair <MatrixState,TraceState> containing the
+ /// saved register allocator state for a value.
+ ///
+ std::pair<AllocInfo, AllocInfo>
+ GetValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn) {
+ return std::make_pair (getValueAllocStateFromModule (TF->MatrixFn, V),
+ getValueAllocStateFromGlobal (TF->TraceFn,
+ TF->getCorrespondingValue (V, preferLiveIn)));
+ }
+
+ } // end namespace llvm
Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.75 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.76
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.75 Sun May 30 03:47:11 2004
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Sun May 30 04:01:27 2004
@@ -133,8 +133,9 @@
return 2047 + StaticStackSize + 176 + R * 8;
}
-static std::pair<AllocInfo, AllocInfo>
-getValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn = true);
+// defined in ValueAllocState.cpp:
+extern std::pair<AllocInfo, AllocInfo>
+GetValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn = true);
void UnpackTraceFunction::rewriteProlog (MachineFunction &MF,
MachineBasicBlock &E) {
@@ -165,7 +166,7 @@
++SI) {
Value *V = *SI;
std::pair<Value *, std::pair<AllocInfo, AllocInfo> > as =
- std::make_pair (V, getValueAllocState (TF, V));
+ std::make_pair (V, GetValueAllocState (TF, V));
AllocStates.insert (as);
AllocInfo &Source = as.second.first, &Target = as.second.second;
assert (Source.AllocState == AllocInfo::Allocated &&
@@ -227,162 +228,6 @@
}
}
-/// Data structures describing the register allocator state
-/// that gets saved by -save-ra-state.
-///
-extern "C" {
- struct OperandAllocState {
- int Instruction;
- int Operand;
- unsigned AllocState;
- int Placement;
- };
- struct FunctionAllocState {
- unsigned numTuples;
- struct OperandAllocState tuples[0]; // variable length
- };
- struct ModuleAllocState {
- unsigned numFunctions;
- struct FunctionAllocState *functions[0]; // variable length
- };
- /// This global is filled in by PhyRegAlloc's -save-ra-state option
- /// in LLC output:
- ///
- extern struct ModuleAllocState _llvm_regAllocState;
-};
-
-/// This global is filled in by PhyRegAlloc's -save-ra-state option in JIT
-/// output:
-///
-extern PhyRegAlloc::SavedStateMapTy ExportedFnAllocState;
-
-/// Returns the index of the given Instruction in the given Function.
-///
-static unsigned getSavedStateIndexOfInstruction (const Function *F,
- const Instruction *I) {
- unsigned Key = 0;
- for (const_inst_iterator II=inst_begin (F), IE=inst_end (F); II!=IE; ++II) {
- if (&*II == I)
- return Key;
- ++Key;
- }
- // By this time we had better have found it, otherwise we are about to do bad
- // things.
- std::cerr << "ERROR: UnpackTraceFunction: Cannot find index of Value "
- << F->getName() << "() in its parent Function using inst_iterator, "
- << "in getSavedStateIndexOfInstruction()\n";
- abort ();
-}
-
-/// Returns the index of the given Argument in the given Function's
-/// argument list.
-///
-static int getNumberOfFunctionArg (const Function *F, const Argument *Arg)
-{
- int ArgNum = 0;
- for (Function::const_aiterator i = F->abegin (), e = F->aend (); i != e; ++i){
- if (Arg == &*i) return ArgNum;
- ++ArgNum;
- }
- std::cerr << "ERROR: getNumberOfFunctionArg couldn't find arg\n";
- 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) {
- 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);
- }
- // Reconstruct the AllocInfo for V by searching
- // _llvm_regAllocState.functions[FI] for a tuple that starts with
- // (InstructionKey, OperandKey, ...):
- for (unsigned i = 0; i < FAllocState->numTuples; ++i) {
- OperandAllocState &T = FAllocState->tuples[i];
- if (T.Instruction == InstructionKey && T.Operand == OperandKey) {
- AllocInfo AI (T.Instruction, T.Operand,
- (AllocInfo::AllocStateTy) T.AllocState, T.Placement);
- DEBUG (std::cerr << "Alloc state saved in module for " << F->getName ()
- << ":" << V->getName () << " (key = " << InstructionKey << ","
- << OperandKey << ") is " << AI << "\n");
- return AI;
- }
- }
- // 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 "
- << F->getName () << "()'s value " << *V
- << " in getValueAllocStateFromModule()\n";
- 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 ExportedFnAllocState exported by PhyRegAlloc.cpp.
-///
-static AllocInfo getValueAllocStateFromGlobal (Function *F, Value *V) {
- // 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);
- }
- // 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) {
- AllocInfo &T = FState[i];
- if (T.Instruction == InstructionKey && T.Operand == OperandKey) {
- DEBUG (std::cerr << "Alloc state saved in global for " << F->getName ()
- << ":" << V->getName () << " (key = " << InstructionKey << ","
- << OperandKey << ") is " << T << "\n");
- return T;
- }
- }
- // 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 "
- << F->getName () << "()'s value " << *V
- << " in getValueAllocStateFromGlobal()\n";
- abort ();
-}
-
-/// getValueAllocState - Returns a pair <MatrixState,TraceState> containing the
-/// saved register allocator state for a value.
-///
-static std::pair<AllocInfo, AllocInfo>
-getValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn) {
- return std::make_pair (getValueAllocStateFromModule (TF->MatrixFn, V),
- getValueAllocStateFromGlobal (TF->TraceFn,
- TF->getCorrespondingValue (V, preferLiveIn)));
-}
-
void UnpackTraceFunction::rewriteEpilog (MachineFunction &MF,
MachineBasicBlock &MBB) {
const TargetRegInfo &TRI = TM->getRegInfo ();
@@ -401,7 +246,7 @@
for (LiveVariableSet::iterator SI = So.begin (), SE = So.end ();
SI != SE; ++SI) {
Value *V = *SI;
- std::pair<AllocInfo, AllocInfo> ai = getValueAllocState (TF, V, false);
+ std::pair<AllocInfo, AllocInfo> ai = GetValueAllocState (TF, V, false);
// Source is traceFn's register, Target is matrixFn's register
AllocInfo &Target = ai.first, &Source = ai.second;
assert (Target.AllocState == AllocInfo::Allocated
More information about the llvm-commits
mailing list