Skip to content

Commit 4f0122b

Browse files
authored
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
1 parent 59f15de commit 4f0122b

File tree

7 files changed

+63
-0
lines changed

7 files changed

+63
-0
lines changed

lib/SPIRV/SPIRVInternal.h

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

lib/SPIRV/SPIRVReader.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4557,6 +4557,11 @@ bool SPIRVToLLVM::transFPGAFunctionMetadata(SPIRVFunction *BF, Function *F) {
45574557
MetadataVec.push_back(ConstantAsMetadata::get(getInt32(M, 1)));
45584558
F->setMetadata(kSPIR2MD::StallEnable, MDNode::get(*Context, MetadataVec));
45594559
}
4560+
if (BF->hasDecorate(DecorationStallFreeINTEL)) {
4561+
std::vector<Metadata *> MetadataVec;
4562+
MetadataVec.push_back(ConstantAsMetadata::get(getInt32(M, 1)));
4563+
F->setMetadata(kSPIR2MD::StallFree, MDNode::get(*Context, MetadataVec));
4564+
}
45604565
if (BF->hasDecorate(DecorationFuseLoopsInFunctionINTEL)) {
45614566
std::vector<Metadata *> MetadataVec;
45624567
auto Literals =

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,14 @@ void LLVMToSPIRVBase::transFPGAFunctionMetadata(SPIRVFunction *BF,
10281028
BF->addDecorate(new SPIRVDecorateStallEnableINTEL(BF));
10291029
}
10301030
}
1031+
if (MDNode *StallFree = F->getMetadata(kSPIR2MD::StallFree)) {
1032+
if (BM->isAllowedToUseExtension(
1033+
ExtensionID::SPV_INTEL_fpga_cluster_attributes)) {
1034+
if (getMDOperandAsInt(StallFree, 0)) {
1035+
BF->addDecorate(new SPIRVDecorateStallFreeINTEL(BF));
1036+
}
1037+
}
1038+
}
10311039
if (MDNode *LoopFuse = F->getMetadata(kSPIR2MD::LoopFuse)) {
10321040
if (BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_loop_fuse)) {
10331041
size_t Depth = getMDOperandAsInt(LoopFuse, 0);
@@ -2612,6 +2620,10 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
26122620
Target->addDecorate(new SPIRVDecorateStallEnableINTEL(Target));
26132621
break;
26142622
}
2623+
case DecorationStallFreeINTEL: {
2624+
Target->addDecorate(new SPIRVDecorateStallFreeINTEL(Target));
2625+
break;
2626+
}
26152627
case DecorationMergeINTEL: {
26162628
ErrLog.checkError(NumOperands == 3, SPIRVEC_InvalidLlvmModule,
26172629
"MergeINTEL requires exactly 3 extra operands");

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:
@@ -684,6 +686,12 @@ class SPIRVDecorateStallEnableINTEL : public SPIRVDecorate {
684686
: SPIRVDecorate(spv::DecorationStallEnableINTEL, TheTarget) {}
685687
};
686688

689+
class SPIRVDecorateStallFreeINTEL : public SPIRVDecorate {
690+
public:
691+
SPIRVDecorateStallFreeINTEL(SPIRVEntry *TheTarget)
692+
: SPIRVDecorate(spv::DecorationStallFreeINTEL, TheTarget) {}
693+
};
694+
687695
class SPIRVDecorateFuseLoopsInFunctionINTEL : public SPIRVDecorate {
688696
public:
689697
// Complete constructor for SPIRVDecorateFuseLoopsInFunctionINTEL

lib/SPIRV/libSPIRV/SPIRVEnum.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ template <> inline void SPIRVMap<Decoration, SPIRVCapVec>::init() {
462462
ADD_VEC_INIT(DecorationMediaBlockIOINTEL, {CapabilityVectorComputeINTEL});
463463
ADD_VEC_INIT(DecorationStallEnableINTEL,
464464
{CapabilityFPGAClusterAttributesINTEL});
465+
ADD_VEC_INIT(DecorationStallFreeINTEL,
466+
{CapabilityFPGAClusterAttributesV2INTEL});
465467
ADD_VEC_INIT(DecorationFuseLoopsInFunctionINTEL, {CapabilityLoopFuseINTEL});
466468
ADD_VEC_INIT(DecorationMathOpDSPModeINTEL, {CapabilityFPGADSPControlINTEL});
467469
ADD_VEC_INIT(DecorationInitiationIntervalINTEL,

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");
@@ -594,6 +595,7 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
594595
add(CapabilityFPGAKernelAttributesv2INTEL, "FPGAKernelAttributesv2INTEL");
595596
add(CapabilityFPGAMemoryAccessesINTEL, "FPGAMemoryAccessesINTEL");
596597
add(CapabilityFPGAClusterAttributesINTEL, "FPGAClusterAttributesINTEL");
598+
add(CapabilityFPGAClusterAttributesV2INTEL, "FPGAClusterAttributesV2INTEL");
597599
add(CapabilityLoopFuseINTEL, "LoopFuseINTEL");
598600
add(CapabilityMemoryAccessAliasingINTEL, "MemoryAccessAliasingINTEL");
599601
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)