diff --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h --- a/mlir/include/mlir/IR/Builders.h +++ b/mlir/include/mlir/IR/Builders.h @@ -407,6 +407,13 @@ /// Creates an operation given the fields represented as an OperationState. Operation *createOperation(const OperationState &state); + /// Creates an operation with the given fields. + Operation * + createOperation(Location loc, StringRef opName, ValueRange operands, + TypeRange types, ArrayRef attributes = {}, + BlockRange successors = {}, + MutableArrayRef> regions = {}); + private: /// Helper for sanity checking preconditions for create* methods below. template diff --git a/mlir/lib/IR/Builders.cpp b/mlir/lib/IR/Builders.cpp --- a/mlir/lib/IR/Builders.cpp +++ b/mlir/lib/IR/Builders.cpp @@ -381,6 +381,17 @@ return insert(Operation::create(state)); } +/// Creates an operation with the given fields. +Operation * +OpBuilder::createOperation(Location loc, StringRef opName, ValueRange operands, + TypeRange types, ArrayRef attributes, + BlockRange successors, + MutableArrayRef> regions) { + OperationState state(loc, opName, operands, types, attributes, successors, + regions); + return createOperation(state); +} + /// Attempts to fold the given operation and places new results within /// 'results'. Returns success if the operation was folded, failure otherwise. /// Note: This function does not erase the operation on a successful fold. diff --git a/mlir/test/lib/Dialect/Test/TestDialect.cpp b/mlir/test/lib/Dialect/Test/TestDialect.cpp --- a/mlir/test/lib/Dialect/Test/TestDialect.cpp +++ b/mlir/test/lib/Dialect/Test/TestDialect.cpp @@ -795,12 +795,9 @@ OpBuilder builder(parser.getBuilder().getContext()); builder.setInsertionPointToStart(&block); - OperationState innerOpState(opLoc, innerOpName); - innerOpState.operands.push_back(lhs); - innerOpState.operands.push_back(rhs); - innerOpState.addTypes(innerOpType); - - Operation *innerOp = builder.createOperation(innerOpState); + SmallVector innerOperands{lhs, rhs}; + Operation *innerOp = + builder.createOperation(opLoc, innerOpName, innerOperands, innerOpType); // Insert a return statement in the block returning the inner-op's result. builder.create(innerOp->getLoc(), innerOp->getResults());