[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-12-13 Thread Matt Arsenault via cfe-commits

arsenm wrote:

It also occurred to me that https://github.com/llvm/llvm-project/pull/170328 
may also have fixed this (although at the possible price of an extra run of the 
pass) 

https://github.com/llvm/llvm-project/pull/168622
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-12-11 Thread Alexey Bataev via cfe-commits

alexey-bataev wrote:

> > Created a revert patch. This patch causes massive perf regressions, which 
> > cannot be easily fixed
> 
> Same here, many Fortran benchmarks degraded. Thanks for addressing it.

I hope it should be fixed already, please check

https://github.com/llvm/llvm-project/pull/168622
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-12-11 Thread Paul Osmialowski via cfe-commits

pawosm-arm wrote:

> Created a revert patch. This patch causes massive perf regressions, which 
> cannot be easily fixed

Same here, many Fortran benchmarks degraded. Thanks for addressing it.

https://github.com/llvm/llvm-project/pull/168622
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-12-09 Thread Alexey Bataev via cfe-commits

alexey-bataev wrote:

Create a revert patch. This patch causes massive perf regressions, which cannot 
be easily fixed

https://github.com/llvm/llvm-project/pull/168622
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-12-07 Thread Aiden Grossman via cfe-commits

boomanaiden154 wrote:

> Is this with LTO? I think we have poor to nonexistent coverage of library 
> info in some of the LTO configurations

No, it wasn't with LTO. Turns out the issue was that the tooling was using a 
custom pass pipeline and wasn't running the new pass, so all the libcalls were 
marked as unsupported.

Sorry for the noise here.

https://github.com/llvm/llvm-project/pull/168622
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-12-07 Thread Matt Arsenault via cfe-commits

arsenm wrote:

> I think this should be NFC, assuming everything is working as intended. It 
> seems that in some cases, certain targets are no longer lowering some 
> functions to libcalls. In my case, I'm seeing `llvm.memset` intrinsics in 
> wasm code get lowered to load/store loops rather than to `memset` calls. 
> Currently investigating why the behavior changed there.

Is this with LTO? I think we have poor to nonexistent coverage of library info 
in some of the LTO configurations 




https://github.com/llvm/llvm-project/pull/168622
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-12-07 Thread Matt Arsenault via cfe-commits

arsenm wrote:

> Shall it be disabled at O0?

No, this should be a mandatory lowering pass. As it is now this shouldn't have 
any impact on anything




https://github.com/llvm/llvm-project/pull/168622
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-12-07 Thread Aiden Grossman via cfe-commits

boomanaiden154 wrote:

> Looks like this change increased size/runtime of the code at O0 with the 
> debug info, we see lots of timeouts in the code compiled with -O0 -g options. 
> Shall it be disabled at O0?

I think this should be NFC, assuming everything is working as intended. It 
seems that in some cases, certain targets are no longer lowering some functions 
to libcalls. In my case, I'm seeing `llvm.memset` intrinsics in wasm code get 
lowered to load/store loops rather than to `memset` calls. Currently 
investigating why the behavior changed there.

https://github.com/llvm/llvm-project/pull/168622
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-12-05 Thread Alexey Bataev via cfe-commits

alexey-bataev wrote:

Looks like this change increased size/runtime of the code at O0 with the debug 
info, we see lots of timeouts in the code compiled with `-O0 -g` options. Shall 
it be disabled at O0?
Debug info requires some extra code for the correct debug info and causes 
emission of extra spills/reloads

https://github.com/llvm/llvm-project/pull/168622
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-12-03 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm closed 
https://github.com/llvm/llvm-project/pull/168622
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-12-02 Thread Saleem Abdulrasool via cfe-commits

https://github.com/compnerd approved this pull request.


https://github.com/llvm/llvm-project/pull/168622
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-12-02 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/168622

>From b406d42aff4886264e76595cea17796feff19759 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Sat, 25 Oct 2025 22:38:27 +0900
Subject: [PATCH 1/2] CodeGen: Add LibcallLoweringInfo analysis pass

The libcall lowering decisions should be program dependent,
depending on the current module's RuntimeLibcallInfo. We need
another related analysis derived from that plus the current
function's subtarget to provide concrete lowering decisions.

This takes on a somewhat unusual form. It's a Module analysis,
with a lookup keyed on the subtarget. This is a separate module
analysis from RuntimeLibraryAnalysis to avoid that depending on
codegen. It's not a function pass to avoid depending on any
particular function, to avoid repeated subtarget map lookups in
most of the use passes, and to avoid any recomputation in the
common case of one subtarget (and keeps it reusable across
repeated compilations).

This also switches ExpandFp and PreISelIntrinsicLowering as
a sample function and module pass. Note this is not yet wired
up to SelectionDAG, which is still using the LibcallLoweringInfo
constructed inside of TargetLowering.
---
 clang/lib/CodeGen/BackendUtil.cpp |  6 ++
 .../llvm/Analysis/RuntimeLibcallInfo.h| 22 --
 .../llvm/CodeGen/LibcallLoweringInfo.h| 68 +++
 llvm/include/llvm/InitializePasses.h  |  1 +
 llvm/lib/Analysis/RuntimeLibcallInfo.cpp  | 16 +
 llvm/lib/CodeGen/CodeGen.cpp  |  1 +
 llvm/lib/CodeGen/ExpandFp.cpp | 40 ---
 llvm/lib/CodeGen/LibcallLoweringInfo.cpp  | 42 
 llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp | 53 ++-
 llvm/lib/Passes/PassRegistry.def  |  1 +
 llvm/test/CodeGen/AArch64/O0-pipeline.ll  |  2 +
 llvm/test/CodeGen/AArch64/O3-pipeline.ll  |  2 +
 llvm/test/CodeGen/AMDGPU/llc-pipeline.ll  | 10 +++
 llvm/test/CodeGen/LoongArch/O0-pipeline.ll|  2 +
 llvm/test/CodeGen/LoongArch/opt-pipeline.ll   |  2 +
 llvm/test/CodeGen/PowerPC/O0-pipeline.ll  |  2 +
 llvm/test/CodeGen/PowerPC/O3-pipeline.ll  |  2 +
 llvm/test/CodeGen/RISCV/O0-pipeline.ll|  2 +
 llvm/test/CodeGen/RISCV/O3-pipeline.ll|  2 +
 llvm/test/CodeGen/SPIRV/llc-pipeline.ll   |  4 ++
 llvm/test/CodeGen/X86/O0-pipeline.ll  |  2 +
 llvm/test/CodeGen/X86/opt-pipeline.ll |  2 +
 .../Transforms/ExpandFp/AMDGPU/frem-inf.ll|  4 +-
 llvm/test/Transforms/ExpandFp/AMDGPU/frem.ll  |  2 +-
 .../ExpandFp/AMDGPU/missing-analysis.ll   |  6 ++
 .../ExpandFp/AMDGPU/pass-parameters.ll| 16 ++---
 .../X86/expand-large-fp-convert-fptosi129.ll  |  2 +-
 .../X86/expand-large-fp-convert-fptoui129.ll  |  2 +-
 .../X86/expand-large-fp-convert-si129tofp.ll  |  2 +-
 .../X86/expand-large-fp-convert-ui129tofp.ll  |  2 +-
 .../X86/expand-large-fp-optnone.ll|  2 +-
 llvm/tools/llc/NewPMDriver.cpp| 12 
 llvm/tools/llc/llc.cpp|  5 ++
 llvm/tools/opt/NewPMDriver.cpp| 23 +--
 llvm/tools/opt/NewPMDriver.h  | 10 +--
 llvm/tools/opt/optdriver.cpp  | 19 --
 36 files changed, 325 insertions(+), 66 deletions(-)
 create mode 100644 llvm/test/Transforms/ExpandFp/AMDGPU/missing-analysis.ll

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index ec609db8d3a3c..af3480d5755f1 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -19,6 +19,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Analysis/GlobalsModRef.h"
+#include "llvm/Analysis/RuntimeLibcallInfo.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Bitcode/BitcodeReader.h"
@@ -655,6 +656,11 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager 
&CodeGenPasses,
   llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
   CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));
 
