<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
Hi Micah, all,
<div><br>
</div>
<div>
<div>
<div>On Dec 13, 2011, at 8:49 AM, Villmow, Micah wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite"><span class="Apple-style-span" style="font-family: Calibri, sans-serif; font-size: 15px; ">If you look at the test cases, you can infer what needs to be done. Basically since this is targeted</span><span class="Apple-style-span" style="border-collapse: separate; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">
<div lang="EN-US" link="blue" vlink="purple" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
<div class="WordSection1" style="page: WordSection1; ">
<div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">
<span style="font-size: 11pt; font-family: Calibri, sans-serif; ">for OpenCL, we annotate OpenCL kernels slightly different than normal functions and that is<o:p></o:p></span></div>
<div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">
<span style="font-size: 11pt; font-family: Calibri, sans-serif; ">what causes the code to be generated. That being said, on my list of things to do is fix this so that<o:p></o:p></span></div>
<div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">
<span style="font-size: 11pt; font-family: Calibri, sans-serif; ">any function will be generated correctly and also create calling conventions that differentiate<o:p></o:p></span></div>
<div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">
<span style="font-size: 11pt; font-family: Calibri, sans-serif; ">between kernels and non-kernels.<o:p></o:p></span></div>
</div>
</div>
</span></blockquote>
<br>
</div>
<div>`triple.ll' in your patch has this metadata, but I can't see how to construct it with clang..</div>
<div><br>
</div>
<div>
<div>%0 = type { i8*, i8*, i8*, i8*, i32 }</div>
<div><br>
</div>
<div>@sgv = internal addrspace(2) constant [1 x i8] zeroinitializer</div>
<div>@fgv = internal addrspace(2) constant [1 x i8] zeroinitializer</div>
<div>@lvgv = internal constant [0 x i8*] zeroinitializer</div>
<div>@llvm.global.annotations = appending global [1 x %0] [%0 { i8* bitcast (void ()* @__OpenCL_foo_kernel to i8*), i8* bitcast ([1 x i8] addrspace(2)* @sgv to i8*), i8* bitcast ([1 x i8] addrspace(2)* @fgv to i8*), i8* bitcast ([0 x i8*]* @lvgv to i8*), i32
 0 }], section "llvm.metadata"</div>
<div><br>
</div>
<div>define void @__OpenCL_foo_kernel() nounwind readnone {</div>
<div>entry:</div>
<div>  ret void</div>
<div>}</div>
<div><br>
</div>
<div>Here's my attempt..  I'm guessing that __kernel in OpenCL triggers your annotation, but when I try to use annotate("doesNothing") there's no sign of "doesNothing" in the resulting IR.</div>
<div>Thus, my attempt with the function pointers.   %0 still has a different form, however.</div>
<div>What do "sgv" and "fgv" stand for?  Stack & Frame?   The semantics of these isn't obvious from the test cases.</div>
<div><br>
</div>
<div><br>
</div>
</div>
<div>
<div>
<div>
<div>
<div>$ cat a.c</div>
<div>static const char __attribute__ ((address_space(2))) sgv[1];</div>
<div>static const char __attribute__ ((address_space(2))) fgv[1];</div>
<div>static const char* lvgv[0];</div>
<div><br>
</div>
<div>void __attribute__ ((annotate("doesNothing"))) func () {</div>
<div>  char val;</div>
<div>  val = sgv[0];</div>
<div>  val = fgv[0];</div>
<div>  val = *lvgv[0];</div>
<div>}</div>
<div><br>
</div>
<div>void __attribute__ ((annotate("foobar"))) (*__OpenCL_my_kernel) ()  = func;</div>
<div>$ clang -S -emit-llvm a.c</div>
<div>$ cat a.s</div>
<div>; ModuleID = 'a.c'</div>
<div>target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"</div>
<div>target triple = "x86_64-unknown-linux-gnu"</div>
<div><br>
</div>
<div>%0 = type { i8*, i8*, i8*, i32 }</div>
<div><br>
</div>
<div>@sgv = internal addrspace(2) constant [1 x i8] zeroinitializer, align 1</div>
<div>@fgv = internal addrspace(2) constant [1 x i8] zeroinitializer, align 1</div>
<div>@lvgv = internal global [0 x i8*] zeroinitializer, align 8</div>
<div>@__OpenCL_my_kernel = global void (...)* bitcast (void ()* @func to void (...)*), align 8</div>
<div>@__OpenCL_my_kernel1 = private global [7 x i8] c"foobar\00"</div>
<div>@.str = private unnamed_addr global [4 x i8] c"a.c\00"</div>
<div>@llvm.global.annotations = appending global [1 x %0] [%0 { i8* bitcast (void (...)** @__OpenCL_my_kernel to i8*), i8* getelementptr inbounds ([7 x i8]* @__OpenCL_my_kernel1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8]* @.str, i32 0, i32 0), i32
 12 }], section "llvm.metadata"</div>
<div><br>
</div>
<div>define void @func() nounwind {</div>
<div>  %val = alloca i8, align 1</div>
<div>  %1 = load i8 addrspace(2)* getelementptr inbounds ([1 x i8] addrspace(2)* @sgv, i32 0, i64 0)</div>
<div>  store i8 %1, i8* %val, align 1</div>
<div>  %2 = load i8 addrspace(2)* getelementptr inbounds ([1 x i8] addrspace(2)* @fgv, i32 0, i64 0)</div>
<div>  store i8 %2, i8* %val, align 1</div>
<div>  %3 = load i8** getelementptr inbounds ([0 x i8*]* @lvgv, i32 0, i64 0)</div>
<div>  %4 = load i8* %3</div>
<div>  store i8 %4, i8* %val, align 1</div>
<div>  ret void</div>
<div>}</div>
<div><br>
</div>
<div>
<div>Adding "__kernel" to "func" does create some metadata when clang is in OpenCL mode, and the IR looks like this:</div>
<div><br>
</div>
<div>
<div>!opencl.kernels = !{!0}</div>
<div><br>
</div>
<div>!0 = metadata !{void ()* @func}</div>
</div>
</div>
</div>
<div><br>
</div>
<div>Cheers,</div>
<div><br>
</div>
<div>Marcus</div>
</div>
</div>
</div>
</div>
</body>
</html>