[llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Wed Apr 7 13:33:01 PDT 2004
Changes in directory reopt/lib/LightWtProfiling:
UnpackTraceFunction.cpp updated: 1.48 -> 1.49
---
Log message:
Start on the new rewriteProlog algorithm.
---
Diffs of the changes: (+65 -1)
Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.48 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.49
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.48 Wed Mar 31 16:40:25 2004
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Wed Apr 7 13:32:55 2004
@@ -43,6 +43,7 @@
MachineBasicBlock &B, const Type *Ty);
void insertBranchMachineInstrs (uint64_t Target, MachineBasicBlock &B);
const MachineInstr *containsReturnInstr (MachineBasicBlock &B);
+ void rewriteProlog (MachineFunction &MF, MachineBasicBlock &E);
};
// Ripped off from SparcV9PrologEpilogInserter
@@ -142,6 +143,67 @@
return 0;
}
+void SparcV9ReoptInfo::rewriteProlog (MachineFunction &MF, MachineBasicBlock &E) {
+ const TargetRegInfo &TRI = TM->getRegInfo ();
+ static const unsigned
+ fp = SparcV9IntRegClass::i6,
+ sp = SparcV9IntRegClass::o6,
+ g0 = SparcV9IntRegClass::g0,
+ g1 = SparcV9IntRegClass::g1;
+
+ // UTF prolog: start out by clearing everything out of the entry basic block
+ // (FIXME: may not work once we start doing optimizations!!! We will probably
+ // have to use a separate MBB)
+ E.clear ();
+
+ // 0. Save caller's stack pointer in %g1.
+ E.push_back (BuildMI (V9::ORr, 3).addMReg (sp).addZImm (0).addMReg (g1,
+ MachineOperand::UseAndDef));
+
+ // 1. Initialize regSet with the set of registers used in this function.
+ std::set<unsigned> regSet;
+ for (MachineFunction::iterator fi = MF.begin (), fe = MF.end ();
+ fi != fe; ++fi) {
+ for (MachineBasicBlock::iterator bi = fi->begin (), be = fi->end ();
+ bi != be; ++bi) {
+ for (unsigned oi = 0, oe = bi->getNumOperands (); oi != oe; ++oi) {
+ if (bi->getOperand (oi).isDef ()) {
+ regSet.insert (bi->getOperand (oi).getReg ());
+ }
+ }
+ }
+ }
+
+ DEBUG(std::cerr << "In rewriteProlog()...\n");
+ DEBUG(std::cerr << " static stack size is " << getStaticStackSize (MF) <<"\n");
+ DEBUG(std::cerr << " reg set (size " << regSet.size () << ") contains: (");
+ DEBUG(for (std::set<unsigned>::iterator i = regSet.begin (),
+ e = regSet.end (); i != e; ++i) { std::cerr << *i << " "; });
+ DEBUG(std::cerr << " )\n\n");
+
+ // 1. Get some stack space: (Stack Frame Size + Space for Regs).
+ unsigned stackSize = getStaticStackSize (MF);
+ int Size = (stackSize + 32 * 8);
+ E.push_back (BuildMI (V9::ADDi, 3).addMReg (sp).addSImm (-Size).addMReg (sp,
+ MachineOperand::UseAndDef));
+
+ // 2. Save used registers onto the stack.
+ std::vector<MachineInstr *> mvec;
+ int RegType;
+ for (std::set<unsigned>::iterator i = regSet.begin (), e = regSet.end ();
+ i != e; ++i) {
+ unsigned R = *i;
+ unsigned RegType = TRI.getRegType (R);
+ TRI.cpReg2MemMI (mvec, R, sp, stackSize + R * 8, 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)
+ E.push_back (*i);
+ }
+
+}
+
} // end namespace llvm
///---------------------- End SPARC backend-specific code -------------------///
@@ -361,7 +423,9 @@
MachineBasicBlock &E = MF.front (); // E = Entry MBB of MF
std::vector<CopyInfo> EntryCopies;
DEBUG(std::cerr << "UnpackTraceFunction: Modifying entry BB\n");
- E.clear ();
+
+ SRI.rewriteProlog (MF, E);
+
for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE;
++SI) {
// Insert copies from each live-in variable's reg. in the matrix fn.
More information about the llvm-commits
mailing list