Skip to content

Commit dec89ea

Browse files
MrSidimsvmaksimo
authored andcommitted
Add intel::nofusion loop attribute translation
The new loop control bit NoFusionINTEL is enabled by the FPGALoopControlsINTEL capability. If this bit is set, it indicates that the loop should not be fused with any adjacent loop. Signed-off-by: Dmitry Sidorov <[email protected]>
1 parent 132176c commit dec89ea

File tree

4 files changed

+63
-10
lines changed

4 files changed

+63
-10
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,8 @@ void SPIRVToLLVM::setLLVMLoopMetadata(const LoopInstType *LM,
962962
assert(NumParam <= LoopControlParameters.size() &&
963963
"Missing loop control parameter!");
964964
}
965+
if (LC & LoopControlNoFusionINTELMask)
966+
Metadata.push_back(getMetadataFromName("llvm.loop.fusion.disable"));
965967
llvm::MDNode *Node = llvm::MDNode::get(*Context, Metadata);
966968

967969
// Set the first operand to refer itself

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,10 @@ LLVMToSPIRV::getLoopControl(const BranchInst *Branch,
11011101
ParametersToSort.emplace_back(
11021102
spv::LoopControlSpeculatedIterationsINTELMask, I);
11031103
LoopControl |= spv::LoopControlSpeculatedIterationsINTELMask;
1104+
} else if (S == "llvm.loop.fusion.disable") {
1105+
BM->addExtension(ExtensionID::SPV_INTEL_fpga_loop_controls);
1106+
BM->addCapability(CapabilityFPGALoopControlsINTEL);
1107+
LoopControl |= spv::LoopControlNoFusionINTELMask;
11041108
}
11051109
}
11061110
}

llvm-spirv/lib/SPIRV/libSPIRV/spirv.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ enum LoopControlMask {
678678
LoopControlLoopCoalesceINTELMask = 0x100000,
679679
LoopControlMaxInterleavingINTELMask = 0x200000,
680680
LoopControlSpeculatedIterationsINTELMask = 0x400000,
681+
LoopControlNoFusionINTELMask = 0x800000,
681682
};
682683

