Skip to content

Commit 3a3f113

Browse files
committed
[mlir][dxsa] Add dcl_tgsm_raw instruction
Example: dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 40 Signed-off-by: Vladimir Shiryaev <tagolog@users.noreply.github.com>
1 parent 014c7b3 commit 3a3f113

6 files changed

Lines changed: 70 additions & 7 deletions

File tree

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -475,13 +475,7 @@ def DXSA_InlineOperandAttr : AttrDef<DXSADialect, "InlineOperand"> {
475475
"uint32_t":$components,
476476
OptionalParameter<"::mlir::dxsa::ComponentMaskAttr">:$mask,
477477
OptionalParameter<"::mlir::DenseI64ArrayAttr">:$index);
478-
let assemblyFormat = [{
479-
`<` `type` `=` $type
480-
`,` `components` `=` $components
481-
(`,` `mask` `=` $mask^)?
482-
(`,` `index` `=` $index^)?
483-
`>`
484-
}];
478+
let assemblyFormat = "`<` struct(params) `>`";
485479
}
486480

487481
def DXSA_DclGlobalFlags : DXSA_Op<"dcl_global_flags"> {
@@ -719,4 +713,26 @@ def DXSA_DclOutput : DXSA_Op<"dcl_output"> {
719713
let assemblyFormat = "$operand attr-dict";
720714
}
721715

716+
def DXSA_DclTgsmRaw : DXSA_Op<"dcl_tgsm_raw"> {
717+
let summary = "declares a reference to a Thread Group Shared Memory region";
718+
let description = [{
719+
The `dxsa.dcl_tgsm_raw` operation declares a reference to a Thread Group Shared Memory region.
720+
721+
The `$operand` is the `g#` register being declared.
722+
The `$byte_count$ is the size of the block of untyped shared memory;
723+
must be a multiple of 4.
724+
725+
Example:
726+
727+
```mlir
728+
dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 1024
729+
```
730+
}];
731+
let arguments = (ins DXSA_InlineOperandAttr:$operand,
732+
ConfinedAttr<I32Attr,
733+
[IntPositive, IntMaxValue<32768>]>:$byte_count);
734+
let assemblyFormat = "$operand `,` $byte_count attr-dict";
735+
let hasVerifier = 1;
736+
}
737+
722738
#endif // DXSA_OPS

mlir/lib/Dialect/DXSA/IR/DXSA.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ void DXSADialect::initialize() {
4141
#define GET_OP_CLASSES
4242
#include "mlir/Dialect/DXSA/IR/DXSAOps.cpp.inc"
4343

44+
//===----------------------------------------------------------------------===//
45+
// Op verifiers
46+
//===----------------------------------------------------------------------===//
47+
48+
LogicalResult DclTgsmRaw::verify() {
49+
auto byteCount = getByteCount();
50+
if (byteCount % 4 != 0)
51+
return emitOpError("byte count must be a multiple of 4, got ") << byteCount;
52+
return success();
53+
}
54+
4455
//===----------------------------------------------------------------------===//
4556
// TableGen'd attribute method definitions
4657
//===----------------------------------------------------------------------===//

mlir/lib/Target/DXSA/BinaryParser.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,12 @@ class DXBuilder {
635635
return dxsa::DclOutput::create(builder, loc, operand);
636636
}
637637

638+
Instruction buildDclTgsmRaw(dxsa::InlineOperandAttr operand,
639+
uint32_t byteCount, Location loc) {
640+
return dxsa::DclTgsmRaw::create(builder, loc, operand,
641+
builder.getI32IntegerAttr(byteCount));
642+
}
643+
638644
private:
639645
MLIRContext *context;
640646
ModuleOp module;
@@ -1174,6 +1180,14 @@ class Parser {
11741180
return builder.buildDclOutput(*operand, loc);
11751181
}
11761182

1183+
FailureOr<Instruction> parseDclTgsmRaw(Location loc) {
1184+
auto operand = parseInlineOperand();
1185+
FAILURE_IF_FAILED(operand);
1186+
auto byteCount = parseToken();
1187+
FAILURE_IF_FAILED(byteCount);
1188+
return builder.buildDclTgsmRaw(*operand, *byteCount, loc);
1189+
}
1190+
11771191
OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
11781192
Instruction &out) {
11791193
FailureOr<Instruction> result;
@@ -1220,6 +1234,9 @@ class Parser {
12201234
case D3D10_SB_OPCODE_DCL_OUTPUT:
12211235
result = parseDclOutput(loc);
12221236
break;
1237+
case D3D11_SB_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_RAW:
1238+
result = parseDclTgsmRaw(loc);
1239+
break;
12231240
default:
12241241
return std::nullopt;
12251242
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_tgsm_raw.bin | FileCheck %s
2+
3+
// CHECK: module {
4+
// CHECK-NEXT: dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 40
5+
// CHECK-NEXT: }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: mlir-opt %s -split-input-file -verify-diagnostics
2+
3+
// expected-error@+1 {{'dxsa.dcl_tgsm_raw' op byte count must be a multiple of 4, got 42}}
4+
dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 42
5+
6+
// -----
7+
8+
// expected-error@+1 {{attribute 'byte_count' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive whose maximum value is 32768}}
9+
dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 0
10+
11+
// -----
12+
13+
// expected-error@+1 {{attribute 'byte_count' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive whose maximum value is 32768}}
14+
dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 32769
16 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)