diff options
author | Yaxun (Sam) Liu <yaxun.liu@amd.com> | 2025-02-27 10:41:04 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-27 10:41:04 -0500 |
commit | 240f2269ffdbd96e68b2159ae537d8486164c10c (patch) | |
tree | c07c7fa87f8205de45967c612089778fcf23bf57 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | c630de934ca2c8381bdd60268179bc14f792ec19 (diff) | |
download | llvm-240f2269ffdbd96e68b2159ae537d8486164c10c.zip llvm-240f2269ffdbd96e68b2159ae537d8486164c10c.tar.gz llvm-240f2269ffdbd96e68b2159ae537d8486164c10c.tar.bz2 |
Add clang atomic control options and attribute (#114841)
Add option and statement attribute for controlling emitting of
target-specific
metadata to atomicrmw instructions in IR.
The RFC for this attribute and option is
https://discourse.llvm.org/t/rfc-add-clang-atomic-control-options-and-pragmas/80641,
Originally a pragma was proposed, then it was changed to clang
attribute.
This attribute allows users to specify one, two, or all three options
and must be applied
to a compound statement. The attribute can also be nested, with inner
attributes
overriding the options specified by outer attributes or the target's
default
options. These options will then determine the target-specific metadata
added to atomic
instructions in the IR.
In addition to the attribute, three new compiler options are introduced:
`-f[no-]atomic-remote-memory`, `-f[no-]atomic-fine-grained-memory`,
`-f[no-]atomic-ignore-denormal-mode`.
These compiler options allow users to override the default options
through the
Clang driver and front end. `-m[no-]unsafe-fp-atomics` is aliased to
`-f[no-]ignore-denormal-mode`.
In terms of implementation, the atomic attribute is represented in the
AST by the
existing AttributedStmt, with minimal changes to AST and Sema.
During code generation in Clang, the CodeGenModule maintains the current
atomic options,
which are used to emit the relevant metadata for atomic instructions.
RAII is used
to manage the saving and restoring of atomic options when entering
and exiting nested AttributedStmt.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 1b7d0ac..3caa79b 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -342,7 +342,8 @@ CodeGenModule::CodeGenModule(ASTContext &C, PreprocessorOpts(PPO), CodeGenOpts(CGO), TheModule(M), Diags(diags), Target(C.getTargetInfo()), ABI(createCXXABI(*this)), VMContext(M.getContext()), VTables(*this), StackHandler(diags), - SanitizerMD(new SanitizerMetadata(*this)) { + SanitizerMD(new SanitizerMetadata(*this)), + AtomicOpts(Target.getAtomicOpts()) { // Initialize the type cache. Types.reset(new CodeGenTypes(*this)); |