[llvm] c7243f2 - [OpenMP] Only strip runtime attributes if needed
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 27 10:35:59 PDT 2022
Author: Joseph Huber
Date: 2022-06-27T13:35:41-04:00
New Revision: c7243f21d3f1b1544f6067f81b02c0af9f2ee8ab
URL: https://github.com/llvm/llvm-project/commit/c7243f21d3f1b1544f6067f81b02c0af9f2ee8ab
DIFF: https://github.com/llvm/llvm-project/commit/c7243f21d3f1b1544f6067f81b02c0af9f2ee8ab.diff
LOG: [OpenMP] Only strip runtime attributes if needed
Summary:
Currently in OpenMPOpt we strip `noinline` attributes from runtime
functions. This is here because the device bitcode library that we link
has problems with needed definitions getting prematurely optimized out.
This is only necessary for OpenMP offloading to GPUs so we should narrow
the scope for where we spend time doing this. In the future this
shouldn't be necessary as we move to using a linked library rather than
pulling in a bitcode library in Clang.
Added:
Modified:
llvm/lib/Transforms/IPO/OpenMPOpt.cpp
llvm/test/Transforms/OpenMP/add_attributes.ll
llvm/test/Transforms/OpenMP/remove_noinline_attributes.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index 0e043599ac5fc..227ad8501f25a 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -501,11 +501,14 @@ struct OMPInformationCache : public InformationCache {
// Remove the `noinline` attribute from `__kmpc`, `_OMP::` and `omp_`
// functions, except if `optnone` is present.
- for (Function &F : M) {
- for (StringRef Prefix : {"__kmpc", "_ZN4_OMP", "omp_"})
- if (F.getName().startswith(Prefix) &&
- !F.hasFnAttribute(Attribute::OptimizeNone))
- F.removeFnAttr(Attribute::NoInline);
+ if (isOpenMPDevice(M)) {
+ for (Function &F : M) {
+ for (StringRef Prefix : {"__kmpc", "_ZN4_OMP", "omp_"})
+ if (F.hasFnAttribute(Attribute::NoInline) &&
+ F.getName().startswith(Prefix) &&
+ !F.hasFnAttribute(Attribute::OptimizeNone))
+ F.removeFnAttr(Attribute::NoInline);
+ }
}
// TODO: We should attach the attributes defined in OMPKinds.def.
diff --git a/llvm/test/Transforms/OpenMP/add_attributes.ll b/llvm/test/Transforms/OpenMP/add_attributes.ll
index 049b0c8da3450..cf8dee300d1bb 100644
--- a/llvm/test/Transforms/OpenMP/add_attributes.ll
+++ b/llvm/test/Transforms/OpenMP/add_attributes.ll
@@ -1208,7 +1208,7 @@ attributes #0 = { noinline cold }
; CHECK: ; Function Attrs: nounwind
; CHECK-NEXT: declare void @__kmpc_proxy_task_completed_ooo(i8*)
-; CHECK: ; Function Attrs: cold convergent nounwind
+; CHECK: ; Function Attrs: cold convergent noinline nounwind
; CHECK-NEXT: declare void @__kmpc_barrier_simple_spmd(%struct.ident_t* nocapture nofree readonly, i32)
; OPTIMISTIC: ; Function Attrs: inaccessiblememonly nofree nosync nounwind willreturn writeonly
@@ -1736,7 +1736,7 @@ attributes #0 = { noinline cold }
; OPTIMISTIC: ; Function Attrs: nofree nosync nounwind willreturn
; OPTIMISTIC-NEXT: declare void @__kmpc_proxy_task_completed_ooo(i8*)
-; OPTIMISTIC: ; Function Attrs: cold convergent nounwind
+; OPTIMISTIC: ; Function Attrs: cold convergent noinline nounwind
; OPTIMISTIC-NEXT: declare void @__kmpc_barrier_simple_spmd(%struct.ident_t* nocapture nofree readonly, i32)
!llvm.module.flags = !{!0}
diff --git a/llvm/test/Transforms/OpenMP/remove_noinline_attributes.ll b/llvm/test/Transforms/OpenMP/remove_noinline_attributes.ll
index 76c506334f0ea..349e2799de27a 100644
--- a/llvm/test/Transforms/OpenMP/remove_noinline_attributes.ll
+++ b/llvm/test/Transforms/OpenMP/remove_noinline_attributes.ll
@@ -93,6 +93,7 @@ define void @a__ZN4_OMP_noinline() noinline nounwind {
ret void
}
-!llvm.module.flags = !{!0}
+!llvm.module.flags = !{!0, !1}
!0 = !{i32 7, !"openmp", i32 50}
+!1 = !{i32 7, !"openmp-device", i32 50}
More information about the llvm-commits
mailing list