diff options
Diffstat (limited to 'mlir')
| -rw-r--r-- | mlir/include/mlir/IR/Builders.h | 6 | ||||
| -rw-r--r-- | mlir/include/mlir/IR/OperationSupport.h | 4 | ||||
| -rw-r--r-- | mlir/lib/IR/Builders.cpp | 12 | ||||
| -rw-r--r-- | mlir/lib/Transforms/MaterializeVectors.cpp | 13 | ||||
| -rw-r--r-- | mlir/lib/Transforms/Vectorize.cpp | 19 |
5 files changed, 22 insertions, 32 deletions
diff --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h index 301e7853c3a..f743930bd58 100644 --- a/mlir/include/mlir/IR/Builders.h +++ b/mlir/include/mlir/IR/Builders.h @@ -357,12 +357,6 @@ public: /// Creates an operation given the fields represented as an OperationState. OperationStmt *createOperation(const OperationState &state); - /// Creates an operation given the fields. - OperationStmt *createOperation(Location location, OperationName name, - ArrayRef<MLValue *> operands, - ArrayRef<Type> types, - ArrayRef<NamedAttribute> attrs); - /// Create operation of specific op type at the current insertion point. template <typename OpTy, typename... Args> OpPointer<OpTy> create(Location location, Args... args) { diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h index a466559257f..308a84aa3b1 100644 --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -232,8 +232,8 @@ public: OperationState(MLIRContext *context, Location location, StringRef name, ArrayRef<SSAValue *> operands, ArrayRef<Type> types, - ArrayRef<NamedAttribute> attributes = {}, - ArrayRef<StmtBlock *> successors = {}) + ArrayRef<NamedAttribute> attributes, + ArrayRef<StmtBlock *> successors) : context(context), location(location), name(name, context), operands(operands.begin(), operands.end()), types(types.begin(), types.end()), diff --git a/mlir/lib/IR/Builders.cpp b/mlir/lib/IR/Builders.cpp index d3c59493718..7ecc5e9f090 100644 --- a/mlir/lib/IR/Builders.cpp +++ b/mlir/lib/IR/Builders.cpp @@ -319,18 +319,6 @@ OperationStmt *MLFuncBuilder::createOperation(const OperationState &state) { return op; } -/// Create an operation given the fields. -OperationStmt *MLFuncBuilder::createOperation(Location location, - OperationName name, - ArrayRef<MLValue *> operands, - ArrayRef<Type> types, - ArrayRef<NamedAttribute> attrs) { - auto *op = OperationStmt::create(location, name, operands, types, attrs, {}, - getContext()); - block->getStatements().insert(insertPoint, op); - return op; -} - ForStmt *MLFuncBuilder::createFor(Location location, ArrayRef<MLValue *> lbOperands, AffineMap lbMap, diff --git a/mlir/lib/Transforms/MaterializeVectors.cpp b/mlir/lib/Transforms/MaterializeVectors.cpp index 1199e970522..faea9953d86 100644 --- a/mlir/lib/Transforms/MaterializeVectors.cpp +++ b/mlir/lib/Transforms/MaterializeVectors.cpp @@ -416,19 +416,22 @@ instantiate(MLFuncBuilder *b, OperationStmt *opStmt, VectorType hwVectorType, "Should call the function specialized for VectorTransferWriteOp"); bool fail = false; auto operands = map( - [hwVectorType, substitutionsMap, &fail](SSAValue *v) { + [hwVectorType, substitutionsMap, &fail](SSAValue *v) -> SSAValue * { auto *res = fail ? nullptr : substitute(v, hwVectorType, substitutionsMap); fail |= !res; return res; }, opStmt->getOperands()); - if (fail) { + if (fail) return nullptr; - } + auto attrs = materializeAttributes(opStmt, hwVectorType); - return b->createOperation(opStmt->getLoc(), opStmt->getName(), operands, - {hwVectorType}, attrs); + + OperationState state(b->getContext(), opStmt->getLoc(), + opStmt->getName().getStringRef(), operands, + {hwVectorType}, attrs); + return b->createOperation(state); } /// Computes the permutationMap required for a VectorTransferOp from the memref diff --git a/mlir/lib/Transforms/Vectorize.cpp b/mlir/lib/Transforms/Vectorize.cpp index 2f74e563cd5..57c0f14301f 100644 --- a/mlir/lib/Transforms/Vectorize.cpp +++ b/mlir/lib/Transforms/Vectorize.cpp @@ -981,9 +981,13 @@ static MLValue *vectorizeConstant(Statement *stmt, const ConstantOp &constant, auto vectorType = type.cast<VectorType>(); auto attr = SplatElementsAttr::get(vectorType, constant.getValue()); auto *constantOpStmt = cast<OperationStmt>(constant.getOperation()); - auto *splat = cast<OperationStmt>(b.createOperation( - loc, constantOpStmt->getName(), {}, {vectorType}, - {make_pair(Identifier::get("value", b.getContext()), attr)})); + + OperationState state( + b.getContext(), loc, constantOpStmt->getName().getStringRef(), {}, + {vectorType}, + {make_pair(Identifier::get("value", b.getContext()), attr)}); + + auto *splat = cast<OperationStmt>(b.createOperation(state)); return cast<MLValue>(splat->getResult(0)); } @@ -1102,7 +1106,7 @@ static OperationStmt *vectorizeOneOperationStmt(MLFuncBuilder *b, auto types = map([state](SSAValue *v) { return getVectorType(v, *state); }, opStmt->getResults()); - auto vectorizeOneOperand = [opStmt, state](SSAValue *op) { + auto vectorizeOneOperand = [opStmt, state](SSAValue *op) -> SSAValue * { return vectorizeOperand(op, opStmt, state); }; auto operands = map(vectorizeOneOperand, opStmt->getOperands()); @@ -1119,9 +1123,10 @@ static OperationStmt *vectorizeOneOperationStmt(MLFuncBuilder *b, // TODO(ntv): Is it worth considering an OperationStmt.clone operation // which changes the type so we can promote an OperationStmt with less // boilerplate? - return cast<OperationStmt>(b->createOperation(opStmt->getLoc(), - opStmt->getName(), operands, - types, opStmt->getAttrs())); + OperationState newOp(b->getContext(), opStmt->getLoc(), + opStmt->getName().getStringRef(), operands, types, + opStmt->getAttrs()); + return b->createOperation(newOp); } /// Iterates over the OperationStmt in the loop and rewrites them using their |

