Skip to content

Commit 83f7f2e

Browse files
authored
merge main into amd-staging (#350)
2 parents 7cee817 + 6eeca37 commit 83f7f2e

File tree

250 files changed

+2820
-1343
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

250 files changed

+2820
-1343
lines changed

clang/docs/OpenMPSupport.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ implementation.
256256
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
257257
| device | device-specific environment variables | :none:`unclaimed` | |
258258
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
259-
| device | omp_target_is_accessible routine | :part:`In Progress` | https://github.com/llvm/llvm-project/pull/138294 |
259+
| device | omp_target_is_accessible routine | :good:`done` | https://github.com/llvm/llvm-project/pull/138294 |
260260
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
261261
| device | omp_get_mapped_ptr routine | :good:`done` | D141545 |
262262
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ Bug Fixes to Attribute Support
695695
- Using ``[[gnu::cleanup(some_func)]]`` where some_func is annotated with
696696
``[[gnu::error("some error")]]`` now correctly triggers an error. (#GH146520)
697697
- Fix a crash when the function name is empty in the `swift_name` attribute. (#GH157075)
698+
- Fixes crashes or missing diagnostics with the `device_kernel` attribute. (#GH161905)
698699

699700
Bug Fixes to C++ Support
700701
^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,7 @@ def SYCLKernel : InheritableAttr {
16231623
let Documentation = [SYCLKernelDocs];
16241624
}
16251625

1626-
def DeviceKernel : DeclOrTypeAttr {
1626+
def DeviceKernel : InheritableAttr {
16271627
let Spellings = [Clang<"device_kernel">,
16281628
Clang<"nvptx_kernel">, Clang<"amdgpu_kernel">,
16291629
CustomKeyword<"__kernel">, CustomKeyword<"kernel">];

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4122,6 +4122,9 @@ def warn_missing_sdksettings_for_availability_checking : Warning<
41224122
"%0 availability is ignored without a valid 'SDKSettings.json' in the SDK">,
41234123
InGroup<DiagGroup<"ignored-availability-without-sdk-settings">>;
41244124

4125+
def err_hidden_device_kernel
4126+
: Error<"%0 is specified as a device kernel but it is not externally visible">;
4127+
41254128
// Thread Safety Attributes
41264129
def warn_thread_attribute_ignored : Warning<
41274130
"ignoring %0 attribute because its argument is invalid">,

clang/lib/AST/ASTConcept.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void ConstraintSatisfaction::Profile(llvm::FoldingSetNodeID &ID,
8686
ID.AddPointer(ConstraintOwner);
8787
ID.AddInteger(TemplateArgs.size());
8888
for (auto &Arg : TemplateArgs)
89-
C.getCanonicalTemplateArgument(Arg).Profile(ID, C);
89+
Arg.Profile(ID, C);
9090
}
9191

9292
ConceptReference *

clang/lib/AST/TypePrinter.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,9 +2147,6 @@ void TypePrinter::printAttributedAfter(const AttributedType *T,
21472147
}
21482148
case attr::AArch64VectorPcs: OS << "aarch64_vector_pcs"; break;
21492149
case attr::AArch64SVEPcs: OS << "aarch64_sve_pcs"; break;
2150-
case attr::DeviceKernel:
2151-
OS << T->getAttr()->getSpelling();
2152-
break;
21532150
case attr::IntelOclBicc:
21542151
OS << "inteloclbicc";
21552152
break;

clang/lib/Basic/Targets/NVPTX.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public TargetInfo {
200200
// a host function.
201201
if (HostTarget)
202202
return HostTarget->checkCallingConvention(CC);
203-
return CCCR_Warning;
203+
return CC == CC_DeviceKernel ? CCCR_OK : CCCR_Warning;
204204
}
205205

206206
bool hasBitIntType() const override { return true; }

clang/lib/CodeGen/Targets/AMDGPU.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,11 @@ void AMDGPUTargetCodeGenInfo::setTargetAttributes(
439439
return;
440440

441441
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
442-
if (FD)
442+
if (FD) {
443443
setFunctionDeclAttributes(FD, F, M);
444-
444+
if (FD->hasAttr<DeviceKernelAttr>() && !M.getLangOpts().OpenCL)
445+
F->setCallingConv(getDeviceKernelCallingConv());
446+
}
445447
if (!getABIInfo().getCodeGenOpts().EmitIEEENaNCompliantInsts)
446448
F->addFnAttr("amdgpu-ieee", "false");
447449
}
@@ -658,7 +660,7 @@ llvm::Value *AMDGPUTargetCodeGenInfo::createEnqueuedBlockKernel(
658660
// kernel address (only the kernel descriptor).
659661
auto *F = llvm::Function::Create(FT, llvm::GlobalValue::InternalLinkage, Name,
660662
&Mod);
661-
F->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL);
663+
F->setCallingConv(getDeviceKernelCallingConv());
662664

663665
llvm::AttrBuilder KernelAttrs(C);
664666
// FIXME: The invoke isn't applying the right attributes either

clang/lib/CodeGen/Targets/NVPTX.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ void NVPTXTargetCodeGenInfo::setTargetAttributes(
264264
// And kernel functions are not subject to inlining
265265
F->addFnAttr(llvm::Attribute::NoInline);
266266
if (FD->hasAttr<CUDAGlobalAttr>()) {
267-
F->setCallingConv(llvm::CallingConv::PTX_Kernel);
267+
F->setCallingConv(getDeviceKernelCallingConv());
268268

269269
for (auto IV : llvm::enumerate(FD->parameters()))
270270
if (IV.value()->hasAttr<CUDAGridConstantAttr>())
@@ -278,7 +278,7 @@ void NVPTXTargetCodeGenInfo::setTargetAttributes(
278278
}
279279
// Attach kernel metadata directly if compiling for NVPTX.
280280
if (FD->hasAttr<DeviceKernelAttr>())
281-
F->setCallingConv(llvm::CallingConv::PTX_Kernel);
281+
F->setCallingConv(getDeviceKernelCallingConv());
282282
}
283283

284284
void NVPTXTargetCodeGenInfo::addNVVMMetadata(llvm::GlobalValue *GV,

clang/lib/CodeGen/Targets/SPIR.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class CommonSPIRTargetCodeGenInfo : public TargetCodeGenInfo {
6464
llvm::Constant *getNullPointer(const CodeGen::CodeGenModule &CGM,
6565
llvm::PointerType *T,
6666
QualType QT) const override;
67+
void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
68+
CodeGen::CodeGenModule &M) const override;
6769
};
6870
class SPIRVTargetCodeGenInfo : public CommonSPIRTargetCodeGenInfo {
6971
public:
@@ -268,6 +270,22 @@ CommonSPIRTargetCodeGenInfo::getNullPointer(const CodeGen::CodeGenModule &CGM,
268270
llvm::ConstantPointerNull::get(NPT), PT);
269271
}
270272

273+
void CommonSPIRTargetCodeGenInfo::setTargetAttributes(
274+
const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
275+
if (M.getLangOpts().OpenCL || GV->isDeclaration())
276+
return;
277+
278+
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
279+
if (!FD)
280+
return;
281+
282+
llvm::Function *F = dyn_cast<llvm::Function>(GV);
283+
assert(F && "Expected GlobalValue to be a Function");
284+
285+
if (FD->hasAttr<DeviceKernelAttr>())
286+
F->setCallingConv(getDeviceKernelCallingConv());
287+
}
288+
271289
LangAS
272290
SPIRVTargetCodeGenInfo::getGlobalVarAddressSpace(CodeGenModule &CGM,
273291
const VarDecl *D) const {
@@ -292,19 +310,23 @@ SPIRVTargetCodeGenInfo::getGlobalVarAddressSpace(CodeGenModule &CGM,
292310

293311
void SPIRVTargetCodeGenInfo::setTargetAttributes(
294312
const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
295-
if (!M.getLangOpts().HIP ||
296-
M.getTarget().getTriple().getVendor() != llvm::Triple::AMD)
297-
return;
298313
if (GV->isDeclaration())
299314
return;
300315

301-
auto F = dyn_cast<llvm::Function>(GV);
302-
if (!F)
316+
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
317+
if (!FD)
303318
return;
304319

305-
auto FD = dyn_cast_or_null<FunctionDecl>(D);
306-
if (!FD)
320+
llvm::Function *F = dyn_cast<llvm::Function>(GV);
321+
assert(F && "Expected GlobalValue to be a Function");
322+
323+
if (FD->hasAttr<DeviceKernelAttr>())
324+
F->setCallingConv(getDeviceKernelCallingConv());
325+
326+
if (!M.getLangOpts().HIP ||
327+
M.getTarget().getTriple().getVendor() != llvm::Triple::AMD)
307328
return;
329+
308330
if (!FD->hasAttr<CUDAGlobalAttr>())
309331
return;
310332

0 commit comments

Comments
 (0)