+  const llvm::TargetOptions &Options = TM->Options;
+  CodeGenPasses.add(new RuntimeLibraryInfoWrapper(
+  TargetTriple, Options.ExceptionModel, Options.FloatABIType,
+  Options.EABIVersion, Options.MCOptions.ABIName, Options.VecLib));
+
   // Normal mode, emit a .s or .o file by running the code generator. Note,
   // this also adds codegenerator level optimization passes.
   CodeGenFileType CGFT = getCodeGenFileType(Action);
diff --git a/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h 
b/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
index 28a2ec47f81ad..2d31c8aa6301b 100644
--- a/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
+++ b/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
@@ -22,7 +22,12 @@ class LLVM_ABI RuntimeLibraryAnalysis
   RuntimeLibraryAnalysis() = default;
   RuntimeLibraryAnalysis(RTLIB::RuntimeLibcallsInfo &

[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-12-02 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/168622

>From b406d42aff4886264e76595cea17796feff19759 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Sat, 25 Oct 2025 22:38:27 +0900
Subject: [PATCH] CodeGen: Add LibcallLoweringInfo analysis pass

The libcall lowering decisions should be program dependent,
depending on the current module's RuntimeLibcallInfo. We need
another related analysis derived from that plus the current
function's subtarget to provide concrete lowering decisions.

This takes on a somewhat unusual form. It's a Module analysis,
with a lookup keyed on the subtarget. This is a separate module
analysis from RuntimeLibraryAnalysis to avoid that depending on
codegen. It's not a function pass to avoid depending on any
particular function, to avoid repeated subtarget map lookups in
most of the use passes, and to avoid any recomputation in the
common case of one subtarget (and keeps it reusable across
repeated compilations).

This also switches ExpandFp and PreISelIntrinsicLowering as
a sample function and module pass. Note this is not yet wired
up to SelectionDAG, which is still using the LibcallLoweringInfo
constructed inside of TargetLowering.
---
 clang/lib/CodeGen/BackendUtil.cpp |  6 ++
 .../llvm/Analysis/RuntimeLibcallInfo.h| 22 --
 .../llvm/CodeGen/LibcallLoweringInfo.h| 68 +++
 llvm/include/llvm/InitializePasses.h  |  1 +
 llvm/lib/Analysis/RuntimeLibcallInfo.cpp  | 16 +
 llvm/lib/CodeGen/CodeGen.cpp  |  1 +
 llvm/lib/CodeGen/ExpandFp.cpp | 40 ---
 llvm/lib/CodeGen/LibcallLoweringInfo.cpp  | 42 
 llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp | 53 ++-
 llvm/lib/Passes/PassRegistry.def  |  1 +
 llvm/test/CodeGen/AArch64/O0-pipeline.ll  |  2 +
 llvm/test/CodeGen/AArch64/O3-pipeline.ll  |  2 +
 llvm/test/CodeGen/AMDGPU/llc-pipeline.ll  | 10 +++
 llvm/test/CodeGen/LoongArch/O0-pipeline.ll|  2 +
 llvm/test/CodeGen/LoongArch/opt-pipeline.ll   |  2 +
 llvm/test/CodeGen/PowerPC/O0-pipeline.ll  |  2 +
 llvm/test/CodeGen/PowerPC/O3-pipeline.ll  |  2 +
 llvm/test/CodeGen/RISCV/O0-pipeline.ll|  2 +
 llvm/test/CodeGen/RISCV/O3-pipeline.ll|  2 +
 llvm/test/CodeGen/SPIRV/llc-pipeline.ll   |  4 ++
 llvm/test/CodeGen/X86/O0-pipeline.ll  |  2 +
 llvm/test/CodeGen/X86/opt-pipeline.ll |  2 +
 .../Transforms/ExpandFp/AMDGPU/frem-inf.ll|  4 +-
 llvm/test/Transforms/ExpandFp/AMDGPU/frem.ll  |  2 +-
 .../ExpandFp/AMDGPU/missing-analysis.ll   |  6 ++
 .../ExpandFp/AMDGPU/pass-parameters.ll| 16 ++---
 .../X86/expand-large-fp-convert-fptosi129.ll  |  2 +-
 .../X86/expand-large-fp-convert-fptoui129.ll  |  2 +-
 .../X86/expand-large-fp-convert-si129tofp.ll  |  2 +-
 .../X86/expand-large-fp-convert-ui129tofp.ll  |  2 +-
 .../X86/expand-large-fp-optnone.ll|  2 +-
 llvm/tools/llc/NewPMDriver.cpp| 12 
 llvm/tools/llc/llc.cpp|  5 ++
 llvm/tools/opt/NewPMDriver.cpp| 23 +--
 llvm/tools/opt/NewPMDriver.h  | 10 +--
 llvm/tools/opt/optdriver.cpp  | 19 --
 36 files changed, 325 insertions(+), 66 deletions(-)
 create mode 100644 llvm/test/Transforms/ExpandFp/AMDGPU/missing-analysis.ll

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index ec609db8d3a3c..af3480d5755f1 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -19,6 +19,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Analysis/GlobalsModRef.h"
+#include "llvm/Analysis/RuntimeLibcallInfo.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Bitcode/BitcodeReader.h"
@@ -655,6 +656,11 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager 
&CodeGenPasses,
   llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
   CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));
 
