Added TargetPassConfig. The first little step toward configuring codegen passes.

Allows command line overrides to be centralized in LLVMTargetMachine.cpp.
LLVMTargetMachine can intercept common passes and give precedence to command line overrides.
Allows adding "internal" target configuration options without touching TargetOptions.
Encapsulates the PassManager.
Provides a good point to initialize all CodeGen passes so that Pass ID's can be used in APIs.
Allows modifying the target configuration hooks without rebuilding the world.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149672 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Andrew Trick
2012-02-03 05:12:41 +00:00
parent 8247e0dca6
commit 843ee2e6a4
25 changed files with 565 additions and 268 deletions

View File

@ -14,6 +14,7 @@
#include "Mips.h"
#include "MipsTargetMachine.h"
#include "llvm/PassManager.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/Support/TargetRegistry.h"
using namespace llvm;
@ -88,37 +89,61 @@ Mips64elTargetMachine(const Target &T, StringRef TT,
CodeGenOpt::Level OL)
: MipsTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {}
namespace {
/// Mips Code Generator Pass Configuration Options.
class MipsPassConfig : public TargetPassConfig {
public:
MipsPassConfig(MipsTargetMachine *TM, PassManagerBase &PM,
bool DisableVerifyFlag)
: TargetPassConfig(TM, PM, DisableVerifyFlag) {}
MipsTargetMachine &getMipsTargetMachine() const {
return getTM<MipsTargetMachine>();
}
const MipsSubtarget &getMipsSubtarget() const {
return *getMipsTargetMachine().getSubtargetImpl();
}
virtual bool addInstSelector();
virtual bool addPreRegAlloc();
virtual bool addPostRegAlloc();
virtual bool addPreEmitPass();
};
} // namespace
TargetPassConfig *MipsTargetMachine::createPassConfig(PassManagerBase &PM,
bool DisableVerify) {
return new MipsPassConfig(this, PM, DisableVerify);
}
// Install an instruction selector pass using
// the ISelDag to gen Mips code.
bool MipsTargetMachine::
addInstSelector(PassManagerBase &PM)
bool MipsPassConfig::addInstSelector()
{
PM.add(createMipsISelDag(*this));
PM.add(createMipsISelDag(getMipsTargetMachine()));
return false;
}
// Implemented by targets that want to run passes immediately before
// machine code is emitted. return true if -print-machineinstrs should
// print out the code after the passes.
bool MipsTargetMachine::
addPreEmitPass(PassManagerBase &PM)
bool MipsPassConfig::addPreEmitPass()
{
PM.add(createMipsDelaySlotFillerPass(*this));
PM.add(createMipsDelaySlotFillerPass(getMipsTargetMachine()));
return true;
}
bool MipsTargetMachine::
addPreRegAlloc(PassManagerBase &PM) {
bool MipsPassConfig::addPreRegAlloc() {
// Do not restore $gp if target is Mips64.
// In N32/64, $gp is a callee-saved register.
if (!Subtarget.hasMips64())
PM.add(createMipsEmitGPRestorePass(*this));
if (!getMipsSubtarget().hasMips64())
PM.add(createMipsEmitGPRestorePass(getMipsTargetMachine()));
return true;
}
bool MipsTargetMachine::
addPostRegAlloc(PassManagerBase &PM) {
PM.add(createMipsExpandPseudoPass(*this));
bool MipsPassConfig::addPostRegAlloc() {
PM.add(createMipsExpandPseudoPass(getMipsTargetMachine()));
return true;
}