aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorAlex Voicu <alexandru.voicu@amd.com>2024-09-29 01:22:52 +0100
committerGitHub <noreply@github.com>2024-09-29 01:22:52 +0100
commite203a67f4cef5844877f6a5720e659ea09729e9a (patch)
tree009db94c26c23ef9bbe793f562107adb137cc366 /clang/lib/CodeGen/CodeGenModule.cpp
parent6558e5615ae9e6af6168b0a363808854fd66663f (diff)
downloadllvm-e203a67f4cef5844877f6a5720e659ea09729e9a.zip
llvm-e203a67f4cef5844877f6a5720e659ea09729e9a.tar.gz
llvm-e203a67f4cef5844877f6a5720e659ea09729e9a.tar.bz2
[cuda][HIP] `__constant__` should imply constant (#110182)
Currently, `__constant__` variables do not get unconditionally marked as `constant` in IR, which seems a bit odd given their definition. This is generally inconsequential for NVPTX/AMDGPU, since said variables get emitted in the constant address space for those BEs. However, it is potentially significant for e.g. HIP-on-SPIR-V cases, as SPIR-V does not allow casts to/from the constant AS (`UniformConstant`), which forces `__constant__` variables to be emitted in the global AS, thus making IR constness meaningful.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 2381fa9..25c1c49 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5622,8 +5622,9 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,
emitter->finalize(GV);
// If it is safe to mark the global 'constant', do so now.
- GV->setConstant(!NeedsGlobalCtor && !NeedsGlobalDtor &&
- D->getType().isConstantStorage(getContext(), true, true));
+ GV->setConstant((D->hasAttr<CUDAConstantAttr>() && LangOpts.CUDAIsDevice) ||
+ (!NeedsGlobalCtor && !NeedsGlobalDtor &&
+ D->getType().isConstantStorage(getContext(), true, true)));
// If it is in a read-only section, mark it 'constant'.
if (const SectionAttr *SA = D->getAttr<SectionAttr>()) {