Skip to content

Commit ef0165a

Browse files
authored
Fix reverse translation for a decoration applied to a function parameter (#2232)
This fixes reverse translation for SPV_INTEL_fpga_memory_accesses. Theoretically it fixes more, but seems like without the extension we don't generate UserSemantic decoration in this case at all. Will be investigated separately. Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com>
1 parent 55966ee commit ef0165a

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

lib/SPIRV/SPIRVReader.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,9 +2352,12 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
23522352

23532353
case OpFunctionCall: {
23542354
SPIRVFunctionCall *BC = static_cast<SPIRVFunctionCall *>(BV);
2355-
auto *Call = CallInst::Create(transFunction(BC->getFunction()),
2356-
transValue(BC->getArgumentValues(), F, BB),
2355+
std::vector<Value *> Args = transValue(BC->getArgumentValues(), F, BB);
2356+
auto *Call = CallInst::Create(transFunction(BC->getFunction()), Args,
23572357
BC->getName(), BB);
2358+
for (auto *Arg : Args)
2359+
if (Arg->getType()->isPointerTy())
2360+
replaceOperandWithAnnotationIntrinsicCallResult(F, Arg);
23582361
setCallingConv(Call);
23592362
setAttrByCalledFunc(Call);
23602363
return mapValue(BV, Call);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_fpga_memory_accesses -o %t.spv
3+
; RUN: llvm-spirv %t.spv -to-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV
4+
5+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
6+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
7+
8+
; CHECK-SPIRV-DAG: Capability FPGAMemoryAccessesINTEL
9+
; CHECK-SPIRV-DAG: Extension "SPV_INTEL_fpga_memory_accesses"
10+
; CHECK-SPIRV: Decorate [[#DecTarget:]] BurstCoalesceINTEL
11+
; CHECK-SPIRV: FunctionCall [[#]] [[#DecTarget]]
12+
13+
; CHECK-LLVM: [[#GV:]] = private unnamed_addr constant [11 x i8] c"{params:1}\00"
14+
; CHECK-LLVM: %[[Call:[a-z0-9_.]+]] = call spir_func ptr addrspace(4) @accessor
15+
; CHECK-LLVM: %[[#Ann:]] = call ptr addrspace(4) @llvm.ptr.annotation.p4.p0(ptr addrspace(4) %call, ptr @[[#GV]], ptr undef, i32 undef, ptr undef)
16+
; CHECK-LLVM: call spir_func ptr addrspace(4) @_ZN8MyStructaSERKS_(ptr addrspace(4) %[[#Ann]]
17+
18+
; ModuleID = 'test.bc'
19+
source_filename = "llvm-link"
20+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
21+
target triple = "spir64-unknown-unknown"
22+
23+
%struct.MyStruct = type { i32 }
24+
25+
$_ZN8MyStructaSERKS_ = comdat any
26+
27+
$accessor = comdat any
28+
29+
@.str.1 = private unnamed_addr addrspace(1) constant [14 x i8] c"<invalid loc>\00", section "llvm.metadata"
30+
@.str.2 = private unnamed_addr addrspace(1) constant [11 x i8] c"{params:1}\00", section "llvm.metadata"
31+
32+
define spir_func void @foo(ptr %Ptr, ptr byval(%struct.MyStruct) align 4 %Val) {
33+
entry:
34+
%Ptr.ascast = addrspacecast ptr %Ptr to ptr addrspace(4)
35+
%Val.ascast = addrspacecast ptr %Val to ptr addrspace(4)
36+
%call = call spir_func noundef ptr addrspace(4) @accessor(ptr addrspace(4) %Ptr.ascast)
37+
%0 = call ptr addrspace(4) @llvm.ptr.annotation.p4.p1(ptr addrspace(4) %call, ptr addrspace(1) @.str.2, ptr addrspace(1) @.str.1, i32 0, ptr addrspace(1) null)
38+
%call1 = call spir_func ptr addrspace(4) @_ZN8MyStructaSERKS_(ptr addrspace(4) %0, ptr addrspace(4) %Val.ascast)
39+
ret void
40+
}
41+
42+
declare ptr addrspace(4) @llvm.ptr.annotation.p4.p1(ptr addrspace(4), ptr addrspace(1), ptr addrspace(1), i32, ptr addrspace(1))
43+
44+
declare spir_func ptr addrspace(4) @_ZN8MyStructaSERKS_(ptr addrspace(4) %this, ptr addrspace(4) %op)
45+
46+
declare spir_func ptr addrspace(4) @accessor(ptr addrspace(4) %this)

0 commit comments

Comments
 (0)