diff --git a/llvm/include/llvm/CodeGen/PreISelIntrinsicLowering.h b/llvm/include/llvm/CodeGen/PreISelIntrinsicLowering.h index aa6a0e6935b33b..955a2437cb94c4 100644 --- a/llvm/include/llvm/CodeGen/PreISelIntrinsicLowering.h +++ b/llvm/include/llvm/CodeGen/PreISelIntrinsicLowering.h @@ -22,9 +22,9 @@ class TargetMachine; struct PreISelIntrinsicLoweringPass : PassInfoMixin { - const TargetMachine &TM; + const TargetMachine *TM; - PreISelIntrinsicLoweringPass(const TargetMachine &TM) : TM(TM) {} + PreISelIntrinsicLoweringPass(const TargetMachine *TM) : TM(TM) {} PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); }; diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h index fb7a3c107d88a4..81c00a3a95c113 100644 --- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h +++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h @@ -628,7 +628,7 @@ void CodeGenPassBuilder::addISelPasses( if (TM.useEmulatedTLS()) addPass(LowerEmuTLSPass()); - addPass(PreISelIntrinsicLoweringPass(TM)); + addPass(PreISelIntrinsicLoweringPass(&TM)); derived().addIRPasses(addPass); derived().addCodeGenPrepare(addPass); diff --git a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp index c0e08063be41d3..6418c54f0b18f0 100644 --- a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp +++ b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp @@ -47,7 +47,7 @@ static cl::opt MemIntrinsicExpandSizeThresholdOpt( namespace { struct PreISelIntrinsicLowering { - const TargetMachine &TM; + const TargetMachine *TM; const function_ref LookupTTI; const function_ref LookupTLI; @@ -57,7 +57,7 @@ struct PreISelIntrinsicLowering { const bool UseMemIntrinsicLibFunc; explicit PreISelIntrinsicLowering( - const TargetMachine &TM_, + const TargetMachine *TM_, function_ref LookupTTI_, function_ref LookupTLI_, bool UseMemIntrinsicLibFunc_ = true) @@ -223,10 +223,12 @@ bool PreISelIntrinsicLowering::shouldExpandMemIntrinsicWithSize( return SizeVal > Threshold || Threshold == 0; } -static bool canEmitLibcall(const TargetMachine &TM, Function *F, +static bool canEmitLibcall(const TargetMachine *TM, Function *F, RTLIB::Libcall LC) { // TODO: Should this consider the address space of the memcpy? - const TargetLowering *TLI = TM.getSubtargetImpl(*F)->getTargetLowering(); + if (!TM) + return true; + const TargetLowering *TLI = TM->getSubtargetImpl(*F)->getTargetLowering(); return TLI->getLibcallName(LC) != nullptr; } @@ -464,7 +466,7 @@ class PreISelIntrinsicLoweringLegacyPass : public ModulePass { return this->getAnalysis().getTLI(F); }; - const auto &TM = getAnalysis().getTM(); + const auto *TM = &getAnalysis().getTM(); PreISelIntrinsicLowering Lowering(TM, LookupTTI, LookupTLI); return Lowering.lowerIntrinsics(M); } diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index 3b92823cd283b4..03c7d0c3c469a8 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -104,7 +104,7 @@ MODULE_PASS("pgo-icall-prom", PGOIndirectCallPromotion()) MODULE_PASS("pgo-instr-gen", PGOInstrumentationGen()) MODULE_PASS("pgo-instr-use", PGOInstrumentationUse()) MODULE_PASS("poison-checking", PoisonCheckingPass()) -MODULE_PASS("pre-isel-intrinsic-lowering", PreISelIntrinsicLoweringPass(*TM)) +MODULE_PASS("pre-isel-intrinsic-lowering", PreISelIntrinsicLoweringPass(TM)) MODULE_PASS("print", PrintModulePass(dbgs())) MODULE_PASS("print-callgraph", CallGraphPrinterPass(dbgs())) MODULE_PASS("print-callgraph-sccs", CallGraphSCCsPrinterPass(dbgs()))