Skip to content

PlaceSafepoints: Fix using default constructed TargetLibraryInfo #92411

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 2 commits into from
May 16, 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: 4 additions & 0 deletions llvm/include/llvm/Analysis/TargetLibraryInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,10 @@ class TargetLibraryInfoWrapperPass : public ImmutablePass {
explicit TargetLibraryInfoWrapperPass(const Triple &T);
explicit TargetLibraryInfoWrapperPass(const TargetLibraryInfoImpl &TLI);

// FIXME: This should be removed when PlaceSafepoints is fixed to not create a
// PassManager inside a pass.
explicit TargetLibraryInfoWrapperPass(const TargetLibraryInfo &TLI);

TargetLibraryInfo &getTLI(const Function &F) {
FunctionAnalysisManager DummyFAM;
TLI = TLA.run(F, DummyFAM);
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Analysis/TargetLibraryInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,10 @@ TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
}

TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
const TargetLibraryInfo &TLIOther)
: TargetLibraryInfoWrapperPass(*TLIOther.Impl) {}

AnalysisKey TargetLibraryAnalysis::Key;

// Register the basic pass.
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ bool PlaceSafepointsPass::runImpl(Function &F, const TargetLibraryInfo &TLI) {
// with for the moment.
legacy::FunctionPassManager FPM(F.getParent());
bool CanAssumeCallSafepoints = enableCallSafepoints(F);

FPM.add(new TargetLibraryInfoWrapperPass(TLI));
auto *PBS = new PlaceBackedgeSafepointsLegacyPass(CanAssumeCallSafepoints);
FPM.add(PBS);
FPM.run(F);
Expand Down
7 changes: 5 additions & 2 deletions llvm/test/Transforms/PlaceSafepoints/libcall.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
; RUN: opt -S -passes=place-safepoints < %s | FileCheck %s
; RUN: opt -S -passes=place-safepoints < %s | FileCheck -check-prefixes=CHECK,WITHLDEXPF %s
; RUN: opt -S -passes=place-safepoints -disable-builtin=ldexp < %s | FileCheck %s


; Libcalls will not contain a safepoint poll, so check that we insert
; a safepoint in a loop containing a libcall.
Expand All @@ -17,7 +19,8 @@ loop:
; CHECK-NEXT: %x_loop = phi double [ %x, %entry ], [ %x_exp, %loop ]
; CHECK-NEXT: %x_exp = call double @ldexp(double %x_loop, i32 5)
; CHECK-NEXT: %done = fcmp ogt double %x_exp, 1.5
; CHECK-NEXT: call void @do_safepoint
; WITHLDEXPF-NEXT: call void @do_safepoint
; CHECK-NEXT: br
%x_loop = phi double [ %x, %entry ], [ %x_exp, %loop ]
%x_exp = call double @ldexp(double %x_loop, i32 5) nounwind readnone
%done = fcmp ogt double %x_exp, 1.5
Expand Down