Skip to content

Commit 56633f5

Browse files
bwlodarczsys-ce-bb
authored andcommitted
Added support for StallFreeINTEL (#2237)
Commit also adds new extension metadata FPGAClusterAttributesV2INTEL. Specification: https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/INTEL/SPV_INTEL_fpga_cluster_attributes.asciidoc Original commit: KhronosGroup/SPIRV-LLVM-Translator@4f0122b
1 parent 495c78b commit 56633f5

File tree

7 files changed

+63
-0
lines changed

7 files changed

+63
-0
lines changed

llvm-spirv/lib/SPIRV/SPIRVInternal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ const static char NoGlobalOffset[] = "no_global_work_offset";
405405
const static char MaxWGDim[] = "max_global_work_dim";
406406
const static char NumSIMD[] = "num_simd_work_items";
407407
const static char StallEnable[] = "stall_enable";
408+
const static char StallFree[] = "stall_free";
408409
const static char FmaxMhz[] = "scheduler_target_fmax_mhz";
409410
const static char LoopFuse[] = "loop_fuse";
410411
const static char PreferDSP[] = "prefer_dsp";

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4545,6 +4545,11 @@ bool SPIRVToLLVM::transFPGAFunctionMetadata(SPIRVFunction *BF, Function *F) {
45454545
MetadataVec.push_back(ConstantAsMetadata::get(getInt32(M, 1)));
45464546
F->setMetadata(kSPIR2MD::StallEnable, MDNode::get(*Context, MetadataVec));
45474547
}
4548+
if (BF->hasDecorate(DecorationStallFreeINTEL)) {
4549+
std::vector<Metadata *> MetadataVec;
4550+
MetadataVec.push_back(ConstantAsMetadata::get(getInt32(M, 1)));
4551+
F->setMetadata(kSPIR2MD::StallFree, MDNode::get(*Context, MetadataVec));
4552+
}
45484553
if (BF->hasDecorate(DecorationFuseLoopsInFunctionINTEL)) {
45494554
std::vector<Metadata *> MetadataVec;
45504555
auto Literals =

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,14 @@ void LLVMToSPIRVBase::transFPGAFunctionMetadata(SPIRVFunction *BF,
10431043
BF->addDecorate(new SPIRVDecorateStallEnableINTEL(BF));
10441044
}
10451045
}
1046+
if (MDNode *StallFree = F->getMetadata(kSPIR2MD::StallFree)) {
1047+
if (BM->isAllowedToUseExtension(
1048+
ExtensionID::SPV_INTEL_fpga_cluster_attributes)) {
1049+
if (getMDOperandAsInt(StallFree, 0)) {
1050+
BF->addDecorate(new SPIRVDecorateStallFreeINTEL(BF));
1051+
}
1052+
}
1053+
}
10461054
if (MDNode *LoopFuse = F->getMetadata(kSPIR2MD::LoopFuse)) {
10471055
if (BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_loop_fuse)) {
10481056
size_t Depth = getMDOperandAsInt(LoopFuse, 0);
@@ -2676,6 +2684,10 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
26762684
Target->addDecorate(new SPIRVDecorateStallEnableINTEL(Target));
26772685
break;
26782686
}
2687+
case DecorationStallFreeINTEL: {
2688+
Target->addDecorate(new SPIRVDecorateStallFreeINTEL(Target));
2689+
break;
2690+
}
26792691
case DecorationMergeINTEL: {
26802692
ErrLog.checkError(NumOperands == 3, SPIRVEC_InvalidLlvmModule,
26812693
"MergeINTEL requires exactly 3 extra operands");

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDecorate.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ class SPIRVDecorate : public SPIRVDecorateGeneric {
173173
return ExtensionID::SPV_INTEL_float_controls2;
174174
case DecorationStallEnableINTEL:
175175
return ExtensionID::SPV_INTEL_fpga_cluster_attributes;
176+
case DecorationStallFreeINTEL:
177+
return ExtensionID::SPV_INTEL_fpga_cluster_attributes;
176178
case DecorationFuseLoopsInFunctionINTEL:
177179
return ExtensionID::SPV_INTEL_loop_fuse;
178180
case internal::DecorationCallableFunctionINTEL:
@@ -693,6 +695,12 @@ class SPIRVDecorateStallEnableINTEL : public SPIRVDecorate {
693695
: SPIRVDecorate(spv::DecorationStallEnableINTEL, TheTarget) {}
694696
};
695697

698+
class SPIRVDecorateStallFreeINTEL : public SPIRVDecorate {
699+
public:
700+
SPIRVDecorateStallFreeINTEL(SPIRVEntry *TheTarget)
701+
: SPIRVDecorate(spv::DecorationStallFreeINTEL, TheTarget) {}
702+
};
703+
696704
class SPIRVDecorateFuseLoopsInFunctionINTEL : public SPIRVDecorate {
697705
public:
698706
// Complete constructor for SPIRVDecorateFuseLoopsInFunctionINTEL

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVEnum.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ template <> inline void SPIRVMap<Decoration, SPIRVCapVec>::init() {
466466
ADD_VEC_INIT(DecorationMediaBlockIOINTEL, {CapabilityVectorComputeINTEL});
467467
ADD_VEC_INIT(DecorationStallEnableINTEL,
468468
{CapabilityFPGAClusterAttributesINTEL});
469+
ADD_VEC_INIT(DecorationStallFreeINTEL,
470+
{CapabilityFPGAClusterAttributesV2INTEL});
469471
ADD_VEC_INIT(DecorationFuseLoopsInFunctionINTEL, {CapabilityLoopFuseINTEL});
470472
ADD_VEC_INIT(DecorationMathOpDSPModeINTEL, {CapabilityFPGADSPControlINTEL});
471473
ADD_VEC_INIT(DecorationInitiationIntervalINTEL,

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ template <> inline void SPIRVMap<Decoration, std::string>::init() {
169169
add(DecorationDontStaticallyCoalesceINTEL, "DontStaticallyCoalesceINTEL");
170170
add(DecorationPrefetchINTEL, "PrefetchINTEL");
171171
add(DecorationStallEnableINTEL, "StallEnableINTEL");
172+
add(DecorationStallFreeINTEL, "StallFreeINTEL");
172173
add(DecorationFuseLoopsInFunctionINTEL, "FuseLoopsInFunctionINTEL");
173174
add(DecorationAliasScopeINTEL, "AliasScopeINTEL");
174175
add(DecorationNoAliasINTEL, "NoAliasINTEL");
@@ -609,6 +610,7 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
609610
add(CapabilityFPGAKernelAttributesv2INTEL, "FPGAKernelAttributesv2INTEL");
610611
add(CapabilityFPGAMemoryAccessesINTEL, "FPGAMemoryAccessesINTEL");
611612
add(CapabilityFPGAClusterAttributesINTEL, "FPGAClusterAttributesINTEL");
613+
add(CapabilityFPGAClusterAttributesV2INTEL, "FPGAClusterAttributesV2INTEL");
612614
add(CapabilityLoopFuseINTEL, "LoopFuseINTEL");
613615
add(CapabilityMemoryAccessAliasingINTEL, "MemoryAccessAliasingINTEL");
614616
add(CapabilityFPGABufferLocationINTEL, "FPGABufferLocationINTEL");
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv --spirv-ext=+SPV_INTEL_fpga_cluster_attributes -spirv-text -o - %t.bc | FileCheck --check-prefix CHECK-SPIRV %s
3+
; RUN: llvm-spirv --spirv-ext=+SPV_INTEL_fpga_cluster_attributes %t.bc -o %t.spv
4+
; spirv-val %t.spv
5+
; RUN: llvm-spirv -r --spirv-ext=+SPV_INTEL_fpga_cluster_attributes %t.spv -o %t.rev.bc
6+
; RUN: llvm-dis %t.rev.bc -o - | FileCheck --check-prefix CHECK-LLVM %s
7+
8+
target triple = "spir64-unknown-unknown"
9+
10+
; CHECK-SPIRV-DAG: Capability FPGAClusterAttributesINTEL
11+
; CHECK-SPIRV-DAG: Capability FPGAClusterAttributesV2INTEL
12+
; CHECK-SPIRV-DAG: Extension "SPV_INTEL_fpga_cluster_attributes"
13+
; CHECK-SPIRV-DAG: Decorate [[#STALLENABLE_DEC:]] StallEnableINTEL
14+
; CHECK-SPIRV-DAG: Decorate [[#STALLFREE_DEC:]] StallFreeINTEL
15+
; CHECK-SPIRV: Function {{[0-9]+}} [[#STALLENABLE_DEC]] {{[0-9]+}} {{[0-9]+}}
16+
; CHECK-SPIRV: Function {{[0-9]+}} [[#STALLFREE_DEC]] {{[0-9]+}} {{[0-9]+}}
17+
; CHECK-LLVM: define spir_func void @test_fpga_stallenable_attr() {{.*}} !stall_enable [[STALL_MD:![0-9]+]]
18+
; CHECK-LLVM: define spir_func void @test_fpga_stallfree_attr() {{.*}} !stall_free [[STALL_MD]]
19+
; CHECK-LLVM: [[STALL_MD]] = !{i32 1}
20+
21+
22+
define spir_func void @test_fpga_stallenable_attr() !stall_enable !0 {
23+
entry:
24+
ret void
25+
}
26+
27+
define spir_func void @test_fpga_stallfree_attr() !stall_free !1 {
28+
entry:
29+
ret void
30+
}
31+
32+
!0 = !{ i32 1 }
33+
!1 = !{ i32 1 }

0 commit comments

Comments
 (0)