Skip to content

Commit 543afcc

Browse files
committed
[mlir][dxsa] Add dcl_function_table
1 parent 629d196 commit 543afcc

4 files changed

Lines changed: 55 additions & 0 deletions

File tree

mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,4 +737,25 @@ def DXSA_DclFunctionBody : DXSA_Op<"dcl_function_body"> {
737737
let assemblyFormat = "$index attr-dict";
738738
}
739739

740+
def DXSA_DclFunctionTable : DXSA_Op<"dcl_function_table"> {
741+
let summary = "declares a function table";
742+
let description = [{
743+
744+
Declare a function table as a set of function bodies that have
745+
been declared earlier.
746+
747+
This is like a C++ vtable except there is an entry per call site
748+
for an interface instead of per method.
749+
750+
Example:
751+
```mlir
752+
dxsa.dcl_function_body 0
753+
dxsa.dcl_function_body 1
754+
dxsa.dcl_function_table 0, [0, 1]
755+
```
756+
}];
757+
let arguments = (ins I32Attr:$index, DenseI32ArrayAttr:$functions);
758+
let assemblyFormat = "$index `,` $functions attr-dict";
759+
}
760+
740761
#endif // DXSA_OPS

mlir/lib/Target/DXSA/BinaryParser.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,13 @@ class DXBuilder {
639639
return dxsa::DclFunctionBody::create(builder, loc, index);
640640
}
641641

642+
Instruction buildDclFunctionTable(uint32_t index, ArrayRef<int32_t> functions,
643+
Location loc) {
644+
auto *ctx = builder.getContext();
645+
return dxsa::DclFunctionTable::create(
646+
builder, loc, index, DenseI32ArrayAttr::get(ctx, functions));
647+
}
648+
642649
private:
643650
MLIRContext *context;
644651
ModuleOp module;
@@ -1184,6 +1191,24 @@ class Parser {
11841191
return builder.buildDclFunctionBody(*index, loc);
11851192
}
11861193

1194+
FailureOr<Instruction> parseDclFunctionTable(Location loc) {
1195+
Token index = parseToken();
1196+
FAILURE_IF_FAILED(index);
1197+
1198+
Token numFunctions = parseToken();
1199+
FAILURE_IF_FAILED(numFunctions);
1200+
1201+
SmallVector<int32_t, 16> functions;
1202+
functions.resize(*numFunctions);
1203+
for (uint32_t i = 0; i < numFunctions; ++i) {
1204+
Token functionIndex = parseToken();
1205+
FAILURE_IF_FAILED(functionIndex);
1206+
functions[i] = *functionIndex;
1207+
}
1208+
1209+
return builder.buildDclFunctionTable(*index, functions, loc);
1210+
}
1211+
11871212
OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
11881213
Instruction &out) {
11891214
FailureOr<Instruction> result;
@@ -1233,6 +1258,9 @@ class Parser {
12331258
case D3D11_SB_OPCODE_DCL_FUNCTION_BODY:
12341259
result = parseDclFunctionBody(loc);
12351260
break;
1261+
case D3D11_SB_OPCODE_DCL_FUNCTION_TABLE:
1262+
result = parseDclFunctionTable(loc);
1263+
break;
12361264
default:
12371265
return std::nullopt;
12381266
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_function_table.bin | FileCheck %s
2+
3+
// CHECK-LABEL: module
4+
5+
// dcl_function_table ft1 = {fb0, fb1}
6+
// CHECK: dxsa.dcl_function_table 1, [0, 1]
20 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)