Skip to content

Commit 97b6e39

Browse files
committed
simplify custom print
1 parent ded9552 commit 97b6e39

File tree

2 files changed

+14
-27
lines changed

2 files changed

+14
-27
lines changed

mlir/include/mlir/Dialect/XeGPU/IR/XeGPUOps.td

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,10 @@ def XeGPU_CreateNdDescOp: XeGPU_Op<"create_nd_tdesc", [Pure, ViewLikeOpInterface
179179
if (attr)
180180
return attr;
181181

182-
auto memrefType = llvm::dyn_cast<MemRefType>(getSourceType());
183-
int rank = 0;
184-
if (memrefType)
185-
//use source memref's rank, as source memref rank may be higher
186-
rank = memrefType.getRank();
187-
else
188-
//nd_tdesc created from ui64, use nd_tdesc's rank
189-
rank = getMixedSizes().size();
182+
int64_t rank = getMixedSizes().size();
190183

191-
// The offsets are allowed to be empty. The Traits verification of OffsetSizeAndStrideOpInterface interface assumes offsets being present.
192-
// place-holder value MAX indicating user doesn't provide offsets, instead of kDynamic which means offsets passed as value.
184+
// Set constant offset to MAX to indicate no offsets provided
185+
// or else the printer can't differeiate this with valid const_offset value (say 0)
193186
setConstOffsets(llvm::SmallVector<int64_t, 4>(rank, std::numeric_limits<int64_t>::max()));
194187

195188
attr = getConstOffsetsAttr();

mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "mlir/Dialect/XeGPU/IR/XeGPU.h"
1313
#include "mlir/IR/Builders.h"
1414
#include "mlir/IR/TypeUtilities.h"
15+
#include "mlir/Interfaces/ViewLikeInterface.h"
1516

1617
#include "llvm/Support/Debug.h"
1718

@@ -328,29 +329,22 @@ ParseResult parseOptionalDynamicIndexList(
328329
return success();
329330
}
330331

332+
331333
void printOptionalDynamicIndexList(OpAsmPrinter &printer, Operation *op,
332334
OperandRange values,
333335
ArrayRef<int64_t> integers,
334-
TypeRange valueTypes = TypeRange()) {
336+
TypeRange valueTypes = TypeRange(),
337+
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square){
335338

336339
if (values.empty() && llvm::all_of(integers, [](int64_t i) {
337-
// place-holder value MAX indicating user doesn't provide offsets
340+
// MAX indiates no user-provided offsets for CreateNdDescOp.
338341
return i == std::numeric_limits<int64_t>::max();
339-
}))
340-
return;
341-
printer << '[';
342-
unsigned dynamicValIdx = 0;
343-
llvm::interleaveComma(integers, printer, [&](int64_t integer) {
344-
if (ShapedType::isDynamic(integer)) {
345-
printer << values[dynamicValIdx];
346-
if (!valueTypes.empty())
347-
printer << " : " << valueTypes[dynamicValIdx];
348-
++dynamicValIdx;
349-
} else {
350-
printer << integer;
351-
}
352-
});
353-
printer << ']';
342+
}))
343+
return;
344+
345+
return printDynamicIndexList(printer, op, values, integers,
346+
/*scalableFlags=*/{}, valueTypes, delimiter);
347+
354348
}
355349

356350
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)