Skip to content

Commit b741f2b

Browse files
committed
[DirectX][ShaderFlags] Add analysis for WaveOps flag
- add Shader Flag analysis for the `WaveOps` flag in DXILShaderFlags.cpp - add testing of all currenlty supported wave ops in wave-ops.ll
1 parent 6832514 commit b741f2b

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

llvm/lib/Target/DirectX/DXILShaderFlags.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,39 @@
3030
using namespace llvm;
3131
using namespace llvm::dxil;
3232

33+
static bool checkWaveOps(Intrinsic::ID IID) {
34+
switch (IID) {
35+
default: return false;
36+
case Intrinsic::dx_wave_is_first_lane:
37+
case Intrinsic::dx_wave_getlaneindex:
38+
case Intrinsic::dx_wave_any:
39+
case Intrinsic::dx_wave_all:
40+
case Intrinsic::dx_wave_readlane:
41+
case Intrinsic::dx_wave_active_countbits:
42+
// Wave Active Op Variants
43+
case Intrinsic::dx_wave_reduce_sum:
44+
case Intrinsic::dx_wave_reduce_usum:
45+
case Intrinsic::dx_wave_reduce_max:
46+
case Intrinsic::dx_wave_reduce_umax:
47+
48+
// Currently unsupported intrinsics
49+
// case Intrinsic::dx_WaveGetLaneCount:
50+
// case Intrinsic::dx_WaveActiveAllEqual:
51+
// case Intrinsic::dx_WaveActiveBallot:
52+
// case Intrinsic::dx_WaveReadLaneFirst:
53+
// case Intrinsic::dx_WaveActiveBit:
54+
// case Intrinsic::dx_WavePrefixOp:
55+
// case Intrinsic::dx_QuadReadLaneAt:
56+
// case Intrinsic::dx_QuadOp:
57+
// case Intrinsic::dx_WavePrefixBitCount:
58+
// case Intrinsic::dx_WaveMatch:
59+
// case Intrinsic::dx_WaveMultiPrefixOp:
60+
// case Intrinsic::dx_WaveMultiPrefixBitCount:
61+
// case Intrinsic::dx_QuadVote:
62+
return true;
63+
}
64+
}
65+
3366
/// Update the shader flags mask based on the given instruction.
3467
/// \param CSF Shader flags mask to update.
3568
/// \param I Instruction to check.
@@ -92,6 +125,8 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF,
92125

93126
// TODO: Set DX11_1_DoubleExtensions if I is a call to DXIL intrinsic
94127
// DXIL::Opcode::Fma https://github.com/llvm/llvm-project/issues/114554
128+
129+
CSF.WaveOps |= checkWaveOps(CI->getIntrinsicID());
95130
}
96131
}
97132

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s
2+
;
3+
; CHECK: ; Shader Flags Value: [[WAVE_FLAG:0x00080000]]
4+
; CHECK: ; Note: shader requires additional functionality:
5+
; CHECK-NEXT: ; Wave level operations
6+
; CHECK-NEXT: ; Note: extra DXIL module flags:
7+
; CHECK-NEXT: {{^;$}}
8+
9+
target triple = "dxil-pc-shadermodel6.7-library"
10+
11+
define noundef i1 @wave_is_first_lane() {
12+
entry:
13+
; CHECK: Function wave_is_first_lane : [[WAVE_FLAG]]
14+
%ret = call i1 @llvm.dx.wave.is.first.lane()
15+
ret i1 %ret
16+
}
17+
18+
define noundef i32 @wave_getlaneindex() {
19+
entry:
20+
; CHECK: Function wave_getlaneindex : [[WAVE_FLAG]]
21+
%ret = call i32 @llvm.dx.wave.getlaneindex()
22+
ret i32 %ret
23+
}
24+
25+
define noundef i1 @wave_any(i1 %x) {
26+
entry:
27+
; CHECK: Function wave_any : [[WAVE_FLAG]]
28+
%ret = call i1 @llvm.dx.wave.any(i1 %x)
29+
ret i1 %ret
30+
}
31+
32+
define noundef i1 @wave_all(i1 %x) {
33+
entry:
34+
; CHECK: Function wave_all : [[WAVE_FLAG]]
35+
%ret = call i1 @llvm.dx.wave.all(i1 %x)
36+
ret i1 %ret
37+
}
38+
39+
define noundef i1 @wave_readlane(i1 %x, i32 %idx) {
40+
entry:
41+
; CHECK: Function wave_readlane : [[WAVE_FLAG]]
42+
%ret = call i1 @llvm.dx.wave.readlane.i1(i1 %x, i32 %idx)
43+
ret i1 %ret
44+
}
45+
46+
define noundef i32 @wave_reduce_sum(i32 noundef %x) {
47+
entry:
48+
; CHECK: Function wave_reduce_sum : [[WAVE_FLAG]]
49+
%ret = call i32 @llvm.dx.wave.reduce.sum.i32(i32 %x)
50+
ret i32 %ret
51+
}
52+
53+
define noundef i32 @wave_reduce_usum(i32 noundef %x) {
54+
entry:
55+
; CHECK: Function wave_reduce_usum : [[WAVE_FLAG]]
56+
%ret = call i32 @llvm.dx.wave.reduce.usum.i32(i32 %x)
57+
ret i32 %ret
58+
}
59+
60+
define noundef i32 @wave_reduce_max(i32 noundef %x) {
61+
entry:
62+
; CHECK: Function wave_reduce_max : [[WAVE_FLAG]]
63+
%ret = call i32 @llvm.dx.wave.reduce.max.i32(i32 %x)
64+
ret i32 %ret
65+
}
66+
67+
define noundef i32 @wave_reduce_umax(i32 noundef %x) {
68+
entry:
69+
; CHECK: Function wave_reduce_umax : [[WAVE_FLAG]]
70+
%ret = call i32 @llvm.dx.wave.reduce.umax.i32(i32 %x)
71+
ret i32 %ret
72+
}
73+
74+
define void @wave_active_countbits(i1 %expr) {
75+
entry:
76+
; CHECK: Function wave_active_countbits : [[WAVE_FLAG]]
77+
%0 = call i32 @llvm.dx.wave.active.countbits(i1 %expr)
78+
ret void
79+
}

0 commit comments

Comments
 (0)