[mlir][dxsa] Refine operands#164
Conversation
| DXSA_SrcOperandAttr:$rhs, | ||
| OptionalAttr<DXSA_ComponentMaskAttr>:$precise); | ||
| let results = (outs); | ||
| let assemblyFormat = "$dst `,` $lhs `,` $rhs attr-dict"; |
There was a problem hiding this comment.
assemblyFormat does not use $precise. Unused?
| return success(); | ||
| } | ||
| if (auto intAttr = llvm::dyn_cast<IntegerAttr>(attr)) { | ||
| outBits = intAttr.getValue().getZExtValue(); |
There was a problem hiding this comment.
This asserts in the case of value not fitting into 64 bits.
asavonic
left a comment
There was a problem hiding this comment.
LGTM overall. With "default" attributes hidden, text format doesn't look too verbose.
| canonical count for the operand type. | ||
| - `min16f` / `min2_8f` / `min16i` / `min16u` - the | ||
| `#dxsa.operand_min_precision` hint. | ||
| - `<chans>` - positional channel list, parsed as a |
There was a problem hiding this comment.
Perhaps rename <chans> to <mask>?
There was a problem hiding this comment.
The whole operand documentation has been reafctored.
| StringRef text(out.data(), out.size()); | ||
| if (text.contains('.')) | ||
| return out; | ||
| size_t exponentPos = text.find_first_of("eE"); |
There was a problem hiding this comment.
I think you can instead use LLVM write_double function with FloatStyle::Fixed style.
| case 4: | ||
| return OperandComponents::vector; | ||
| default: | ||
| return OperandComponents::reserved; |
There was a problem hiding this comment.
Do we actually need this? Can we do anything with "reserved" number of components other than to emit an error?
| /// Parses one literal element of an `l(...)` / `d(...)` payload. Accepts a | ||
| /// float literal, a decimal integer, or a hex integer, and reinterprets the | ||
| /// value as the raw bit pattern at the requested width. | ||
| static ParseResult parseImmValue(AsmParser &parser, bool is64, |
There was a problem hiding this comment.
Do we need floating point immediate here at all? IIRC, a type is not encoded, just bit size.
The original disassembler prints them as integer and floats, but I think it does this by looking at the corresponding instruction. If an immediate operand is used in an FP instruction, then it is printed as FP. I don't think we have to do the same here.
The point is, to avoid dancing around different formats, we can support only integer format (or hex - whatever format MLIR can parse by default).
ce14854 to
2960121
Compare
| <x> | ||
| ``` | ||
| }]; | ||
| let parameters = (ins ArrayRefParameter<"int64_t">:$channels); |
There was a problem hiding this comment.
why int64_t? Can it be, say, -1? If not, why not just plain `unsigned?
| if (auto intAttr = llvm::dyn_cast<IntegerAttr>(attr)) { | ||
| auto width = is64 ? 64u : 32u; | ||
| auto value = intAttr.getValue(); | ||
| if (value.getBitWidth() < width) { |
There was a problem hiding this comment.
Does this mean that it would automatically accept, say 42 : i13 and just drop the type promoting to 32-bit int? Is sign-extension always desired? Say, we're having 0x7FFFFFFF: i31, you will extend this to 0xFFFFFFFF. Is this ok?
| } | ||
|
|
||
| template <typename Float, typename UInt> | ||
| static bool floatSpellingReparsesToIdenticalBits(Float value, UInt bits) { |
There was a problem hiding this comment.
This is terrible.... Do we really need this?
| imm.bits = bits; | ||
| imm.byteWidth = sizeof(UInt); | ||
|
|
||
| // Positive zero is the only value spelled as a bare `0`; every other pattern, |
There was a problem hiding this comment.
Why do you need to guess in the IR? This is not in general user-written code. IR should be precise.
| //===----------------------------------------------------------------------===// | ||
|
|
||
| /// Parses the body of a 32-bit immediate-literal operand. | ||
| ParseResult mlir::dxsa::parseImm32Body(AsmParser &parser, |
There was a problem hiding this comment.
Why do you need to export all these functions? Aren't these internal business of the parser?
|
|
||
| /// Parses a single channel keyword `x`, `y`, `z` or `w`. | ||
| static ParseResult parseChannel(AsmParser &parser, | ||
| SmallVectorImpl<int64_t> &channels) { |
There was a problem hiding this comment.
Why it takes vectors and pushes to it rather than returning item inderectly? This seems to differ from existing parser API.
| return channel == 0 ? 'x' : channel == 1 ? 'y' : channel == 2 ? 'z' : 'w'; | ||
| } | ||
|
|
||
| static std::optional<int64_t> channelFromKeyword(StringRef keyword) { |
There was a problem hiding this comment.
Do you really need to wrap integer into optional? It seems to be used only once, fold into parseChannel and you will be able to return error directly.
There was a problem hiding this comment.
Oh, btw, and there is llvm::StringSwitch for you.
| } | ||
|
|
||
| /// Parses an index entry that begins with the already-parsed integer `value`, | ||
| /// e.g. `2`, `2 : i64`, `2 : i64 + r<...>`. |
There was a problem hiding this comment.
Do you really allow, say, i17? It seems you silently ignore it.
| void IndexAttr::print(AsmPrinter &printer) const { | ||
| if (auto imm = getImm()) { | ||
| printer << imm.getValue(); | ||
| if (imm.getType().isInteger(64)) |
There was a problem hiding this comment.
Aren't you hardcode everything to i32 during parsing (in parseIntIndexEntry)?
| mask = ComponentMaskAttr::get(ctx, ComponentMask::x | ComponentMask::y | | ||
| ComponentMask::z | ComponentMask::w); | ||
|
|
||
| return parser.getChecked<DstOperandAttr>(loc, ctx, *operandType, components, |
There was a problem hiding this comment.
Parsing is great, but for mere mortals you'd probably add some additional attr builders that would automatically add defaults
| return {}; | ||
|
|
||
| applySrcOperandDefaults(ctx, *type, body); | ||
| return parser.getChecked<SrcOperandAttr>( |
There was a problem hiding this comment.
See comment about about default attribute builders
| dxsa.add r<0>, cb<2 : i64 + r<3, <x>>>, r<2> | ||
|
|
||
| // ----- | ||
|
|
||
| // CHECK: dxsa.add r<0>, cb<[1 : i64, 2 + r<3, <x>>, r<5, <y>>]>, r<2> | ||
| dxsa.add r<0>, cb<[1 : i64, 2 + r<3, <x>>, r<5, <y>>]>, r<2> |
There was a problem hiding this comment.
you're allowing other types (e.g. i17 and i43). You need either disallow them or test
| @@ -0,0 +1,47 @@ | |||
| // RUN: mlir-opt %s -split-input-file | FileCheck %s | |||
There was a problem hiding this comment.
you should use --verify-roundtrip in all dialect syntax / op tests
74a9f0e to
d70f9e9
Compare
Example: dxsa.add r<0>, r<1>, r<2> dxsa.add_sat r<0>, r<1>, r<2> dxsa.add r<0>, r<1>, l(1.0, 2.0, 3.0, 4.0) dxsa.add r<0>, -r<1>, |r<2>| Signed-off-by: Vladimir Shiryaev <tagolog@users.noreply.github.com>
d70f9e9 to
6c5bf58
Compare
Example:
dxsa.add r<0>, r<1>, r<2>
dxsa.add_sat r<0>, r<1>, r<2>
dxsa.add r<0>, r<1>, l(1.0, 2.0, 3.0, 4.0)
dxsa.add r<0>, -r<1>, |r<2>|