[llvm] a4837fe - [CodeGen] Allow PreISel lowering to run without TM (#102150)

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 6 07:22:00 PDT 2024


Author: Alexis Engelke
Date: 2024-08-06T16:21:56+02:00
New Revision: a4837fe3c1b3507254b2ce643f9e74db02a56f4b

URL: https://github.com/llvm/llvm-project/commit/a4837fe3c1b3507254b2ce643f9e74db02a56f4b
DIFF: https://github.com/llvm/llvm-project/commit/a4837fe3c1b3507254b2ce643f9e74db02a56f4b.diff

LOG: [CodeGen] Allow PreISel lowering to run without TM (#102150)

Fixes #101652 after build bot failures where TM in the opt pass builder
is nullptr.

Added: 
    

Modified: 
    llvm/include/llvm/CodeGen/PreISelIntrinsicLowering.h
    llvm/include/llvm/Passes/CodeGenPassBuilder.h
    llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
    llvm/lib/Passes/PassRegistry.def

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/PreISelIntrinsicLowering.h b/llvm/include/llvm/CodeGen/PreISelIntrinsicLowering.h
index aa6a0e6935b33..955a2437cb94c 100644
--- a/llvm/include/llvm/CodeGen/PreISelIntrinsicLowering.h
+++ b/llvm/include/llvm/CodeGen/PreISelIntrinsicLowering.h
@@ -22,9 +22,9 @@ class TargetMachine;
 
 struct PreISelIntrinsicLoweringPass
     : PassInfoMixin<PreISelIntrinsicLoweringPass> {
-  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 fb7a3c107d88a..81c00a3a95c11 100644
--- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h
+++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
@@ -628,7 +628,7 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::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 c0e08063be41d..6418c54f0b18f 100644
--- a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -47,7 +47,7 @@ static cl::opt<int64_t> MemIntrinsicExpandSizeThresholdOpt(
 namespace {
 
 struct PreISelIntrinsicLowering {
-  const TargetMachine &TM;
+  const TargetMachine *TM;
   const function_ref<TargetTransformInfo &(Function &)> LookupTTI;
   const function_ref<TargetLibraryInfo &(Function &)> LookupTLI;
 
@@ -57,7 +57,7 @@ struct PreISelIntrinsicLowering {
   const bool UseMemIntrinsicLibFunc;
 
   explicit PreISelIntrinsicLowering(
-      const TargetMachine &TM_,
+      const TargetMachine *TM_,
       function_ref<TargetTransformInfo &(Function &)> LookupTTI_,
       function_ref<TargetLibraryInfo &(Function &)> 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<TargetLibraryInfoWrapperPass>().getTLI(F);
     };
 
-    const auto &TM = getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
+    const auto *TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
     PreISelIntrinsicLowering Lowering(TM, LookupTTI, LookupTLI);
     return Lowering.lowerIntrinsics(M);
   }

diff  --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index 3b92823cd283b..03c7d0c3c469a 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()))


        


More information about the llvm-commits mailing list