diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2015-02-01 10:11:22 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2015-02-01 10:11:22 +0000 |
commit | 7724e8efa2d3b71f293807f4323f4e760a37f249 (patch) | |
tree | 9a206cb91acbffc2e490f92cfe5c0b91e454b8be /tools | |
parent | 270f7a2669ebb7f81503819b0569d2368993a090 (diff) |
[PM] Port TTI to the new pass manager, introducing a TargetIRAnalysis to
produce it.
This adds a function to the TargetMachine that produces this analysis
via a callback for each function. This in turn faves the way to produce
a *different* TTI per-function with the correct subtarget cached.
I've also done the necessary wiring in the opt tool to thread the target
machine down and make it available to the pass registry so that we can
construct this analysis from a target machine when available.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227721 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/opt/NewPMDriver.cpp | 8 | ||||
-rw-r--r-- | tools/opt/NewPMDriver.h | 6 | ||||
-rw-r--r-- | tools/opt/PassRegistry.def | 2 | ||||
-rw-r--r-- | tools/opt/Passes.cpp | 2 | ||||
-rw-r--r-- | tools/opt/Passes.h | 5 | ||||
-rw-r--r-- | tools/opt/opt.cpp | 18 |
6 files changed, 27 insertions, 14 deletions
diff --git a/tools/opt/NewPMDriver.cpp b/tools/opt/NewPMDriver.cpp index b0845c7b1f5..a73750dd492 100644 --- a/tools/opt/NewPMDriver.cpp +++ b/tools/opt/NewPMDriver.cpp @@ -27,6 +27,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ToolOutputFile.h" +#include "llvm/Target/TargetMachine.h" using namespace llvm; using namespace opt_tool; @@ -36,9 +37,10 @@ static cl::opt<bool> cl::desc("Print pass management debugging information")); bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M, - tool_output_file *Out, StringRef PassPipeline, - OutputKind OK, VerifierKind VK) { - Passes P; + TargetMachine *TM, tool_output_file *Out, + StringRef PassPipeline, OutputKind OK, + VerifierKind VK) { + Passes P(TM); FunctionAnalysisManager FAM(DebugPM); CGSCCAnalysisManager CGAM(DebugPM); diff --git a/tools/opt/NewPMDriver.h b/tools/opt/NewPMDriver.h index f977baca7f8..5384fe295e1 100644 --- a/tools/opt/NewPMDriver.h +++ b/tools/opt/NewPMDriver.h @@ -26,6 +26,7 @@ namespace llvm { class LLVMContext; class Module; +class TargetMachine; class tool_output_file; namespace opt_tool { @@ -48,8 +49,9 @@ enum VerifierKind { /// file. It's interface is consequentially somewhat ad-hoc, but will go away /// when the transition finishes. bool runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M, - tool_output_file *Out, StringRef PassPipeline, - opt_tool::OutputKind OK, opt_tool::VerifierKind VK); + TargetMachine *TM, tool_output_file *Out, + StringRef PassPipeline, opt_tool::OutputKind OK, + opt_tool::VerifierKind VK); } #endif diff --git a/tools/opt/PassRegistry.def b/tools/opt/PassRegistry.def index 9361d98c9a5..4ee9e97158e 100644 --- a/tools/opt/PassRegistry.def +++ b/tools/opt/PassRegistry.def @@ -55,6 +55,8 @@ FUNCTION_ANALYSIS("domtree", DominatorTreeAnalysis()) FUNCTION_ANALYSIS("loops", LoopAnalysis()) FUNCTION_ANALYSIS("no-op-function", NoOpFunctionAnalysis()) FUNCTION_ANALYSIS("targetlibinfo", TargetLibraryAnalysis()) +FUNCTION_ANALYSIS("targetir", + TM ? TM->getTargetIRAnalysis() : TargetIRAnalysis()) #undef FUNCTION_ANALYSIS #ifndef FUNCTION_PASS diff --git a/tools/opt/Passes.cpp b/tools/opt/Passes.cpp index 46c165abc03..b098a7c2351 100644 --- a/tools/opt/Passes.cpp +++ b/tools/opt/Passes.cpp @@ -20,11 +20,13 @@ #include "llvm/Analysis/LazyCallGraph.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/TargetLibraryInfo.h" +#include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/IRPrintingPasses.h" #include "llvm/IR/PassManager.h" #include "llvm/IR/Verifier.h" #include "llvm/Support/Debug.h" +#include "llvm/Target/TargetMachine.h" #include "llvm/Transforms/InstCombine/InstCombine.h" #include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h" diff --git a/tools/opt/Passes.h b/tools/opt/Passes.h index 90a6c6b871d..d3cb628469b 100644 --- a/tools/opt/Passes.h +++ b/tools/opt/Passes.h @@ -21,6 +21,7 @@ #include "llvm/IR/PassManager.h" namespace llvm { +class TargetMachine; /// \brief This class provides access to all of LLVM's passes. /// @@ -29,7 +30,11 @@ namespace llvm { /// of the built-in passes, and those may reference these members during /// construction. class Passes { + TargetMachine *TM; + public: + explicit Passes(TargetMachine *TM = nullptr) : TM(TM) {} + /// \brief Registers all available module analysis passes. /// /// This is an interface that can be used to populate a \c diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 93b44d4f7f4..af2cdd82460 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -370,6 +370,12 @@ int main(int argc, char **argv) { } } + Triple ModuleTriple(M->getTargetTriple()); + TargetMachine *Machine = nullptr; + if (ModuleTriple.getArch()) + Machine = GetTargetMachine(ModuleTriple); + std::unique_ptr<TargetMachine> TM(Machine); + // If the output is set to be emitted to standard out, and standard out is a // console, print out a warning message and refuse to do it. We don't // impress anyone by spewing tons of binary goo to a terminal. @@ -391,8 +397,8 @@ int main(int argc, char **argv) { // The user has asked to use the new pass manager and provided a pipeline // string. Hand off the rest of the functionality to the new code for that // layer. - return runPassPipeline(argv[0], Context, *M, Out.get(), PassPipeline, - OK, VK) + return runPassPipeline(argv[0], Context, *M, TM.get(), Out.get(), + PassPipeline, OK, VK) ? 0 : 1; } @@ -403,7 +409,7 @@ int main(int argc, char **argv) { PassManager Passes; // Add an appropriate TargetLibraryInfo pass for the module's triple. - TargetLibraryInfoImpl TLII(Triple(M->getTargetTriple())); + TargetLibraryInfoImpl TLII(ModuleTriple); // The -disable-simplify-libcalls flag actually disables all builtin optzns. if (DisableSimplifyLibCalls) @@ -420,12 +426,6 @@ int main(int argc, char **argv) { if (DL) Passes.add(new DataLayoutPass()); - Triple ModuleTriple(M->getTargetTriple()); - TargetMachine *Machine = nullptr; - if (ModuleTriple.getArch()) - Machine = GetTargetMachine(Triple(ModuleTriple)); - std::unique_ptr<TargetMachine> TM(Machine); - // Add internal analysis passes from the target machine. Passes.add(createTargetTransformInfoWrapperPass( TM ? TM->getTTI() : TargetTransformInfo(DL))); |