-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce CodeSectionINTEL storage class (#2728)
This storage class is used for function pointers. It's added as based on cl_intel_function_pointers specification, it is not guaranteed that sizeof(void(*)(void) == sizeof(void *) - to allow consumers use this fact, we cannot say that function pointer belongs to the same storage class as data pointers. It wasn't added during initial implementation, now it's time to fill this gap. As it would be a breaking change its generation is added only under -spirv-emit-function-ptr-addr-space option. Also SPIR-V consumer may pass this option during reverse translation to get new address space even in a case, when OpConstantFunctionPointerINTEL doesn't reside in CodeSectionINTEL storage class. Expected behavior: No option is passed to the forward translation stage and function pointers are in addrspace(9): no CodeSectionINTEL storage class in SPIR-V The option is passed to the forward translation stage and function pointers are in addrepace(9): CodeSectionINTEL storage class is generated No option is passed to the reverse translation stage: function pointers are in private address space The option is passed to the reverse translation stage: function pointers are in addrspace(9) Spec: https://github.com/intel/llvm/blob/sycl/sycl/doc/design/spirv-extensions/SPV_INTEL_function_pointers.asciidoc The previous approach: #1392
- Loading branch information
Showing
24 changed files
with
1,311 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
test/extensions/INTEL/SPV_INTEL_function_pointers/CodeSectionINTEL/alias.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
; RUN: llvm-as %s -o %t.bc | ||
; RUN: llvm-spirv -spirv-ext=+SPV_INTEL_function_pointers -spirv-text %t.bc -o - | FileCheck %s --check-prefix=CHECK-SPIRV | ||
; RUN: llvm-spirv -spirv-ext=+SPV_INTEL_function_pointers %t.bc -o %t.spv | ||
; RUN: llvm-spirv -r -spirv-emit-function-ptr-addr-space %t.spv -o - | llvm-dis -o - | FileCheck %s --check-prefix=CHECK-LLVM | ||
|
||
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" | ||
target triple = "spir64-unknown-unknown" | ||
|
||
; Check that aliases are dereferenced and translated to their aliasee values | ||
; when used since they can't be translated directly. | ||
|
||
; CHECK-SPIRV-DAG: Name [[#FOO:]] "foo" | ||
; CHECK-SPIRV-DAG: Name [[#BAR:]] "bar" | ||
; CHECK-SPIRV-DAG: Name [[#Y:]] "y" | ||
; CHECK-SPIRV-DAG: Name [[#FOOPTR:]] "foo.alias" | ||
; CHECK-SPIRV-DAG: Decorate [[#FOO]] LinkageAttributes "foo" Export | ||
; CHECK-SPIRV-DAG: Decorate [[#BAR]] LinkageAttributes "bar" Export | ||
; CHECK-SPIRV-DAG: TypeInt [[#I32:]] 32 0 | ||
; CHECK-SPIRV-DAG: TypeInt [[#I64:]] 64 0 | ||
; CHECK-SPIRV-DAG: TypeFunction [[#FOO_TYPE:]] [[#I32]] [[#I32]] | ||
; CHECK-SPIRV-DAG: TypeVoid [[#VOID:]] | ||
; CHECK-SPIRV-DAG: TypePointer [[#I64PTR:]] 7 [[#I64]] | ||
; CHECK-SPIRV-DAG: TypeFunction [[#BAR_TYPE:]] [[#VOID]] [[#I64PTR]] | ||
; CHECK-SPIRV-DAG: TypePointer [[#FOOPTR_TYPE:]] 7 [[#FOO_TYPE]] | ||
; CHECK-SPIRV-DAG: ConstantFunctionPointerINTEL [[#FOOPTR_TYPE]] [[#FOOPTR]] [[#FOO]] | ||
|
||
; CHECK-SPIRV: Function [[#I32]] [[#FOO]] 0 [[#FOO_TYPE]] | ||
|
||
; CHECK-SPIRV: Function [[#VOID]] [[#BAR]] 0 [[#BAR_TYPE]] | ||
; CHECK-SPIRV: FunctionParameter [[#I64PTR]] [[#Y]] | ||
; CHECK-SPIRV: ConvertPtrToU [[#I64]] [[#PTRTOINT:]] [[#FOOPTR]] | ||
; CHECK-SPIRV: Store [[#Y]] [[#PTRTOINT]] 2 8 | ||
|
||
; CHECK-LLVM: define spir_func i32 @foo(i32 %x) addrspace(9) | ||
|
||
; CHECK-LLVM: define spir_kernel void @bar(ptr %y) | ||
; CHECK-LLVM: [[PTRTOINT:%.*]] = ptrtoint ptr addrspace(9) @foo to i64 | ||
; CHECK-LLVM: store i64 [[PTRTOINT]], ptr %y, align 8 | ||
|
||
define spir_func i32 @foo(i32 %x) { | ||
ret i32 %x | ||
} | ||
|
||
@foo.alias = internal alias i32 (i32), ptr @foo | ||
|
||
define spir_kernel void @bar(ptr %y) { | ||
store i64 ptrtoint (ptr @foo.alias to i64), ptr %y | ||
ret void | ||
} |
53 changes: 53 additions & 0 deletions
53
test/extensions/INTEL/SPV_INTEL_function_pointers/CodeSectionINTEL/bitcast.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
; OpenCL C source: | ||
; char foo(char a) { | ||
; return a; | ||
; } | ||
; void bar() { | ||
; int (*fun_ptr)(int) = &foo; | ||
; fun_ptr(0); | ||
; } | ||
|
||
; RUN: llvm-as %s -o %t.bc | ||
; RUN: llvm-spirv %t.bc -spirv-ext=+SPV_INTEL_function_pointers -o %t.spv | ||
; RUN: llvm-spirv %t.spv -to-text -o %t.spt | ||
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV | ||
; RUN: llvm-spirv -r -spirv-emit-function-ptr-addr-space %t.spv -o %t.r.bc | ||
; RUN: llvm-dis %t.r.bc -o %t.r.ll | ||
; RUN: FileCheck < %t.r.ll %s --check-prefix=CHECK-LLVM | ||
|
||
; CHECK-SPIRV-DAG: TypeInt [[#I8:]] 8 | ||
; CHECK-SPIRV-DAG: TypeInt [[#I32:]] 32 | ||
; CHECK-SPIRV-DAG: TypeFunction [[#FOO_TY:]] [[#I8]] [[#I8]] | ||
; CHECK-SPIRV-DAG: TypeFunction [[#DEST_TY:]] [[#I32]] [[#I32]] | ||
; CHECK-SPIRV-DAG: TypePointer [[#DEST_TY_PTR:]] [[#]] [[#DEST_TY]] | ||
; CHECK-SPIRV-DAG: TypePointer [[#FOO_TY_PTR:]] [[#]] [[#FOO_TY]] | ||
; CHECK-SPIRV: ConstantFunctionPointerINTEL [[#FOO_TY_PTR]] [[#FOO_PTR:]] [[#FOO:]] | ||
; CHECK-SPIRV: Function [[#]] [[#FOO]] [[#]] [[#FOO_TY]] | ||
|
||
; CHECK-SPIRV: Bitcast [[#DEST_TY_PTR]] [[#]] [[#FOO_PTR]] | ||
|
||
; CHECK-LLVM: bitcast ptr addrspace(9) @foo to ptr addrspace(9) | ||
|
||
; ModuleID = './example.c' | ||
source_filename = "./example.c" | ||
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" | ||
target triple = "spir" | ||
|
||
; Function Attrs: noinline nounwind optnone | ||
define dso_local spir_func signext i8 @foo(i8 signext %0) #0 { | ||
ret i8 %0 | ||
} | ||
|
||
; Function Attrs: noinline nounwind optnone | ||
define dso_local spir_func void @bar() #0 { | ||
%1 = call i32 @foo(i32 0) | ||
ret void | ||
} | ||
|
||
attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } | ||
|
||
!llvm.module.flags = !{!0} | ||
!llvm.ident = !{!1} | ||
|
||
!0 = !{i32 1, !"wchar_size", i32 4} | ||
!1 = !{!"clang version 11.0.0 (https://github.com/llvm/llvm-project.git 0e1accd0f726eef2c47be9f37dd0a06cb50d207e)"} |
Oops, something went wrong.