Skip to content

Commit

Permalink
[CodeGen] Allow PreISel lowering to run without TM (llvm#102150)
Browse files Browse the repository at this point in the history
Fixes llvm#101652 after build bot failures where TM in the opt pass builder
is nullptr.
  • Loading branch information
aengelke authored Aug 6, 2024
1 parent e958456 commit a4837fe
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions llvm/include/llvm/CodeGen/PreISelIntrinsicLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Passes/CodeGenPassBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 7 additions & 5 deletions llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down

0 comments on commit a4837fe

Please sign in to comment.