forked from KhronosGroup/SPIRV-LLVM-Translator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport to 17] Introduce CodeSectionINTEL storage class (KhronosGro…
…up#2728) (KhronosGroup#2783) 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: KhronosGroup#1392 Co-authored-by: Dmitry Sidorov <[email protected]>
- Loading branch information
Showing
23 changed files
with
1,281 additions
and
7 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 -emit-opaque-pointers %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) | ||
|
||
; 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), i32 (i32)* @foo | ||
|
||
define spir_kernel void @bar(i64* %y) { | ||
store i64 ptrtoint (i32 (i32)* @foo.alias to i64), i64* %y | ||
ret void | ||
} |
54 changes: 54 additions & 0 deletions
54
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,54 @@ | ||
; 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 -emit-opaque-pointers %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 = bitcast i8 (i8)* @foo to i32 (i32)* | ||
%2 = call i32 %1(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)"} |
67 changes: 67 additions & 0 deletions
67
test/extensions/INTEL/SPV_INTEL_function_pointers/CodeSectionINTEL/const-function-pointer.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,67 @@ | ||
; 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 - | FileCheck %s --check-prefix=CHECK-SPIRV | ||
; RUN: llvm-spirv -r -spirv-emit-function-ptr-addr-space -emit-opaque-pointers %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: Capability FunctionPointersINTEL | ||
; CHECK-SPIRV: Extension "SPV_INTEL_function_pointers" | ||
; CHECK-SPIRV: Name [[F1Name:[0-9]+]] "f1" | ||
; CHECK-SPIRV: Name [[F2Name:[0-9]+]] "f2" | ||
; CHECK-SPIRV-DAG: TypeInt [[Int32:[0-9]+]] 32 | ||
; CHECK-SPIRV-DAG: TypeInt [[Int64:[0-9]+]] 64 | ||
; CHECK-SPIRV-DAG: Constant [[Int32]] [[XArg:[0-9]+]] 32 | ||
; CHECK-SPIRV-DAG: Constant [[Int32]] [[YArg:[0-9]+]] 2 | ||
|
||
; CHECK-SPIRV: ConstantFunctionPointerINTEL {{[0-9]+}} [[F1:[0-9]+]] [[F1Name]] | ||
; CHECK-SPIRV: ConstantFunctionPointerINTEL {{[0-9]+}} [[F2:[0-9]+]] [[F2Name]] | ||
; CHECK-SPIRV: ConstantComposite {{[0-9]+}} [[ConstComp:[0-9]+]] [[F1]] [[F2]] | ||
; CHECK-SPIRV: Variable {{[0-9]+}} [[Var:[0-9]+]] {{[0-9]+}} [[ConstComp]] | ||
|
||
; CHECK-SPIRV: InBoundsPtrAccessChain {{[0-9]+}} [[GEP:[0-9]+]] [[Var]] {{[0-9]+}} {{[0-9]+}} | ||
; CHECK-SPIRV: Load {{[0-9]+}} [[FuncPtr:[0-9]+]] [[GEP]] | ||
; CHECK-SPIRV: FunctionPointerCallINTEL [[Int32]] {{[0-9]+}} [[FuncPtr]] [[XArg]] [[YArg]] | ||
|
||
; CHECK-LLVM: @__const.main.funcs = internal constant [2 x ptr addrspace(9)] [ptr addrspace(9) @f1, ptr addrspace(9) @f2], align 16 | ||
; CHECK-LLVM: %[[Idx:[a-z0-9]+]] = getelementptr inbounds [2 x ptr addrspace(9)], ptr @__const.main.funcs, i64 0, i64 %{{[a-z0-9]+}} | ||
; CHECK-LLVM: %[[FuncPtr:[a-z0-9]+]] = load ptr addrspace(9), ptr %[[Idx]], align 8 | ||
; CHECK-LLVM: %{{[a-z0-9]+}} = call spir_func addrspace(9) i32 %[[FuncPtr]](i32 32, i32 2) | ||
|
||
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "spir-unknown-unknown" | ||
|
||
@__const.main.funcs = private unnamed_addr constant [2 x i32 (i32, i32)*] [i32 (i32, i32)* @f1, i32 (i32, i32)* @f2], align 16 | ||
|
||
; Function Attrs: norecurse nounwind readnone uwtable | ||
define dso_local i32 @f1(i32 %a, i32 %b) #0 { | ||
entry: | ||
%add = add nsw i32 %b, %a | ||
ret i32 %add | ||
} | ||
|
||
; Function Attrs: norecurse nounwind readnone uwtable | ||
define dso_local i32 @f2(i32 %a, i32 %b) #0 { | ||
entry: | ||
%sub = sub nsw i32 %a, %b | ||
ret i32 %sub | ||
} | ||
|
||
; Function Attrs: nounwind uwtable | ||
define dso_local i32 @main() local_unnamed_addr #1 { | ||
entry: | ||
%call = tail call i32 @rand() #3 | ||
%rem = srem i32 %call, 2 | ||
%idxprom = sext i32 %rem to i64 | ||
%arrayidx = getelementptr inbounds [2 x i32 (i32, i32)*], [2 x i32 (i32, i32)*]* @__const.main.funcs, i64 0, i64 %idxprom | ||
%0 = load i32 (i32, i32)*, i32 (i32, i32)** %arrayidx, align 8 | ||
%call1 = tail call i32 %0(i32 32, i32 2) #3 | ||
ret i32 %call1 | ||
} | ||
|
||
; Function Attrs: nounwind | ||
declare dso_local i32 @rand() local_unnamed_addr #2 | ||
|
||
attributes #0 = { norecurse nounwind readnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "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" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } | ||
attributes #1 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "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" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } | ||
attributes #2 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } |
Oops, something went wrong.