}],
"void", "getAsmResultNames",
(ins "::mlir::OpAsmSetValueNameFn":$setNameFn),
- "", ";"
+ "", "return;"
+ >,
+ InterfaceMethod<[{
+ Get a special name to use when printing the block arguments for a region
+ immediately nested under this operation.
+ }],
+ "void", "getAsmBlockArgumentNames",
+ (ins
+ "::mlir::Region&":$region,
+ "::mlir::OpAsmSetValueNameFn":$setNameFn
+ ),
+ "", "return;"
>,
StaticInterfaceMethod<[{
Return the default dialect used when printing/parsing operations in
/// 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 {}
};
} // namespace mlir
}
void SSANameState::numberValuesInRegion(Region ®ion) {
+ auto setBlockArgNameFn = [&](Value arg, StringRef name) {
+ assert(!valueIDs.count(arg) && "arg numbered multiple times");
+ assert(arg.cast<BlockArgument>().getOwner()->getParent() == ®ion &&
+ "arg not defined in current region");
+ setValueName(arg, name);
+ };
+
+ if (!printerFlags.shouldPrintGenericOpForm()) {
+ if (Operation *op = region.getParentOp()) {
+ if (auto asmInterface = dyn_cast<OpAsmOpInterface>(op))
+ asmInterface.getAsmBlockArgumentNames(region, setBlockArgNameFn);
+ }
+ }
+
// Number the values within this region in a breadth-first order.
unsigned nextBlockID = 0;
for (auto &block : region) {
}
void SSANameState::numberValuesInBlock(Block &block) {
- auto setArgNameFn = [&](Value arg, StringRef name) {
- assert(!valueIDs.count(arg) && "arg numbered multiple times");
- assert(arg.cast<BlockArgument>().getOwner() == &block &&
- "arg not defined in 'block'");
- setValueName(arg, name);
- };
-
- bool isEntryBlock = block.isEntryBlock();
- if (isEntryBlock && !printerFlags.shouldPrintGenericOpForm()) {
- if (auto *op = block.getParentOp()) {
- if (auto asmInterface = interfaces.getInterfaceFor(op->getDialect()))
- asmInterface->getAsmBlockArgumentNames(&block, setArgNameFn);
- }
- }
-
// Number the block arguments. We give entry block arguments a special name
// 'arg'.
+ bool isEntryBlock = block.isEntryBlock();
SmallString<32> specialNameBuffer(isEntryBlock ? "arg" : "");
llvm::raw_svector_ostream specialName(specialNameBuffer);
for (auto arg : block.getArguments()) {
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[i].dyn_cast<StringAttr>())
- setNameFn(args[i], strAttr.getValue());
- }
- }
};
struct TestDialectFoldInterface : public DialectFoldInterface {
return parser.parseRegion(*body, ivsInfo, argTypes);
}
+void PolyForOp::getAsmBlockArgumentNames(Region ®ion,
+ OpAsmSetValueNameFn setNameFn) {
+ auto arrayAttr = getOperation()->getAttrOfType<ArrayAttr>("arg_names");
+ if (!arrayAttr)
+ return;
+ auto args = getRegion().front().getArguments();
+ auto e = std::min(arrayAttr.size(), args.size());
+ for (unsigned i = 0; i < e; ++i) {
+ if (auto strAttr = arrayAttr[i].dyn_cast<StringAttr>())
+ setNameFn(args[i], strAttr.getValue());
+ }
+}
+
//===----------------------------------------------------------------------===//
// Test removing op with inner ops.
//===----------------------------------------------------------------------===//
let printer = [{ return ::print(p, *this); }];
}
-def PolyForOp : TEST_Op<"polyfor">
+def PolyForOp : TEST_Op<"polyfor", [OpAsmOpInterface]>
{
let summary = "polyfor operation";
let description = [{
Test op with multiple region arguments, each argument of index type.
}];
-
+ let extraClassDeclaration = [{
+ void getAsmBlockArgumentNames(mlir::Region ®ion,
+ mlir::OpAsmSetValueNameFn setNameFn);
+ }];
let regions = (region SizedRegion<1>:$region);
let parser = [{ return ::parse$cppClass(parser, result); }];
}