@@ -499,7 +499,8 @@ CodeGenTypes::arrangeCXXConstructorCall(const CallArgList &args,
499499// / Arrange the argument and result information for the declaration or
500500// / definition of the given function.
501501const CGFunctionInfo &
502- CodeGenTypes::arrangeFunctionDeclaration (const FunctionDecl *FD) {
502+ CodeGenTypes::arrangeFunctionDeclaration (const GlobalDecl GD) {
503+ const FunctionDecl *FD = cast<FunctionDecl>(GD.getDecl ());
503504 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD))
504505 if (MD->isImplicitObjectMemberFunction ())
505506 return arrangeCXXMethodDeclaration (MD);
@@ -509,6 +510,13 @@ CodeGenTypes::arrangeFunctionDeclaration(const FunctionDecl *FD) {
509510 assert (isa<FunctionType>(FTy));
510511 setCUDAKernelCallingConvention (FTy, CGM, FD);
511512
513+ if (FD->hasAttr <OpenCLKernelAttr>() &&
514+ GD.getKernelReferenceKind () == KernelReferenceKind::Stub) {
515+ const FunctionType *FT = FTy->getAs <FunctionType>();
516+ CGM.getTargetCodeGenInfo ().setOCLKernelStubCallingConvention (FT);
517+ FTy = FT->getCanonicalTypeUnqualified ();
518+ }
519+
512520 // When declaring a function without a prototype, always use a
513521 // non-variadic type.
514522 if (CanQual<FunctionNoProtoType> noProto = FTy.getAs <FunctionNoProtoType>()) {
@@ -581,13 +589,11 @@ CodeGenTypes::arrangeUnprototypedObjCMessageSend(QualType returnType,
581589const CGFunctionInfo &
582590CodeGenTypes::arrangeGlobalDeclaration (GlobalDecl GD) {
583591 // FIXME: Do we need to handle ObjCMethodDecl?
584- const FunctionDecl *FD = cast<FunctionDecl>(GD.getDecl ());
585-
586592 if (isa<CXXConstructorDecl>(GD.getDecl ()) ||
587593 isa<CXXDestructorDecl>(GD.getDecl ()))
588594 return arrangeCXXStructorDeclaration (GD);
589595
590- return arrangeFunctionDeclaration (FD );
596+ return arrangeFunctionDeclaration (GD );
591597}
592598
593599// / Arrange a thunk that takes 'this' as the first parameter followed by
@@ -2392,7 +2398,6 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
23922398 // Collect function IR attributes from the callee prototype if we have one.
23932399 AddAttributesFromFunctionProtoType (getContext (), FuncAttrs,
23942400 CalleeInfo.getCalleeFunctionProtoType ());
2395-
23962401 const Decl *TargetDecl = CalleeInfo.getCalleeDecl ().getDecl ();
23972402
23982403 // Attach assumption attributes to the declaration. If this is a call
@@ -2499,7 +2504,11 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
24992504 NumElemsParam);
25002505 }
25012506
2502- if (TargetDecl->hasAttr <OpenCLKernelAttr>()) {
2507+ if (TargetDecl->hasAttr <OpenCLKernelAttr>() &&
2508+ CallingConv != CallingConv::CC_C &&
2509+ CallingConv != CallingConv::CC_SpirFunction) {
2510+ // Check CallingConv to avoid adding uniform-work-group-size attribute to
2511+ // OpenCL Kernel Stub
25032512 if (getLangOpts ().OpenCLVersion <= 120 ) {
25042513 // OpenCL v1.2 Work groups are always uniform
25052514 FuncAttrs.addAttribute (" uniform-work-group-size" , " true" );
0 commit comments