[llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Thu Nov 6 13:09:45 PST 2003
Changes in directory reopt/lib/LightWtProfiling:
UnpackTraceFunction.cpp updated: 1.12 -> 1.13
---
Log message:
Include llvm/Support/InstIterator.h.
Add a stub function to load pointers to values on the stack into registers.
Flesh out the body of insertCopyMachineInstrs somewhat.
Add comments that say certain methods are currently SPARC-specific.
Fix a >80-char line.
Flesh out the body of getSavedStateIndexOfInstruction(). Make it take
an Instruction *. Change callers to match.
Add an abort to the stub of getSavedStateIndexOfOperandInInstruction().
---
Diffs of the changes: (+72 -21)
Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.12 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.13
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.12 Tue Nov 4 16:39:52 2003
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Thu Nov 6 12:56:48 2003
@@ -13,35 +13,69 @@
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/Support/InstIterator.h"
#include "llvm/Module.h"
#include "reopt/ScratchMemory.h"
#include "reopt/MappingInfo.h"
#include "Support/Debug.h"
-/// Insert (a) machine instruction(s) for the current architecture, that
-/// copies the value in Source to the location specified by Target, at
-/// the beginning of B.
+void addGetPointerToStackValInstrs (std::vector<MachineInstr *> &mvec,
+ AllocInfo &Source, unsigned SrcReg) {
+ // Let OFFSET be the offset of the value from %fp
+ // construct add %fp, <OFFSET>, <DESTREG>
+}
+
+/// Insert (a) machine instruction(s) that copies the value in Source
+/// to the location specified by Target, at the beginning of B. Note
+/// that the current implementation is SPARC-specific.
///
-/// FIXME: Not yet finished
+/// FIXME: Not yet finished.
///
void insertCopyMachineInstrs (AllocInfo &Source, AllocInfo &Target,
MachineBasicBlock &B) {
- if (Source.AllocState == AllocInfo::Spilled && Target.AllocState == AllocInfo::Allocated) {
- //Insert load instruction from stack loc. Source into register Target
- } else if (Source.AllocState == AllocInfo::Allocated && Target.AllocState == AllocInfo::Allocated) {
- //Insert move instruction from register Source to register Target
- } else if (Source.AllocState == AllocInfo::Allocated && Target.AllocState == AllocInfo::Spilled) {
- //Insert store instruction from register Source to stack loc. Target
- } else if (Source.AllocState == AllocInfo::Spilled && Target.AllocState == AllocInfo::Spilled) {
- //Get a temporary register Temp somehow (maybe use the path reg, %g1?)
- //Insert load instruction from stack loc. Source into register Temp
- //Insert store instruction from register Temp to stack loc. Target
+ UltraSparc TM;
+ const TargetRegInfo &TRI = TM.getRegInfo ();
+ std::vector<MachineInstr *> mvec;
+ unsigned SrcReg, TargReg;
+ int Offset, RegType;
+ if (Source.AllocState == AllocInfo::Spilled
+ && Target.AllocState == AllocInfo::Allocated) {
+ // Emit instructions to construct pointer to Source into SrcReg
+ addGetPointerToStackValInstrs (mvec, Source, SrcReg);
+ // Emit load instruction from stack loc. Source into register Target
+ TRI.cpMem2RegMI (mvec, SrcReg, Offset, TargReg, RegType);
+ } else if (Source.AllocState == AllocInfo::Allocated\
+ && Target.AllocState == AllocInfo::Allocated) {
+ // Emit move instruction from register Source to register Target
+ TRI.cpReg2RegMI (mvec, Source.Placement, Target.Placement, RegType);
+ } else if (Source.AllocState == AllocInfo::Allocated
+ && Target.AllocState == AllocInfo::Spilled) {
+ // Emit instructions to construct pointer to Target into TargReg
+ addGetPointerToStackValInstrs (mvec, Target, TargReg);
+ // Emit store instruction from register Source to stack loc. Target
+ TRI.cpReg2MemMI (mvec, Source.Placement, TargReg, Offset, RegType);
+ } else if (Source.AllocState == AllocInfo::Spilled
+ && Target.AllocState == AllocInfo::Spilled) {
+ // Emit instructions to construct pointer to Source into SrcReg
+ addGetPointerToStackValInstrs (mvec, Source, SrcReg);
+ // Emit load instruction from address in SrcReg into register SrcReg
+ TRI.cpMem2RegMI (mvec, SrcReg, Offset, SrcReg, RegType);
+ // Emit instructions to construct pointer to Target into TargReg
+ addGetPointerToStackValInstrs (mvec, Target, TargReg);
+ // Emit store instruction from register SrcReg to stack loc. Target
+ TRI.cpReg2MemMI (mvec, SrcReg, TargReg, Offset, RegType);
}
+ // Add whatever the TargetRegInfo gave us to the MachineBasicBlock we were
+ // provided.
+ for (std::vector<MachineInstr *>::iterator i = mvec.begin (),
+ e = mvec.end (); i != e; ++i)
+ B.push_back (*i);
}
/// Emit the same sequence of MachineInstrs that
/// replaceMachineCodeForFunction() would emit, to branch from the end
-/// of B to TargetAddr.
+/// of B to TargetAddr. Note that the current implementation is
+/// SPARC-specific.
///
/// FIXME: refactor this so it shares code with SparcV9CodeEmitter.cpp's
/// JITResolver::insertJumpAtAddr(), JITResolver::insertFarJumpAtAddr()
@@ -70,7 +104,7 @@
// sethi %uhi(Target), %g5 ;; get upper 22 bits of Target into %g5
BuildMI(V9::SETHI, 2).addSImm(Target >> 42).addReg(g5),
// or %g5, %ulo(Target), %g5 ;; get 10 lower bits of upper word into %g5
- BuildMI(V9::ORi, 3).addReg(g5).addSImm((Target >> 32) & 0x03ff).addReg(g5),
+ BuildMI(V9::ORi,3).addReg(g5).addSImm((Target >> 32) & 0x03ff).addReg(g5),
// sllx %g5, 32, %g5 ;; shift those 10 bits to the upper word
BuildMI(V9::SLLXi6, 3).addReg(g5).addSImm(32).addReg(g5),
// sethi %hi(Target), %g1 ;; extract bits 10-31 into the dest reg
@@ -150,11 +184,25 @@
abort ();
}
-unsigned getSavedStateIndexOfInstruction (Function *F, Value *V) {
+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 ();
}
unsigned getSavedStateIndexOfOperandInInstruction (Function *F, Value *V,
unsigned VI) {
+ // FIXME; not yet implemented
+ abort ();
}
/// Returns the register number or stack position where V can be found in the
@@ -165,8 +213,9 @@
AllocInfo getValueAllocStateFromModule (Function *F, Value *V) {
// 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);
unsigned FI = getSavedStateIndexOfFunction (F);
- unsigned VI = getSavedStateIndexOfInstruction (F, V);
+ unsigned VI = getSavedStateIndexOfInstruction (F, Instr);
unsigned VO = getSavedStateIndexOfOperandInInstruction (F, V, VI);
// Reconstruct the AllocInfo for V by searching
// _llvm_regAllocState.functions[FI] for a tuple that starts with
@@ -192,11 +241,12 @@
/// variable ExportedFnAllocState exported by PhyRegAlloc.cpp.
///
AllocInfo getValueAllocStateFromGlobal (Function *F, Value *V) {
+ Instruction *Instr = cast<Instruction> (V);
// Get the saved PhyRegAlloc state for F out of ExportedFnAllocState:
std::vector<AllocInfo> &FState = ExportedFnAllocState[F];
// Figure out the indices (VI, VO) that can be used to look up V, which is an
// operand of some instruction in F, in FState:
- unsigned VI = getSavedStateIndexOfInstruction (F, V);
+ unsigned VI = getSavedStateIndexOfInstruction (F, Instr);
unsigned VO = getSavedStateIndexOfOperandInInstruction (F, V, VI);
// Retrieve the AllocInfo for V by searching FState for a tuple that starts
// with (VI, VO, ...):
@@ -213,8 +263,9 @@
abort ();
}
-/// Returns a pointer to the return instruction in B, if B contains one,
-/// or null otherwise. FIXME: SPARC target-specific.
+/// Returns a pointer to the return instruction in B, if B contains
+/// one, or null otherwise. Note that the current implementation is
+/// SPARC-specific.
///
const MachineInstr *containsReturnInstruction (MachineBasicBlock &B) {
for (MachineBasicBlock::const_reverse_iterator i = B.rbegin (),
More information about the llvm-commits
mailing list