/// OpAsmInterface.td#getAsmResultNames for usage details and documentation.
virtual void getAsmResultNames(Operation *op,
OpAsmSetValueNameFn setNameFn) const {}
+
+ /// Get a special name to use when printing the entry block arguments of the
+ /// region contained by an operation in this dialect.
+ virtual void getAsmBlockArgumentNames(Block *block,
+ OpAsmSetValueNameFn setNameFn) const {}
};
//===--------------------------------------------------------------------===//
}
void OperationPrinter::numberValuesInBlock(Block &block) {
+ auto setArgNameFn = [&](Value *arg, StringRef name) {
+ assert(!valueIDs.count(arg) && "arg numbered multiple times");
+ assert(cast<BlockArgument>(arg)->getOwner() == &block &&
+ "arg not defined in 'block'");
+ setValueName(arg, name);
+ };
+
bool isEntryBlock = block.isEntryBlock();
+ if (isEntryBlock && state) {
+ if (auto *op = block.getParentOp()) {
+ if (auto dialectAsmInterface = state->getOpAsmInterface(op->getDialect()))
+ dialectAsmInterface->getAsmBlockArgumentNames(&block, setArgNameFn);
+ }
+ }
// Number the block arguments. We give entry block arguments a special name
// 'arg'.
SmallString<32> specialNameBuffer(isEntryBlock ? "arg" : "");
llvm::raw_svector_ostream specialName(specialNameBuffer);
for (auto *arg : block.getArguments()) {
+ if (valueIDs.count(arg))
+ continue;
if (isEntryBlock) {
specialNameBuffer.resize(strlen("arg"));
specialName << nextArgumentID++;
--- /dev/null
+// RUN: mlir-opt %s | FileCheck %s
+
+// CHECK-LABEL: func @custom_region_names
+func @custom_region_names() -> () {
+ "test.polyfor"() ( {
+ ^bb0(%arg0: index, %arg1: index, %arg2: index):
+ "foo"() : () -> ()
+ }) { arg_names = ["i", "j", "k"] } : () -> ()
+ // CHECK: test.polyfor
+ // CHECK-NEXT: ^bb{{.*}}(%i: index, %j: index, %k: index):
+ return
+}
if (auto asmOp = dyn_cast<AsmDialectInterfaceOp>(op))
setNameFn(asmOp, "result");
}
+
+ void getAsmBlockArgumentNames(Block *block,
+ OpAsmSetValueNameFn setNameFn) const final {
+ auto op = block->getParentOp();
+ auto arrayAttr = op->getAttrOfType<ArrayAttr>("arg_names");
+ if (!arrayAttr)
+ return;
+ auto args = block->getArguments();
+ auto e = std::min(arrayAttr.size(), args.size());
+ for (unsigned i = 0; i < e; ++i) {
+ if (auto strAttr = arrayAttr.getValue()[i].dyn_cast<StringAttr>())
+ setNameFn(args[i], strAttr.getValue());
+ }
+ }
};
struct TestOpFolderDialectInterface : public OpFolderDialectInterface {