[llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Fri Apr 9 13:04:35 PDT 2004
Changes in directory reopt/lib/LightWtProfiling:
UnpackTraceFunction.cpp updated: 1.52 -> 1.53
---
Log message:
Move all the prolog rewriting stuff into rewriteProlog, and all the
epilog rewriting stuff into a new method called rewriteEpilog.
Other minor cleanups.
---
Diffs of the changes: (+71 -61)
Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.52 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.53
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.52 Fri Apr 9 12:06:51 2004
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Fri Apr 9 13:03:24 2004
@@ -45,7 +45,8 @@
MachineBasicBlock &B, const Type *Ty);
void insertBranchMachineInstrs (uint64_t Target, MachineBasicBlock &B);
const MachineInstr *containsReturnInstr (MachineBasicBlock &B);
- void rewriteProlog (MachineFunction &MF, MachineBasicBlock &E);
+ void rewriteProlog (MachineFunction &MF, MachineBasicBlock &MBB);
+ void rewriteEpilog (MachineFunction &MF, MachineBasicBlock &MBB);
public:
UnpackTraceFunction (TargetMachine *_TM, TraceFunction *_TF) :
TM (_TM), TF (_TF) { }
@@ -65,6 +66,14 @@
Ty (_Ty) {}
};
+/// Print method for CopyInfo objects.
+///
+std::ostream &operator<< (std::ostream &OS, CopyInfo &CI) {
+ OS << "(Src " << CI.Src << " Targ " << CI.Targ << " Blk " << CI.Blk
+ << " Ty " << *CI.Ty << ")";
+ return OS;
+}
+
/// Create a new UnpackTraceFunction pass that will unpack a given
/// TraceFunction, for which machine code has been generated, into
/// its matrix function.
@@ -172,6 +181,9 @@
return 0;
}
+static AllocInfo getValueAllocStateFromModule (Function *F, Value *V);
+static AllocInfo getValueAllocStateFromGlobal (Function *F, Value *V);
+
void UnpackTraceFunction::rewriteProlog (MachineFunction &MF,
MachineBasicBlock &E) {
const TargetRegInfo &TRI = TM->getRegInfo ();
@@ -236,6 +248,35 @@
ve = mvec.end (); vi != ve; ++vi)
E.push_back (*vi);
}
+
+ // 4. Insert copies from each live-in variable's reg. in the matrix fn.
+ // to its reg. in the trace.
+ Function *TraceF = TF->TraceFn, *MatrixF = TF->MatrixFn;
+ LiveVariableSet &Si = TF->LiveInSet, &So = TF->LiveOutSet;
+ std::vector<CopyInfo> EntryCopies;
+ DEBUG(std::cerr << "UnpackTraceFunction: Modifying entry BB\n");
+ for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE;
+ ++SI) {
+ Value *V = *SI;
+ DEBUG(std::cerr
+ << "UnpackTraceFunction: Looking for alloc state for value: ";
+ WriteAsOperand (std::cerr, V, true, true, MatrixF->getParent ());
+ std::cerr << "\n");
+ AllocInfo Source = getValueAllocStateFromModule (MatrixF, V);
+ DEBUG(std::cerr << "UnpackTraceFunction: Source = " << Source << "\n");
+ AllocInfo Target =
+ getValueAllocStateFromGlobal (TraceF, TF->getCorrespondingValue (V));
+ DEBUG(std::cerr << "UnpackTraceFunction: Target = " << Target << "\n");
+ if (Source != Target)
+ EntryCopies.push_back (CopyInfo (Source, Target, &E, V->getType ()));
+ }
+ DEBUG(std::cerr << "UnpackTraceFunction: Inserting copy MachineInstrs:\n");
+ for (std::vector<CopyInfo>::iterator i = EntryCopies.begin (),
+ e = EntryCopies.end (); i != e; ++i) {
+ DEBUG(std::cerr << "UnpackTraceFunction: " << *i << "\n");
+ insertCopyMachineInstrs (i->Src, i->Targ, *i->Blk, i->Ty);
+ }
+ DEBUG(std::cerr << "-------------\n\n");
}
/// Data structures describing the register allocator state
@@ -385,12 +426,33 @@
abort ();
}
-/// Print method for CopyInfo objects.
-///
-std::ostream &operator<< (std::ostream &OS, CopyInfo &CI) {
- OS << "(Src " << CI.Src << " Targ " << CI.Targ << " Blk " << CI.Blk
- << " Ty " << *CI.Ty << ")";
- return OS;
+void UnpackTraceFunction::rewriteEpilog (MachineFunction &MF,
+ MachineBasicBlock &MBB) {
+ Function *TraceF = TF->TraceFn, *MatrixF = TF->MatrixFn;
+ LiveVariableSet &Si = TF->LiveInSet, &So = TF->LiveOutSet;
+ // Let ReturnAddress be the address in memory of the compiled
+ // code for the MachineBasicBlock in MatrixF that RI would have
+ // returned to. Find it by using MappingInfo.
+ BasicBlock *RBB = const_cast<BasicBlock *> (MBB.getBasicBlock ());
+ assert ((TF->ReturnBlockForTraceExit.find (RBB) !=
+ TF->ReturnBlockForTraceExit.end ())
+ && "Can't find matrix fn BB address to return to from trace");
+ uint64_t ReturnAddress =
+ getBasicBlockInfo(TF->ReturnBlockForTraceExit[RBB]).first;
+ MBB.clear (); // Empty it out first.
+ // Insert copies from each live-out variable's reg. in the trace
+ // to its reg. in the matrix function.
+ for (LiveVariableSet::iterator SI = So.begin (), SE = So.end ();
+ SI != SE; ++SI) {
+ Value *V = *SI;
+ AllocInfo Source =
+ getValueAllocStateFromGlobal (TraceF, TF->getCorrespondingValue (V));
+ AllocInfo Target = getValueAllocStateFromModule (MatrixF, V);
+ if (Source != Target)
+ insertCopyMachineInstrs (Source, Target, MBB, V->getType ());
+ }
+ // Insert a branch back to the return BasicBlock of the matrix fn.
+ insertBranchMachineInstrs (ReturnAddress, MBB);
}
/// This method is provided with MF, which is the
@@ -418,65 +480,13 @@
// Modify ENTRY MachineBasicBlock of MF
MachineBasicBlock &E = MF.front (); // E = Entry MBB of MF
- std::vector<CopyInfo> EntryCopies;
- DEBUG(std::cerr << "UnpackTraceFunction: Modifying entry BB\n");
-
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.
- // to its reg. in the trace.
- Value *V = *SI;
- DEBUG(std::cerr
- << "UnpackTraceFunction: Looking for alloc state for value: ";
- WriteAsOperand (std::cerr, V, true, true, MatrixF->getParent ());
- std::cerr << "\n");
- AllocInfo Source = getValueAllocStateFromModule (MatrixF, V);
- DEBUG(std::cerr << "UnpackTraceFunction: Source = " << Source << "\n");
- AllocInfo Target =
- getValueAllocStateFromGlobal (TraceF, TF->getCorrespondingValue (V));
- DEBUG(std::cerr << "UnpackTraceFunction: Target = " << Target << "\n");
- if (Source != Target)
- EntryCopies.push_back (CopyInfo (Source, Target, &E, V->getType ()));
- }
-
- DEBUG(std::cerr << "UnpackTraceFunction: Inserting copy MachineInstrs:\n");
- for (std::vector<CopyInfo>::iterator i = EntryCopies.begin (),
- e = EntryCopies.end (); i != e; ++i) {
- DEBUG(std::cerr << "UnpackTraceFunction: " << *i << "\n");
- insertCopyMachineInstrs (i->Src, i->Targ, *i->Blk, i->Ty);
- }
- DEBUG(std::cerr << "-------------\n\n");
-
// Modify EXIT MachineBasicBlocks of MF
for (MachineFunction::iterator I = MF.begin (), E = MF.end (); I != E; ++I) {
MachineBasicBlock &MBB = *I;
- if (const MachineInstr *RI = containsReturnInstr (MBB)) {
- // Let ReturnAddress be the address in memory of the compiled
- // code for the MachineBasicBlock in MatrixF that RI would have
- // returned to. Find it by using MappingInfo.
- BasicBlock *RBB = const_cast<BasicBlock *> (MBB.getBasicBlock ());
- assert ((TF->ReturnBlockForTraceExit.find (RBB) !=
- TF->ReturnBlockForTraceExit.end ())
- && "Can't find matrix fn BB address to return to from trace");
- uint64_t ReturnAddress =
- getBasicBlockInfo(TF->ReturnBlockForTraceExit[RBB]).first;
- MBB.clear (); // Empty it out first.
- // Insert copies from each live-out variable's reg. in the trace
- // to its reg. in the matrix function.
- for (LiveVariableSet::iterator SI = So.begin (), SE = So.end ();
- SI != SE; ++SI) {
- Value *V = *SI;
- AllocInfo Source =
- getValueAllocStateFromGlobal (TraceF, TF->getCorrespondingValue (V));
- AllocInfo Target = getValueAllocStateFromModule (MatrixF, V);
- if (Source != Target)
- insertCopyMachineInstrs (Source, Target, MBB, V->getType ());
- }
- // Insert a branch back to the return BasicBlock of the matrix fn.
- insertBranchMachineInstrs (ReturnAddress, MBB);
- }
+ if (const MachineInstr *RI = containsReturnInstr (MBB))
+ rewriteEpilog (MF, MBB);
}
return true; // MachineFunction was modified
More information about the llvm-commits
mailing list