#define GET_OP_CLASSES
#include "mlir/StandardOps/Ops.h.inc"
-/// The "alloc" operation allocates a region of memory, as specified by its
-/// memref type. For example:
-///
-/// %0 = alloc() : memref<8x64xf32, (d0, d1) -> (d0, d1), 1>
-///
-/// The optional list of dimension operands are bound to the dynamic dimensions
-/// specified in its memref type. In the example below, the ssa value '%d' is
-/// bound to the second dimension of the memref (which is dynamic).
-///
-/// %0 = alloc(%d) : memref<8x?xf32, (d0, d1) -> (d0, d1), 1>
-///
-/// The optional list of symbol operands are bound to the symbols of the
-/// memrefs affine map. In the example below, the ssa value '%s' is bound to
-/// the symbol 's0' in the affine map specified in the allocs memref type.
-///
-/// %0 = alloc()[%s] : memref<8x64xf32, (d0, d1)[s0] -> ((d0 + s0), d1), 1>
-///
-/// This operation returns a single ssa value of memref type, which can be used
-/// by subsequent load and store operations.
-class AllocOp
- : public Op<AllocOp, OpTrait::VariadicOperands, OpTrait::OneResult> {
-public:
- friend Operation;
- using Op::Op;
-
- /// The result of an alloc is always a MemRefType.
- MemRefType getType() { return getResult()->getType().cast<MemRefType>(); }
-
- static StringRef getOperationName() { return "std.alloc"; }
-
- // Hooks to customize behavior of this op.
- static void build(Builder *builder, OperationState *result,
- MemRefType memrefType, ArrayRef<Value *> operands = {});
- LogicalResult verify();
- static ParseResult parse(OpAsmParser *parser, OperationState *result);
- void print(OpAsmPrinter *p);
- static void getCanonicalizationPatterns(OwningRewritePatternList &results,
- MLIRContext *context);
-};
-
/// The "br" operation represents a branch operation in a function.
/// The operation takes variable number of operands and produces no results.
/// The operand number and types for each successor must match the
static bool isClassFor(Operation *op);
};
-/// The "dealloc" operation frees the region of memory referenced by a memref
-/// which was originally created by the "alloc" operation.
-/// The "dealloc" operation should not be called on memrefs which alias an
-// alloc'd memref (i.e. memrefs returned by the "view" and "reshape"
-/// operations).
-///
-/// %0 = alloc() : memref<8x64xf32, (d0, d1) -> (d0, d1), 1>
-///
-/// dealloc %0 : memref<8x64xf32, (d0, d1) -> (d0, d1), 1>
-///
-class DeallocOp
- : public Op<DeallocOp, OpTrait::OneOperand, OpTrait::ZeroResult> {
-public:
- friend Operation;
- using Op::Op;
-
- Value *getMemRef() { return getOperand(); }
- void setMemRef(Value *value) { setOperand(value); }
-
- static StringRef getOperationName() { return "std.dealloc"; }
-
- // Hooks to customize behavior of this op.
- static void build(Builder *builder, OperationState *result, Value *memref);
- LogicalResult verify();
- static ParseResult parse(OpAsmParser *parser, OperationState *result);
- void print(OpAsmPrinter *p);
- static void getCanonicalizationPatterns(OwningRewritePatternList &results,
- MLIRContext *context);
-};
-
/// The "dim" operation takes a memref or tensor operand and returns an
/// "index". It requires a single integer attribute named "index". It
/// returns the size of the specified dimension. For example:
let hasConstantFolder = 0b1;
}
+def AllocOp : Op<Standard_Dialect, "alloc"> {
+ let summary = "memory allocation operation";
+ let description = [{
+ The "alloc" operation allocates a region of memory, as specified by its
+ memref type. For example:
+
+ %0 = alloc() : memref<8x64xf32, (d0, d1) -> (d0, d1), 1>
+
+ The optional list of dimension operands are bound to the dynamic dimensions
+ specified in its memref type. In the example below, the ssa value '%d' is
+ bound to the second dimension of the memref (which is dynamic).
+
+ %0 = alloc(%d) : memref<8x?xf32, (d0, d1) -> (d0, d1), 1>
+
+ The optional list of symbol operands are bound to the symbols of the
+ memrefs affine map. In the example below, the ssa value '%s' is bound to
+ the symbol 's0' in the affine map specified in the allocs memref type.
+
+ %0 = alloc()[%s] : memref<8x64xf32, (d0, d1)[s0] -> ((d0 + s0), d1), 1>
+
+ This operation returns a single ssa value of memref type, which can be used
+ by subsequent load and store operations.
+ }];
+
+ let arguments = (ins Variadic<Index>:$value);
+ let results = (outs MemRef<AnyType>);
+
+ let builders = [OpBuilder<
+ "Builder *builder, OperationState *result, MemRefType memrefType", [{
+ result->types.push_back(memrefType);
+ }]
+ >];
+
+ let parser = [{ return parseAllocOp(parser, result); }];
+ let printer = [{ return printAllocOp(p, *this); }];
+ let verifier = [{ return ::verify(*this); }];
+
+ let extraClassDeclaration = [{
+ MemRefType getType() { return getResult()->getType().cast<MemRefType>(); }
+ }];
+
+ let hasCanonicalizer = 0b1;
+}
+
def AndOp : IntArithmeticOp<"and", [Commutative]> {
let summary = "integer binary and";
let hasConstantFolder = 0b1;
let hasConstantFolder = 1;
}
+def DeallocOp : Op<Standard_Dialect, "dealloc"> {
+ let summary = "memory deallocation operation";
+ let description = [{
+ The "dealloc" operation frees the region of memory referenced by a memref
+ which was originally created by the "alloc" operation.
+ The "dealloc" operation should not be called on memrefs which alias an
+ alloc'd memref (i.e. memrefs returned by the "view" and "reshape"
+ operations).
+
+ %0 = alloc() : memref<8x64xf32, (d0, d1) -> (d0, d1), 1>
+ dealloc %0 : memref<8x64xf32, (d0, d1) -> (d0, d1), 1>
+ }];
+
+ let arguments = (ins MemRef<AnyType>:$memref);
+
+ let parser = [{ return parseDeallocOp(parser, result); }];
+ let printer = [{ return printDeallocOp(p, *this); }];
+ let verifier = [{ return ::verify(*this); }];
+
+ let hasCanonicalizer = 0b1;
+}
+
def DivFOp : FloatArithmeticOp<"divf"> {
let summary = "floating point division operation";
}
StandardOpsDialect::StandardOpsDialect(MLIRContext *context)
: Dialect(/*name=*/"std", context) {
- addOperations<AllocOp, BranchOp, CallOp, CallIndirectOp, CmpFOp, CmpIOp,
- CondBranchOp, DeallocOp, DimOp, DmaStartOp, DmaWaitOp,
- ExtractElementOp, LoadOp, MemRefCastOp, ReturnOp, SelectOp,
- StoreOp, TensorCastOp,
+ addOperations<BranchOp, CallOp, CallIndirectOp, CmpFOp, CmpIOp, CondBranchOp,
+ DimOp, DmaStartOp, DmaWaitOp, ExtractElementOp, LoadOp,
+ MemRefCastOp, ReturnOp, SelectOp, StoreOp, TensorCastOp,
#define GET_OP_LIST
#include "mlir/StandardOps/Ops.cpp.inc"
>();
// AllocOp
//===----------------------------------------------------------------------===//
-void AllocOp::build(Builder *builder, OperationState *result,
- MemRefType memrefType, ArrayRef<Value *> operands) {
- result->addOperands(operands);
- result->types.push_back(memrefType);
-}
-
-void AllocOp::print(OpAsmPrinter *p) {
- MemRefType type = getType();
+static void printAllocOp(OpAsmPrinter *p, AllocOp op) {
*p << "alloc";
+
// Print dynamic dimension operands.
- printDimAndSymbolList(operand_begin(), operand_end(),
+ MemRefType type = op.getType();
+ printDimAndSymbolList(op.operand_begin(), op.operand_end(),
type.getNumDynamicDims(), p);
- p->printOptionalAttrDict(getAttrs(), /*elidedAttrs=*/{"map"});
+ p->printOptionalAttrDict(op.getAttrs(), /*elidedAttrs=*/{"map"});
*p << " : " << type;
}
-ParseResult AllocOp::parse(OpAsmParser *parser, OperationState *result) {
+static ParseResult parseAllocOp(OpAsmParser *parser, OperationState *result) {
MemRefType type;
// Parse the dimension operands and optional symbol operands, followed by a
// Verification still checks that the total number of operands matches
// the number of symbols in the affine map, plus the number of dynamic
// dimensions in the memref.
- if (numDimOperands != type.getNumDynamicDims()) {
- return parser->emitError(parser->getNameLoc(),
- "dimension operand count does not equal memref "
- "dynamic dimension count");
- }
+ if (numDimOperands != type.getNumDynamicDims())
+ return parser->emitError(parser->getNameLoc())
+ << "dimension operand count does not equal memref dynamic dimension "
+ "count";
result->types.push_back(type);
return success();
}
-LogicalResult AllocOp::verify() {
- auto memRefType = getResult()->getType().dyn_cast<MemRefType>();
+static LogicalResult verify(AllocOp op) {
+ auto memRefType = op.getResult()->getType().dyn_cast<MemRefType>();
if (!memRefType)
- return emitOpError("result must be a memref");
+ return op.emitOpError("result must be a memref");
unsigned numSymbols = 0;
if (!memRefType.getAffineMaps().empty()) {
//
// Verify that the layout affine map matches the rank of the memref.
if (affineMap.getNumDims() != memRefType.getRank())
- return emitOpError("affine map dimension count must equal memref rank");
+ return op.emitOpError(
+ "affine map dimension count must equal memref rank");
}
unsigned numDynamicDims = memRefType.getNumDynamicDims();
// Check that the total number of operands matches the number of symbols in
// the affine map, plus the number of dynamic dimensions specified in the
// memref type.
- if (getOperation()->getNumOperands() != numDynamicDims + numSymbols)
- return emitOpError(
+ if (op.getOperation()->getNumOperands() != numDynamicDims + numSymbols)
+ return op.emitOpError(
"operand count does not equal dimension plus symbol operand count");
// Verify that all operands are of type Index.
- for (auto *operand : getOperands())
+ for (auto *operand : op.getOperands())
if (!operand->getType().isIndex())
- return emitOpError("requires operands to be of type Index");
+ return op.emitOpError("requires operands to be of type Index");
return success();
}
auto dealloc = op->cast<DeallocOp>();
// Check that the memref operand's defining operation is an AllocOp.
- Value *memref = dealloc.getMemRef();
+ Value *memref = dealloc.memref();
Operation *defOp = memref->getDefiningOp();
if (!isa_and_nonnull<AllocOp>(defOp))
return matchFailure();
};
} // end anonymous namespace.
-void DeallocOp::build(Builder *builder, OperationState *result, Value *memref) {
- result->addOperands(memref);
-}
-
-void DeallocOp::print(OpAsmPrinter *p) {
- *p << "dealloc " << *getMemRef() << " : " << getMemRef()->getType();
+static void printDeallocOp(OpAsmPrinter *p, DeallocOp op) {
+ *p << "dealloc " << *op.memref() << " : " << op.memref()->getType();
}
-ParseResult DeallocOp::parse(OpAsmParser *parser, OperationState *result) {
+static ParseResult parseDeallocOp(OpAsmParser *parser, OperationState *result) {
OpAsmParser::OperandType memrefInfo;
MemRefType type;
parser->resolveOperand(memrefInfo, type, result->operands));
}
-LogicalResult DeallocOp::verify() {
- if (!getMemRef()->getType().isa<MemRefType>())
- return emitOpError("operand must be a memref");
+static LogicalResult verify(DeallocOp op) {
+ if (!op.memref()->getType().isa<MemRefType>())
+ return op.emitOpError("operand must be a memref");
return success();
}