This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Change OMPIRBuilder to append function attributes
ClosedPublic

Authored by jhuber6 on Mar 16 2021, 1:25 PM.

Details

Summary

Currently the OMPIRBuilder overwrites the function's existing attributes
when it assigns the ones defined in OMPKinds.def. This changes the
behavior to append the current function's attributes with them instead.

Diff Detail

Event Timeline

jhuber6 created this revision.Mar 16 2021, 1:25 PM
jhuber6 requested review of this revision.Mar 16 2021, 1:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2021, 1:25 PM

can you upload your patches with context please.

jhuber6 updated this revision to Diff 331126.Mar 16 2021, 4:26 PM

Adding context, forgot to specify the range.

jdoerfert accepted this revision.Mar 23 2021, 2:56 PM

LG, two nits.

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
49

no llvm:: above. call getAttributes only once.

This revision is now accepted and ready to land.Mar 23 2021, 2:56 PM
jhuber6 updated this revision to Diff 332843.Mar 23 2021, 6:28 PM

Making changes.

With this change OMPIRBuilder may produce invalid IR if existing function attributes conflict with the new attributes it is trying to add. The problem can be reproduced on llvm/test/Transforms/OpenMP/gpu_state_machine_function_ptr_replacement.ll test where __kmpc_global_thread_num function is declared with the following attributes

declare i32 @__kmpc_global_thread_num(%struct.ident_t* nocapture readnone)

With ‘optimistic’ attributes OMPIRBuilder will try to add ‘readonly’ to the function argument which would cause a verification error

$ opt -S -openmpopt -openmp-ir-builder-optimistic-attributes llvm/test/Transforms/OpenMP/gpu_state_machine_function_ptr_replacement.ll
Attributes 'readnone and readonly' are incompatible!
void (%struct.ident_t*, i32)* @__kmpc_barrier_simple_spmd
Attributes 'readnone and readonly' are incompatible!
i32 (%struct.ident_t*)* @__kmpc_global_thread_num
LLVM ERROR: Broken module found, compilation aborted!
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.

With this change OMPIRBuilder may produce invalid IR if existing function attributes conflict with the new attributes it is trying to add. The problem can be reproduced on llvm/test/Transforms/OpenMP/gpu_state_machine_function_ptr_replacement.ll test where __kmpc_global_thread_num function is declared with the following attributes

declare i32 @__kmpc_global_thread_num(%struct.ident_t* nocapture readnone)

With ‘optimistic’ attributes OMPIRBuilder will try to add ‘readonly’ to the function argument which would cause a verification error

$ opt -S -openmpopt -openmp-ir-builder-optimistic-attributes llvm/test/Transforms/OpenMP/gpu_state_machine_function_ptr_replacement.ll
Attributes 'readnone and readonly' are incompatible!
void (%struct.ident_t*, i32)* @__kmpc_barrier_simple_spmd
Attributes 'readnone and readonly' are incompatible!
i32 (%struct.ident_t*)* @__kmpc_global_thread_num
LLVM ERROR: Broken module found, compilation aborted!
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.

I believe this is a feature. If the attributes aren't compatible then one of them is wrong. I changed the test here, https://reviews.llvm.org/rGf047cb45bd38.