Skip to content

[mlir][OpenMP][llvm]Atomic control backend #143769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -2299,21 +2299,21 @@ def fsymbol_partition_EQ : Joined<["-"], "fsymbol-partition=">, Group<f_Group>,

defm atomic_remote_memory : BoolFOption<"atomic-remote-memory",
LangOpts<"AtomicRemoteMemory">, DefaultFalse,
PosFlag<SetTrue, [], [ClangOption, CC1Option], "May have">,
NegFlag<SetFalse, [], [ClangOption], "Assume no">,
BothFlags<[], [ClangOption], " atomic operations on remote memory">>;
PosFlag<SetTrue, [], [ClangOption, CC1Option, FlangOption, FC1Option], "May have">,
NegFlag<SetFalse, [], [ClangOption, FlangOption], "Assume no">,
BothFlags<[], [ClangOption, FlangOption], " atomic operations on remote memory">>;

defm atomic_fine_grained_memory : BoolFOption<"atomic-fine-grained-memory",
LangOpts<"AtomicFineGrainedMemory">, DefaultFalse,
PosFlag<SetTrue, [], [ClangOption, CC1Option], "May have">,
NegFlag<SetFalse, [], [ClangOption], "Assume no">,
BothFlags<[], [ClangOption], " atomic operations on fine-grained memory">>;
PosFlag<SetTrue, [], [ClangOption, CC1Option, FlangOption, FC1Option], "May have">,
NegFlag<SetFalse, [], [ClangOption, FlangOption], "Assume no">,
BothFlags<[], [ClangOption, FlangOption], " atomic operations on fine-grained memory">>;

defm atomic_ignore_denormal_mode : BoolFOption<"atomic-ignore-denormal-mode",
LangOpts<"AtomicIgnoreDenormalMode">, DefaultFalse,
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Allow">,
NegFlag<SetFalse, [], [ClangOption], "Disallow">,
BothFlags<[], [ClangOption], " atomic operations to ignore denormal mode">>;
PosFlag<SetTrue, [], [ClangOption, CC1Option, FlangOption, FC1Option], "Allow">,
NegFlag<SetFalse, [], [ClangOption, FlangOption], "Disallow">,
BothFlags<[], [ClangOption, FlangOption], " atomic operations to ignore denormal mode">>;

defm memory_profile : OptInCC1FFlag<"memory-profile", "Enable", "Disable", " heap memory profiling">;
def fmemory_profile_EQ : Joined<["-"], "fmemory-profile=">,
Expand Down Expand Up @@ -5272,9 +5272,9 @@ defm amdgpu_precise_memory_op
" precise memory mode (AMDGPU only)">;

def munsafe_fp_atomics : Flag<["-"], "munsafe-fp-atomics">,
Visibility<[ClangOption, CC1Option]>, Alias<fatomic_ignore_denormal_mode>;
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, Alias<fatomic_ignore_denormal_mode>;
def mno_unsafe_fp_atomics : Flag<["-"], "mno-unsafe-fp-atomics">,
Visibility<[ClangOption]>, Alias<fno_atomic_ignore_denormal_mode>;
Visibility<[ClangOption, FlangOption]>, Alias<fno_atomic_ignore_denormal_mode>;

def faltivec : Flag<["-"], "faltivec">, Group<f_Group>;
def fno_altivec : Flag<["-"], "fno-altivec">, Group<f_Group>;
Expand Down
5 changes: 5 additions & 0 deletions flang/include/flang/Frontend/TargetOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class TargetOptions {

/// Print verbose assembly
bool asmVerbose = false;

/// Atomic control options for AMD gpu
bool amdgpuIgnoreDenormalMode = false;
bool amdgpuRemoteMemory = false;
bool amdgpuFineGrainedMemory = false;
};

} // end namespace Fortran::frontend
Expand Down
14 changes: 14 additions & 0 deletions flang/include/flang/Optimizer/Dialect/Support/FIRContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,24 @@ void setTargetCPU(mlir::ModuleOp mod, llvm::StringRef cpu);
/// Get the target CPU string from the Module or return a null reference.
llvm::StringRef getTargetCPU(mlir::ModuleOp mod);

// Setters and getters for atomic control options.
void setAmdgpuIgnoreDenormalMode(mlir::ModuleOp mod);
bool getAmdgpuIgnoreDenormalMode(mlir::ModuleOp mod);
void setAmdgpuFineGrainedMemory(mlir::ModuleOp mod);
bool getAmdgpuFineGrainedMemory(mlir::ModuleOp mod);
void setAmdgpuRemoteMemory(mlir::ModuleOp mod);
bool getAmdgpuRemoteMemory(mlir::ModuleOp mod);

/// Set the tune CPU for the module. `cpu` must not be deallocated while
/// module `mod` is still live.
void setTuneCPU(mlir::ModuleOp mod, llvm::StringRef cpu);

// set atomic control options for AMD gpu.
void setAmdgpuAtomicControlOptions(mlir::ModuleOp mod,
bool amdgpuIgnoreDenormalMode,
bool amdgpuNoFineGrainedMemory,
bool amdgpuNoRemoteMemory);

/// Get the tune CPU string from the Module or return a null reference.
llvm::StringRef getTuneCPU(mlir::ModuleOp mod);

Expand Down
12 changes: 12 additions & 0 deletions flang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,18 @@ static void parseTargetArgs(TargetOptions &opts, llvm::opt::ArgList &args) {
args.getLastArg(clang::driver::options::OPT_triple))
opts.triple = a->getValue();

if (llvm::Triple(opts.triple).isAMDGPU()) {
opts.amdgpuIgnoreDenormalMode = args.hasFlag(
clang::driver::options::OPT_fatomic_ignore_denormal_mode,
clang::driver::options::OPT_fno_atomic_ignore_denormal_mode, false);
opts.amdgpuFineGrainedMemory = args.hasFlag(
clang::driver::options::OPT_fatomic_fine_grained_memory,
clang::driver::options::OPT_fno_atomic_fine_grained_memory, false);
opts.amdgpuRemoteMemory = args.hasFlag(
clang::driver::options::OPT_fatomic_remote_memory,
clang::driver::options::OPT_fno_atomic_remote_memory, false);
}

if (const llvm::opt::Arg *a =
args.getLastArg(clang::driver::options::OPT_target_cpu))
opts.cpu = a->getValue();
Expand Down
6 changes: 6 additions & 0 deletions flang/lib/Lower/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6644,6 +6644,12 @@ Fortran::lower::LoweringBridge::LoweringBridge(
fir::setKindMapping(*module, kindMap);
fir::setTargetCPU(*module, targetMachine.getTargetCPU());
fir::setTuneCPU(*module, targetOpts.cpuToTuneFor);
if (targetOpts.amdgpuIgnoreDenormalMode)
fir::setAmdgpuIgnoreDenormalMode(*module);
if (targetOpts.amdgpuFineGrainedMemory)
fir::setAmdgpuFineGrainedMemory(*module);
if (targetOpts.amdgpuRemoteMemory)
fir::setAmdgpuRemoteMemory(*module);
fir::setTargetFeatures(*module, targetMachine.getTargetFeatureString());
fir::support::setMLIRDataLayout(*module, targetMachine.createDataLayout());
fir::setIdent(*module, Fortran::common::getFlangFullVersion());
Expand Down
10 changes: 8 additions & 2 deletions flang/lib/Lower/OpenMP/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2850,9 +2850,15 @@ genAtomicUpdate(lower::AbstractConverter &converter, mlir::Location loc,
}
}

mlir::ModuleOp module = builder.getModule();
mlir::omp::AtomicControlAttr atomicControlAttr =
mlir::omp::AtomicControlAttr::get(
builder.getContext(), fir::getAmdgpuIgnoreDenormalMode(module),
fir::getAmdgpuFineGrainedMemory(module),
fir::getAmdgpuRemoteMemory(module));
builder.restoreInsertionPoint(atomicAt);
auto updateOp =
builder.create<mlir::omp::AtomicUpdateOp>(loc, atomAddr, hint, memOrder);
auto updateOp = builder.create<mlir::omp::AtomicUpdateOp>(
loc, atomAddr, atomicControlAttr, hint, memOrder);

mlir::Region &region = updateOp->getRegion(0);
mlir::Block *block = builder.createBlock(&region, {}, {atomType}, {loc});
Expand Down
32 changes: 32 additions & 0 deletions flang/lib/Optimizer/Dialect/Support/FIRContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,38 @@ void fir::setTuneCPU(mlir::ModuleOp mod, llvm::StringRef cpu) {
mod->setAttr(tuneCpuName, mlir::StringAttr::get(ctx, cpu));
}

static constexpr const char *amdgpuIgnoreDenormalModeName =
"fir.amdgpu.ignore.denormal.mode";
void fir::setAmdgpuIgnoreDenormalMode(mlir::ModuleOp mod) {
auto *ctx = mod.getContext();
mod->setAttr(amdgpuIgnoreDenormalModeName, mlir::UnitAttr::get(ctx));
}

bool fir::getAmdgpuIgnoreDenormalMode(mlir::ModuleOp mod) {
return mod->hasAttrOfType<mlir::UnitAttr>(amdgpuIgnoreDenormalModeName);
}

static constexpr const char *amdgpuFineGrainedMemoryName =
"fir.amdgpu.fine.grained.memory";
void fir::setAmdgpuFineGrainedMemory(mlir::ModuleOp mod) {
auto *ctx = mod.getContext();
mod->setAttr(amdgpuFineGrainedMemoryName, mlir::UnitAttr::get(ctx));
}

bool fir::getAmdgpuFineGrainedMemory(mlir::ModuleOp mod) {
return mod->hasAttrOfType<mlir::UnitAttr>(amdgpuFineGrainedMemoryName);
}
static constexpr const char *amdgpuRemoteMemoryName =
"fir.amdgpu.remote.memory";
void fir::setAmdgpuRemoteMemory(mlir::ModuleOp mod) {
auto *ctx = mod.getContext();
mod->setAttr(amdgpuRemoteMemoryName, mlir::UnitAttr::get(ctx));
}

bool fir::getAmdgpuRemoteMemory(mlir::ModuleOp mod) {
return mod->hasAttrOfType<mlir::UnitAttr>(amdgpuRemoteMemoryName);
}

