Skip to content

Commit dc27c2d

Browse files
committed
[DirectX][ShaderFlags] Add analysis for WaveOps flag
- Add emitDXILOpProperties to build boolean tables of which ops hold which properties into `DXILEmitter.cpp` - Check each call instruction to see if it invokes an intrinsic that is marked as IsWave, and set the WaveOps flag if this is true for any intrinsics. Done in DXILShaderFlags.cpp
1 parent 77b5bf1 commit dc27c2d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

llvm/lib/Target/DirectX/DXILShaderFlags.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
///
1212
//===----------------------------------------------------------------------===//
1313

14+
#include "DXILConstants.h"
1415
#include "DXILShaderFlags.h"
1516
#include "DirectX.h"
1617
#include "llvm/ADT/SCCIterator.h"
@@ -30,6 +31,25 @@
3031
using namespace llvm;
3132
using namespace llvm::dxil;
3233

34+
static dxil::Properties getOpCodeProperties(dxil::OpCode OpCode) {
35+
dxil::Properties Props;
36+
switch (OpCode) {
37+
#define DXIL_OP_PROPERTIES(OpCode, ...) \
38+
case OpCode: Props = dxil::Properties{__VA_ARGS__}; break;
39+
#include "DXILOperation.inc"
40+
}
41+
return Props;
42+
}
43+
44+
static bool checkWaveOps(Intrinsic::ID IID) {
45+
switch (IID) {
46+
#define DXIL_OP_INTRINSIC(OpCode, IntrinsicID, ...) \
47+
case IntrinsicID: return getOpCodeProperties(OpCode).IsWave;
48+
#include "DXILOperation.inc"
49+
}
50+
return false;
51+
}
52+
3353
/// Update the shader flags mask based on the given instruction.
3454
/// \param CSF Shader flags mask to update.
3555
/// \param I Instruction to check.
@@ -92,6 +112,8 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF,
92112

93113
// TODO: Set DX11_1_DoubleExtensions if I is a call to DXIL intrinsic
94114
// DXIL::Opcode::Fma https://github.com/llvm/llvm-project/issues/114554
115+
116+
CSF.WaveOps |= checkWaveOps(CI->getIntrinsicID());
95117
}
96118
}
97119

llvm/utils/TableGen/DXILEmitter.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,21 @@ static void emitDXILProperties(const RecordKeeper &Records, raw_ostream &OS) {
437437
OS << "#endif\n\n";
438438
}
439439

440+
/// Emit a table of bools denoting a DXIL op's properties
441+
static void emitDXILOpProperties(const RecordKeeper &Records,
442+
ArrayRef<DXILOperationDesc> Ops,
443+
raw_ostream &OS) {
444+
auto DefinedProps = Records.getAllDerivedDefinitions("DXILProperty");
445+
OS << "#ifdef DXIL_OP_PROPERTIES\n";
446+
for (const auto &Op : Ops) {
447+
OS << "DXIL_OP_PROPERTIES(dxil::OpCode::" << Op.OpName;
448+
emitBoolTable(Op.PropRecs, DefinedProps, OS);
449+
OS << ")\n";
450+
}
451+
OS << "#undef DXIL_OP_PROPERTIES\n";
452+
OS << "#endif\n\n";
453+
}
454+
440455
/// Emit a list of DXIL op function types
441456
static void emitDXILOpFunctionTypes(ArrayRef<DXILOperationDesc> Ops,
442457
raw_ostream &OS) {
@@ -641,6 +656,7 @@ static void emitDxilOperation(const RecordKeeper &Records, raw_ostream &OS) {
641656
emitDXILAttributes(Records, OS);
642657
emitDXILOpAttributes(Records, DXILOps, OS);
643658
emitDXILProperties(Records, OS);
659+
emitDXILOpProperties(Records, DXILOps, OS);
644660
emitDXILOpFunctionTypes(DXILOps, OS);
645661
emitDXILIntrinsicArgSelectTypes(Records, OS);
646662
emitDXILIntrinsicMap(DXILOps, OS);

0 commit comments

Comments
 (0)