Skip to content

Commit cfe95be

Browse files
committed
[mlir][dxsa] Add dcl_function_table
1 parent 1d7cebd commit cfe95be

4 files changed

Lines changed: 52 additions & 0 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,4 +734,24 @@ def DXSA_DclFunctionBody : DXSA_Op<"dcl_function_body"> {
734734
let assemblyFormat = "$index attr-dict";
735735
}
736736

737+
def DXSA_DclFunctionTable : DXSA_Op<"dcl_function_table"> {
738+
let summary = "declares a function table";
739+
let description = [{
740+
Declare a function table as a set of function bodies that have
741+
been declared earlier.
742+
743+
This is like a C++ vtable except there is an entry per call site
744+
for an interface instead of per method.
745+
746+
Example:
747+
```mlir
748+
dxsa.dcl_function_body 0
749+
dxsa.dcl_function_body 1
750+
dxsa.dcl_function_table 0, <functions = [0, 1]>
751+
```
752+
}];
753+
let arguments = (ins I32Attr:$index, DenseI32ArrayAttr:$functions);
754+
let assemblyFormat = "$index `,` `<` `functions` `=` $functions `>` attr-dict";
755+
}
756+
737757
#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+
auto index = parseToken();
1196+
FAILURE_IF_FAILED(index);
1197+
1198+
auto 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+
auto 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_function_table.bin | FileCheck %s
2+
3+
// CHECK-LABEL: module
4+
// CHECK-NEXT: dxsa.dcl_function_table 1, <functions = [0, 1]>
20 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)