aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorhev <wangrui@loongson.cn>2024-01-06 08:51:59 +0800
committerGitHub <noreply@github.com>2024-01-06 08:51:59 +0800
commit4df566290751403f470fea3b27aa148ab1ddf144 (patch)
treec8c7a6f62ac2d1b84c73461c93e605d6dfa7cda8 /clang/lib/CodeGen/CodeGenModule.cpp
parent4f215fdd62d3f014750339eab9a46946b6fb1c4a (diff)
downloadllvm-4df566290751403f470fea3b27aa148ab1ddf144.zip
llvm-4df566290751403f470fea3b27aa148ab1ddf144.tar.gz
llvm-4df566290751403f470fea3b27aa148ab1ddf144.tar.bz2
[clang] Add per-global code model attribute (#72078)
This patch adds a per-global code model attribute, which can override the target's code model to access global variables. Currently, the code model attribute is only supported on LoongArch. This patch also maps GCC's code model names to LLVM's, which allows for better compatibility between the two compilers. Suggested-by: Arthur Eubanks <aeubanks@google.com> Link: https://discourse.llvm.org/t/how-to-best-implement-code-model-overriding-for-certain-values/71816 Link: https://discourse.llvm.org/t/rfc-add-per-global-code-model-attribute/74944 --------- Signed-off-by: WANG Rui <wangrui@loongson.cn>
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index d78f259..4fd3233 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4869,6 +4869,10 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
isExternallyVisible(D->getLinkageAndVisibility().getLinkage()))
GV->setSection(".cp.rodata");
+ // Handle code model attribute
+ if (const auto *CMA = D->getAttr<CodeModelAttr>())
+ GV->setCodeModel(CMA->getModel());
+
// Check if we a have a const declaration with an initializer, we may be
// able to emit it as available_externally to expose it's value to the
// optimizer.