diff options
author | Francis Visoiu Mistrih <fvisoiumistrih@apple.com> | 2017-05-18 17:21:13 +0000 |
---|---|---|
committer | Francis Visoiu Mistrih <fvisoiumistrih@apple.com> | 2017-05-18 17:21:13 +0000 |
commit | ae1c8533580a486b128643a10b59f50e39896752 (patch) | |
tree | 93ce4a2726afdde753c6e8422f69d929e2dd263b /tools/opt | |
parent | 71f289771fdb2074d0a578e5a752ea11af45e9f4 (diff) |
[LegacyPassManager] Remove TargetMachine constructors
This provides a new way to access the TargetMachine through
TargetPassConfig, as a dependency.
The patterns replaced here are:
* Passes handling a null TargetMachine call
`getAnalysisIfAvailable<TargetPassConfig>`.
* Passes not handling a null TargetMachine
`addRequired<TargetPassConfig>` and call
`getAnalysis<TargetPassConfig>`.
* MachineFunctionPasses now use MF.getTarget().
* Remove all the TargetMachine constructors.
* Remove INITIALIZE_TM_PASS.
This fixes a crash when running `llc -start-before prologepilog`.
PEI needs StackProtector, which gets constructed without a TargetMachine
by the pass manager. The StackProtector pass doesn't handle the case
where there is no TargetMachine, so it segfaults.
Related to PR30324.
Differential Revision: https://reviews.llvm.org/D33222
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303360 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/opt')
-rw-r--r-- | tools/opt/opt.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index c362dff3a3e..bef197d603c 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -24,6 +24,7 @@ #include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/Bitcode/BitcodeWriterPass.h" #include "llvm/CodeGen/CommandFlags.h" +#include "llvm/CodeGen/TargetPassConfig.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/DebugInfo.h" #include "llvm/IR/IRPrintingPasses.h" @@ -579,6 +580,13 @@ int main(int argc, char **argv) { NoOutput = true; } + if (TM) { + // FIXME: We should dyn_cast this when supported. + auto <M = static_cast<LLVMTargetMachine &>(*TM); + Pass *TPC = LTM.createPassConfig(Passes); + Passes.add(TPC); + } + // Create a new optimization pass for each one specified on the command line for (unsigned i = 0; i < PassList.size(); ++i) { if (StandardLinkOpts && @@ -619,9 +627,7 @@ int main(int argc, char **argv) { const PassInfo *PassInf = PassList[i]; Pass *P = nullptr; - if (PassInf->getTargetMachineCtor()) - P = PassInf->getTargetMachineCtor()(TM.get()); - else if (PassInf->getNormalCtor()) + if (PassInf->getNormalCtor()) P = PassInf->getNormalCtor()(); else errs() << argv[0] << ": cannot create pass: " |