<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jan 20, 2015 at 11:33 AM, Alexander Kornienko <span dir="ltr"><<a href="mailto:alexfh@google.com" target="_blank">alexfh@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Tue, Jan 20, 2015 at 7:44 AM, Sameer Sahasrabuddhe <span dir="ltr"><<a href="mailto:sameer.sahasrabuddhe@amd.com" target="_blank">sameer.sahasrabuddhe@amd.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: sameerds<br>
Date: Tue Jan 20 00:44:32 2015<br>
New Revision: 226548<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=226548&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=226548&view=rev</a><br>
Log:<br>
Introduce SPIR calling conventions.<br>
<br>
This implements Section 3.7 from the SPIR 1.2 spec:<br>
<br>
    SPIR kernels should use "spir_kernel" calling convention.<br>
    Non-kernel functions use "spir_func" calling convention. All<br>
    other calling conventions are disallowed.<br>
<br>
The patch works only for OpenCL source. Any other uses will need<br>
to ensure that kernels are assigned the spir_kernel calling<br>
convention correctly.<br>
<br>
<br>
Added:<br>
    cfe/trunk/test/CodeGenOpenCL/<a href="http://spir-calling-conv.cl" target="_blank">spir-calling-conv.cl</a><br>
Modified:<br>
    cfe/trunk/include/clang/Basic/Specifiers.h<br>
    cfe/trunk/lib/AST/ASTContext.cpp<br>
    cfe/trunk/lib/AST/Type.cpp<br>
    cfe/trunk/lib/AST/TypePrinter.cpp<br>
    cfe/trunk/lib/Basic/Targets.cpp<br>
    cfe/trunk/lib/CodeGen/CGCall.cpp<br>
    cfe/trunk/lib/Sema/SemaType.cpp<br>
    cfe/trunk/tools/libclang/CXType.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Basic/Specifiers.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Specifiers.h?rev=226548&r1=226547&r2=226548&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Specifiers.h?rev=226548&r1=226547&r2=226548&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/Specifiers.h (original)<br>
+++ cfe/trunk/include/clang/Basic/Specifiers.h Tue Jan 20 00:44:32 2015<br>
@@ -210,7 +210,9 @@ namespace clang {<br>
     CC_AAPCS,       // __attribute__((pcs("aapcs")))<br>
     CC_AAPCS_VFP,   // __attribute__((pcs("aapcs-vfp")))<br>
     CC_PnaclCall,   // __attribute__((pnaclcall))<br>
-    CC_IntelOclBicc // __attribute__((intel_ocl_bicc))<br>
+    CC_IntelOclBicc, // __attribute__((intel_ocl_bicc))<br>
+    CC_SpirFunction, // default for OpenCL functions on SPIR target<br>
+    CC_SpirKernel    // inferred for OpenCL kernels on SPIR target<br>
   };<br>
<br>
   /// \brief Checks whether the given calling convention supports variadic<br>
@@ -222,6 +224,8 @@ namespace clang {<br>
     case CC_X86ThisCall:<br>
     case CC_X86Pascal:<br>
     case CC_X86VectorCall:<br>
+    case CC_SpirFunction:<br>
+    case CC_SpirKernel:<br>
       return false;<br>
     default:<br>
       return true;<br>
<br>
Modified: cfe/trunk/lib/AST/ASTContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=226548&r1=226547&r2=226548&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=226548&r1=226547&r2=226548&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/ASTContext.cpp (original)<br>
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Jan 20 00:44:32 2015<br>
@@ -8043,7 +8043,9 @@ CallingConv ASTContext::getDefaultCallin<br>
   if (IsCXXMethod)<br>
     return ABI->getDefaultMethodCallConv(IsVariadic);<br>
<br>
-  return (LangOpts.MRTD && !IsVariadic) ? CC_X86StdCall : CC_C;<br>
+  if (LangOpts.MRTD && !IsVariadic) return CC_X86StdCall;<br>
+<br>
+  return Target->getDefaultCallingConv(TargetInfo::CCMT_Unknown);<br>
 }<br>
