mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-04 22:07:27 +00:00
Move machine code generation/destruction passes out of Sparc.cpp because
they are generic git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4310 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e42a84f64f
commit
227c3d355b
@ -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
|
||||
|
@ -113,48 +113,6 @@ UltraSparcFrameInfo::getDynamicAreaOffset(MachineFunction& mcInfo,
|
||||
return offset;
|
||||
}
|
||||
|
||||
//===---------------------------------------------------------------------===//
|
||||
// Default code generation passes.
|
||||
//
|
||||
// Native code generation for a specified target.
|
||||
//===---------------------------------------------------------------------===//
|
||||
|
||||
class ConstructMachineCodeForFunction : public FunctionPass {
|
||||
TargetMachine &Target;
|
||||
public:
|
||||
ConstructMachineCodeForFunction(TargetMachine &T) : Target(T) {}
|
||||
|
||||
const char *getPassName() const {
|
||||
return "ConstructMachineCodeForFunction";
|
||||
}
|
||||
|
||||
bool runOnFunction(Function &F) {
|
||||
MachineFunction::construct(&F, Target);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
struct FreeMachineCodeForFunction : public FunctionPass {
|
||||
const char *getPassName() const { return "FreeMachineCodeForFunction"; }
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// class UltraSparcMachine
|
||||
//
|
||||
@ -187,7 +145,7 @@ UltraSparc::UltraSparc()
|
||||
void UltraSparc::addPassesToEmitAssembly(PassManager &PM, std::ostream &Out)
|
||||
{
|
||||
// Construct and initialize the MachineFunction object for this fn.
|
||||
PM.add(new ConstructMachineCodeForFunction(*this));
|
||||
PM.add(createMachineCodeConstructionPass(*this));
|
||||
|
||||
//Insert empty stackslots in the stack frame of each function
|
||||
//so %fp+offset-8 and %fp+offset-16 are empty slots now!
|
||||
@ -224,7 +182,7 @@ void UltraSparc::addPassesToEmitAssembly(PassManager &PM, std::ostream &Out)
|
||||
// function has been emitted.
|
||||
//
|
||||
PM.add(getFunctionAsmPrinterPass(Out));
|
||||
PM.add(new FreeMachineCodeForFunction()); // Free stuff no longer needed
|
||||
PM.add(createMachineCodeDestructionPass()); // Free stuff no longer needed
|
||||
|
||||
// Emit Module level assembly after all of the functions have been processed.
|
||||
PM.add(getModuleAsmPrinterPass(Out));
|
||||
|
Loading…
Reference in New Issue
Block a user