@@ -516,7 +516,6 @@ void CIRGenModule::emitGlobal(GlobalDecl GD) {
516
516
517
517
assert (!Global->hasAttr <IFuncAttr>() && " NYI" );
518
518
assert (!Global->hasAttr <CPUDispatchAttr>() && " NYI" );
519
- assert (!langOpts.CUDA && " NYI" );
520
519
521
520
if (langOpts.OpenMP ) {
522
521
// If this is OpenMP, check if it is legal to emit this global normally.
@@ -559,6 +558,7 @@ void CIRGenModule::emitGlobal(GlobalDecl GD) {
559
558
return ;
560
559
}
561
560
} else {
561
+ assert (!langOpts.CUDA && " NYI" );
562
562
const auto *VD = cast<VarDecl>(Global);
563
563
assert (VD->isFileVarDecl () && " Cannot emit local var decl as global." );
564
564
if (VD->isThisDeclarationADefinition () != VarDecl::Definition &&
@@ -2291,7 +2291,7 @@ static std::string getMangledNameImpl(CIRGenModule &CGM, GlobalDecl GD,
2291
2291
assert (0 && " NYI" );
2292
2292
} else if (FD && FD->hasAttr <CUDAGlobalAttr>() &&
2293
2293
GD.getKernelReferenceKind () == KernelReferenceKind::Stub) {
2294
- assert ( 0 && " NYI " );
2294
+ Out << " __device_stub__ " << II-> getName ( );
2295
2295
} else {
2296
2296
Out << II->getName ();
2297
2297
}
@@ -2309,7 +2309,23 @@ static std::string getMangledNameImpl(CIRGenModule &CGM, GlobalDecl GD,
2309
2309
if (const auto *FD = dyn_cast<FunctionDecl>(ND)) {
2310
2310
assert (!FD->isMultiVersion () && " NYI" );
2311
2311
}
2312
- assert (!CGM.getLangOpts ().GPURelocatableDeviceCode && " NYI" );
2312
+
2313
+ // we need to generate a unique mangled name if relocatable-device-code
2314
+ // is specified, so we postfix it with CUID, which is unique.
2315
+ if (CGM.getASTContext ().shouldExternalize (ND) &&
2316
+ CGM.getLangOpts ().GPURelocatableDeviceCode &&
2317
+ CGM.getLangOpts ().CUDAIsDevice ) {
2318
+ // ptxas does not allow '.' in symbol names. On the other hand, HIP prefers
2319
+ // postfix beginning with '.' since the symbol name can be demangled.
2320
+ if (CGM.getLangOpts ().HIP )
2321
+ Out << (isa<VarDecl>(ND) ? " .static." : " .intern." );
2322
+ else
2323
+ Out << (isa<VarDecl>(ND) ? " __static__" : " __intern__" );
2324
+
2325
+ // TODO: generate a unique id with other means
2326
+ assert (!CGM.getLangOpts ().CUID .empty () && " NYI" );
2327
+ Out << CGM.getASTContext ().getCUIDHash ();
2328
+ }
2313
2329
2314
2330
return std::string (Out.str ());
2315
2331
}
@@ -2325,8 +2341,6 @@ StringRef CIRGenModule::getMangledName(GlobalDecl GD) {
2325
2341
}
2326
2342
}
2327
2343
2328
- assert (!langOpts.CUDAIsDevice && " NYI" );
2329
-
2330
2344
// Keep the first result in the case of a mangling collision.
2331
2345
const auto *ND = cast<NamedDecl>(GD.getDecl ());
2332
2346
std::string MangledName = getMangledNameImpl (*this , GD, ND);
0 commit comments