[llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Wed Apr 21 16:06:05 PDT 2004
Changes in directory reopt/lib/LightWtProfiling:
UnpackTraceFunction.cpp updated: 1.56 -> 1.57
---
Log message:
Rename regSet to regsUsed. Cache it in the UnpackTraceFunction pass object.
Rename getRegsUsedInFunction() to UnpackTraceFunction::findRegsUsedInFunction().
If it sees intCC or floatCC regs, then it inserts ccr or fsr (respectively)
instead of the CC reg(s) it actually saw, so that we only save & restore the
CCs once per trace entry/exit.
rewriteProlog and rewriteEpilog are now using getUnifiedRegNum() to get
the register numbers they use in instructions. Register operands that I put in
SPARC MachineInstrs must use unified register numbers.
Print out the types and classes of registers when I save them, for debugging.
When saving and reloading registers, pick a G register, and use it for
scratch space. This is necessary to save and reload the CC regs.
Disable epilog rewriting for now until I can fix it... but many of the
rewriteProlog fixes mentioned above also apply to rewriteEpilog.
---
Diffs of the changes: (+87 -42)
Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.56 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.57
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.56 Fri Apr 9 15:10:25 2004
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Wed Apr 21 16:05:31 2004
@@ -40,7 +40,12 @@
TargetMachine *TM;
TraceFunction *TF;
+ /// Registers clobbered in the trace. Filled in by findRegsUsedInFunction ().
+ ///
+ std::set<unsigned> regsUsed;
+
unsigned getStaticStackSize (MachineFunction &MF);
+ void findRegsUsedInFunction (MachineFunction &MF);
void insertCopyMachineInstrs (AllocInfo &Source, AllocInfo &Target,
MachineBasicBlock &B, const Type *Ty);
void insertBranchMachineInstrs (uint64_t Target, MachineBasicBlock &B);
@@ -184,30 +189,60 @@
static AllocInfo getValueAllocStateFromModule (Function *F, Value *V);
static AllocInfo getValueAllocStateFromGlobal (Function *F, Value *V);
-/// Return the set of registers used in this function. Registers are
+/// Fill in the set of registers used in this function, which is kept in
+/// 'regsUsed' in the UnpackTraceFunction Pass object, and is used by
+/// rewriteProlog() and rewriteEpilog(). Registers are
/// represented by their 'unified register numbers' as used in the SPARCv9
/// back-end.
///
-static std::set<unsigned> getRegsUsedInFunction (MachineFunction &MF) {
- std::set<unsigned> regSet;
+void
+UnpackTraceFunction::findRegsUsedInFunction (MachineFunction &MF) {
+ const TargetRegInfo &TRI = TM->getRegInfo ();
+ bool intCCRegSeen = false, floatCCRegSeen = false;
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 ());
- return regSet;
+ for (unsigned oi = 0, oe = bi->getNumOperands (); oi != oe; ++oi) {
+ const MachineOperand &MO = bi->getOperand (oi);
+ if (MO.isDef ()) {
+ unsigned regNo = MO.getReg ();
+ if (TRI.getRegType(regNo) == SparcV9RegInfo::IntCCRegType) {
+ intCCRegSeen = true;
+ } else if (TRI.getRegType(regNo) == SparcV9RegInfo::FloatCCRegType
+ || TRI.getRegType(regNo) == SparcV9RegInfo::SpecialRegType) {
+ floatCCRegSeen = true;
+ } else {
+ regsUsed.insert (MO.getReg ());
+ }
+ }
+ }
+
+ // Deal with some sparc lunacy: If any of the floatcc regs are used, then we
+ // only put %fsr in the set, not the floatcc regs which were actually used.
+ // If the intcc regs are used, then we only put %ccr in the
+ // set, not the individual intcc regs.
+ if (floatCCRegSeen) {
+ unsigned fsrReg = TRI.getUnifiedRegNum(SparcV9RegInfo::SpecialRegClassID,
+ SparcV9SpecialRegClass::fsr);
+ regsUsed.insert (fsrReg);
+ }
+ if (intCCRegSeen) {
+ unsigned ccrReg = TRI.getUnifiedRegNum(SparcV9RegInfo::IntCCRegClassID,
+ SparcV9IntCCRegClass::ccr);
+ regsUsed.insert (ccrReg);
+ }
}
void UnpackTraceFunction::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;
+fp = TRI.getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,SparcV9IntRegClass::i6),
+sp = TRI.getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,SparcV9IntRegClass::o6),
+g0 = TRI.getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,SparcV9IntRegClass::g0),
+g1 = TRI.getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,SparcV9IntRegClass::g1),
+g2 = TRI.getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,SparcV9IntRegClass::g2);
// 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
@@ -218,16 +253,16 @@
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 = getRegsUsedInFunction (MF);
+ // 1. Initialize regsUsed with the set of registers used in this function.
+ findRegsUsedInFunction (MF);
unsigned stackSize = getStaticStackSize (MF);
DEBUG(std::cerr << "rewriteProlog: Static stack size is "
<< stackSize << "\n"
- << "rewriteProlog: Reg set (size " << regSet.size ()
+ << "rewriteProlog: Reg set (size " << regsUsed.size ()
<< ") contains: (");
- DEBUG(for (std::set<unsigned>::iterator i = regSet.begin (),
- e = regSet.end (); i != e; ++i) { std::cerr << *i << " "; });
+ DEBUG(for (std::set<unsigned>::iterator i = regsUsed.begin (),
+ e = regsUsed.end (); i != e; ++i) { std::cerr << *i << " "; });
DEBUG(std::cerr << " )\n");
// 2. Get some stack space: (Stack Frame Size + Space for Regs).
@@ -238,20 +273,31 @@
// 3. Save used registers onto the stack.
std::vector<MachineInstr *> mvec;
int RegType;
- for (std::set<unsigned>::iterator i = regSet.begin (), e = regSet.end ();
+ for (std::set<unsigned>::iterator i = regsUsed.begin (), e = regsUsed.end ();
i != e; ++i) {
mvec.clear ();
unsigned R = *i;
unsigned RegType = TRI.getRegType (R);
+ static const char *RegTypeStrings[] = { "IntRegType",
+ "FPSingleRegType", "FPDoubleRegType", "IntCCRegType",
+ "FloatCCRegType", "SpecialRegType" };
+ static const char *RegClassStrings[] = { "IntRegClassID",
+ "FloatRegClassID", "IntCCRegClassID", "FloatCCRegClassID",
+ "SpecialRegClassID" };
DEBUG (std::cerr << "rewriteProlog: Saving reg#" << R << ", type = "
- << RegType << ", " << "Class = "
- << TRI.getRegClassIDOfRegType(RegType) << "\n");
- TRI.cpReg2MemMI (mvec, R, sp, stackSize + R * 8, RegType);
+ << RegType << " (" << RegTypeStrings[RegType]
+ << "), Class = " << TRI.getRegClassIDOfRegType(RegType)
+ << " ("
+ << RegClassStrings[TRI.getRegClassIDOfRegType(RegType)]
+ << ")\n");
+ TRI.cpReg2MemMI (mvec, R, sp, stackSize + R * 8, RegType, g2);
// Add whatever the TargetRegInfo gave us to the MachineBasicBlock we are
// working on.
for (std::vector<MachineInstr *>::iterator vi = mvec.begin (),
- ve = mvec.end (); vi != ve; ++vi)
+ ve = mvec.end (); vi != ve; ++vi) {
+ DEBUG (std::cerr << "rewriteProlog: Insns: " << **vi);
E.push_back (*vi);
+ }
}
// 4. Insert copies from each live-in variable's reg. in the matrix fn.
@@ -430,12 +476,14 @@
void UnpackTraceFunction::rewriteEpilog (MachineFunction &MF,
MachineBasicBlock &MBB) {
+ return; // FIXME - disabling epilog rewriting for now
const TargetRegInfo &TRI = TM->getRegInfo ();
static const unsigned
- fp = SparcV9IntRegClass::i6,
- sp = SparcV9IntRegClass::o6,
- g0 = SparcV9IntRegClass::g0,
- g1 = SparcV9IntRegClass::g1;
+fp = TRI.getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,SparcV9IntRegClass::i6),
+sp = TRI.getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,SparcV9IntRegClass::o6),
+g0 = TRI.getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,SparcV9IntRegClass::g0),
+g1 = TRI.getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,SparcV9IntRegClass::g1),
+g2 = TRI.getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,SparcV9IntRegClass::g2);
Function *TraceF = TF->TraceFn, *MatrixF = TF->MatrixFn;
LiveVariableSet &So = TF->LiveOutSet;
@@ -445,7 +493,15 @@
MBB.clear ();
// Restore old FP.
- // FIXME
+ std::vector<MachineInstr *> mvec;
+ unsigned stackSize = getStaticStackSize (MF);
+ TRI.cpMem2RegMI (mvec, sp, stackSize + fp * 8, fp, TRI.getRegType(fp), g2);
+
+ // Add whatever the TargetRegInfo gave us to the MachineBasicBlock we are
+ // working on.
+ for (std::vector<MachineInstr *>::iterator vi = mvec.begin (),
+ ve = mvec.end (); vi != ve; ++vi)
+ MBB.push_back (*vi);
// Insert copies from each live-out variable's reg. in the trace
// to its reg. in the matrix function.
@@ -460,22 +516,10 @@
}
// Get the set of registers used in this function which we saved in
- // rewriteProlog, earlier.
- std::set<unsigned> regSet = getRegsUsedInFunction (MF);
-
- unsigned stackSize = getStaticStackSize (MF);
- DEBUG(std::cerr << "rewriteEpilog: Static stack size is "
- << stackSize << "\n"
- << "rewriteEpilog: 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");
-
- // Restore all used registers from stack except SP.
- std::vector<MachineInstr *> mvec;
+ // rewriteProlog, earlier, and restore all used registers from stack
+ // except SP.
int RegType;
- for (std::set<unsigned>::iterator i = regSet.begin (), e = regSet.end ();
+ for (std::set<unsigned>::iterator i = regsUsed.begin (), e = regsUsed.end ();
i != e; ++i) {
mvec.clear ();
unsigned R = *i;
@@ -483,7 +527,8 @@
DEBUG (std::cerr << "rewriteEpilog: Reloading reg#" << R << ", type = "
<< RegType << ", " << "Class = "
<< TRI.getRegClassIDOfRegType(RegType) << "\n");
- TRI.cpMem2RegMI (mvec, sp, stackSize + R * 8, R, RegType);
+ TRI.cpMem2RegMI (mvec, sp, stackSize + R * 8, R, RegType, g2);
+
// Add whatever the TargetRegInfo gave us to the MachineBasicBlock we are
// working on.
for (std::vector<MachineInstr *>::iterator vi = mvec.begin (),
More information about the llvm-commits
mailing list