summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Dialect/SPIRV
diff options
context:
space:
mode:
authorRiver Riddle <riverriddle@google.com>2019-11-05 17:58:16 -0800
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-11-05 17:58:48 -0800
commit8e0f4860cdc07b4c681c434792cede24f16961e3 (patch)
tree0738f42b14d9f8cfce24ae9b5ffcde9a384d772c /mlir/lib/Dialect/SPIRV
parent500e858e6522c3b55c3f23e95689f146e09db43e (diff)
downloadbcm5719-llvm-8e0f4860cdc07b4c681c434792cede24f16961e3.tar.gz
bcm5719-llvm-8e0f4860cdc07b4c681c434792cede24f16961e3.zip
Add (parse|print)OptionalAttrDictWithKeyword hooks to simplify parsing attribute dictionaries with regions.
Many operations with regions add an additional 'attributes' prefix when printing the attribute dictionary to differentiate it from the region body. This leads to duplicated logic for detecting when to actually print the attribute dictionary. PiperOrigin-RevId: 278747681
Diffstat (limited to 'mlir/lib/Dialect/SPIRV')
-rw-r--r--mlir/lib/Dialect/SPIRV/SPIRVOps.cpp20
1 files changed, 3 insertions, 17 deletions
diff --git a/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp b/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp
index e8176191a8d..778e7cb3b24 100644
--- a/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp
@@ -1628,10 +1628,8 @@ static ParseResult parseModuleOp(OpAsmParser &parser, OperationState &state) {
if (parser.parseRegion(*body, /*arguments=*/{}, /*argTypes=*/{}))
return failure();
- if (succeeded(parser.parseOptionalKeyword("attributes"))) {
- if (parser.parseOptionalAttrDict(state.attributes))
- return failure();
- }
+ if (parser.parseOptionalAttrDictWithKeyword(state.attributes))
+ return failure();
spirv::ModuleOp::ensureTerminator(*body, parser.getBuilder(), state.location);
return success();
@@ -1657,19 +1655,7 @@ static void print(spirv::ModuleOp moduleOp, OpAsmPrinter &printer) {
printer.printRegion(op->getRegion(0), /*printEntryBlockArgs=*/false,
/*printBlockTerminators=*/false);
-
- bool printAttrDict =
- elidedAttrs.size() != 2 ||
- llvm::any_of(op->getAttrs(), [&addressingModelAttrName,
- &memoryModelAttrName](NamedAttribute attr) {
- return attr.first != addressingModelAttrName &&
- attr.first != memoryModelAttrName;
- });
-
- if (printAttrDict) {
- printer << " attributes";
- printer.printOptionalAttrDict(op->getAttrs(), elidedAttrs);
- }
+ printer.printOptionalAttrDictWithKeyword(op->getAttrs(), elidedAttrs);
}
static LogicalResult verify(spirv::ModuleOp moduleOp) {
OpenPOWER on IntegriCloud