+  const llvm::TargetOptions &Options = TM->Options;
+  CodeGenPasses.add(new RuntimeLibraryInfoWrapper(
+  TargetTriple, Options.ExceptionModel, Options.FloatABIType,
+  Options.EABIVersion, Options.MCOptions.ABIName, Options.VecLib));
+
   // Normal mode, emit a .s or .o file by running the code generator. Note,
   // this also adds codegenerator level optimization passes.
   CodeGenFileType CGFT = getCodeGenFileType(Action);
diff --git a/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h 
b/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
index 28a2ec47f81ad..2d31c8aa6301b 100644
--- a/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
+++ b/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
@@ -22,7 +22,12 @@ class LLVM_ABI RuntimeLibraryAnalysis
   RuntimeLibraryAnalysis() = default;
   RuntimeLibraryAnalysis(RTLIB::RuntimeLibcallsInfo &&Bas

[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-12-02 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/168622

>From a0aef4f12afebfd672d3aeb00f038b73a5eb6019 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Sat, 25 Oct 2025 22:38:27 +0900
Subject: [PATCH] CodeGen: Add LibcallLoweringInfo analysis pass

The libcall lowering decisions should be program dependent,
depending on the current module's RuntimeLibcallInfo. We need
another related analysis derived from that plus the current
function's subtarget to provide concrete lowering decisions.

This takes on a somewhat unusual form. It's a Module analysis,
with a lookup keyed on the subtarget. This is a separate module
analysis from RuntimeLibraryAnalysis to avoid that depending on
codegen. It's not a function pass to avoid depending on any
particular function, to avoid repeated subtarget map lookups in
most of the use passes, and to avoid any recomputation in the
common case of one subtarget (and keeps it reusable across
repeated compilations).

This also switches ExpandFp and PreISelIntrinsicLowering as
a sample function and module pass. Note this is not yet wired
up to SelectionDAG, which is still using the LibcallLoweringInfo
constructed inside of TargetLowering.
---
 clang/lib/CodeGen/BackendUtil.cpp |  6 ++
 .../llvm/Analysis/RuntimeLibcallInfo.h| 22 --
 .../llvm/CodeGen/LibcallLoweringInfo.h| 68 +++
 llvm/include/llvm/InitializePasses.h  |  1 +
 llvm/lib/Analysis/RuntimeLibcallInfo.cpp  | 16 +
 llvm/lib/CodeGen/CodeGen.cpp  |  1 +
 llvm/lib/CodeGen/ExpandFp.cpp | 40 ---
 llvm/lib/CodeGen/LibcallLoweringInfo.cpp  | 42 
 llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp | 53 ++-
 llvm/lib/Passes/PassRegistry.def  |  1 +
 llvm/test/CodeGen/AArch64/O0-pipeline.ll  |  2 +
 llvm/test/CodeGen/AArch64/O3-pipeline.ll  |  2 +
 llvm/test/CodeGen/AMDGPU/llc-pipeline.ll  | 10 +++
 llvm/test/CodeGen/LoongArch/O0-pipeline.ll|  2 +
 llvm/test/CodeGen/LoongArch/opt-pipeline.ll   |  2 +
 llvm/test/CodeGen/PowerPC/O0-pipeline.ll  |  2 +
 llvm/test/CodeGen/PowerPC/O3-pipeline.ll  |  2 +
 llvm/test/CodeGen/RISCV/O0-pipeline.ll|  2 +
 llvm/test/CodeGen/RISCV/O3-pipeline.ll|  2 +
 llvm/test/CodeGen/SPIRV/llc-pipeline.ll   |  4 ++
 llvm/test/CodeGen/X86/O0-pipeline.ll  |  2 +
 llvm/test/CodeGen/X86/opt-pipeline.ll |  2 +
 .../Transforms/ExpandFp/AMDGPU/frem-inf.ll|  4 +-
 llvm/test/Transforms/ExpandFp/AMDGPU/frem.ll  |  2 +-
 .../ExpandFp/AMDGPU/missing-analysis.ll   |  6 ++
 .../ExpandFp/AMDGPU/pass-parameters.ll| 16 ++---
 .../X86/expand-large-fp-convert-fptosi129.ll  |  2 +-
 .../X86/expand-large-fp-convert-fptoui129.ll  |  2 +-
 .../X86/expand-large-fp-convert-si129tofp.ll  |  2 +-
 .../X86/expand-large-fp-convert-ui129tofp.ll  |  2 +-
 .../X86/expand-large-fp-optnone.ll|  2 +-
 llvm/tools/llc/NewPMDriver.cpp| 12 
 llvm/tools/llc/llc.cpp|  5 ++
 llvm/tools/opt/NewPMDriver.cpp| 23 +--
 llvm/tools/opt/NewPMDriver.h  | 10 +--
 llvm/tools/opt/optdriver.cpp  | 21 +++---
 36 files changed, 325 insertions(+), 68 deletions(-)
 create mode 100644 llvm/test/Transforms/ExpandFp/AMDGPU/missing-analysis.ll

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 5590d217e96ff..8519df1f9ab1c 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -19,6 +19,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Analysis/GlobalsModRef.h"
+#include "llvm/Analysis/RuntimeLibcallInfo.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Bitcode/BitcodeReader.h"
@@ -667,6 +668,11 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager 
&CodeGenPasses,
   llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
   CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));
 
