diff options
author | Chris Lattner <sabre@nondot.org> | 2002-10-28 01:12:41 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-10-28 01:12:41 +0000 |
commit | 6d8a6c645c7cc0ce853d1c508a25893fb01d019f (patch) | |
tree | b7b423fd031e773bc1cc6bd03fe8431f76e125e0 /llvm/lib/CodeGen/MachineFunction.cpp | |
parent | f200a3e251978a9966027073285884100774f912 (diff) | |
download | bcm5719-llvm-6d8a6c645c7cc0ce853d1c508a25893fb01d019f.tar.gz bcm5719-llvm-6d8a6c645c7cc0ce853d1c508a25893fb01d019f.zip |
Move machine code generation/destruction passes out of Sparc.cpp because
they are generic
llvm-svn: 4310
Diffstat (limited to 'llvm/lib/CodeGen/MachineFunction.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineFunction.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp index 0e940f88be1..39fa913015b 100644 --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -9,11 +9,13 @@ #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineInstr.h" // For debug output #include "llvm/CodeGen/MachineCodeForBasicBlock.h" +#include "llvm/CodeGen/MachineCodeForInstruction.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/MachineFrameInfo.h" #include "llvm/Target/MachineCacheInfo.h" #include "llvm/Function.h" #include "llvm/iOther.h" +#include "llvm/Pass.h" #include <limits.h> const int INVALID_FRAME_OFFSET = INT_MAX; // std::numeric_limits<int>::max(); @@ -21,6 +23,60 @@ const int INVALID_FRAME_OFFSET = INT_MAX; // std::numeric_limits<int>::max(); static AnnotationID MCFM_AID( AnnotationManager::getID("CodeGen::MachineCodeForFunction")); + +//===---------------------------------------------------------------------===// +// Code generation/destruction passes +//===---------------------------------------------------------------------===// + +namespace { + class ConstructMachineFunction : public FunctionPass { + TargetMachine &Target; + public: + ConstructMachineFunction(TargetMachine &T) : Target(T) {} + + const char *getPassName() const { + return "ConstructMachineFunction"; + } + + bool runOnFunction(Function &F) { + MachineFunction::construct(&F, Target); + return false; + } + }; + + struct DestroyMachineFunction : public FunctionPass { + const char *getPassName() const { return "FreeMachineFunction"; } + + static void freeMachineCode(Instruction &I) { + MachineCodeForInstruction::destroy(&I); + } + + bool runOnFunction(Function &F) { + for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) + for (BasicBlock::iterator I = FI->begin(), E = FI->end(); I != E; ++I) + MachineCodeForInstruction::get(I).dropAllReferences(); + + for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) + for_each(FI->begin(), FI->end(), freeMachineCode); + + return false; + } + }; +} + +Pass *createMachineCodeConstructionPass(TargetMachine &Target) { + return new ConstructMachineFunction(Target); +} + +Pass *createMachineCodeDestructionPass() { + return new DestroyMachineFunction(); +} + + +//===---------------------------------------------------------------------===// +// MachineFunction implementation +//===---------------------------------------------------------------------===// + // The next two methods are used to construct and to retrieve // the MachineCodeForFunction object for the given function. // construct() -- Allocates and initializes for a given function and target |