From ca23bd78d4bed96020f7e681a88c4c767fe594aa Mon Sep 17 00:00:00 2001 From: Uday Bondhugula Date: Fri, 6 Dec 2019 16:16:32 -0800 Subject: [PATCH] NFC - update doc, comments, vim syntax file - for the symbol rules, the code was updated but the doc wasn't. Signed-off-by: Uday Bondhugula Closes tensorflow/mlir#284 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/284 from bondhugula:doc 9aad8b8a715559f7ce61265f3da3f8a3c11b45ea PiperOrigin-RevId: 284283712 --- mlir/g3doc/Dialects/Affine.md | 9 ++++++--- mlir/include/mlir/Analysis/AffineStructures.h | 16 +++++++++------- mlir/include/mlir/IR/AffineExpr.h | 5 ++--- mlir/lib/Analysis/AffineStructures.cpp | 2 +- mlir/lib/Dialect/AffineOps/AffineOps.cpp | 9 ++++++++- mlir/utils/vim/syntax/mlir.vim | 10 +++++++++- 6 files changed, 35 insertions(+), 16 deletions(-) diff --git a/mlir/g3doc/Dialects/Affine.md b/mlir/g3doc/Dialects/Affine.md index 60494570d0c0..11cb93c10ea1 100644 --- a/mlir/g3doc/Dialects/Affine.md +++ b/mlir/g3doc/Dialects/Affine.md @@ -66,9 +66,12 @@ function, a value defined at the top level of that function (outside of all loops and if operations), the result of a [`constant` operation](Standard.md#constant-operation), or the result of an [`affine.apply` operation](#affineapply-operation) that recursively takes as -arguments any symbolic identifiers. Dimensions may be bound not only to anything -that a symbol is bound to, but also to induction variables of enclosing -[`affine.for` operations](#affinefor-operation), and the result of an +arguments any symbolic identifiers, or the result of a [`dim` +operation](Standard.md#dim-operation) on either a memref that is a function +argument or a memref where the corresponding dimension is either static or a +dynamic one in turn bound to a symbolic identifier. Dimensions may be bound not +only to anything that a symbol is bound to, but also to induction variables of +enclosing [`affine.for` operations](#affinefor-operation), and the result of an [`affine.apply` operation](#affineapply-operation) (which recursively may use other dimensions and symbols). diff --git a/mlir/include/mlir/Analysis/AffineStructures.h b/mlir/include/mlir/Analysis/AffineStructures.h index ce49c842a401..143956e3b5cb 100644 --- a/mlir/include/mlir/Analysis/AffineStructures.h +++ b/mlir/include/mlir/Analysis/AffineStructures.h @@ -655,7 +655,7 @@ public: Optional getConstantUpperBound(unsigned pos) const; /// Gets the lower and upper bound of the pos^th identifier treating - /// [0, offset) U [offset + num, symbStartPos) as dimensions and + /// [0, offset) U [offset + num, symStartPos) as dimensions and /// [symStartPos, getNumDimAndSymbolIds) as symbols. The returned /// multi-dimensional maps in the pair represent the max and min of /// potentially multiple affine expressions. The upper bound is exclusive. @@ -664,7 +664,7 @@ public: std::pair getLowerAndUpperBound(unsigned pos, unsigned offset, unsigned num, unsigned symStartPos, ArrayRef localExprs, - MLIRContext *context); + MLIRContext *context) const; /// Returns true if the set can be trivially detected as being /// hyper-rectangular on the specified contiguous set of identifiers. @@ -788,11 +788,13 @@ private: AffineExpr simplifyAffineExpr(AffineExpr expr, unsigned numDims, unsigned numSymbols); -/// Flattens 'expr' into 'flattenedExpr'. Returns failure if 'expr' could not be -/// flattened (i.e., semi-affine is not yet handled). 'cst' contains constraints -/// that connect newly introduced local identifiers to existing dimensional and -/// symbolic identifiers. See documentation for AffineExprFlattener on how -/// mod's and div's are flattened. +/// Flattens 'expr' into 'flattenedExpr', which contains the coefficients of the +/// dimensions, symbols, and additional variables that represent floor divisions +/// of dimensions, symbols, and in turn other floor divisions. Returns failure +/// if 'expr' could not be flattened (i.e., semi-affine is not yet handled). +/// 'cst' contains constraints that connect newly introduced local identifiers +/// to existing dimensional and symbolic identifiers. See documentation for +/// AffineExprFlattener on how mod's and div's are flattened. LogicalResult getFlattenedAffineExpr(AffineExpr expr, unsigned numDims, unsigned numSymbols, llvm::SmallVectorImpl *flattenedExpr, diff --git a/mlir/include/mlir/IR/AffineExpr.h b/mlir/include/mlir/IR/AffineExpr.h index 2420deb5b7e8..cca7eac536f5 100644 --- a/mlir/include/mlir/IR/AffineExpr.h +++ b/mlir/include/mlir/IR/AffineExpr.h @@ -267,9 +267,8 @@ AffineExpr simplifyAffineExpr(AffineExpr expr, unsigned numDims, /// Flattens 'expr' into 'flattenedExpr'. Returns true on success or false /// if 'expr' could not be flattened (i.e., semi-affine is not yet handled). -/// 'cst' contains constraints that connect newly introduced local identifiers -/// to existing dimensional and / symbolic identifiers. See documentation for -/// AffineExprFlattener on how mod's and div's are flattened. +/// See documentation for AffineExprFlattener on how mod's and div's are +/// flattened. bool getFlattenedAffineExpr(AffineExpr expr, unsigned numDims, unsigned numSymbols, llvm::SmallVectorImpl *flattenedExpr); diff --git a/mlir/lib/Analysis/AffineStructures.cpp b/mlir/lib/Analysis/AffineStructures.cpp index 80dc73755c75..e57045c639db 100644 --- a/mlir/lib/Analysis/AffineStructures.cpp +++ b/mlir/lib/Analysis/AffineStructures.cpp @@ -1525,7 +1525,7 @@ void FlatAffineConstraints::removeRedundantInequalities() { std::pair FlatAffineConstraints::getLowerAndUpperBound( unsigned pos, unsigned offset, unsigned num, unsigned symStartPos, - ArrayRef localExprs, MLIRContext *context) { + ArrayRef localExprs, MLIRContext *context) const { assert(pos + offset < getNumDimIds() && "invalid dim start pos"); assert(symStartPos >= (pos + offset) && "invalid sym start pos"); assert(getNumLocalIds() == localExprs.size() && diff --git a/mlir/lib/Dialect/AffineOps/AffineOps.cpp b/mlir/lib/Dialect/AffineOps/AffineOps.cpp index 2cd357fd5419..7232c6eb28c9 100644 --- a/mlir/lib/Dialect/AffineOps/AffineOps.cpp +++ b/mlir/lib/Dialect/AffineOps/AffineOps.cpp @@ -173,7 +173,8 @@ static bool isDimOpValidSymbol(DimOp dimOp) { // Value can be used as a symbol if it is a constant, or it is defined at // the top level, or it is a result of affine apply operation with symbol -// arguments. +// arguments, or a result of the dim op on a memref satisfying certain +// constraints. bool mlir::isValidSymbol(Value *value) { // The value must be an index type. if (!value->getType().isIndex()) @@ -747,6 +748,8 @@ template struct SimplifyAffineOp : public OpRewritePattern { using OpRewritePattern::OpRewritePattern; + /// Replace the affine op with another instance of it with the supplied + /// map and mapOperands. void replaceAffineOp(PatternRewriter &rewriter, AffineOpTy affineOp, AffineMap map, ArrayRef mapOperands) const; @@ -2039,5 +2042,9 @@ OpFoldResult AffineMinOp::fold(ArrayRef operands) { return results[minIndex]; } +//===----------------------------------------------------------------------===// +// TableGen'd op method definitions +//===----------------------------------------------------------------------===// + #define GET_OP_CLASSES #include "mlir/Dialect/AffineOps/AffineOps.cpp.inc" diff --git a/mlir/utils/vim/syntax/mlir.vim b/mlir/utils/vim/syntax/mlir.vim index 5774d10e7749..d9b6a3b29a11 100644 --- a/mlir/utils/vim/syntax/mlir.vim +++ b/mlir/utils/vim/syntax/mlir.vim @@ -31,7 +31,11 @@ syn match mlirType /x\s*\zsvector/ " Operations. " Core ops (not exhaustive yet). " TODO: the list is not exhaustive. -syn keyword mlirOps alloc addf addi call call_indirect cmpi constant dealloc dma_start dma_wait dim extract_element for getTensor if load memref_cast mulf muli splat store select subf subi tensor_cast +syn keyword mlirOps alloc alloca addf addi call call_indirect cmpi constant +syn keyword mlirOps dealloc divf dma_start dma_wait dim extract_element +syn keyword getTensor index_cast load memref_cast memref_shape_cast mulf muli +syn keyword prefetch sitofp splat store select subf subi subview tensor_cast +syn keyword view " Affine ops. syn match mlirOps /\/ @@ -41,13 +45,17 @@ syn match mlirOps /\/ syn match mlirOps /\/ syn match mlirOps /\/ syn match mlirOps /\/ +syn match mlirOps /\/ +syn match mlirOps /\/ " TODO: dialect name prefixed ops (llvm or std). " Keywords. syn keyword mlirKeyword + \ dense \ else \ func + \ module \ return \ step \ to