+  const llvm::TargetOptions &Options = TM->Options;
+  CodeGenPasses.add(new RuntimeLibraryInfoWrapper(
+  TargetTriple, Options.ExceptionModel, Options.FloatABIType,
+  Options.EABIVersion, Options.MCOptions.ABIName, Options.VecLib));
+
   // Normal mode, emit a .s or .o file by running the code generator. Note,
   // this also adds codegenerator level optimization passes.
   CodeGenFileType CGFT = getCodeGenFileType(Action);
diff --git a/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h 
b/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
index 28a2ec47f81ad..2d31c8aa6301b 100644
--- a/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
+++ b/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
@@ -22,7 +22,12 @@ class LLVM_ABI RuntimeLibraryAnalysis
   RuntimeLibraryAnalysis() = default;
   RuntimeLibraryAnalysis(RTLIB::RuntimeLibcallsInfo &&Bas

[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-11-28 Thread Matt Arsenault via cfe-commits


@@ -1126,13 +1134,29 @@ PreservedAnalyses ExpandFpPass::run(Function &F, 
FunctionAnalysisManager &FAM) {
   AssumptionCache *AC = nullptr;
   if (OptLevel != CodeGenOptLevel::None)
 AC = &FAM.getResult(F);
-  return runImpl(F, TLI, AC) ? PreservedAnalyses::none()
- : PreservedAnalyses::all();
+
+  auto &MAMProxy = FAM.getResult(F);
+
+  const LibcallLoweringModuleAnalysisResult *LibcallLowering =
+  MAMProxy.getCachedResult(*F.getParent());
+
+  if (!LibcallLowering) {
+F.getContext().emitError("'" + LibcallLoweringModuleAnalysis::name() +
+ "' analysis required");

arsenm wrote:

New pass manager doesn't have that, and can't trigger a run of an outer 
analysis from an inner 

https://github.com/llvm/llvm-project/pull/168622
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-11-28 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov approved this pull request.

LGTM, but someone with knowledge of the pass manager should take a look

https://github.com/llvm/llvm-project/pull/168622
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-11-28 Thread Sergei Barannikov via cfe-commits


@@ -1126,13 +1134,29 @@ PreservedAnalyses ExpandFpPass::run(Function &F, 
FunctionAnalysisManager &FAM) {
   AssumptionCache *AC = nullptr;
   if (OptLevel != CodeGenOptLevel::None)
 AC = &FAM.getResult(F);
-  return runImpl(F, TLI, AC) ? PreservedAnalyses::none()
- : PreservedAnalyses::all();
+
+  auto &MAMProxy = FAM.getResult(F);
+
+  const LibcallLoweringModuleAnalysisResult *LibcallLowering =
+  MAMProxy.getCachedResult(*F.getParent());
+
+  if (!LibcallLowering) {
+F.getContext().emitError("'" + LibcallLoweringModuleAnalysis::name() +
+ "' analysis required");

s-barannikov wrote:

If it is required, why don't add it to required passes?

https://github.com/llvm/llvm-project/pull/168622
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-11-28 Thread Matt Arsenault via cfe-commits


@@ -73,6 +77,70 @@ class LibcallLoweringInfo {
   }
 };
 
+/// Record a mapping from subtarget to LibcallLoweringInfo.
+class LibcallLoweringModuleAnalysisResult {
+private:
+  using LibcallLoweringMap =
+  DenseMap;
+  mutable LibcallLoweringMap LoweringMap;
+  const RTLIB::RuntimeLibcallsInfo *RTLCI = nullptr;
+
+public:
+  LibcallLoweringModuleAnalysisResult() = default;
+  LibcallLoweringModuleAnalysisResult(RTLIB::RuntimeLibcallsInfo &RTLCI)
+  : RTLCI(&RTLCI) {}
+
+  void init(const RTLIB::RuntimeLibcallsInfo *RT) { RTLCI = RT; }
+
+  void clear() {
+RTLCI = nullptr;
+LoweringMap.clear();
+  }
+
+  LLVM_ABI bool invalidate(Module &, const PreservedAnalyses &,
+   ModuleAnalysisManager::Invalidator &);
+
+  const LibcallLoweringInfo &
+  getLibcallLowering(const TargetSubtargetInfo &Subtarget) const {
+return LoweringMap.try_emplace(&Subtarget, *RTLCI, 
Subtarget).first->second;
+  }
+};
+
+class LibcallLoweringModuleAnalysis
+: public AnalysisInfoMixin {
+private:
+  friend AnalysisInfoMixin;
+  LLVM_ABI static AnalysisKey Key;

arsenm wrote:

Copied from TargetLibraryAnalysis 

https://github.com/llvm/llvm-project/pull/168622
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-11-28 Thread Matt Arsenault via cfe-commits


@@ -1104,6 +1109,7 @@ class ExpandFpLegacyPass : public FunctionPass {
   AU.addRequired();
 AU.addPreserved();
 AU.addPreserved();
+AU.addRequired();

arsenm wrote:

Me neither. Things seem to work out OK if you ignore the macro part 

https://github.com/llvm/llvm-project/pull/168622
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] CodeGen: Add LibcallLoweringInfo analysis pass (PR #168622)

2025-11-28 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm edited 
https://github.com/llvm/llvm-project/pull/168622
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits