Skip to content

Conversation

@anchuraj
Copy link
Contributor

@anchuraj anchuraj commented Jun 11, 2025

Atomic Control Options are used to specify architectural characteristics to help lowering of atomic operations. The options used are:
-f[no-]atomic-remote-memory, -f[no-]atomic-fine-grained-memory,
-f[no-]atomic-ignore-denormal-mode.
Legacy option -m[no-]unsafe-fp-atomics is aliased to
-f[no-]ignore-denormal-mode.
More details can be found in #102569. This PR implements the llvm support for these options with OpenMP atomic.

@github-actions
Copy link

github-actions bot commented Jun 11, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- flang/include/flang/Frontend/TargetOptions.h flang/include/flang/Optimizer/Dialect/Support/FIRContext.h flang/lib/Frontend/CompilerInvocation.cpp flang/lib/Lower/Bridge.cpp flang/lib/Lower/OpenMP/Atomic.cpp flang/lib/Optimizer/Dialect/Support/FIRContext.cpp llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
View the diff from clang-format here.
diff --git a/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h b/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h
index 0e8451fe0..beae07f13 100644
--- a/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h
+++ b/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h
@@ -58,13 +58,16 @@ 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);
 
-/// Sets that Denormal Mode can be ignored for lowering of floating point atomic operations.
+/// Sets that Denormal Mode can be ignored for lowering of floating point atomic
+/// operations.
 void setAtomicIgnoreDenormalMode(mlir::ModuleOp mod, bool value);
-/// Gets whether Denormal Mode can be ignored or not for lowering of floating point atomic operations.
+/// Gets whether Denormal Mode can be ignored or not for lowering of floating
+/// point atomic operations.
 bool getAtomicIgnoreDenormalMode(mlir::ModuleOp mod);
 /// Sets that fine grained memory is used for lowering of atomic operations.
 void setAtomicFineGrainedMemory(mlir::ModuleOp mod, bool value);
