summaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/MLProgram/IR/MLProgramOps.cpp
diff options
context:
space:
mode:
authorJacques Pienaar <jpienaar@google.com>2022-06-16 20:01:54 -0700
committerJacques Pienaar <jpienaar@google.com>2022-06-16 20:01:54 -0700
commitd30c0221cf5aa36c079b7cc0d36fb89f7b32149b (patch)
tree417562bc577f291487b08f293a73c318098d8958 /mlir/lib/Dialect/MLProgram/IR/MLProgramOps.cpp
parentf2bcf330588b9038d6631866aadc19430011734c (diff)
[mlir] Split MLProgram global load and store to Graph variants
* Split ops into X_graph variants as discussed; * Remove tokens from non-Graph region variants and rely on side-effect modelling there while removing side-effect modelling from Graph variants and relying on explicit ordering there; * Make tokens required to be produced by Graph variants - but kept explicit token type specification given previous discussion on this potentially being configurable in future; This results in duplicating some code. I considered adding helper functions but decided against adding an abstraction there early given size of duplication and creating accidental coupling. Differential Revision: https://reviews.llvm.org/D127813
Diffstat (limited to 'mlir/lib/Dialect/MLProgram/IR/MLProgramOps.cpp')
-rw-r--r--mlir/lib/Dialect/MLProgram/IR/MLProgramOps.cpp65
1 files changed, 59 insertions, 6 deletions
diff --git a/mlir/lib/Dialect/MLProgram/IR/MLProgramOps.cpp b/mlir/lib/Dialect/MLProgram/IR/MLProgramOps.cpp
index 9411ea17b816..2f1e4b93a6ac 100644
--- a/mlir/lib/Dialect/MLProgram/IR/MLProgramOps.cpp
+++ b/mlir/lib/Dialect/MLProgram/IR/MLProgramOps.cpp
@@ -18,12 +18,11 @@ using namespace mlir::ml_program;
//===----------------------------------------------------------------------===//
/// Parse and print an ordering clause for a variadic of consuming tokens
-/// and an optional producing token.
+/// and an producing token.
///
/// Syntax:
/// ordering(%0, %1 -> !ml_program.token)
/// ordering(() -> !ml_program.token)
-/// ordering(%0, %1)
///
/// If both the consuming and producing token are not present on the op, then
/// the clause prints nothing.
@@ -46,10 +45,11 @@ static ParseResult parseTokenOrdering(
return failure();
}
- // Parse optional producer token.
- if (succeeded(parser.parseOptionalArrow()))
- if (failed(parser.parseType(produceTokenType)))
- return failure();
+ // Parse producer token.
+ if (failed(parser.parseArrow()))
+ return failure();
+ if (failed(parser.parseType(produceTokenType)))
+ return failure();
if (failed(parser.parseRParen()))
return failure();
@@ -221,6 +221,30 @@ GlobalLoadConstOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
}
//===----------------------------------------------------------------------===//
+// GlobalLoadGraphOp
+//===----------------------------------------------------------------------===//
+
+GlobalOp GlobalLoadGraphOp::getGlobalOp(SymbolTableCollection &symbolTable) {
+ return symbolTable.lookupNearestSymbolFrom<GlobalOp>(
+ getOperation()->getParentOp(), getGlobalAttr());
+}
+
+LogicalResult
+GlobalLoadGraphOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
+ GlobalOp referrent = getGlobalOp(symbolTable);
+ if (!referrent)
+ return emitOpError() << "undefined global: " << getGlobal();
+
+ if (referrent.getType() != getResult().getType()) {
+ return emitOpError() << "cannot load from global typed "
+ << referrent.getType() << " as "
+ << getResult().getType();
+ }
+
+ return success();
+}
+
+//===----------------------------------------------------------------------===//
// GlobalStoreOp
//===----------------------------------------------------------------------===//
@@ -250,6 +274,35 @@ GlobalStoreOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
}
//===----------------------------------------------------------------------===//
+// GlobalStoreGraphOp
+//===----------------------------------------------------------------------===//
+
+GlobalOp GlobalStoreGraphOp::getGlobalOp(SymbolTableCollection &symbolTable) {
+ return symbolTable.lookupNearestSymbolFrom<GlobalOp>(
+ getOperation()->getParentOp(), getGlobalAttr());
+}
+
+LogicalResult
+GlobalStoreGraphOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
+ GlobalOp referrent = getGlobalOp(symbolTable);
+ if (!referrent)
+ return emitOpError() << "undefined global: " << getGlobal();
+
+ if (!referrent.getIsMutable()) {
+ return emitOpError() << "cannot store to an immutable global "
+ << getGlobal();
+ }
+
+ if (referrent.getType() != getValue().getType()) {
+ return emitOpError() << "cannot store to a global typed "
+ << referrent.getType() << " from "
+ << getValue().getType();
+ }
+
+ return success();
+}
+
+//===----------------------------------------------------------------------===//
// SubgraphOp
//===----------------------------------------------------------------------===//