-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[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
anchuraj
wants to merge
9
commits into
llvm:main
Choose a base branch
from
anchuraj:atomic-control-backend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9a6d860
to
d0d8e44
Compare
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- 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 f8da410dd..399a5bfec 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -3244,19 +3244,17 @@ convertOmpAtomicUpdate(omp::AtomicUpdateOp &opInst,
mlir::omp::AtomicControlAttr atomicControlAttr =
opInst.getAtomicControlAttr();
- bool isIgnoreDenormalMode =
- atomicControlAttr.getIgnoreDenormalMode();
- bool isNoFineGrainedMemory =
- !atomicControlAttr.getFineGrainedMemory();
+ bool isIgnoreDenormalMode = atomicControlAttr.getIgnoreDenormalMode();
+ bool isNoFineGrainedMemory = !atomicControlAttr.getFineGrainedMemory();
bool 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();
@@ -3352,10 +3350,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.
@@ -3365,8 +3361,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();
|
f75aa26
to
da81ad9
Compare
da81ad9
to
028dd10
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.