-/// Gets whether fine grained memory is used or not for lowering of atomic operations.
+/// Gets whether fine grained memory is used or not for lowering of atomic
+/// operations.
 bool getAtomicFineGrainedMemory(mlir::ModuleOp mod);
 /// Sets that remote memory is used for lowering of atomic operations.
 void setAtomicRemoteMemory(mlir::ModuleOp mod, bool value);
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index f8185f752..3795ce2e0 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -6666,7 +6666,8 @@ Fortran::lower::LoweringBridge::LoweringBridge(
   fir::setKindMapping(*module, kindMap);
   fir::setTargetCPU(*module, targetMachine.getTargetCPU());
   fir::setTuneCPU(*module, targetOpts.cpuToTuneFor);
-  fir::setAtomicIgnoreDenormalMode(*module, targetOpts.atomicIgnoreDenormalMode);
+  fir::setAtomicIgnoreDenormalMode(*module,
+                                   targetOpts.atomicIgnoreDenormalMode);
   fir::setAtomicFineGrainedMemory(*module, targetOpts.atomicFineGrainedMemory);
   fir::setAtomicRemoteMemory(*module, targetOpts.atomicRemoteMemory);
   fir::setTargetFeatures(*module, targetMachine.getTargetFeatureString());
diff --git a/flang/lib/Optimizer/Dialect/Support/FIRContext.cpp b/flang/lib/Optimizer/Dialect/Support/FIRContext.cpp
index 885efa653..c9c921008 100644
--- a/flang/lib/Optimizer/Dialect/Support/FIRContext.cpp
+++ b/flang/lib/Optimizer/Dialect/Support/FIRContext.cpp
@@ -91,11 +91,11 @@ void fir::setTuneCPU(mlir::ModuleOp mod, llvm::StringRef cpu) {
 static constexpr const char *atomicIgnoreDenormalModeName =
     "fir.atomic_ignore_denormal_mode";
 void fir::setAtomicIgnoreDenormalMode(mlir::ModuleOp mod, bool value) {
-  if(value) {
+  if (value) {
     auto *ctx = mod.getContext();
     mod->setAttr(atomicIgnoreDenormalModeName, mlir::UnitAttr::get(ctx));
   } else {
-    if(mod->hasAttr(atomicIgnoreDenormalModeName))
+    if (mod->hasAttr(atomicIgnoreDenormalModeName))
       mod->removeAttr(atomicIgnoreDenormalModeName);
   }
 }
@@ -104,13 +104,14 @@ bool fir::getAtomicIgnoreDenormalMode(mlir::ModuleOp mod) {
   return mod->hasAttrOfType<mlir::UnitAttr>(atomicIgnoreDenormalModeName);
 }
 
-static constexpr const char *atomicFineGrainedMemoryName = "fir.atomic_fine_grained_memory";
+static constexpr const char *atomicFineGrainedMemoryName =
+    "fir.atomic_fine_grained_memory";
 void fir::setAtomicFineGrainedMemory(mlir::ModuleOp mod, bool value) {
-  if(value) {
+  if (value) {
     auto *ctx = mod.getContext();
     mod->setAttr(atomicFineGrainedMemoryName, mlir::UnitAttr::get(ctx));
   } else {
-    if(mod->hasAttr(atomicFineGrainedMemoryName))
+    if (mod->hasAttr(atomicFineGrainedMemoryName))
       mod->removeAttr(atomicFineGrainedMemoryName);
   }
 }
@@ -118,13 +119,14 @@ void fir::setAtomicFineGrainedMemory(mlir::ModuleOp mod, bool value) {
 bool fir::getAtomicFineGrainedMemory(mlir::ModuleOp mod) {
   return mod->hasAttrOfType<mlir::UnitAttr>(atomicFineGrainedMemoryName);
 }
-static constexpr const char *atomicRemoteMemoryName = "fir.atomic_remote_memory";
+static constexpr const char *atomicRemoteMemoryName =
+    "fir.atomic_remote_memory";
 void fir::setAtomicRemoteMemory(mlir::ModuleOp mod, bool value) {
-  if(value) {
+  if (value) {
     auto *ctx = mod.getContext();
     mod->setAttr(atomicRemoteMemoryName, mlir::UnitAttr::get(ctx));
   } else {
-    if(mod->hasAttr(atomicRemoteMemoryName))
+    if (mod->hasAttr(atomicRemoteMemoryName))
       mod->removeAttr(atomicRemoteMemoryName);
   }
 }
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index 5adc19b84..6a521b699 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -3250,24 +3250,21 @@ convertOmpAtomicUpdate(omp::AtomicUpdateOp &opInst,
   bool isIgnoreDenormalMode = false;
   bool isNoFineGrainedMemory = false;
   bool isNoRemoteMemory = false;
-  if(opInst->hasAttr(opInst.getAtomicControlAttrName())) {
+  if (opInst->hasAttr(opInst.getAtomicControlAttrName())) {
     mlir::omp::AtomicControlAttr atomicControlAttr =
         opInst.getAtomicControlAttr();
-    isIgnoreDenormalMode =
-        atomicControlAttr.getIgnoreDenormalMode();
-    isNoFineGrainedMemory =
-        !atomicControlAttr.getFineGrainedMemory();
+    isIgnoreDenormalMode = atomicControlAttr.getIgnoreDenormalMode();
+    isNoFineGrainedMemory = !atomicControlAttr.getFineGrainedMemory();
     isNoRemoteMemory = !atomicControlAttr.getRemoteMemory();
-    
   }
   // Handle ambiguous alloca, if any.
   auto allocaIP = findAllocaInsertPoint(builder, moduleTranslation);
   llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
   llvm::OpenMPIRBuilder::InsertPointOrErrorTy afterIP =
-      ompBuilder->createAtomicUpdate(
-          ompLoc, allocaIP, llvmAtomicX, llvmExpr, atomicOrdering, binop,
-          updateFn, isXBinopExpr, isIgnoreDenormalMode,
-          isNoFineGrainedMemory, isNoRemoteMemory);
+      ompBuilder->createAtomicUpdate(ompLoc, allocaIP, llvmAtomicX, llvmExpr,
+                                     atomicOrdering, binop, updateFn,
+                                     isXBinopExpr, isIgnoreDenormalMode,
+                                     isNoFineGrainedMemory, isNoRemoteMemory);
 
   if (failed(handleError(afterIP, *opInst)))
     return failure();
@@ -3363,10 +3360,8 @@ convertOmpAtomicCapture(omp::AtomicCaptureOp atomicCaptureOp,
   if (atomicUpdateOp) {
     mlir::omp::AtomicControlAttr atomicControlAttr =
         atomicUpdateOp.getAtomicControlAttr();
-    isIgnoreDenormalMode =
-        atomicControlAttr.getIgnoreDenormalMode();
-    isNoFineGrainedMemory =
-        !atomicControlAttr.getFineGrainedMemory();
+    isIgnoreDenormalMode = atomicControlAttr.getIgnoreDenormalMode();
+    isNoFineGrainedMemory = !atomicControlAttr.getFineGrainedMemory();
     isNoRemoteMemory = !atomicControlAttr.getRemoteMemory();
   }
   // Handle ambiguous alloca, if any.
@@ -3376,8 +3371,7 @@ convertOmpAtomicCapture(omp::AtomicCaptureOp atomicCaptureOp,
       ompBuilder->createAtomicCapture(
           ompLoc, allocaIP, llvmAtomicX, llvmAtomicV, llvmExpr, atomicOrdering,
           binop, updateFn, atomicUpdateOp, isPostfixUpdate, isXBinopExpr,
-          isIgnoreDenormalMode, isNoFineGrainedMemory,
-          isNoRemoteMemory);
+          isIgnoreDenormalMode, isNoFineGrainedMemory, isNoRemoteMemory);
 
   if (failed(handleError(afterIP, *atomicCaptureOp)))
     return failure();

@anchuraj anchuraj force-pushed the atomic-control-backend branch 3 times, most recently from f75aa26 to da81ad9 Compare June 13, 2025 18:46
@anchuraj anchuraj changed the title Atomic control backend [mlir][OpenMP][llvm]Atomic control backend Jun 13, 2025
@anchuraj anchuraj force-pushed the atomic-control-backend branch from da81ad9 to 028dd10 Compare July 2, 2025 19:56
@anchuraj anchuraj force-pushed the atomic-control-backend branch from 028dd10 to 36f6970 Compare July 7, 2025 15:48
anchuraj added a commit that referenced this pull request Jul 24, 2025
Atomic Control Options are used to specify architectural characteristics
to help lowering of atomic operations. The options used are:
`-f[no-]atomic-remote-memory`, `-f[no-]atomic-fine-grained-memory`,
 `-f[no-]atomic-ignore-denormal-mode`.
Legacy option `-m[no-]unsafe-fp-atomics` is aliased to
`-f[no-]ignore-denormal-mode`.
More details can be found in
#102569. This PR implements the
frontend support for these options with OpenMP atomic in flang.

Backend changes are available in the draft PR:
#143769 which will be raised
after this merged.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jul 24, 2025
… (#143441)

Atomic Control Options are used to specify architectural characteristics
to help lowering of atomic operations. The options used are:
`-f[no-]atomic-remote-memory`, `-f[no-]atomic-fine-grained-memory`,
 `-f[no-]atomic-ignore-denormal-mode`.
Legacy option `-m[no-]unsafe-fp-atomics` is aliased to
`-f[no-]ignore-denormal-mode`.
More details can be found in
llvm/llvm-project#102569. This PR implements the
frontend support for these options with OpenMP atomic in flang.

Backend changes are available in the draft PR:
llvm/llvm-project#143769 which will be raised
after this merged.
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Jul 28, 2025
Atomic Control Options are used to specify architectural characteristics
to help lowering of atomic operations. The options used are:
`-f[no-]atomic-remote-memory`, `-f[no-]atomic-fine-grained-memory`,
 `-f[no-]atomic-ignore-denormal-mode`.
Legacy option `-m[no-]unsafe-fp-atomics` is aliased to
`-f[no-]ignore-denormal-mode`.
More details can be found in
llvm#102569. This PR implements the
frontend support for these options with OpenMP atomic in flang.

Backend changes are available in the draft PR:
llvm#143769 which will be raised
after this merged.
@anchuraj anchuraj closed this Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant