aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CIR/CodeGen/CIRGenModule.cpp
diff options
context:
space:
mode:
authorAndy Kaylor <akaylor@nvidia.com>2025-08-12 10:02:00 -0700
committerGitHub <noreply@github.com>2025-08-12 10:02:00 -0700
commit54f53c988df3ef0380cae288591f66b151239aab (patch)
tree30678b446c4b6fe5cd2872b6f6839c145a0bc7ec /clang/lib/CIR/CodeGen/CIRGenModule.cpp
parent7f195b36eefcaa7423cd0c60c003460bf571e9e5 (diff)
downloadllvm-54f53c988df3ef0380cae288591f66b151239aab.zip
llvm-54f53c988df3ef0380cae288591f66b151239aab.tar.gz
llvm-54f53c988df3ef0380cae288591f66b151239aab.tar.bz2
[CIR] Introduce the CIR global_view attribute (#153044)
This change introduces the #cir.global_view attribute and adds support for using that attribute to handle initializing a global variable with the address of another global variable. This does not yet include support for the optional list of indices to get an offset from the base address. Those will be added in a follow-up patch.
Diffstat (limited to 'clang/lib/CIR/CodeGen/CIRGenModule.cpp')
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenModule.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 895a07e..45dfcf5 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -655,6 +655,16 @@ mlir::Value CIRGenModule::getAddrOfGlobalVar(const VarDecl *d, mlir::Type ty,
g.getSymName());
}
+cir::GlobalViewAttr CIRGenModule::getAddrOfGlobalVarAttr(const VarDecl *d) {
+ assert(d->hasGlobalStorage() && "Not a global variable");
+ mlir::Type ty = getTypes().convertTypeForMem(d->getType());
+
+ cir::GlobalOp globalOp = getOrCreateCIRGlobal(d, ty, NotForDefinition);
+ assert(!cir::MissingFeatures::addressSpace());
+ cir::PointerType ptrTy = builder.getPointerTo(globalOp.getSymType());
+ return builder.getGlobalViewAttr(ptrTy, globalOp);
+}
+
void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *vd,
bool isTentative) {
if (getLangOpts().OpenCL || getLangOpts().OpenMPIsTargetDevice) {