<br>
 bool ASTContext::isNearlyEmpty(const CXXRecordDecl *RD) const {<br>
<br>
Modified: cfe/trunk/lib/AST/Type.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=226548&r1=226547&r2=226548&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=226548&r1=226547&r2=226548&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/Type.cpp (original)<br>
+++ cfe/trunk/lib/AST/Type.cpp Tue Jan 20 00:44:32 2015<br>
@@ -1588,6 +1588,8 @@ StringRef FunctionType::getNameForCallCo<br>
   case CC_AAPCS_VFP: return "aapcs-vfp";<br>
   case CC_PnaclCall: return "pnaclcall";<br>
   case CC_IntelOclBicc: return "intel_ocl_bicc";<br>
+  case CC_SpirFunction: return "spir_function";<br>
+  case CC_SpirKernel: return "spir_kernel";<br>
   }<br>
<br>
   llvm_unreachable("Invalid calling convention.");<br>
<br>
Modified: cfe/trunk/lib/AST/TypePrinter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=226548&r1=226547&r2=226548&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=226548&r1=226547&r2=226548&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/TypePrinter.cpp (original)<br>
+++ cfe/trunk/lib/AST/TypePrinter.cpp Tue Jan 20 00:44:32 2015<br>
@@ -697,6 +697,10 @@ void TypePrinter::printFunctionProtoAfte<br>
     case CC_X86_64SysV:<br>
       OS << " __attribute__((sysv_abi))";<br>
       break;<br>
+    case CC_SpirFunction:<br>
+    case CC_SpirKernel:<br>
+      // Do nothing. These CCs are not available as attributes.<br>
+      break;<br>
     }<br>
   }<br>
<br>
<br>
Modified: cfe/trunk/lib/Basic/Targets.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=226548&r1=226547&r2=226548&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=226548&r1=226547&r2=226548&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Basic/Targets.cpp (original)<br>
+++ cfe/trunk/lib/Basic/Targets.cpp Tue Jan 20 00:44:32 2015<br>
@@ -6346,6 +6346,15 @@ namespace {<br>
     BuiltinVaListKind getBuiltinVaListKind() const override {<br>
       return TargetInfo::VoidPtrBuiltinVaList;<br>
     }<br>
+<br>
+    CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {<br>
+      return (CC == CC_SpirFunction ||<br>
+              CC == CC_SpirKernel) ? CCCR_OK : CCCR_Warning;<br>
+    }<br>
+<br>
+    CallingConv getDefaultCallingConv(CallingConvMethodType MT) const override {<br>
+      return CC_SpirFunction;<br>
+    }<br>
   };<br>
<br>
<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGCall.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=226548&r1=226547&r2=226548&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=226548&r1=226547&r2=226548&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Tue Jan 20 00:44:32 2015<br>
@@ -51,6 +51,8 @@ static unsigned ClangCallConvToLLVMCallC<br>
   case CC_X86Pascal: return llvm::CallingConv::C;<br>
   // TODO: Add support for __vectorcall to LLVM.<br>
   case CC_X86VectorCall: return llvm::CallingConv::X86_VectorCall;<br>
+  case CC_SpirFunction: return llvm::CallingConv::SPIR_FUNC;<br>
+  case CC_SpirKernel: return llvm::CallingConv::SPIR_KERNEL;<br>
   }<br>
 }<br>
<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaType.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=226548&r1=226547&r2=226548&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=226548&r1=226547&r2=226548&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaType.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaType.cpp Tue Jan 20 00:44:32 2015<br>
@@ -2476,8 +2476,24 @@ getCCForDeclaratorChunk(Sema &S, Declara<br>
     }<br>
   }<br>
