From: Andrew Trick Date: Sat, 4 Feb 2012 02:56:45 +0000 (+0000) Subject: Make TargetPassConfig an ImmutablePass so CodeGenPasses can query options X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=7461334084aa77286b6f9af596fb0f6ba0465685;p=oota-llvm.git Make TargetPassConfig an ImmutablePass so CodeGenPasses can query options git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149752 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/CodeGen/Passes.h b/include/llvm/CodeGen/Passes.h index 627568a4e4d..308026dd866 100644 --- a/include/llvm/CodeGen/Passes.h +++ b/include/llvm/CodeGen/Passes.h @@ -15,6 +15,7 @@ #ifndef LLVM_CODEGEN_PASSES_H #define LLVM_CODEGEN_PASSES_H +#include "llvm/Pass.h" #include "llvm/Target/TargetMachine.h" #include @@ -32,9 +33,12 @@ namespace llvm { /// Target-Independent Code Generator Pass Configuration Options. /// +/// This is an ImmutablePass solely for the purpose of exposing CodeGen options +/// to the internals of other CodeGen passes. +/// /// FIXME: Why are we passing the DisableVerify flags around instead of setting /// an options in the target machine, like all the other driver options? -class TargetPassConfig { +class TargetPassConfig : public ImmutablePass { protected: TargetMachine *TM; PassManagerBase ± @@ -43,8 +47,12 @@ protected: public: TargetPassConfig(TargetMachine *tm, PassManagerBase &pm, bool DisableVerifyFlag); + // Dummy constructor. + TargetPassConfig(); + + virtual ~TargetPassConfig(); - virtual ~TargetPassConfig() {} + static char ID; /// Get the right type of TargetMachine for this target. template TMC &getTM() const { diff --git a/include/llvm/InitializePasses.h b/include/llvm/InitializePasses.h index ac129c77d54..c1940d6aa77 100644 --- a/include/llvm/InitializePasses.h +++ b/include/llvm/InitializePasses.h @@ -228,6 +228,7 @@ void initializeStripNonDebugSymbolsPass(PassRegistry&); void initializeStripSymbolsPass(PassRegistry&); void initializeStrongPHIEliminationPass(PassRegistry&); void initializeTailCallElimPass(PassRegistry&); +void initializeTargetPassConfigPass(PassRegistry&); void initializeTargetDataPass(PassRegistry&); void initializeTargetLibraryInfoPass(PassRegistry&); void initializeTwoAddressInstructionPassPass(PassRegistry&); diff --git a/lib/CodeGen/CodeGen.cpp b/lib/CodeGen/CodeGen.cpp index cbbf7f50580..7651e221fd5 100644 --- a/lib/CodeGen/CodeGen.cpp +++ b/lib/CodeGen/CodeGen.cpp @@ -49,6 +49,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) { initializeStackProtectorPass(Registry); initializeStackSlotColoringPass(Registry); initializeStrongPHIEliminationPass(Registry); + initializeTargetPassConfigPass(Registry); initializeTwoAddressInstructionPassPass(Registry); initializeUnreachableBlockElimPass(Registry); initializeUnreachableMachineBlockElimPass(Registry); diff --git a/lib/CodeGen/LLVMTargetMachine.cpp b/lib/CodeGen/LLVMTargetMachine.cpp index 3490e8f26fe..ff729baf803 100644 --- a/lib/CodeGen/LLVMTargetMachine.cpp +++ b/lib/CodeGen/LLVMTargetMachine.cpp @@ -125,27 +125,14 @@ LLVMTargetMachine::LLVMTargetMachine(const Target &T, StringRef Triple, "and that InitializeAllTargetMCs() is being invoked!"); } -TargetPassConfig::TargetPassConfig(TargetMachine *tm, PassManagerBase &pm, - bool DisableVerifyFlag) - : TM(tm), PM(pm), DisableVerify(DisableVerifyFlag) { - // Register all target independent codegen passes to activate their PassIDs. - initializeCodeGen(*PassRegistry::getPassRegistry()); -} - -/// createPassConfig - Create a pass configuration object to be used by -/// addPassToEmitX methods for generating a pipeline of CodeGen passes. -TargetPassConfig *LLVMTargetMachine::createPassConfig(PassManagerBase &PM, - bool DisableVerify) { - return new TargetPassConfig(this, PM, DisableVerify); -} - bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM, formatted_raw_ostream &Out, CodeGenFileType FileType, bool DisableVerify) { // Add common CodeGen passes. MCContext *Context = 0; - OwningPtr PassConfig(createPassConfig(PM, DisableVerify)); + TargetPassConfig *PassConfig = createPassConfig(PM, DisableVerify); + PM.add(PassConfig); if (PassConfig->addCodeGenPasses(Context)) return true; assert(Context != 0 && "Failed to get MCContext"); diff --git a/lib/CodeGen/Passes.cpp b/lib/CodeGen/Passes.cpp index 5f57088eedd..f2618282c3a 100644 --- a/lib/CodeGen/Passes.cpp +++ b/lib/CodeGen/Passes.cpp @@ -14,9 +14,43 @@ #include "llvm/CodeGen/RegAllocRegistry.h" #include "llvm/CodeGen/Passes.h" +#include "llvm/Support/ErrorHandling.h" using namespace llvm; +//===---------------------------------------------------------------------===// +/// TargetPassConfig +//===---------------------------------------------------------------------===// + +INITIALIZE_PASS(TargetPassConfig, "targetpassconfig", + "Target Pass Configuration", false, false) +char TargetPassConfig::ID = 0; + +// Out of line virtual method. +TargetPassConfig::~TargetPassConfig() {} + +TargetPassConfig::TargetPassConfig(TargetMachine *tm, PassManagerBase &pm, + bool DisableVerifyFlag) + : ImmutablePass(ID), TM(tm), PM(pm), DisableVerify(DisableVerifyFlag) { + // Register all target independent codegen passes to activate their PassIDs, + // including this pass itself. + initializeCodeGen(*PassRegistry::getPassRegistry()); +} + +/// createPassConfig - Create a pass configuration object to be used by +/// addPassToEmitX methods for generating a pipeline of CodeGen passes. +/// +/// Targets may override this to extend TargetPassConfig. +TargetPassConfig *LLVMTargetMachine::createPassConfig(PassManagerBase &PM, + bool DisableVerify) { + return new TargetPassConfig(this, PM, DisableVerify); +} + +TargetPassConfig::TargetPassConfig() + : ImmutablePass(ID), PM(*(PassManagerBase*)0) { + llvm_unreachable("TargetPassConfig should not be constructed on-the-fly"); +} + //===---------------------------------------------------------------------===// /// /// RegisterRegAlloc class - Track the registration of register allocators.