Skip to content

Commit 791d407

Browse files
DmitryBushevAlexeySotkin
authored andcommitted
Update translator for new Fast Composite extension
SPV_INTEL_fast_composite extension specification separated some decorations and execution modes from SPV_INTEL_vector_compute
1 parent d593a5d commit 791d407

File tree

10 files changed

+67
-13
lines changed

10 files changed

+67
-13
lines changed

lib/SPIRV/SPIRVReader.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,12 @@ bool SPIRVToLLVM::transMetadata() {
23732373
transOCLMetadata(BF);
23742374
transVectorComputeMetadata(BF);
23752375

2376+
if (BF->hasDecorate(DecorationCallableFunctionINTEL))
2377+
F->addFnAttr(kVCMetadata::VCCallable);
2378+
if (isKernel(BF) &&
2379+
BF->getExecutionMode(ExecutionModeFastCompositeKernelINTEL))
2380+
F->addFnAttr(kVCMetadata::VCFCEntry);
2381+
23762382
if (F->getCallingConv() != CallingConv::SPIR_KERNEL)
23772383
continue;
23782384

@@ -2509,8 +2515,6 @@ bool SPIRVToLLVM::transVectorComputeMetadata(SPIRVFunction *BF) {
25092515
SPIRVWord SIMTMode = 0;
25102516
if (BF->hasDecorate(DecorationSIMTCallINTEL, 0, &SIMTMode))
25112517
F->addFnAttr(kVCMetadata::VCSIMTCall, std::to_string(SIMTMode));
2512-
if (BF->hasDecorate(DecorationVectorComputeCallableFunctionINTEL))
2513-
F->addFnAttr(kVCMetadata::VCCallable);
25142518

25152519
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E;
25162520
++I) {

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,9 @@ SPIRVFunction *LLVMToSPIRV::transFunctionDecl(Function *F) {
533533
if (Attrs.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt))
534534
BF->addDecorate(DecorationFuncParamAttr, FunctionParameterAttributeSext);
535535

536+
if (Attrs.hasFnAttribute(kVCMetadata::VCCallable))
537+
BF->addDecorate(DecorationCallableFunctionINTEL);
538+
536539
transVectorComputeMetadata(F);
537540

538541
SPIRVDBG(dbgs() << "[transFunction] " << *F << " => ";
@@ -565,10 +568,6 @@ void LLVMToSPIRV::transVectorComputeMetadata(Function *F) {
565568
BF->addDecorate(DecorationSIMTCallINTEL, SIMTMode);
566569
}
567570

568-
if (Attrs.hasFnAttribute(kVCMetadata::VCCallable)) {
569-
BF->addDecorate(DecorationVectorComputeCallableFunctionINTEL);
570-
}
571-
572571
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E;
573572
++I) {
574573
auto ArgNo = I->getArgNo();
@@ -1637,6 +1636,10 @@ bool LLVMToSPIRV::transExecutionMode() {
16371636
BF->addExecutionMode(BM->add(new SPIRVExecutionMode(
16381637
BF, static_cast<ExecutionMode>(EMode), TargetWidth)));
16391638
} break;
1639+
case spv::ExecutionModeFastCompositeKernelINTEL: {
1640+
BF->addExecutionMode(BM->add(
1641+
new SPIRVExecutionMode(BF, static_cast<ExecutionMode>(EMode))));
1642+
} break;
16401643
default:
16411644
llvm_unreachable("invalid execution mode");
16421645
}

lib/SPIRV/TransOCLMD.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ void TransOCLMD::preprocessVectorComputeMetadata(Module *M, SPIRVMDBuilder *B,
271271
.add(SLMSize)
272272
.done();
273273
}
274+
if (Attrs.hasFnAttribute(kVCMetadata::VCFCEntry)) {
275+
EM.addOp().add(&F).add(spv::ExecutionModeFastCompositeKernelINTEL).done();
276+
}
274277
}
275278
}
276279

lib/SPIRV/VectorComputeUtil.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ const static char VCVolatile[] = "VCVolatile";
109109
const static char VCByteOffset[] = "VCByteOffset";
110110
const static char VCSIMTCall[] = "VCSIMTCall";
111111
const static char VCCallable[] = "VCCallable";
112+
const static char VCFCEntry[] = "VCFCEntry";
112113
} // namespace kVCMetadata
113114

114115
namespace kVCType {

lib/SPIRV/libSPIRV/SPIRVEnum.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ template <> inline void SPIRVMap<SPIRVExecutionModeKind, SPIRVCapVec>::init() {
247247
{CapabilityFloatingPointModeINTEL});
248248
ADD_VEC_INIT(ExecutionModeSharedLocalMemorySizeINTEL,
249249
{CapabilityVectorComputeINTEL});
250+
ADD_VEC_INIT(ExecutionModeFastCompositeKernelINTEL,
251+
{CapabilityFastCompositeINTEL});
250252
}
251253

252254
template <> inline void SPIRVMap<SPIRVMemoryModelKind, SPIRVCapVec>::init() {
@@ -374,8 +376,7 @@ template <> inline void SPIRVMap<Decoration, SPIRVCapVec>::init() {
374376
{CapabilityFunctionFloatControlINTEL});
375377
ADD_VEC_INIT(DecorationFunctionFloatingPointModeINTEL,
376378
{CapabilityFunctionFloatControlINTEL});
377-
ADD_VEC_INIT(DecorationVectorComputeCallableFunctionINTEL,
378-
{CapabilityVectorComputeINTEL});
379+
ADD_VEC_INIT(DecorationCallableFunctionINTEL, {CapabilityFastCompositeINTEL});
379380
}
380381

