Hello,
I’d like to know the format a function’s name must conform to. Can I be pointed to LLVM documention that specifies the nomenclature for functions and other Identifiers as well (%registers, ModuleID etc.) ?
Thanks,
Sanjay
Hello,
I’d like to know the format a function’s name must conform to. Can I be pointed to LLVM documention that specifies the nomenclature for functions and other Identifiers as well (%registers, ModuleID etc.) ?
Thanks,
Sanjay
Perhaps you can refer to [1]. Function name should be a global one.
[1] http://llvm.org/docs/LangRef.html#identifiers
HTH,
chenwj
Thank You Chen !
Hi Sanjay,
since I’ve seen you working with GPU code generation, one additional heads up: You must take care that your function names are also legal in the target architecture (such as PTX).
While backends can legalize function names, NVPTX can’t/doesn’t (it can’t, really, because kernel invocation can be done by a name string). This means that you mustn’t have, e.g., a dot in your function name. The dot is legal in an LLVM identifier, but not in a ptx function name. This also is noteworthy because the slot tracker automatically inserts dots into function names for deduplication.
Best,
Philip
Thanks for the heads up Philip !
I did come across a strange case where LLVM allowed “%” to be a part of a function’s name. This was in the context of my patch https://reviews.llvm.org/D33985, where I prefix the name of the source function and the Scop ( A special kind of Region that Polly can optimize, the name of the Scop is the name of the Region ) to the name of the PTX kernel generated from the Scop. For e.g. The edits like the following to <polly_src>/lib/CodeGen/PPCGCodeGeneration.cpp achieves the above mentioned prefixing,
@@ -1419,7 +1438,9 @@ void GPUNodeBuilder::createKernel(__isl_take isl_ast_node *KernelStmt) {
Builder.SetInsertPoint(&HostInsertPoint);
Value *Parameters = createLaunchParameters(Kernel, F, SubtreeValues);
(Where getOrigName returns the name of the Scop before the IRBuilder modified it)
Produces the effect,
— a/test/GPGPU/kernel-params-only-some-arrays.ll
+++ b/test/GPGPU/kernel-params-only-some-arrays.ll
@@ -16,12 +16,12 @@
; B[i] += 42;
; }
-; KERNEL: ; ModuleID = ‘kernel_0’
-; KERNEL-NEXT: source_filename = “kernel_0”
+; KERNEL: ; ModuleID = ‘kernel_params_only_some_arrays_%or.cond—%or.end9_kernel_0’
+; KERNEL-NEXT: source_filename = “kernel_params_only_some_arrays_%or.cond—%or.end9_kernel_0”
I don’t understand how Module verification was fine with this name. What are your thoughts ?
Produces the effect,
--- a/test/GPGPU/kernel-params-only-some-arrays.ll
<polly/kernel-params-only-some-arrays.ll at 6b8cb877c2fa3ee0e626cac5811115a9c5c71b5b · llvm-mirror/polly · GitHub;
+++ b/test/GPGPU/kernel-params-only-some-arrays.ll
@@ -16,12 +16,12 @@
; B[i] += 42;
; }-; KERNEL: ; ModuleID = 'kernel_0'
-; KERNEL-NEXT: source_filename = "kernel_0"
+; KERNEL: ; ModuleID = 'kernel_params_only_some_
arrays_%or.cond---%or.end9_kernel_0'
+; KERNEL-NEXT: source_filename = "kernel_params_only_some_
arrays_%or.cond---%or.end9_kernel_0"I don't understand how Module verification
<polly/PPCGCodeGeneration.cpp at 6b8cb877c2fa3ee0e626cac5811115a9c5c71b5b · llvm-mirror/polly · GitHub;
was fine with this name. What are your thoughts ?
I think ModuleID and source_filename are just simple string, or they are
not? I don't see any function name here.
Hello Chen,
Here’s some context. kernel-params-only-some-arrays.ll is a file used to test Polly’s GPU codegeneration feature. I had made changes to Polly to rename the PTX functions it would produce, So these changes had to reflect in this test case as well. Here’s the entire diff,
— a/test/GPGPU/kernel-params-only-some-arrays.ll
+++ b/test/GPGPU/kernel-params-only-some-arrays.ll
@@ -16,12 +16,12 @@
; B[i] += 42;
; }
-; KERNEL: ; ModuleID = ‘kernel_0’
-; KERNEL-NEXT: source_filename = “kernel_0”
+; KERNEL: ; ModuleID = ‘kernel_params_only_some_arrays_%or.cond—%or.end9_kernel_0’
+; KERNEL-NEXT: source_filename = “kernel_params_only_some_arrays_%or.cond—%or.end9_kernel_0”
; KERNEL-NEXT: 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-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64”
; KERNEL-NEXT: target triple = “nvptx64-nvidia-cuda”
-; KERNEL: define ptx_kernel void @kernel_0(i8 addrspace(1)* %MemRef_A)
+; KERNEL: define ptx_kernel void @kernel_params_only_some_arrays_%or.cond—%or.end9_kernel_0(i8 addrspace(1)* %MemRef_A)
; KERNEL-NEXT: entry:
; KERNEL-NEXT: %0 = call i32 @llvm.nvvm.read.ptx.sreg.ctaid.x()
; KERNEL-NEXT: %b0 = zext i32 %0 to i64
@@ -31,12 +31,12 @@
; KERNEL: ret void
; KERNEL-NEXT: }
-; KERNEL: ; ModuleID = ‘kernel_1’
-; KERNEL-NEXT: source_filename = “kernel_1”
+; KERNEL: ; ModuleID = ‘kernel_params_only_some_arrays_%or.cond—%or.end9_kernel_1’
+; KERNEL-NEXT: source_filename = “kernel_params_only_some_arrays_%or.cond—%or.end9_kernel_1”
; KERNEL-NEXT: 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-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64”
; KERNEL-NEXT: target triple = “nvptx64-nvidia-cuda”
-; KERNEL: define ptx_kernel void @kernel_1(i8 addrspace(1)* %MemRef_B)
+; KERNEL: define ptx_kernel void @kernel_params_only_some_arrays_%or.cond—%or.end9_kernel_1(i8 addrspace(1)* %MemRef_B)
; KERNEL-NEXT: entry:
; KERNEL-NEXT: %0 = call i32 @llvm.nvvm.read.ptx.sreg.ctaid.x()
; KERNEL-NEXT: %b0 = zext i32 %0 to i64
I couldn’t understand how “%” was actually a part of the name of a function. The module was also passed to verifyModule here, which puzzles me even more.
$
llc sum.ll
llc: sum.ll:7:15: error: expected '(' in function argument list
define i32 @su%%%%m(i32 %a, i32 %b) #0 {
^
My `llc` reports error on the function name with %. The only difference I
can tell is your function
started with "define ptx_kernel". Do you think that make verify rule
different?
Regards,
chenwj