forked from OSchip/llvm-project
[mlir] NFC: use doxygen-style comments in AffineToStandard.cpp
This commit is contained in:
parent
5f87510c37
commit
6895a1c37e
|
@ -29,14 +29,14 @@
|
||||||
using namespace mlir;
|
using namespace mlir;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
// Visit affine expressions recursively and build the sequence of operations
|
/// Visit affine expressions recursively and build the sequence of operations
|
||||||
// that correspond to it. Visitation functions return an Value of the
|
/// that correspond to it. Visitation functions return an Value of the
|
||||||
// expression subtree they visited or `nullptr` on error.
|
/// expression subtree they visited or `nullptr` on error.
|
||||||
class AffineApplyExpander
|
class AffineApplyExpander
|
||||||
: public AffineExprVisitor<AffineApplyExpander, Value> {
|
: public AffineExprVisitor<AffineApplyExpander, Value> {
|
||||||
public:
|
public:
|
||||||
// This internal class expects arguments to be non-null, checks must be
|
/// This internal class expects arguments to be non-null, checks must be
|
||||||
// performed at the call site.
|
/// performed at the call site.
|
||||||
AffineApplyExpander(OpBuilder &builder, ArrayRef<Value> dimValues,
|
AffineApplyExpander(OpBuilder &builder, ArrayRef<Value> dimValues,
|
||||||
ArrayRef<Value> symbolValues, Location loc)
|
ArrayRef<Value> symbolValues, Location loc)
|
||||||
: builder(builder), dimValues(dimValues), symbolValues(symbolValues),
|
: builder(builder), dimValues(dimValues), symbolValues(symbolValues),
|
||||||
|
@ -59,15 +59,15 @@ public:
|
||||||
return buildBinaryExpr<MulIOp>(expr);
|
return buildBinaryExpr<MulIOp>(expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Euclidean modulo operation: negative RHS is not allowed.
|
/// Euclidean modulo operation: negative RHS is not allowed.
|
||||||
// Remainder of the euclidean integer division is always non-negative.
|
/// Remainder of the euclidean integer division is always non-negative.
|
||||||
//
|
///
|
||||||
// Implemented as
|
/// Implemented as
|
||||||
//
|
///
|
||||||
// a mod b =
|
/// a mod b =
|
||||||
// let remainder = srem a, b;
|
/// let remainder = srem a, b;
|
||||||
// negative = a < 0 in
|
/// negative = a < 0 in
|
||||||
// select negative, remainder + b, remainder.
|
/// select negative, remainder + b, remainder.
|
||||||
Value visitModExpr(AffineBinaryOpExpr expr) {
|
Value visitModExpr(AffineBinaryOpExpr expr) {
|
||||||
auto rhsConst = expr.getRHS().dyn_cast<AffineConstantExpr>();
|
auto rhsConst = expr.getRHS().dyn_cast<AffineConstantExpr>();
|
||||||
if (!rhsConst) {
|
if (!rhsConst) {
|
||||||
|
@ -95,16 +95,16 @@ public:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Floor division operation (rounds towards negative infinity).
|
/// Floor division operation (rounds towards negative infinity).
|
||||||
//
|
///
|
||||||
// For positive divisors, it can be implemented without branching and with a
|
/// For positive divisors, it can be implemented without branching and with a
|
||||||
// single division operation as
|
/// single division operation as
|
||||||
//
|
///
|
||||||
// a floordiv b =
|
/// a floordiv b =
|
||||||
// let negative = a < 0 in
|
/// let negative = a < 0 in
|
||||||
// let absolute = negative ? -a - 1 : a in
|
/// let absolute = negative ? -a - 1 : a in
|
||||||
// let quotient = absolute / b in
|
/// let quotient = absolute / b in
|
||||||
// negative ? -quotient - 1 : quotient
|
/// negative ? -quotient - 1 : quotient
|
||||||
Value visitFloorDivExpr(AffineBinaryOpExpr expr) {
|
Value visitFloorDivExpr(AffineBinaryOpExpr expr) {
|
||||||
auto rhsConst = expr.getRHS().dyn_cast<AffineConstantExpr>();
|
auto rhsConst = expr.getRHS().dyn_cast<AffineConstantExpr>();
|
||||||
if (!rhsConst) {
|
if (!rhsConst) {
|
||||||
|
@ -136,16 +136,16 @@ public:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ceiling division operation (rounds towards positive infinity).
|
/// Ceiling division operation (rounds towards positive infinity).
|
||||||
//
|
///
|
||||||
// For positive divisors, it can be implemented without branching and with a
|
/// For positive divisors, it can be implemented without branching and with a
|
||||||
// single division operation as
|
/// single division operation as
|
||||||
//
|
///
|
||||||
// a ceildiv b =
|
/// a ceildiv b =
|
||||||
// let negative = a <= 0 in
|
/// let negative = a <= 0 in
|
||||||
// let absolute = negative ? -a : a - 1 in
|
/// let absolute = negative ? -a : a - 1 in
|
||||||
// let quotient = absolute / b in
|
/// let quotient = absolute / b in
|
||||||
// negative ? -quotient : quotient + 1
|
/// negative ? -quotient : quotient + 1
|
||||||
Value visitCeilDivExpr(AffineBinaryOpExpr expr) {
|
Value visitCeilDivExpr(AffineBinaryOpExpr expr) {
|
||||||
auto rhsConst = expr.getRHS().dyn_cast<AffineConstantExpr>();
|
auto rhsConst = expr.getRHS().dyn_cast<AffineConstantExpr>();
|
||||||
if (!rhsConst) {
|
if (!rhsConst) {
|
||||||
|
@ -206,16 +206,16 @@ private:
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
// Create a sequence of operations that implement the `expr` applied to the
|
/// Create a sequence of operations that implement the `expr` applied to the
|
||||||
// given dimension and symbol values.
|
/// given dimension and symbol values.
|
||||||
mlir::Value mlir::expandAffineExpr(OpBuilder &builder, Location loc,
|
mlir::Value mlir::expandAffineExpr(OpBuilder &builder, Location loc,
|
||||||
AffineExpr expr, ArrayRef<Value> dimValues,
|
AffineExpr expr, ArrayRef<Value> dimValues,
|
||||||
ArrayRef<Value> symbolValues) {
|
ArrayRef<Value> symbolValues) {
|
||||||
return AffineApplyExpander(builder, dimValues, symbolValues, loc).visit(expr);
|
return AffineApplyExpander(builder, dimValues, symbolValues, loc).visit(expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a sequence of operations that implement the `affineMap` applied to
|
/// Create a sequence of operations that implement the `affineMap` applied to
|
||||||
// the given `operands` (as it it were an AffineApplyOp).
|
/// the given `operands` (as it it were an AffineApplyOp).
|
||||||
Optional<SmallVector<Value, 8>> static expandAffineMap(
|
Optional<SmallVector<Value, 8>> static expandAffineMap(
|
||||||
OpBuilder &builder, Location loc, AffineMap affineMap,
|
OpBuilder &builder, Location loc, AffineMap affineMap,
|
||||||
ArrayRef<Value> operands) {
|
ArrayRef<Value> operands) {
|
||||||
|
@ -232,17 +232,17 @@ Optional<SmallVector<Value, 8>> static expandAffineMap(
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Given a range of values, emit the code that reduces them with "min" or "max"
|
/// Given a range of values, emit the code that reduces them with "min" or "max"
|
||||||
// depending on the provided comparison predicate. The predicate defines which
|
/// depending on the provided comparison predicate. The predicate defines which
|
||||||
// comparison to perform, "lt" for "min", "gt" for "max" and is used for the
|
/// comparison to perform, "lt" for "min", "gt" for "max" and is used for the
|
||||||
// `cmpi` operation followed by the `select` operation:
|
/// `cmpi` operation followed by the `select` operation:
|
||||||
//
|
///
|
||||||
// %cond = cmpi "predicate" %v0, %v1
|
/// %cond = cmpi "predicate" %v0, %v1
|
||||||
// %result = select %cond, %v0, %v1
|
/// %result = select %cond, %v0, %v1
|
||||||
//
|
///
|
||||||
// Multiple values are scanned in a linear sequence. This creates a data
|
/// Multiple values are scanned in a linear sequence. This creates a data
|
||||||
// dependences that wouldn't exist in a tree reduction, but is easier to
|
/// dependences that wouldn't exist in a tree reduction, but is easier to
|
||||||
// recognize as a reduction by the subsequent passes.
|
/// recognize as a reduction by the subsequent passes.
|
||||||
static Value buildMinMaxReductionSeq(Location loc, CmpIPredicate predicate,
|
static Value buildMinMaxReductionSeq(Location loc, CmpIPredicate predicate,
|
||||||
ArrayRef<Value> values,
|
ArrayRef<Value> values,
|
||||||
OpBuilder &builder) {
|
OpBuilder &builder) {
|
||||||
|
@ -258,9 +258,9 @@ static Value buildMinMaxReductionSeq(Location loc, CmpIPredicate predicate,
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit instructions that correspond to the affine map in the lower bound
|
/// Emit instructions that correspond to the affine map in the lower bound
|
||||||
// applied to the respective operands, and compute the maximum value across
|
/// applied to the respective operands, and compute the maximum value across
|
||||||
// the results.
|
/// the results.
|
||||||
Value mlir::lowerAffineLowerBound(AffineForOp op, OpBuilder &builder) {
|
Value mlir::lowerAffineLowerBound(AffineForOp op, OpBuilder &builder) {
|
||||||
SmallVector<Value, 8> boundOperands(op.getLowerBoundOperands());
|
SmallVector<Value, 8> boundOperands(op.getLowerBoundOperands());
|
||||||
auto lbValues = expandAffineMap(builder, op.getLoc(), op.getLowerBoundMap(),
|
auto lbValues = expandAffineMap(builder, op.getLoc(), op.getLowerBoundMap(),
|
||||||
|
@ -271,8 +271,8 @@ Value mlir::lowerAffineLowerBound(AffineForOp op, OpBuilder &builder) {
|
||||||
builder);
|
builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit instructions that correspond to computing the minimum value amoung the
|
/// Emit instructions that correspond to computing the minimum value amoung the
|
||||||
// values of a (potentially) multi-output affine map applied to `operands`.
|
/// values of a (potentially) multi-output affine map applied to `operands`.
|
||||||
static Value lowerAffineMapMin(OpBuilder &builder, Location loc, AffineMap map,
|
static Value lowerAffineMapMin(OpBuilder &builder, Location loc, AffineMap map,
|
||||||
ValueRange operands) {
|
ValueRange operands) {
|
||||||
if (auto values =
|
if (auto values =
|
||||||
|
@ -281,9 +281,9 @@ static Value lowerAffineMapMin(OpBuilder &builder, Location loc, AffineMap map,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit instructions that correspond to the affine map in the upper bound
|
/// Emit instructions that correspond to the affine map in the upper bound
|
||||||
// applied to the respective operands, and compute the minimum value across
|
/// applied to the respective operands, and compute the minimum value across
|
||||||
// the results.
|
/// the results.
|
||||||
Value mlir::lowerAffineUpperBound(AffineForOp op, OpBuilder &builder) {
|
Value mlir::lowerAffineUpperBound(AffineForOp op, OpBuilder &builder) {
|
||||||
return lowerAffineMapMin(builder, op.getLoc(), op.getUpperBoundMap(),
|
return lowerAffineMapMin(builder, op.getLoc(), op.getUpperBoundMap(),
|
||||||
op.getUpperBoundOperands());
|
op.getUpperBoundOperands());
|
||||||
|
@ -306,7 +306,7 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Affine terminators are removed.
|
/// Affine terminators are removed.
|
||||||
class AffineTerminatorLowering : public OpRewritePattern<AffineTerminatorOp> {
|
class AffineTerminatorLowering : public OpRewritePattern<AffineTerminatorOp> {
|
||||||
public:
|
public:
|
||||||
using OpRewritePattern<AffineTerminatorOp>::OpRewritePattern;
|
using OpRewritePattern<AffineTerminatorOp>::OpRewritePattern;
|
||||||
|
@ -387,8 +387,8 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Convert an "affine.apply" operation into a sequence of arithmetic
|
/// Convert an "affine.apply" operation into a sequence of arithmetic
|
||||||
// operations using the StandardOps dialect.
|
/// operations using the StandardOps dialect.
|
||||||
class AffineApplyLowering : public OpRewritePattern<AffineApplyOp> {
|
class AffineApplyLowering : public OpRewritePattern<AffineApplyOp> {
|
||||||
public:
|
public:
|
||||||
using OpRewritePattern<AffineApplyOp>::OpRewritePattern;
|
using OpRewritePattern<AffineApplyOp>::OpRewritePattern;
|
||||||
|
@ -405,9 +405,9 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Apply the affine map from an 'affine.load' operation to its operands, and
|
/// Apply the affine map from an 'affine.load' operation to its operands, and
|
||||||
// feed the results to a newly created 'std.load' operation (which replaces the
|
/// feed the results to a newly created 'std.load' operation (which replaces the
|
||||||
// original 'affine.load').
|
/// original 'affine.load').
|
||||||
class AffineLoadLowering : public OpRewritePattern<AffineLoadOp> {
|
class AffineLoadLowering : public OpRewritePattern<AffineLoadOp> {
|
||||||
public:
|
public:
|
||||||
using OpRewritePattern<AffineLoadOp>::OpRewritePattern;
|
using OpRewritePattern<AffineLoadOp>::OpRewritePattern;
|
||||||
|
@ -427,9 +427,9 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Apply the affine map from an 'affine.prefetch' operation to its operands, and
|
/// Apply the affine map from an 'affine.prefetch' operation to its operands,
|
||||||
// feed the results to a newly created 'std.prefetch' operation (which replaces
|
/// and feed the results to a newly created 'std.prefetch' operation (which
|
||||||
// the original 'affine.prefetch').
|
/// replaces the original 'affine.prefetch').
|
||||||
class AffinePrefetchLowering : public OpRewritePattern<AffinePrefetchOp> {
|
class AffinePrefetchLowering : public OpRewritePattern<AffinePrefetchOp> {
|
||||||
public:
|
public:
|
||||||
using OpRewritePattern<AffinePrefetchOp>::OpRewritePattern;
|
using OpRewritePattern<AffinePrefetchOp>::OpRewritePattern;
|
||||||
|
@ -451,9 +451,9 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Apply the affine map from an 'affine.store' operation to its operands, and
|
/// Apply the affine map from an 'affine.store' operation to its operands, and
|
||||||
// feed the results to a newly created 'std.store' operation (which replaces the
|
/// feed the results to a newly created 'std.store' operation (which replaces
|
||||||
// original 'affine.store').
|
/// the original 'affine.store').
|
||||||
class AffineStoreLowering : public OpRewritePattern<AffineStoreOp> {
|
class AffineStoreLowering : public OpRewritePattern<AffineStoreOp> {
|
||||||
public:
|
public:
|
||||||
using OpRewritePattern<AffineStoreOp>::OpRewritePattern;
|
using OpRewritePattern<AffineStoreOp>::OpRewritePattern;
|
||||||
|
@ -474,9 +474,9 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Apply the affine maps from an 'affine.dma_start' operation to each of their
|
/// Apply the affine maps from an 'affine.dma_start' operation to each of their
|
||||||
// respective map operands, and feed the results to a newly created
|
/// respective map operands, and feed the results to a newly created
|
||||||
// 'std.dma_start' operation (which replaces the original 'affine.dma_start').
|
/// 'std.dma_start' operation (which replaces the original 'affine.dma_start').
|
||||||
class AffineDmaStartLowering : public OpRewritePattern<AffineDmaStartOp> {
|
class AffineDmaStartLowering : public OpRewritePattern<AffineDmaStartOp> {
|
||||||
public:
|
public:
|
||||||
using OpRewritePattern<AffineDmaStartOp>::OpRewritePattern;
|
using OpRewritePattern<AffineDmaStartOp>::OpRewritePattern;
|
||||||
|
@ -514,9 +514,9 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Apply the affine map from an 'affine.dma_wait' operation tag memref,
|
/// Apply the affine map from an 'affine.dma_wait' operation tag memref,
|
||||||
// and feed the results to a newly created 'std.dma_wait' operation (which
|
/// and feed the results to a newly created 'std.dma_wait' operation (which
|
||||||
// replaces the original 'affine.dma_wait').
|
/// replaces the original 'affine.dma_wait').
|
||||||
class AffineDmaWaitLowering : public OpRewritePattern<AffineDmaWaitOp> {
|
class AffineDmaWaitLowering : public OpRewritePattern<AffineDmaWaitOp> {
|
||||||
public:
|
public:
|
||||||
using OpRewritePattern<AffineDmaWaitOp>::OpRewritePattern;
|
using OpRewritePattern<AffineDmaWaitOp>::OpRewritePattern;
|
||||||
|
|
Loading…
Reference in New Issue