<br>
-  return S.Context.getDefaultCallingConvention(FTI.isVariadic,<br>
-                                               IsCXXInstanceMethod);<br>
+  CallingConv CC = S.Context.getDefaultCallingConvention(FTI.isVariadic,<br>
+                                                         IsCXXInstanceMethod);<br>
+<br>
+  // Attribute AT_OpenCLKernel affects the calling convention only on<br>
+  // the SPIR target, hence it cannot be treated as a calling<br>
+  // convention attribute. This is the simplest place to infer<br>
+  // "spir_kernel" for OpenCL kernels on SPIR.<br>
+  if (CC == CC_SpirFunction) {<br>
+    for (const AttributeList *Attr = D.getDeclSpec().getAttributes().getList();<br>
+         Attr; Attr = Attr->getNext()) {<br>
+      if (Attr->getKind() == AttributeList::AT_OpenCLKernel) {<br>
+        CC = CC_SpirKernel;<br>
+        break;<br>
+      }<br>
+    }<br>
+  }<br>
+<br>
+  return CC;<br>
 }<br>
<br>
 static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,<br>
<br>
Added: cfe/trunk/test/CodeGenOpenCL/<a href="http://spir-calling-conv.cl" target="_blank">spir-calling-conv.cl</a><br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/spir-calling-conv.cl?rev=226548&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/spir-calling-conv.cl?rev=226548&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenOpenCL/<a href="http://spir-calling-conv.cl" target="_blank">spir-calling-conv.cl</a> (added)<br>
+++ cfe/trunk/test/CodeGenOpenCL/<a href="http://spir-calling-conv.cl" target="_blank">spir-calling-conv.cl</a> Tue Jan 20 00:44:32 2015<br>
@@ -0,0 +1,18 @@<br>
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - | FileCheck %s<br>
+<br>
+int get_dummy_id(int D);<br>
+<br>
+kernel void bar(global int *A);<br>
+<br>
+kernel void foo(global int *A)<br>
+// CHECK: define spir_kernel void @foo(i32 addrspace(1)* %A)<br>
+{<br>
+  int id = get_dummy_id(0);<br>
+  // CHECK: %call = tail call spir_func i32 @get_dummy_id(i32 0)<br></blockquote><div><br></div></div></div><div>This <a href="http://lab.llvm.org:8080/green/job/clang-stage2-configure-Rlto_check/1183/" target="_blank">test fails</a>. Please fix or revert.</div></div></div></div></blockquote><div><br></div><div>Clarification: this test fails only in some configurations, thus it doesn't look like a trivial typo in the test which I could fix myself.</div><div><br></div><div>This is blocking us, so I'm going to revert the revision.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Thanks!</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+  A[id] = id;<br>
+  bar(A);<br>
+  // CHECK: tail call spir_kernel void @bar(i32 addrspace(1)* %A)<br>
+}<br>
+<br>
+// CHECK: declare spir_func i32 @get_dummy_id(i32)<br>
+// CHECK: declare spir_kernel void @bar(i32 addrspace(1)*)<br>
<br>
Modified: cfe/trunk/tools/libclang/CXType.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXType.cpp?rev=226548&r1=226547&r2=226548&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXType.cpp?rev=226548&r1=226547&r2=226548&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/tools/libclang/CXType.cpp (original)<br>
+++ cfe/trunk/tools/libclang/CXType.cpp Tue Jan 20 00:44:32 2015<br>
@@ -527,6 +527,9 @@ CXCallingConv clang_getFunctionTypeCalli<br>
       TCALLINGCONV(AAPCS_VFP);<br>
       TCALLINGCONV(PnaclCall);<br>
       TCALLINGCONV(IntelOclBicc);<br>
+    case CC_SpirFunction: return CXCallingConv_Unexposed;<br>
+    case CC_SpirKernel: return CXCallingConv_Unexposed;<br>
+      break;<br>
     }<br>
 #undef TCALLINGCONV<br>
   }<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></span></div><br></div></div></blockquote></div>
</div></div>