[llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Wed Jan 28 11:55:01 PST 2004
Changes in directory reopt/lib/LightWtProfiling:
UnpackTraceFunction.cpp updated: 1.33 -> 1.34
---
Log message:
Revised head-of-file comment and UnpackTraceFunction::runOnMachineFunction()'s
comment.
Separated code into three parts: that which is specific to the SPARC
back-end in general (SparcReoptInfo), that which is specific to the
SPARC back-end's graph-coloring register allocator in particular, and
the main UnpackTraceFunction algorithm. These may become separate
files at some point.
---
Diffs of the changes: (+87 -50)
Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.33 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.34
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.33 Mon Jan 26 13:19:44 2004
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Wed Jan 28 11:54:34 2004
@@ -7,17 +7,13 @@
//
//===----------------------------------------------------------------------===//
//
-// Methods to convert functions, which had previously been converted from
+// Pass to convert functions, which had previously been converted from
// traces into functions, back into traces, and reattach them to the functions
// they came from.
//
//===----------------------------------------------------------------------===//
#include "TraceToFunction.h"
-#include "../../../../lib/Target/Sparc/RegAlloc/AllocInfo.h"
-#include "../../../../lib/Target/Sparc/RegAlloc/PhyRegAlloc.h"
-#include "../../../../lib/Target/Sparc/SparcRegInfo.h"
-#include "../../../../lib/Target/Sparc/SparcTargetMachine.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/IntrinsicLowering.h"
@@ -26,34 +22,32 @@
#include "Support/Debug.h"
#include "reopt/MappingInfo.h"
+///---------------------- SPARC backend-specific code -------------------------///
+
+#include "../../../../lib/Target/Sparc/RegAlloc/AllocInfo.h"
+#include "../../../../lib/Target/Sparc/RegAlloc/PhyRegAlloc.h"
+#include "../../../../lib/Target/Sparc/SparcRegInfo.h"
+#include "../../../../lib/Target/Sparc/SparcTargetMachine.h"
+
namespace llvm {
-class UnpackTraceFunction : public MachineFunctionPass {
+class SparcReoptInfo {
TargetMachine *TM;
- TraceFunction *TF;
-
+public:
+ SparcReoptInfo (TargetMachine *_TM) : TM (_TM) {}
void insertCopyMachineInstrs (AllocInfo &Source, AllocInfo &Target,
MachineBasicBlock &B, const Type *Ty);
-public:
- UnpackTraceFunction (TargetMachine *_TM, TraceFunction *_TF) : TM (_TM),
- TF (_TF) { }
- const char *getPassName () const { return "Unpack trace function"; }
- virtual bool runOnMachineFunction (MachineFunction &MF);
+ void insertBranchMachineInstrs (uint64_t Target, MachineBasicBlock &B);
+ const MachineInstr *containsReturnInstr (MachineBasicBlock &B);
};
-FunctionPass *createUnpackTraceFunctionPass (TargetMachine *TM,
- TraceFunction *TF) {
- return new UnpackTraceFunction (TM, TF);
-}
-
/// Insert the appropriate 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.
+/// Source to the location specified by Target, at the beginning of B.
///
-void UnpackTraceFunction::insertCopyMachineInstrs (AllocInfo &Source,
- AllocInfo &Target,
- MachineBasicBlock &B,
- const Type *Ty) {
+void SparcReoptInfo::insertCopyMachineInstrs (AllocInfo &Source,
+ AllocInfo &Target,
+ MachineBasicBlock &B,
+ const Type *Ty) {
const TargetRegInfo &TRI = TM->getRegInfo ();
std::vector<MachineInstr *> mvec;
int RegType;
@@ -97,10 +91,10 @@
B.push_back (*i);
}
-/// Emit a branch from the end of B to TargetAddr. Note that the current
-/// implementation is SPARC-specific.
+/// Append to B a branch from the end of B to TargetAddr.
///
-static void insertBranchMachineInstrs (uint64_t Target, MachineBasicBlock &B) {
+void SparcReoptInfo::insertBranchMachineInstrs (uint64_t Target,
+ MachineBasicBlock &B) {
// If the target is close enough to fit into the 19-bit disp of a "ba"
// instruction, then we really DO get a "ba" instruction. We get the backend
// to calculate the PC-relative address from the absolute address upon
@@ -116,6 +110,27 @@
B.push_back (BuildMI (V9::NOP, 0));
}
+/// Returns a pointer to the return instruction in B, if B contains
+/// one, or null otherwise.
+///
+const MachineInstr *SparcReoptInfo::containsReturnInstr (MachineBasicBlock &B) {
+ for (MachineBasicBlock::const_reverse_iterator i = B.rbegin (),
+ e = B.rend (); i != e; ++i) {
+ const MachineInstr *MI = *i;
+ if (MI->getOpcode () == V9::JMPLRETi)
+ return MI;
+ }
+ return 0;
+}
+
+} // end namespace llvm
+
+///---------------------- End SPARC backend-specific code ---------------------///
+
+///---------------------- SPARC register allocator-specific code --------------///
+
+namespace llvm {
+
extern "C" {
struct OperandAllocState {
unsigned Instruction;
@@ -134,11 +149,14 @@
struct FunctionAllocState *functions[0];
};
- /// This global is filled in by PhyRegAlloc's -save-ra-state option:
+ /// This global is filled in by PhyRegAlloc's -save-ra-state option
+ /// in LLC output:
///
extern struct ModuleAllocState _llvm_regAllocState;
};
+/// This global is filled in by PhyRegAlloc's -save-ra-state option in JIT output:
+///
extern PhyRegAlloc::SavedStateMapTy ExportedFnAllocState;
static unsigned getSavedStateIndexOfInstruction (const Function *F,
@@ -226,29 +244,48 @@
abort ();
}
-/// Returns a pointer to the return instruction in B, if B contains
-/// one, or null otherwise. Note that the current implementation is
-/// SPARC-specific.
+} // end namespace llvm
+
+///------------------End SPARC register allocator-specific code ---------------///
+
+namespace llvm {
+
+/// UnpackTraceFunction - This pass inserts copies in two places in the machine
+/// code for TF->TraceFn: first, at the entry basic block to copy the values in
+/// TF->LiveInSet from TF->MatrixFn's registers to TF->TraceFn's registers, and
+/// second, at each exit basic block to copy the values in TF->LiveOutSet from
+/// TF->TraceFn's registers to TF->MatrixFn's registers.
///
-static const MachineInstr *containsReturnInstruction (MachineBasicBlock &B) {
- for (MachineBasicBlock::const_reverse_iterator i = B.rbegin (),
- e = B.rend (); i != e; ++i) {
- const MachineInstr *MI = *i;
- if (MI->getOpcode () == V9::JMPLRETi)
- return MI;
- }
- return 0;
+class UnpackTraceFunction : public MachineFunctionPass {
+ TargetMachine *TM;
+ TraceFunction *TF;
+ SparcReoptInfo SRI;
+public:
+ UnpackTraceFunction (TargetMachine *_TM, TraceFunction *_TF) :
+ TM (_TM), TF (_TF), SRI (_TM) { }
+ const char *getPassName () const { return "Unpack trace function"; }
+ virtual bool runOnMachineFunction (MachineFunction &MF);
+};
+
+FunctionPass *createUnpackTraceFunctionPass (TargetMachine *TM,
+ TraceFunction *TF) {
+ return new UnpackTraceFunction (TM, TF);
}
-/// Insert copies in two places in the machine code for TraceF:
-/// first, at the entry basic block to copy the values in Si from
-/// MatrixF's registers to TraceF's registers, and second,
-/// at each exit basic block to copy the values in So from TraceF's
-/// registers to MatrixF's registers. MF is TraceF's MachineFunction.
+/// runOnMachineFunction - This method is provided with MF, which is the
+/// machine code for TF->TraceFn. We modify it (according to the description
+/// of the pass, above) using the information provided along with TF when this
+/// Pass object was created.
+///
+/// Admittedly, that is a pretty lame design, but for now, it means that we can
+/// only deal with one TraceFn and one MatrixFn in any given
+/// UnpackTraceFunction pass. If this stuff gets popular, we can have
+/// TraceFunctionPasses and TraceMachineFunctionPasses, or the Trace stuff can
+/// be an AnalysisPass, or something.
///
bool UnpackTraceFunction::runOnMachineFunction (MachineFunction &MF) {
- // This is pretty lame, but for now, we can only deal with one
- // TraceFn and one MatrixFn in any given UnpackTraceFunction pass.
+ // Make sure we are looking at the MachineFunction corresponding to the
+ // only TraceFunction we have.
if (MF.getFunction () != TF->TraceFn)
return false;
@@ -265,13 +302,13 @@
AllocInfo Source = getValueAllocStateFromModule (MatrixF, V);
AllocInfo Target = getValueAllocStateFromGlobal (TraceF, V);
if (Source != Target)
- insertCopyMachineInstrs (Source, Target, E, V->getType ());
+ SRI.insertCopyMachineInstrs (Source, Target, E, V->getType ());
}
// Modify EXIT MachineBasicBlocks of MF
for (MachineFunction::iterator I = MF.begin (), E = MF.end (); I != E; ++I) {
MachineBasicBlock &MBB = *I;
- if (const MachineInstr *RI = containsReturnInstruction (MBB)) {
+ if (const MachineInstr *RI = SRI.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.
@@ -296,10 +333,10 @@
AllocInfo Source = getValueAllocStateFromGlobal (TraceF, V);
AllocInfo Target = getValueAllocStateFromModule (MatrixF, V);
if (Source != Target)
- insertCopyMachineInstrs (Source, Target, MBB, V->getType ());
+ SRI.insertCopyMachineInstrs (Source, Target, MBB, V->getType ());
}
// Insert a branch back to the return BasicBlock of the matrix fn.
- insertBranchMachineInstrs (ReturnAddress, MBB);
+ SRI.insertBranchMachineInstrs (ReturnAddress, MBB);
}
}
More information about the llvm-commits
mailing list