Skip to content

Commit d514fc4

Browse files
committed
Merge branch 'anom/const-var' into anom/constant-var
2 parents 8a3c8f1 + a250e36 commit d514fc4

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

clang/lib/CIR/CodeGen/CIRGenModule.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -569,15 +569,14 @@ bool CIRGenModule::shouldEmitCUDAGlobalVar(const VarDecl *global) const {
569569
// size and host-side address in order to provide access to
570570
// their device-side incarnations.
571571

572-
if (
573-
global->getType()->isCUDADeviceBuiltinSurfaceType() ||
572+
if (global->getType()->isCUDADeviceBuiltinSurfaceType() ||
574573
global->getType()->isCUDADeviceBuiltinTextureType()) {
575574
llvm_unreachable("NYI");
576575
}
577576

578577
return !langOpts.CUDAIsDevice || global->hasAttr<CUDADeviceAttr>() ||
579-
global->hasAttr<CUDAConstantAttr>() ||
580-
global->hasAttr<CUDASharedAttr>();
578+
global->hasAttr<CUDAConstantAttr>() ||
579+
global->hasAttr<CUDASharedAttr>();
581580
}
582581

583582
void CIRGenModule::emitGlobal(GlobalDecl gd) {
@@ -1497,7 +1496,7 @@ void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *d,
14971496
// __shared__ variables is not marked as externally initialized,
14981497
// because they must not be initialized.
14991498
if (linkage != cir::GlobalLinkageKind::InternalLinkage &&
1500-
(d->hasAttr<CUDADeviceAttr>())) {
1499+
(d->hasAttr<CUDADeviceAttr>() || d->hasAttr<CUDAConstantAttr>())) {
15011500
gv->setAttr(CUDAExternallyInitializedAttr::getMnemonic(),
15021501
CUDAExternallyInitializedAttr::get(&getMLIRContext()));
15031502
}
@@ -1511,7 +1510,7 @@ void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *d,
15111510
// TODO(cir): If it is safe to mark the global 'constant', do so now.
15121511
gv.setConstant((d->hasAttr<CUDAConstantAttr>() && langOpts.CUDAIsDevice) ||
15131512
(!needsGlobalCtor && !needsGlobalDtor &&
1514-
isTypeConstant(d->getType(), true, true)));
1513+
isTypeConstant(d->getType(), true, true)));
15151514

15161515
// If it is in a read-only section, mark it 'constant'.
15171516
if (const SectionAttr *sa = d->getAttr<SectionAttr>())

clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/NVPTX.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class NVPTXTargetLoweringInfo : public TargetLoweringInfo {
5252
case Kind::offload_global:
5353
return 1;
5454
case Kind::offload_constant:
55-
return 2;
55+
return 4;
5656
case Kind::offload_generic:
5757
return 4;
5858
default:

clang/test/CIR/CodeGen/CUDA/global-vars.cu

+4
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ __device__ int a;
1717
__shared__ int shared;
1818
// CIR-DEVICE: cir.global external addrspace(offload_local) @shared = #cir.undef
1919
// LLVM-DEVICE: @shared = addrspace(3) global i32 undef, align 4
20+
21+
__constant__ int b;
22+
// CIR-DEVICE: cir.global constant external addrspace(offload_constant) @b = #cir.int<0> : !s32i {alignment = 4 : i64, cu.externally_initialized = #cir.cu.externally_initialized}
23+
// LLVM-DEVICE: @b = addrspace(4) externally_initialized constant i32 0, align 4

0 commit comments

Comments
 (0)