Skip to content

Commit

Permalink
[OpenMP] Add RTL function to externalization RAII
Browse files Browse the repository at this point in the history
This patch adds the '_kmpc_get_hardware_num_threads_in_block'
OpenMP RTL function to the externalization RAII struct. This was getting
optimized out and then being replaced with an undefined value once added
back in, causing bugs for complex reductions.

Fixes #53909.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D120076
  • Loading branch information
jhuber6 committed Feb 17, 2022
1 parent f6d3901 commit 74cacf2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions llvm/lib/Transforms/IPO/OpenMPOpt.cpp
Expand Up @@ -2119,6 +2119,8 @@ struct OpenMPOpt {
OMPRTL___kmpc_barrier_simple_generic);
ExternalizationRAII ThreadId(OMPInfoCache,
OMPRTL___kmpc_get_hardware_thread_id_in_block);
ExternalizationRAII NumThreads(
OMPInfoCache, OMPRTL___kmpc_get_hardware_num_threads_in_block);
ExternalizationRAII WarpSize(OMPInfoCache, OMPRTL___kmpc_get_warp_size);

registerAAs(IsModulePass);
Expand Down
Expand Up @@ -178,7 +178,16 @@ entry:
ret void
}

declare i32 @__kmpc_get_hardware_num_threads_in_block()
define internal i32 @__kmpc_get_hardware_num_threads_in_block() {
; CHECK-LABEL: define {{[^@]+}}@__kmpc_get_hardware_num_threads_in_block
; CHECK-SAME: () #[[ATTR1]] {
; CHECK-NEXT: [[RET:%.*]] = call i32 @__kmpc_get_hardware_num_threads_in_block_dummy()
; CHECK-NEXT: ret i32 [[RET]]
;
%ret = call i32 @__kmpc_get_hardware_num_threads_in_block_dummy()
ret i32 %ret
}
declare i32 @__kmpc_get_hardware_num_threads_in_block_dummy()
declare i32 @__kmpc_target_init(%struct.ident_t*, i8, i1 zeroext, i1 zeroext) #1
declare void @__kmpc_target_deinit(%struct.ident_t* nocapture readnone, i8, i1 zeroext) #1
declare void @__kmpc_parallel_51(%struct.ident_t*, i32, i32, i32, i32, i8*, i8*, i8**, i64)
Expand Down

0 comments on commit 74cacf2

Please sign in to comment.