summaryrefslogtreecommitdiffstats
path: root/mlir/lib/IR
diff options
context:
space:
mode:
authorRiver Riddle <riverriddle@google.com>2019-12-11 16:26:08 -0800
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-12-11 16:26:45 -0800
commit851a8516d3883088b0c02601f9c1bb269e85051c (patch)
tree7c0485fe353c4d6f10d92e7b36c4be90346c8068 /mlir/lib/IR
parent9dfa84a269e245ebaff032f698a798f71da2c1b5 (diff)
downloadbcm5719-llvm-851a8516d3883088b0c02601f9c1bb269e85051c.tar.gz
bcm5719-llvm-851a8516d3883088b0c02601f9c1bb269e85051c.zip
Make OpBuilder::insert virtual instead of OpBuilder::createOperation.
It is sometimes useful to create operations separately from the builder before insertion as it may be easier to erase them in isolation if necessary. One example use case for this is folding, as we will only want to insert newly generated constant operations on success. This has the added benefit of fixing some silent PatternRewriter failures related to cloning, as the OpBuilder 'clone' methods don't call createOperation. PiperOrigin-RevId: 285086242
Diffstat (limited to 'mlir/lib/IR')
-rw-r--r--mlir/lib/IR/Builders.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/mlir/lib/IR/Builders.cpp b/mlir/lib/IR/Builders.cpp
index 4d6cd3550ca..8c54df4d55b 100644
--- a/mlir/lib/IR/Builders.cpp
+++ b/mlir/lib/IR/Builders.cpp
@@ -306,6 +306,13 @@ AffineMap Builder::getShiftedAffineMap(AffineMap map, int64_t shift) {
OpBuilder::~OpBuilder() {}
+/// Insert the given operation at the current insertion point and return it.
+Operation *OpBuilder::insert(Operation *op) {
+ if (block)
+ block->getOperations().insert(insertPoint, op);
+ return op;
+}
+
/// Add new block and set the insertion point to the end of it. The block is
/// inserted at the provided insertion point of 'parent'.
Block *OpBuilder::createBlock(Region *parent, Region::iterator insertPt) {
@@ -328,10 +335,7 @@ Block *OpBuilder::createBlock(Block *insertBefore) {
/// Create an operation given the fields represented as an OperationState.
Operation *OpBuilder::createOperation(const OperationState &state) {
- assert(block && "createOperation() called without setting builder's block");
- auto *op = Operation::create(state);
- insert(op);
- return op;
+ return insert(Operation::create(state));
}
/// Attempts to fold the given operation and places new results within
@@ -359,9 +363,3 @@ void OpBuilder::tryFold(Operation *op, SmallVectorImpl<Value *> &results) {
[](OpFoldResult result) { return result.get<Value *>(); });
op->erase();
}
-
-/// Insert the given operation at the current insertion point.
-void OpBuilder::insert(Operation *op) {
- if (block)
- block->getOperations().insert(insertPoint, op);
-}
OpenPOWER on IntegriCloud