Skip to content

Commit

Permalink
[OpenMP][AMDGPU] Refactor setting uniform work group size attribute
Browse files Browse the repository at this point in the history
Work group size attribute was set in Clang specific class. That's why
we cannot reuse this code in Flang.

If we move setting of this attribute to OpenMPIRBuilder, then we can reuse this
code in Flang and Clang. Function createOffloadEntry from OpenMPIRBuilder is
already used by Clang (via OpenMPIRBuilder::createOffloadEntriesAndInfoMetadata
function).

Differential Revision: https://reviews.llvm.org/D148525

Reviewed By: jdoerfert
  • Loading branch information
DominikAdamski committed Apr 21, 2023
1 parent 87cef78 commit f900567
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 1 addition & 4 deletions clang/lib/CodeGen/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9588,12 +9588,9 @@ void AMDGPUTargetCodeGenInfo::setTargetAttributes(

const bool IsHIPKernel =
M.getLangOpts().HIP && FD && FD->hasAttr<CUDAGlobalAttr>();
const bool IsOpenMPkernel =
M.getLangOpts().OpenMPIsDevice &&
(F->getCallingConv() == llvm::CallingConv::AMDGPU_KERNEL);

// TODO: This should be moved to language specific attributes instead.
if (IsHIPKernel || IsOpenMPkernel)
if (IsHIPKernel)
F->addFnAttr("uniform-work-group-size", "true");

if (M.getContext().getTargetInfo().allowAMDGPUUnsafeFPAtomics())
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4892,6 +4892,8 @@ void OpenMPIRBuilder::createOffloadEntry(Constant *ID, Constant *Addr,

// Add a function attribute for the kernel.
Fn->addFnAttr(Attribute::get(Ctx, "kernel"));
if (Triple(M.getTargetTriple()).isAMDGCN())
Fn->addFnAttr("uniform-work-group-size", "true");
}

// We only generate metadata for function that contain target regions.
Expand Down

0 comments on commit f900567

Please sign in to comment.