[llvm-commits] [llvm] r149752 - in /llvm/trunk: include/llvm/CodeGen/Passes.h include/llvm/InitializePasses.h lib/CodeGen/CodeGen.cpp lib/CodeGen/LLVMTargetMachine.cpp lib/CodeGen/Passes.cpp
Andrew Trick
atrick at apple.com
Fri Feb 3 18:56:45 PST 2012
Author: atrick
Date: Fri Feb 3 20:56:45 2012
New Revision: 149752
URL: http://llvm.org/viewvc/llvm-project?rev=149752&view=rev
Log:
Make TargetPassConfig an ImmutablePass so CodeGenPasses can query options
Modified:
llvm/trunk/include/llvm/CodeGen/Passes.h
llvm/trunk/include/llvm/InitializePasses.h
llvm/trunk/lib/CodeGen/CodeGen.cpp
llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
llvm/trunk/lib/CodeGen/Passes.cpp
Modified: llvm/trunk/include/llvm/CodeGen/Passes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/Passes.h?rev=149752&r1=149751&r2=149752&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/Passes.h (original)
+++ llvm/trunk/include/llvm/CodeGen/Passes.h Fri Feb 3 20:56:45 2012
@@ -15,6 +15,7 @@
#ifndef LLVM_CODEGEN_PASSES_H
#define LLVM_CODEGEN_PASSES_H
+#include "llvm/Pass.h"
#include "llvm/Target/TargetMachine.h"
#include <string>
@@ -32,9 +33,12 @@
/// 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 &PM;
@@ -43,8 +47,12 @@
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<typename TMC> TMC &getTM() const {
Modified: llvm/trunk/include/llvm/InitializePasses.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=149752&r1=149751&r2=149752&view=diff
==============================================================================
--- llvm/trunk/include/llvm/InitializePasses.h (original)
+++ llvm/trunk/include/llvm/InitializePasses.h Fri Feb 3 20:56:45 2012
@@ -228,6 +228,7 @@
void initializeStripSymbolsPass(PassRegistry&);
void initializeStrongPHIEliminationPass(PassRegistry&);
void initializeTailCallElimPass(PassRegistry&);
+void initializeTargetPassConfigPass(PassRegistry&);
void initializeTargetDataPass(PassRegistry&);
void initializeTargetLibraryInfoPass(PassRegistry&);
void initializeTwoAddressInstructionPassPass(PassRegistry&);
Modified: llvm/trunk/lib/CodeGen/CodeGen.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGen.cpp?rev=149752&r1=149751&r2=149752&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CodeGen.cpp (original)
+++ llvm/trunk/lib/CodeGen/CodeGen.cpp Fri Feb 3 20:56:45 2012
@@ -49,6 +49,7 @@
initializeStackProtectorPass(Registry);
initializeStackSlotColoringPass(Registry);
initializeStrongPHIEliminationPass(Registry);
+ initializeTargetPassConfigPass(Registry);
initializeTwoAddressInstructionPassPass(Registry);
initializeUnreachableBlockElimPass(Registry);
initializeUnreachableMachineBlockElimPass(Registry);
Modified: llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp?rev=149752&r1=149751&r2=149752&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp (original)
+++ llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp Fri Feb 3 20:56:45 2012
@@ -125,27 +125,14 @@
"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<TargetPassConfig> 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");
Modified: llvm/trunk/lib/CodeGen/Passes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/Passes.cpp?rev=149752&r1=149751&r2=149752&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/Passes.cpp (original)
+++ llvm/trunk/lib/CodeGen/Passes.cpp Fri Feb 3 20:56:45 2012
@@ -14,10 +14,44 @@
#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.
///
More information about the llvm-commits
mailing list