@@ -60,6 +60,8 @@ class CommonSPIRTargetCodeGenInfo : public TargetCodeGenInfo {
6060      llvm::Type *ElementType, llvm::LLVMContext &Ctx) const ;
6161  void 
6262  setOCLKernelStubCallingConvention (const  FunctionType *&FT) const  override ;
63+   void  setTargetAttributes (const  Decl *D, llvm::GlobalValue *GV,
64+                            CodeGen::CodeGenModule &M) const  override ;
6365};
6466class  SPIRVTargetCodeGenInfo  : public  CommonSPIRTargetCodeGenInfo  {
6567public: 
@@ -238,6 +240,20 @@ void CommonSPIRTargetCodeGenInfo::setOCLKernelStubCallingConvention(
238240      FT, FT->getExtInfo ().withCallingConv (CC_SpirFunction));
239241}
240242
243+ void  CommonSPIRTargetCodeGenInfo::setTargetAttributes (
244+     const  Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const  {
245+   const  FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
246+   if  (!FD)
247+     return ;
248+ 
249+   llvm::Function *F = cast<llvm::Function>(GV);
250+ 
251+   //  Attach kernel metadata directly if compiling for SPIR.
252+   if  (FD->hasAttr <SPIRKernelAttr>()) {
253+     F->setCallingConv (llvm::CallingConv::SPIR_KERNEL);
254+   }
255+ }
256+ 
241257LangAS
242258SPIRVTargetCodeGenInfo::getGlobalVarAddressSpace (CodeGenModule &CGM,
243259                                                 const  VarDecl *D) const  {
@@ -262,6 +278,7 @@ SPIRVTargetCodeGenInfo::getGlobalVarAddressSpace(CodeGenModule &CGM,
262278
263279void  SPIRVTargetCodeGenInfo::setTargetAttributes (
264280    const  Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const  {
281+   CommonSPIRTargetCodeGenInfo::setTargetAttributes (D, GV, M);
265282  if  (!M.getLangOpts ().HIP  ||
266283      M.getTarget ().getTriple ().getVendor () != llvm::Triple::AMD)
267284    return ;
0 commit comments