381382
template <> inline void SPIRVMap<BuiltIn, SPIRVCapVec>::init() {

lib/SPIRV/libSPIRV/SPIRVIsValidEnum.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ inline bool isValid(spv::Decoration V) {
416416
case DecorationFunctionRoundingModeINTEL:
417417
case DecorationFunctionDenormModeINTEL:
418418
case DecorationFunctionFloatingPointModeINTEL:
419-
case DecorationVectorComputeCallableFunctionINTEL:
419+
case DecorationCallableFunctionINTEL:
420420
return true;
421421
default:
422422
return false;

lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,7 @@ template <> inline void SPIRVMap<Decoration, std::string>::init() {
351351
add(DecorationFunctionDenormModeINTEL, "FunctionDenormModeINTEL");
352352
add(DecorationFunctionFloatingPointModeINTEL,
353353
"FunctionFloatingPointModeINTEL");
354-
add(DecorationVectorComputeCallableFunctionINTEL,
355-
"VectorComputeCallableFunctionINTEL");
354+
add(DecorationCallableFunctionINTEL, "CallableFunctionINTEL");
356355
}
357356
SPIRV_DEF_NAMEMAP(Decoration, SPIRVDecorationNameMap)
358357

@@ -510,6 +509,7 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
510509
add(CapabilitySubgroupAvcMotionEstimationChromaINTEL,
511510
"SubgroupAvcMotionEstimationChromaINTEL");
512511
add(CapabilityFunctionFloatControlINTEL, "FunctionFloatControlINTEL");
512+
add(CapabilityFastCompositeINTEL, "FastCompositeINTEL");
513513
}
514514
SPIRV_DEF_NAMEMAP(Capability, SPIRVCapabilityNameMap)
515515

lib/SPIRV/libSPIRV/spirv.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ enum ExecutionMode {
136136
ExecutionModeRoundingModeRTNINTEL = 5621,
137137
ExecutionModeFloatingPointModeALTINTEL = 5622,
138138
ExecutionModeFloatingPointModeIEEEINTEL = 5623,
139+
ExecutionModeFastCompositeKernelINTEL = 6088,
139140
ExecutionModeMax = 0x7fffffff,
140141
};
141142

@@ -416,7 +417,7 @@ enum Decoration {
416417
DecorationFunctionRoundingModeINTEL = 5822,
417418
DecorationFunctionDenormModeINTEL = 5823,
418419
DecorationFunctionFloatingPointModeINTEL = 6080,
419-
DecorationVectorComputeCallableFunctionINTEL = 6087,
420+
DecorationCallableFunctionINTEL = 6087,
420421
DecorationMax = 0x7fffffff,
421422
};
422423

@@ -696,6 +697,7 @@ enum Capability {
696697
CapabilityRoundToInfinityINTEL = 5582,
697698
CapabilityFloatingPointModeINTEL = 5583,
698699
CapabilityFunctionFloatControlINTEL = 5821,
700+
CapabilityFastCompositeINTEL = 6093,
699701
CapabilityMax = 0x7fffffff,
700702
};
701703

test/callable-attribute-decoration.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ define dso_local <4 x i32> @foo(<4 x i32> %a, <4 x i32> %b) #0 {
1212
entry:
1313
ret <4 x i32> %a
1414
}
15-
; CHECK-SPIRV: 3 Decorate {{[0-9]+}} VectorComputeCallableFunctionINTEL
15+
; CHECK-SPIRV: 3 Decorate {{[0-9]+}} CallableFunctionINTEL
1616
; CHECK-LLVM: attributes
1717
; CHECK-LLVM-SAME: "VCCallable"
1818

test/fast-composit-entry.ll

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv
3+
; RUN: llvm-spirv %t.spv -o %t.spt --to-text
4+
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
5+
; RUN: llvm-spirv %t.spv -o %t.bc -r
6+
; RUN: llvm-dis %t.bc -o %t.ll
7+
; RUN: FileCheck < %t.ll %s --check-prefix=CHECK-LLVM
8+
9+
target triple = "spir64-unknown-unknown"
10+
11+
12+
; CHECK-SPIRV: {{[0-9]+}} EntryPoint {{[0-9]+}} [[FOO_ID:[0-9]+]] "foo"
13+
; CHECK-SPIRV: {{[0-9]+}} EntryPoint {{[0-9]+}} [[BAR_ID:[0-9]+]] "bar"
14+
; CHECK-SPIRV: 3 ExecutionMode [[FOO_ID]] 6088
15+
; CHECK-SPIRV-NOT: 3 ExecutionMode [[BAR_ID]] 6088
16+
17+
; CHECK-LLVM: define spir_kernel void @foo
18+
; CHECK-LLVM-SAME: #[[FOO_ATTR_ID:[0-9]+]]
19+
; CHECK-LLVM: define spir_kernel void @bar
20+
; CHECK-LLVM-SAME: #[[BAR_ATTR_ID:[0-9]+]]
21+
22+
; CHECK-LLVM: attributes #[[FOO_ATTR_ID]]
23+
; CHECK-LLVM-SAME: "VCFCEntry"
24+
; CHECK-LLVM: attributes #[[BAR_ATTR_ID]]
25+
; CHECK-LLVM-NOT: "VCFCEntry"
26+
27+
28+
define spir_kernel void @foo(<4 x i32> %a, <4 x i32> %b) #0 {
29+
entry:
30+
ret void
31+
}
32+
33+
define spir_kernel void @bar(<4 x i32> %a, <4 x i32> %b) #1 {
34+
entry:
35+
ret void
36+
}
37+
38+
attributes #0 = { noinline nounwind "VCFCEntry" "VCFloatControl"="0" "VCFunction" }
39+
attributes #1 = { noinline nounwind "VCFloatControl"="48" "VCFunction" }
40+

0 commit comments

Comments
 (0)