Skip to content

Commit

Permalink
[OpenMP] Only strip runtime attributes if needed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jhuber6 committed Jun 27, 2022
1 parent 5358457 commit c7243f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
13 changes: 8 additions & 5 deletions llvm/lib/Transforms/IPO/OpenMPOpt.cpp
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Transforms/OpenMP/add_attributes.ll
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
3 changes: 2 additions & 1 deletion llvm/test/Transforms/OpenMP/remove_noinline_attributes.ll
Expand Up @@ -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}

0 comments on commit c7243f2

Please sign in to comment.