[llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Thu Jul 15 14:54:05 PDT 2004
Changes in directory reopt/lib/LightWtProfiling:
UnpackTraceFunction.cpp updated: 1.98 -> 1.99
---
Log message:
Squash a bogus 'may be used uninitialized' warning for R in rewriteProlog().
Add the new epilog rewriter (rewriteEpilogInstr()).
---
Diffs of the changes: (+113 -24)
Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.98 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.99
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.98 Mon Jul 12 05:01:24 2004
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Thu Jul 15 16:53:55 2004
@@ -222,7 +222,7 @@
std::pair<AllocInfo, AllocInfo> &ai = AllocStates[V];
AllocInfo &Source = ai.first, &Target = ai.second;
mvec.clear ();
- unsigned R;
+ unsigned R = (unsigned) -1;
assert ((Target.AllocState == AllocInfo::Allocated
|| Target.AllocState == AllocInfo::Spilled)
&& (Source.AllocState == AllocInfo::Allocated
@@ -463,35 +463,123 @@
}
}
-void UnpackTraceFunction::rewriteEpilog (MachineFunction &MF,
- MachineBasicBlock &MBB) {
+bool UnpackTraceFunction::rewriteEpilogInstr (MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator iter){
+ static const unsigned sp = SparcV9::o6, fp = SparcV9::i6, g1 = SparcV9::g1,
+ g2 = SparcV9::g2, g3 = SparcV9::g3, matrixFP = SparcV9::g3;
+ const TargetInstrInfo &TII = *TM->getInstrInfo ();
const SparcV9RegInfo &TRI = *TM->getRegInfo ();
- static const unsigned fp = SparcV9::i6, sp = SparcV9::o6, g1 = SparcV9::g1,
- g2 = SparcV9::g2;
+ MachineInstr &inst = *iter;
+
+ DEBUG (std::cerr << "rewriteEpilogInstr: examining instr = " << inst << "\n");
+ if (TII.isStore (inst.getOpcode ())) {
+ // It's a store, take it apart...
+ MachineOperand &targetBaseReg = inst.getOperand (1);
+ if (Value *storeBasePtrV = targetBaseReg.getVRegValueOrNull()) {
+ ValueMap::iterator i = TF->ArgToLiveOutMap.find(storeBasePtrV);
+ if (i != TF->ArgToLiveOutMap.end ()) {
+ // We're storing a live-out value into a live-out pseudo-arg.
+ assert (isa<Argument> (storeBasePtrV) && "Expecting an Argument");
+ Value *V = i->second;
+ assert (std::find (TF->LiveOutVector.begin (), TF->LiveOutVector.end (),
+ V) != TF->LiveOutVector.end ()
+ && "Expecting a live-out value");
+
+ // Currently we can't handle offsets which are not zero.
+ assert (inst.getOperand (2).isImmediate()
+ && "Can only handle stores with immediate offsets");
+ assert (inst.getOperand (2).getImmedValue() == 0
+ && "Can only handle stores @ offset 0 of live-out pseudo-args");
+
+ // Change the target of the store to point either onto the
+ // TraceFn's stack (for arguments which are in registers in
+ // MatrixFn) or onto MatrixFn's stack (for arguments which are
+ // spilled onto the stack in MatrixFn).
+ int newImmedOffset = 9999;
+ int newBaseReg = 9999;
+
+ std::pair<AllocInfo, AllocInfo> ai = GetValueAllocState (TF, V, false);
+ AllocInfo &MatrixAI = ai.first;
+ if (MatrixAI.AllocState == AllocInfo::Allocated) {
+ assert (fpIsTraceFP
+ && "Need TraceFn frame pointer to store live-out registers");
+ // MatrixAI.Placement is the register allocated to V in MatrixFn.
+ unsigned MatrixReg = MatrixAI.Placement;
+ // Store V onto TraceFn's stack, from which it will be reloaded into a
+ // MatrixFn register.
+ newBaseReg = sp;
+ newImmedOffset = stackOffsetForReg (MatrixReg);
+ // Add it to the RegsToSave set if it's not already there
+ if (RegsToSave.find (MatrixReg) == RegsToSave.end ())
+ RegsToSave.insert (MatrixReg);
+ } else if (MatrixAI.AllocState == AllocInfo::Spilled) {
+ // MatrixAI.Placement is the stack slot allocated to V in MatrixFn.
+ // Make sure we have MatrixFn's frame pointer in a register:
+ if (!g3IsMatrixFP) {
+ // Insert a load instruction before this one to load matrixFP off
+ // the TraceFn stack.
+ std::vector<MachineInstr *> mvec;
+ TRI.cpMem2RegMI (mvec, sp, stackOffsetForReg (fp), matrixFP,
+ TRI.getRegType(matrixFP), g2);
+ for (std::vector<MachineInstr *>::iterator i = mvec.begin (),
+ e = mvec.end (); i != e; ++i) {
+ DEBUG (std::cerr << "rewriteEpilogInstr: inserting " << *i << "\n");
+ MBB.insert (iter, *i);
+ }
+ g3IsMatrixFP = true;
+ }
+ // Store it into its stack slot on MatrixFn's stack.
+ newBaseReg = matrixFP;
+ newImmedOffset = MatrixAI.Placement;
+ } else {
+ assert (0 && "Live-outs must be allocated or spilled in MatrixFn");
+ }
+ // Change the store instruction to have the new base register and
+ // offset.
+ assert (newImmedOffset != 9999 && newBaseReg != 9999
+ && "Failed to compute new immed. offset or base reg.");
+ inst.SetMachineOperandReg (1, newBaseReg);
+ inst.SetMachineOperandConst (2, MachineOperand::MO_SignExtendedImmed,
+ newImmedOffset);
+ }
+ }
+ // Widen integer stores - all stack slots are 64 bits wide.
+ if (inst.getOpcode() == V9::STBi || inst.getOpcode () == V9::STHi
+ || inst.getOpcode () == V9::STWi)
+ inst.setOpcode (V9::STXi);
+ DEBUG (std::cerr << "rewriteEpilogInstr: rewrote instr = " << inst << "\n");
+ } else if (((inst.getOpcode () == V9::ADDi || inst.getOpcode () == V9::ORi)
+ && (inst.getOperand (2).isDef ()
+ && inst.getOperand (2).hasAllocatedReg ()
+ && inst.getOperand (2).getReg () == SparcV9::i0))
+ || (inst.getOpcode () == V9::JMPLRETi
+ || inst.getOpcode () == V9::RESTOREr
+ || inst.getOpcode () == V9::RESTOREi)) {
+ // This is old epilog code, or part of a 'ret int ...' instruction. Nuke it.
+ return true;
+ }
+ return false; // Don't delete the instr.
+}
+void UnpackTraceFunction::rewriteEpilog (MachineFunction &MF,
+ MachineBasicBlock &MBB) {
// We start out each trace-exit MBB with %fp holding the TraceFn frame
// pointer.
fpIsTraceFP = true;
- // Replace the contents of the trace-exit MBB with live-out stores followed
- // by a branch back to the matrix function's basic block. First, clear the
- // MBB, then insert stores from each live-out variable's reg. in the trace
- // to its stack slot in the trace function, from which it will be
- // reloaded below into a register.
- MBB.clear ();
- LiveVariableVector &So = TF->LiveOutVector;
- for (LiveVariableVector::iterator SI = So.begin (), SE = So.end ();
- SI != SE; ++SI) {
- Value *V = *SI;
- 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;
- DEBUG (std::cerr << "rewriteEpilog: copying live-out value: ";
- PrintValueAIs(V->getName(), Target, Source));
- addLiveOutCopy (MF, MBB, Source, Target, V,
- TF->getCorrespondingValue (V, false));
+ // Rewrite any stores into live-out pseudo-arguments to store into stack
+ // slots instead. Delete old epilog leftovers in the process.
+ for (MachineBasicBlock::iterator i = MBB.begin (), e = MBB.end (); i != e; ) {
+ if (rewriteEpilogInstr (MBB, i)) {
+ MachineBasicBlock::iterator goner = i;
+ DEBUG (std::cerr << "rewriteEpilog: deleting " << *goner << "\n");
+ ++i;
+ MBB.erase (goner);
+ } else {
+ ++i;
+ }
}
-
+
// Find the BasicBlock in MatrixFn that this block's return instr.
// would have returned to, by consulting the mapping information
// generated by TraceFunctionBuilder.
@@ -511,8 +599,9 @@
// Restore MatrixFn's FP. Warning! After this point, addLiveOutCopy won't work
// anymore, because it depends on being able to access TraceFn's frame
// pointer in %fp.
+ const SparcV9RegInfo &TRI = *TM->getRegInfo ();
+ static const unsigned fp = SparcV9::i6, sp = SparcV9::o6, g2 = SparcV9::g2;
std::vector<MachineInstr *> mvec;
- mvec.clear ();
TRI.cpMem2RegMI (mvec, sp, stackOffsetForReg (fp), fp, TRI.getRegType(fp),
g2);
for (std::vector<MachineInstr *>::iterator vi = mvec.begin (),
More information about the llvm-commits
mailing list