683684
enum FunctionControlShift {

llvm-spirv/test/transcoding/SPV_INTEL_fpga_loop_controls/FPGALoopMergeInst.ll

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
; int i = 0;
77
; int m = 42;
88

9-
; [[intelfpga::ivdep]]
9+
; [[intel::ivdep]]
1010
; while (i < m) {
1111
; if (i % 2) {
1212
; ++i;
@@ -15,7 +15,7 @@
1515
; }
1616

1717
; i = 0;
18-
; [[intelfpga::ii(2)]]
18+
; [[intel::ii(2)]]
1919
; while (i < m) {
2020
; if (i % 3) {
2121
; ++i;
@@ -24,7 +24,7 @@
2424
; }
2525

2626
; i = 0;
27-
; [[intelfpga::max_concurrency(4)]]
27+
; [[intel::max_concurrency(4)]]
2828
; while (i < m) {
2929
; if (i % 5) {
3030
; ++i;
@@ -33,7 +33,7 @@
3333
; }
3434

3535
; i = 0;
36-
; [[intelfpga::ivdep(2)]]
36+
; [[intel::ivdep(2)]]
3737
; while (true) {
3838
; if (i % 2) {
3939
; ++i;
@@ -46,22 +46,22 @@
4646

4747
; void loop_pipelining() {
4848
; int a[10];
49-
; [[intelfpga::disable_loop_pipelining]]
49+
; [[intel::disable_loop_pipelining]]
5050
; for (int i = 0; i != 10; ++i)
5151
; a[i] = 0;
5252
; }
5353

5454
; void loop_coalesce() {
5555
; int i = 0, m = 42;
56-
; [[intelfpga::loop_coalesce(4)]]
56+
; [[intel::loop_coalesce(4)]]
5757
; while (i < m) {
5858
; if (i % 2) {
5959
; ++i;
6060
; continue;
6161
; }
6262
; }
6363
; i = 0;
64-
; [[intelfpga::loop_coalesce]]
64+
; [[intel::loop_coalesce]]
6565
; while (i < m) {
6666
; if (i % 3) {
6767
; ++i;
@@ -72,21 +72,28 @@
7272

7373
; void max_interleaving() {
7474
; int a[10];
75-
; [[intelfpga::max_interleaving(3)]]
75+
; [[intel::max_interleaving(3)]]
7676
; for (int i = 0; i != 10; ++i)
7777
; a[i] = 0;
7878
; }
7979

8080
; void speculated_iterations() {
8181
; int a[10];
82-
; [[intelfpga::speculated_iterations(4)]]
82+
; [[intel::speculated_iterations(4)]]
83+
; for (int i = 0; i != 10; ++i)
84+
; a[i] = 0;
85+
; }
86+
;
87+
; void nofusion() {
88+
; int a[10];
89+
; [[intel::nofusion]]
8390
; for (int i = 0; i != 10; ++i)
8491
; a[i] = 0;
8592
; }
8693

8794
; TODO: This source code will result in different LLVM IR after
8895
; rev [a47242e4b2c1c9] of https://github.com/intel/llvm (the
89-
; [[intelfpga::ivdep]] attribute will be represented otherwise).
96+
; [[intel::ivdep]] attribute will be represented otherwise).
9097
; It's worth factoring out the old representation's translation:
9198
; (!"llvm.loop.ivdep.*" <-> LoopControlDependency*Mask)
9299
; into a separate test file
@@ -437,6 +444,40 @@ for.end: ; preds = %for.cond
437444
ret void
438445
}
439446

447+
; Function Attrs: noinline nounwind optnone
448+
define spir_func void @nofusion() #3 {
449+
entry:
450+
%a = alloca [10 x i32], align 4
451+
%i = alloca i32, align 4
452+
store i32 0, i32* %i, align 4
453+
br label %for.cond
454+
455+
; Per SPIR-V spec, LoopControlNoFusionINTELMask = 0x800000 (8388608)
456+
; CHECK-SPIRV: 4 LoopMerge {{[0-9]+}} {{[0-9]+}} 8388608
457+
; CHECK-SPIRV-NEXT: 4 BranchConditional {{[0-9]+}} {{[0-9]+}} {{[0-9]+}}
458+
; CHECK-SPIRV-NEGATIVE-NOT: 4 LoopMerge {{[0-9]+}} {{[0-9]+}} 8388608
459+
for.cond: ; preds = %for.inc, %entry
460+
%0 = load i32, i32* %i, align 4
461+
%cmp = icmp ne i32 %0, 10
462+
br i1 %cmp, label %for.body, label %for.end
463+
464+
for.body: ; preds = %for.cond
465+
%1 = load i32, i32* %i, align 4
466+
%idxprom = sext i32 %1 to i64
467+
%arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* %a, i64 0, i64 %idxprom
468+
store i32 0, i32* %arrayidx, align 4
469+
br label %for.inc
470+
471+
for.inc: ; preds = %for.body
472+
%2 = load i32, i32* %i, align 4
473+
%inc = add nsw i32 %2, 1
474+
store i32 %inc, i32* %i, align 4
475+
br label %for.cond, !llvm.loop !29
476+
477+
for.end: ; preds = %for.cond
478+
ret void
479+
}
480+
440481
attributes #0 = { "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"="false" "stack-protector-buffer-size"="8" "sycl-module-id"="FPGALoopMergeInst.cpp" "uniform-work-group-size"="true" "unsafe-fp-math"="false" "use-soft-float"="false" }
441482
attributes #1 = { argmemonly nounwind willreturn }
442483
attributes #2 = { inlinehint nounwind "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"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
@@ -477,6 +518,8 @@ attributes #4 = { nounwind }
477518
!26 = !{!"llvm.loop.max_interleaving.count", i32 3}
478519
!27 = distinct !{!27, !28}
479520
!28 = !{!"llvm.loop.intel.speculated.iterations.count", i32 4}
521+
!29 = distinct !{!29, !30}
522+
!30 = !{!"llvm.loop.fusion.disable"}
480523

481524
; CHECK-LLVM: br label %while.cond, !llvm.loop ![[MD_A:[0-9]+]]
482525
; CHECK-LLVM: br label %while.cond{{[0-9]+}}, !llvm.loop ![[MD_B:[0-9]+]]
@@ -487,6 +530,7 @@ attributes #4 = { nounwind }
487530
; CHECK-LLVM: br label %while.cond{{[0-9]+}}, !llvm.loop ![[MD_G:[0-9]+]]
488531
; CHECK-LLVM: br label %for.cond{{[0-9]*}}, !llvm.loop ![[MD_H:[0-9]+]]
489532
; CHECK-LLVM: br label %for.cond{{[0-9]*}}, !llvm.loop ![[MD_I:[0-9]+]]
533+
; CHECK-LLVM: br label %for.cond{{[0-9]*}}, !llvm.loop ![[MD_NF:[0-9]+]]
490534

491535
; CHECK-LLVM: ![[MD_A]] = distinct !{![[MD_A]], ![[MD_ivdep_enable:[0-9]+]]}
492536
; CHECK-LLVM: ![[MD_ivdep_enable]] = !{!"llvm.loop.ivdep.enable"}
@@ -507,3 +551,5 @@ attributes #4 = { nounwind }
507551
; CHECK-LLVM: ![[MD_max_interleaving]] = !{!"llvm.loop.max_interleaving.count", i32 3}
508552
; CHECK-LLVM: ![[MD_I]] = distinct !{![[MD_I]], ![[MD_spec_iterations:[0-9]+]]}
509553
; CHECK-LLVM: ![[MD_spec_iterations]] = !{!"llvm.loop.intel.speculated.iterations.count", i32 4}
554+
; CHECK-LLVM: ![[MD_NF]] = distinct !{![[MD_NF]], ![[MD_nofusion:[0-9]+]]}
555+
; CHECK-LLVM: ![[MD_nofusion]] = !{!"llvm.loop.fusion.disable"}

0 commit comments

Comments
 (0)