llvm::StringRef fir::getTuneCPU(mlir::ModuleOp mod) {
if (auto attr = mod->getAttrOfType<mlir::StringAttr>(tuneCpuName))
return attr.getValue();
Expand Down
19 changes: 19 additions & 0 deletions flang/test/Driver/atomic-control-options.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
! RUN: %flang_fc1 -emit-llvm -triple amdgcn-amd-amdhsa -fopenmp -fopenmp-is-device -munsafe-fp-atomics %s -o -|FileCheck -check-prefix=UNSAFE-FP-ATOMICS %s
! RUN: %flang_fc1 -emit-llvm -triple amdgcn-amd-amdhsa -fopenmp -fopenmp-is-device -fatomic-ignore-denormal-mode %s -o -|FileCheck -check-prefix=IGNORE-DENORMAL-MODE %s
! RUN: %flang_fc1 -emit-llvm -triple amdgcn-amd-amdhsa -fopenmp -fopenmp-is-device -fatomic-fine-grained-memory %s -o -|FileCheck -check-prefix=FINE-GRAINED-MEMORY %s
! RUN: %flang_fc1 -emit-llvm -triple amdgcn-amd-amdhsa -fopenmp -fopenmp-is-device -fatomic-remote-memory %s -o -|FileCheck -check-prefix=REMOTE-MEMORY %s
program test
implicit none
integer :: A, threads
threads = 128
A = 0
!$omp target parallel num_threads(threads)
!$omp atomic
A = A + 1
!$omp end target parallel
end program test

!UNSAFE-FP-ATOMICS: %{{.*}} = atomicrmw add ptr {{.*}}, i32 1 monotonic, align 4, !amdgpu.ignore.denormal.mode !{{.*}}, !amdgpu.no.fine.grained.memory !{{.*}}, !amdgpu.no.remote.memory !{{.*}}
!IGNORE-DENORMAL-MODE: %{{.*}} = atomicrmw add ptr {{.*}}, i32 1 monotonic, align 4, !amdgpu.ignore.denormal.mode !{{.*}}, !amdgpu.no.fine.grained.memory !{{.*}}, !amdgpu.no.remote.memory !{{.*}}
!FINE-GRAINED-MEMORY: %{{.*}} = atomicrmw add ptr {{.*}}, i32 1 monotonic, align 4, !amdgpu.no.remote.memory !{{.*}}
!REMOTE-MEMORY: %{{.*}} = atomicrmw add ptr {{.*}}, i32 1 monotonic, align 4, !amdgpu.no.fine.grained.memory !{{.*}}
4 changes: 2 additions & 2 deletions flang/test/Fir/convert-to-llvm-openmp-and-fir.fir
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ func.func @_QPs() {
%c1_i32 = arith.constant 1 : i32
%1 = arith.addi %arg0, %c1_i32 : i32
omp.yield(%1 : i32)
}
} {atomic_control = #omp.atomic_control<>}
return
}
fir.global internal @_QFsEc : i32 {
Expand All @@ -634,7 +634,7 @@ fir.global internal @_QFsEc : i32 {
// CHECK: %[[CONST_1:.*]] = llvm.mlir.constant(1 : i32) : i32
// CHECK: %[[OUT_VAL:.*]] = llvm.add %[[IN_VAL]], %[[CONST_1]] : i32
// CHECK: omp.yield(%[[OUT_VAL]] : i32)
// CHECK: }
// CHECK: } {atomic_control = #omp.atomic_control<>}
// CHECK: llvm.return
// CHECK: }
// CHECK: llvm.mlir.global internal @[[GLOBAL]]() {{.*}} : i32 {
Expand Down
37 changes: 37 additions & 0 deletions flang/test/Lower/OpenMP/atomic-control-options.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
! RUN: %flang_fc1 -emit-hlfir -triple amdgcn-amd-amdhsa -fopenmp -fopenmp-is-device -munsafe-fp-atomics %s -o - | FileCheck -check-prefix=UNSAFE-FP-ATOMICS %s
! RUN: %flang_fc1 -emit-hlfir -triple amdgcn-amd-amdhsa -fopenmp -fopenmp-is-device -fatomic-ignore-denormal-mode %s -o - | FileCheck -check-prefix=IGNORE-DENORMAL %s
! RUN: %flang_fc1 -emit-hlfir -triple amdgcn-amd-amdhsa -fopenmp -fopenmp-is-device -fatomic-fine-grained-memory %s -o - | FileCheck -check-prefix=FINE-GRAINED-MEMORY %s
! RUN: %flang_fc1 -emit-hlfir -triple amdgcn-amd-amdhsa -fopenmp -fopenmp-is-device -fatomic-remote-memory %s -o - | FileCheck -check-prefix=REMOTE-MEMORY %s
program test
implicit none
integer :: A, B, threads
threads = 128
A = 0
B = 0
!UNSAFE-FP-ATOMICS: omp.atomic.update %{{.*}} : !fir.ref<i32> {
!UNSAFE-FP-ATOMICS: } {atomic_control = #omp.atomic_control<amdgpu_ignore_denormal_mode = true>}
!IGNORE-DENORMAL: omp.atomic.update %{{.*}} : !fir.ref<i32> {
!IGNORE-DENORMAL: } {atomic_control = #omp.atomic_control<amdgpu_ignore_denormal_mode = true>}
!FINE-GRAINED-MEMORY: omp.atomic.update %{{.*}} : !fir.ref<i32> {
!FINE-GRAINED-MEMORY: } {atomic_control = #omp.atomic_control<amdgpu_fine_grained_memory = true>}
!REMOTE-MEMORY: omp.atomic.update %{{.*}} : !fir.ref<i32> {
!REMOTE-MEMORY: } {atomic_control = #omp.atomic_control<amdgpu_remote_memory = true>}
!$omp target parallel num_threads(threads)
!$omp atomic
A = A + 1
!$omp end target parallel
!UNSAFE-FP-ATOMICS: omp.atomic.update %{{.*}} : !fir.ref<i32> {
!UNSAFE-FP-ATOMICS: } {atomic_control = #omp.atomic_control<amdgpu_ignore_denormal_mode = true>}
!IGNORE-DENORMAL: omp.atomic.update %{{.*}} : !fir.ref<i32> {
!IGNORE-DENORMAL: } {atomic_control = #omp.atomic_control<amdgpu_ignore_denormal_mode = true>}
!FINE-GRAINED-MEMORY: omp.atomic.update %{{.*}} : !fir.ref<i32> {
!FINE-GRAINED-MEMORY: } {atomic_control = #omp.atomic_control<amdgpu_fine_grained_memory = true>}
!REMOTE-MEMORY: omp.atomic.update %{{.*}} : !fir.ref<i32> {
!REMOTE-MEMORY: } {atomic_control = #omp.atomic_control<amdgpu_remote_memory = true>}
!$omp target parallel num_threads(threads)
!$omp atomic capture
A = A + B
B = A
!$omp end atomic
!$omp end target parallel
end program test
14 changes: 11 additions & 3 deletions llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -3278,7 +3278,9 @@ class OpenMPIRBuilder {
emitAtomicUpdate(InsertPointTy AllocaIP, Value *X, Type *XElemTy, Value *Expr,
AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
AtomicUpdateCallbackTy &UpdateOp, bool VolatileX,
bool IsXBinopExpr);
bool IsXBinopExpr, bool IsAmdgpuIgnoreDenormalMode,
bool IsAmdgpuNoFineGrainedMemory,
bool IsAmdgpuNoRemoteMemory);

/// Emit the binary op. described by \p RMWOp, using \p Src1 and \p Src2 .
///
Expand Down Expand Up @@ -3349,7 +3351,10 @@ class OpenMPIRBuilder {
LLVM_ABI InsertPointOrErrorTy createAtomicUpdate(
const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &X,
Value *Expr, AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
AtomicUpdateCallbackTy &UpdateOp, bool IsXBinopExpr);
AtomicUpdateCallbackTy &UpdateOp, bool IsXBinopExpr,
bool IsAmdgpuIgnoreDenormalMode = false,
bool IsAmdgpuNoFineGrainedMemory = false,
bool IsAmdgpuNoRemoteMemory = false);

/// Emit atomic update for constructs: --- Only Scalar data types
/// V = X; X = X BinOp Expr ,
Expand Down Expand Up @@ -3384,7 +3389,10 @@ class OpenMPIRBuilder {
const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &X,
AtomicOpValue &V, Value *Expr, AtomicOrdering AO,
AtomicRMWInst::BinOp RMWOp, AtomicUpdateCallbackTy &UpdateOp,
bool UpdateExpr, bool IsPostfixUpdate, bool IsXBinopExpr);
bool UpdateExpr, bool IsPostfixUpdate, bool IsXBinopExpr,
bool IsAmdgpuIgnoreDenormalMode = false,
bool IsAmdgpuNoFineGrainedMemory = false,
bool IsAmdgpuNoRemoteMemory = false);

/// Emit atomic compare for constructs: --- Only scalar data types
/// cond-expr-stmt:
Expand Down
31 changes: 25 additions & 6 deletions llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8761,7 +8761,9 @@ OpenMPIRBuilder::createAtomicWrite(const LocationDescription &Loc,
OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createAtomicUpdate(
const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &X,
Value *Expr, AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
AtomicUpdateCallbackTy &UpdateOp, bool IsXBinopExpr) {
AtomicUpdateCallbackTy &UpdateOp, bool IsXBinopExpr,
bool IsAmdgpuIgnoreDenormalMode, bool IsNoFineGrainedMemory,
bool IsNoRemoteMemory) {
assert(!isConflictIP(Loc.IP, AllocaIP) && "IPs must not be ambiguous");
if (!updateToLocation(Loc))
return Loc.IP;
Expand All @@ -8781,7 +8783,8 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createAtomicUpdate(

Expected<std::pair<Value *, Value *>> AtomicResult =
emitAtomicUpdate(AllocaIP, X.Var, X.ElemTy, Expr, AO, RMWOp, UpdateOp,
X.IsVolatile, IsXBinopExpr);
X.IsVolatile, IsXBinopExpr, IsAmdgpuIgnoreDenormalMode,
IsNoFineGrainedMemory, IsNoRemoteMemory);
if (!AtomicResult)
return AtomicResult.takeError();
checkAndEmitFlushAfterAtomic(Loc, AO, AtomicKind::Update);
Expand Down Expand Up @@ -8828,7 +8831,9 @@ Value *OpenMPIRBuilder::emitRMWOpAsInstruction(Value *Src1, Value *Src2,
Expected<std::pair<Value *, Value *>> OpenMPIRBuilder::emitAtomicUpdate(
InsertPointTy AllocaIP, Value *X, Type *XElemTy, Value *Expr,
AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
AtomicUpdateCallbackTy &UpdateOp, bool VolatileX, bool IsXBinopExpr) {
AtomicUpdateCallbackTy &UpdateOp, bool VolatileX, bool IsXBinopExpr,
bool IsAmdgpuIgnoreDenormalMode, bool IsAmdgpuNoFineGrainedMemory,
bool IsAmdgpuNoRemoteMemory) {
// TODO: handle the case where XElemTy is not byte-sized or not a power of 2
// or a complex datatype.
bool emitRMWOp = false;
Expand All @@ -8851,7 +8856,18 @@ Expected<std::pair<Value *, Value *>> OpenMPIRBuilder::emitAtomicUpdate(

std::pair<Value *, Value *> Res;
if (emitRMWOp) {
Res.first = Builder.CreateAtomicRMW(RMWOp, X, Expr, llvm::MaybeAlign(), AO);
AtomicRMWInst *atomicRMWInst =
Builder.CreateAtomicRMW(RMWOp, X, Expr, llvm::MaybeAlign(), AO);
if (IsAmdgpuIgnoreDenormalMode)
atomicRMWInst->setMetadata("amdgpu.ignore.denormal.mode",
llvm::MDNode::get(Builder.getContext(), {}));
if (IsAmdgpuNoFineGrainedMemory)
atomicRMWInst->setMetadata("amdgpu.no.fine.grained.memory",
llvm::MDNode::get(Builder.getContext(), {}));
if (IsAmdgpuNoRemoteMemory)
atomicRMWInst->setMetadata("amdgpu.no.remote.memory",
llvm::MDNode::get(Builder.getContext(), {}));
Res.first = atomicRMWInst;
// not needed except in case of postfix captures. Generate anyway for
// consistency with the else part. Will be removed with any DCE pass.
// AtomicRMWInst::Xchg does not have a coressponding instruction.
Expand Down Expand Up @@ -8983,7 +8999,9 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createAtomicCapture(
const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &X,
AtomicOpValue &V, Value *Expr, AtomicOrdering AO,
AtomicRMWInst::BinOp RMWOp, AtomicUpdateCallbackTy &UpdateOp,
bool UpdateExpr, bool IsPostfixUpdate, bool IsXBinopExpr) {
bool UpdateExpr, bool IsPostfixUpdate, bool IsXBinopExpr,
bool IsAmdgpuIgnoreDenormalMode, bool IsAmdgpuNoFineGrainedMemory,
bool IsAmdgpuNoRemoteMemory) {
if (!updateToLocation(Loc))
return Loc.IP;

Expand All @@ -9004,7 +9022,8 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createAtomicCapture(
AtomicRMWInst::BinOp AtomicOp = (UpdateExpr ? RMWOp : AtomicRMWInst::Xchg);
Expected<std::pair<Value *, Value *>> AtomicResult =
emitAtomicUpdate(AllocaIP, X.Var, X.ElemTy, Expr, AO, AtomicOp, UpdateOp,
X.IsVolatile, IsXBinopExpr);
X.IsVolatile, IsXBinopExpr, IsAmdgpuIgnoreDenormalMode,
IsAmdgpuNoFineGrainedMemory, IsAmdgpuNoRemoteMemory);
if (!AtomicResult)
return AtomicResult.takeError();
Value *CapturedVal =
Expand Down
15 changes: 15 additions & 0 deletions mlir/include/mlir/Dialect/OpenMP/OpenMPAttrDefs.td
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ def FlagsAttr : OpenMP_Attr<"Flags", "flags"> {
let assemblyFormat = "`<` struct(params) `>`";
}

//===----------------------------------------------------------------------===//
// AtomicControlAttr
//===----------------------------------------------------------------------===//

// Atomic control attributes hold information about architectural
// characteristics which are required for lowering atomic operations.
def AtomicControlAttr : OpenMP_Attr<"AtomicControl", "atomic_control"> {
let parameters =
(ins DefaultValuedParameter<"bool", "false">:$amdgpu_ignore_denormal_mode,
DefaultValuedParameter<"bool", "false">:$amdgpu_fine_grained_memory,
DefaultValuedParameter<"bool", "false">:$amdgpu_remote_memory);

let assemblyFormat = "`<` struct(params) `>`";
}

//===----------------------------------------------------------------------===//
// TaskDependArrayAttr
//===----------------------------------------------------------------------===//
Expand Down
8 changes: 5 additions & 3 deletions mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1543,9 +1543,11 @@ def AtomicUpdateOp : OpenMP_Op<"atomic.update", traits = [
operations.
}] # clausesDescription;

let arguments = !con((ins Arg<OpenMP_PointerLikeType,
"Address of variable to be updated",
[MemRead, MemWrite]>:$x), clausesArgs);
let arguments = !con(
(ins Arg<OpenMP_PointerLikeType,
"Address of variable to be updated", [MemRead, MemWrite]>:$x,
AtomicControlAttr:$atomic_control),
clausesArgs);

// Override region definition.
let regions = (region SizedRegion<1>:$region);
Expand Down
Loading
Loading