Skip to content

Commit 9d1fe4f

Browse files
committed
[DXIL][ShaderFlags] Add analysis for WaveOps flag
- updates DXILShaderFlags to check if any functions call a wave intrinsic - adds a testcase to iswave.ll
1 parent 751ca17 commit 9d1fe4f

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

llvm/lib/Target/DirectX/DXILShaderFlags.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,32 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "DXILShaderFlags.h"
15+
#include "DXILConstants.h"
1516
#include "DirectX.h"
1617
#include "llvm/IR/Instruction.h"
18+
#include "llvm/IR/Instructions.h"
19+
#include "llvm/IR/IntrinsicsDirectX.h"
1720
#include "llvm/IR/Module.h"
1821
#include "llvm/Support/FormatVariadic.h"
1922

2023
using namespace llvm;
2124
using namespace llvm::dxil;
2225

26+
// Include hasProperty which is generated by tabelGen
27+
#define DXIL_OP_PROPERTY_HELPER
28+
#include "DXILOperation.inc"
29+
#undef DXIL_OP_PROPERTY_HELPER
30+
31+
static bool checkWaveOps(const CallInst *CI) {
32+
switch (CI->getIntrinsicID()) {
33+
#define DXIL_OP_INTRINSIC(OpCode, Intrin) \
34+
case Intrin: \
35+
return hasProperty(OpCode, dxil::Property::IsWave);
36+
#include "DXILOperation.inc"
37+
}
38+
return false;
39+
}
40+
2341
static void updateFlags(ComputedShaderFlags &Flags, const Instruction &I) {
2442
Type *Ty = I.getType();
2543
if (Ty->isDoubleTy()) {
@@ -34,6 +52,9 @@ static void updateFlags(ComputedShaderFlags &Flags, const Instruction &I) {
3452
break;
3553
}
3654
}
55+
56+
if (auto *CI = dyn_cast<CallInst>(&I))
57+
Flags.WaveOps |= checkWaveOps(CI);
3758
}
3859

3960
ComputedShaderFlags ComputedShaderFlags::computeFlags(Module &M) {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s
2+
3+
target triple = "dxil-pc-shadermodel6.7-library"
4+
5+
; CHECK: ; Shader Flags Value: 0x00080000
6+
; CHECK: ; Note: shader requires additional functionality:
7+
; CHECK-NEXT: ; Wave level operations
8+
; CHECK-NEXT: ; Note: extra DXIL module flags:
9+
; CHECK-NEXT: {{^;$}}
10+
11+
; TODO: is there a way that we can split the input file into many?
12+
; as the shader flag will be true if any are set
13+
14+
define i32 @wrla(i32 %expr, i32 %idx) {
15+
%ret = call i32 @llvm.dx.wave.readlane.i32(i32 %expr, i32 %idx)
16+
ret i32 %ret
17+
}
18+
19+
define i1 @waat(i1 %x) {
20+
%ret = call i1 @llvm.dx.wave.any(i1 %x)
21+
ret i1 %ret
22+
}
23+
24+
define i32 @wabc(i1 %x) {
25+
%ret = call i32 @llvm.dx.wave.active.countbits(i1 %x)
26+
ret i32 %ret
27+
}
28+
29+
define i1 @wifl() {
30+
%ret = call i1 @llvm.dx.wave.is.first.lane()
31+
ret i1 %ret
32+
}
33+
34+
define i32 @wgli() {
35+
%ret = call i32 @llvm.dx.wave.getlaneindex()
36+
ret i32 %ret
37+
}

0 commit comments

Comments
 (0)