[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 llvm-svn: 303360
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "llvm/Analysis/ScalarEvolution.h"
|
||||
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
|
||||
#include "llvm/CodeGen/Passes.h"
|
||||
#include "llvm/CodeGen/TargetPassConfig.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
#include "llvm/IR/DIBuilder.h"
|
||||
#include "llvm/IR/DataLayout.h"
|
||||
@@ -767,13 +768,12 @@ class SafeStackLegacyPass : public FunctionPass {
|
||||
|
||||
public:
|
||||
static char ID; // Pass identification, replacement for typeid..
|
||||
SafeStackLegacyPass(const TargetMachine *TM) : FunctionPass(ID), TM(TM) {
|
||||
SafeStackLegacyPass() : FunctionPass(ID), TM(nullptr) {
|
||||
initializeSafeStackLegacyPassPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
SafeStackLegacyPass() : SafeStackLegacyPass(nullptr) {}
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.addRequired<TargetPassConfig>();
|
||||
AU.addRequired<TargetLibraryInfoWrapperPass>();
|
||||
AU.addRequired<AssumptionCacheTracker>();
|
||||
}
|
||||
@@ -793,8 +793,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TM)
|
||||
report_fatal_error("Target machine is required");
|
||||
TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
|
||||
auto *TL = TM->getSubtargetImpl(F)->getTargetLowering();
|
||||
if (!TL)
|
||||
report_fatal_error("TargetLowering instance is required");
|
||||
@@ -821,11 +820,10 @@ public:
|
||||
} // anonymous namespace
|
||||
|
||||
char SafeStackLegacyPass::ID = 0;
|
||||
INITIALIZE_TM_PASS_BEGIN(SafeStackLegacyPass, "safe-stack",
|
||||
"Safe Stack instrumentation pass", false, false)
|
||||
INITIALIZE_TM_PASS_END(SafeStackLegacyPass, "safe-stack",
|
||||
"Safe Stack instrumentation pass", false, false)
|
||||
INITIALIZE_PASS_BEGIN(SafeStackLegacyPass, "safe-stack",
|
||||
"Safe Stack instrumentation pass", false, false)
|
||||
INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
|
||||
INITIALIZE_PASS_END(SafeStackLegacyPass, "safe-stack",
|
||||
"Safe Stack instrumentation pass", false, false)
|
||||
|
||||
FunctionPass *llvm::createSafeStackPass(const llvm::TargetMachine *TM) {
|
||||
return new SafeStackLegacyPass(TM);
|
||||
}
|
||||
FunctionPass *llvm::createSafeStackPass() { return new SafeStackLegacyPass(); }
|
||||
|
||||
Reference in New Issue
Block a user