From ffea03f2165c5a4fda672495bf853aa2d8c7d1b5 Mon Sep 17 00:00:00 2001 From: Andrew Trick Date: Wed, 8 Feb 2012 21:22:39 +0000 Subject: Added TargetPassConfig::setOpt git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150093 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/Passes.h | 6 ++++++ lib/CodeGen/LLVMTargetMachine.cpp | 2 ++ lib/CodeGen/Passes.cpp | 11 ++++++++++- lib/Target/PTX/PTXTargetMachine.cpp | 2 ++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/llvm/CodeGen/Passes.h b/include/llvm/CodeGen/Passes.h index 8849571731..7bc93114d6 100644 --- a/include/llvm/CodeGen/Passes.h +++ b/include/llvm/CodeGen/Passes.h @@ -39,6 +39,7 @@ class TargetPassConfig : public ImmutablePass { protected: TargetMachine *TM; PassManagerBase ± + bool Initialized; // Flagged after all passes are configured. // Target Pass Options // @@ -62,6 +63,8 @@ public: return TM->getTargetLowering(); } + void setInitialized() { Initialized = true; } + CodeGenOpt::Level getOptLevel() const { return TM->getOptLevel(); } void setDisableVerify(bool disable) { DisableVerify = disable; } @@ -84,6 +87,9 @@ public: /// Fully developed targets will not generally override this. virtual void addMachinePasses(); protected: + // Helper to verify the analysis is really immutable. + void setOpt(bool &Opt, bool Val); + /// Methods with trivial inline returns are convenient points in the common /// codegen pass pipeline where targets may insert passes. Methods with /// out-of-line standard implementations are major CodeGen stages called by diff --git a/lib/CodeGen/LLVMTargetMachine.cpp b/lib/CodeGen/LLVMTargetMachine.cpp index f07a85f39c..d14fbb2c33 100644 --- a/lib/CodeGen/LLVMTargetMachine.cpp +++ b/lib/CodeGen/LLVMTargetMachine.cpp @@ -147,6 +147,8 @@ static MCContext *addPassesToGenerateCode(LLVMTargetMachine *TM, PassConfig->addMachinePasses(); + PassConfig->setInitialized(); + return Context; } diff --git a/lib/CodeGen/Passes.cpp b/lib/CodeGen/Passes.cpp index 2877cf165b..6d12dd839c 100644 --- a/lib/CodeGen/Passes.cpp +++ b/lib/CodeGen/Passes.cpp @@ -84,7 +84,10 @@ char TargetPassConfig::ID = 0; TargetPassConfig::~TargetPassConfig() {} TargetPassConfig::TargetPassConfig(TargetMachine *tm, PassManagerBase &pm) - : ImmutablePass(ID), TM(tm), PM(pm), DisableVerify(false) { + : ImmutablePass(ID), TM(tm), PM(pm), Initialized(false), + DisableVerify(false), + EnableTailMerge(true) { + // Register all target independent codegen passes to activate their PassIDs, // including this pass itself. initializeCodeGen(*PassRegistry::getPassRegistry()); @@ -103,6 +106,12 @@ TargetPassConfig::TargetPassConfig() llvm_unreachable("TargetPassConfig should not be constructed on-the-fly"); } +// Helper to verify the analysis is really immutable. +void TargetPassConfig::setOpt(bool &Opt, bool Val) { + assert(!Initialized && "PassConfig is immutable"); + Opt = Val; +} + void TargetPassConfig::addPass(char &ID) { // FIXME: check user overrides Pass *P = Pass::createPass(ID); diff --git a/lib/Target/PTX/PTXTargetMachine.cpp b/lib/Target/PTX/PTXTargetMachine.cpp index 8901fa0b97..41bcfd564d 100644 --- a/lib/Target/PTX/PTXTargetMachine.cpp +++ b/lib/Target/PTX/PTXTargetMachine.cpp @@ -385,5 +385,7 @@ bool PTXPassConfig::addCodeGenPasses(MCContext *&OutContext) { PM.add(createPTXMFInfoExtract(getPTXTargetMachine(), getOptLevel())); PM.add(createPTXFPRoundingModePass(getPTXTargetMachine(), getOptLevel())); + setInitialized(); + return false; } -- cgit v1.2.3