Skip to content

[CodeGen] Allow PreISel lowering to run without TM #102150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading