@@ -569,12 +569,12 @@ 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 (global->hasAttr <CUDAConstantAttr>() ||
573- global->getType ()->isCUDADeviceBuiltinTextureType ()) {
572+ if (global->getType ()->isCUDADeviceBuiltinTextureType ()) {
574573 llvm_unreachable (" NYI" );
575574 }
576575
577576 return !langOpts.CUDAIsDevice || global->hasAttr <CUDADeviceAttr>() ||
577+ global->hasAttr <CUDAConstantAttr>() ||
578578 global->hasAttr <CUDASharedAttr>() ||
579579 global->getType ()->isCUDADeviceBuiltinSurfaceType ();
580580}
@@ -1492,7 +1492,7 @@ void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *d,
14921492 // __shared__ variables is not marked as externally initialized,
14931493 // because they must not be initialized.
14941494 if (linkage != cir::GlobalLinkageKind::InternalLinkage &&
1495- (d->hasAttr <CUDADeviceAttr>() ||
1495+ (d->hasAttr <CUDADeviceAttr>() || d-> hasAttr <CUDAConstantAttr>() ||
14961496 d->getType ()->isCUDADeviceBuiltinSurfaceType ())) {
14971497 gv->setAttr (CUDAExternallyInitializedAttr::getMnemonic (),
14981498 CUDAExternallyInitializedAttr::get (&getMLIRContext ()));
@@ -1505,8 +1505,9 @@ void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *d,
15051505 emitter->finalize (gv);
15061506
15071507 // TODO(cir): If it is safe to mark the global 'constant', do so now.
1508- gv.setConstant (!needsGlobalCtor && !needsGlobalDtor &&
1509- isTypeConstant (d->getType (), true , true ));
1508+ gv.setConstant ((d->hasAttr <CUDAConstantAttr>() && langOpts.CUDAIsDevice ) ||
1509+ (!needsGlobalCtor && !needsGlobalDtor &&
1510+ isTypeConstant (d->getType (), true , true )));
15101511
15111512 // If it is in a read-only section, mark it 'constant'.
15121513 if (const SectionAttr *sa = d->getAttr <SectionAttr>())
0 commit comments