2020-11-05 02:08:34 +08:00
|
|
|
//===-- mlir-c/AffineExpr.h - C API for MLIR Affine Expressions ---*- C -*-===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM
|
|
|
|
// Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-10-21 15:32:01 +08:00
|
|
|
|
|
|
|
#ifndef MLIR_C_AFFINEEXPR_H
|
|
|
|
#define MLIR_C_AFFINEEXPR_H
|
|
|
|
|
|
|
|
#include "mlir-c/IR.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2021-01-25 22:22:16 +08:00
|
|
|
// Opaque type declarations.
|
|
|
|
//
|
|
|
|
// Types are exposed to C bindings as structs containing opaque pointers. They
|
|
|
|
// are not supposed to be inspected from C. This allows the underlying
|
|
|
|
// representation to change without affecting the API users. The use of structs
|
|
|
|
// instead of typedefs enables some type safety as structs are not implicitly
|
|
|
|
// convertible to each other.
|
|
|
|
//
|
|
|
|
// Instances of these types may or may not own the underlying object. The
|
|
|
|
// ownership semantics is defined by how an instance of the type was obtained.
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2020-11-03 02:56:25 +08:00
|
|
|
|
|
|
|
#define DEFINE_C_API_STRUCT(name, storage) \
|
|
|
|
struct name { \
|
|
|
|
storage *ptr; \
|
|
|
|
}; \
|
|
|
|
typedef struct name name
|
|
|
|
|
2020-10-21 15:32:01 +08:00
|
|
|
DEFINE_C_API_STRUCT(MlirAffineExpr, const void);
|
|
|
|
|
2020-11-03 02:56:25 +08:00
|
|
|
#undef DEFINE_C_API_STRUCT
|
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Gets the context that owns the affine expression.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirContext
|
|
|
|
mlirAffineExprGetContext(MlirAffineExpr affineExpr);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2021-01-07 18:09:09 +08:00
|
|
|
/// Returns `true` if the two affine expressions are equal.
|
|
|
|
MLIR_CAPI_EXPORTED bool mlirAffineExprEqual(MlirAffineExpr lhs,
|
|
|
|
MlirAffineExpr rhs);
|
|
|
|
|
|
|
|
/// Returns `true` if the given affine expression is a null expression. Note
|
|
|
|
/// constant zero is not a null expression.
|
2021-01-13 00:02:56 +08:00
|
|
|
inline static bool mlirAffineExprIsNull(MlirAffineExpr affineExpr) {
|
2021-01-07 18:09:09 +08:00
|
|
|
return affineExpr.ptr == NULL;
|
|
|
|
}
|
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Prints an affine expression by sending chunks of the string representation
|
|
|
|
/// and forwarding `userData to `callback`. Note that the callback may be called
|
|
|
|
/// several times with consecutive chunks of the string.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED void mlirAffineExprPrint(MlirAffineExpr affineExpr,
|
|
|
|
MlirStringCallback callback,
|
|
|
|
void *userData);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Prints the affine expression to the standard error stream.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED void mlirAffineExprDump(MlirAffineExpr affineExpr);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Checks whether the given affine expression is made out of only symbols and
|
|
|
|
/// constants.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool
|
2020-11-09 08:49:36 +08:00
|
|
|
mlirAffineExprIsSymbolicOrConstant(MlirAffineExpr affineExpr);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Checks whether the given affine expression is a pure affine expression, i.e.
|
|
|
|
/// mul, floordiv, ceildic, and mod is only allowed w.r.t constants.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAffineExprIsPureAffine(MlirAffineExpr affineExpr);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Returns the greatest known integral divisor of this affine expression. The
|
|
|
|
/// result is always positive.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED int64_t
|
|
|
|
mlirAffineExprGetLargestKnownDivisor(MlirAffineExpr affineExpr);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given affine expression is a multiple of 'factor'.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAffineExprIsMultipleOf(MlirAffineExpr affineExpr,
|
|
|
|
int64_t factor);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Checks whether the given affine expression involves AffineDimExpr
|
|
|
|
/// 'position'.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAffineExprIsFunctionOfDim(MlirAffineExpr affineExpr,
|
|
|
|
intptr_t position);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Affine Dimension Expression.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2021-01-07 18:09:09 +08:00
|
|
|
/// Checks whether the given affine expression is a dimension expression.
|
|
|
|
MLIR_CAPI_EXPORTED bool mlirAffineExprIsADim(MlirAffineExpr affineExpr);
|
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Creates an affine dimension expression with 'position' in the context.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineDimExprGet(MlirContext ctx,
|
|
|
|
intptr_t position);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Returns the position of the given affine dimension expression.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED intptr_t
|
|
|
|
mlirAffineDimExprGetPosition(MlirAffineExpr affineExpr);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Affine Symbol Expression.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2021-01-07 18:09:09 +08:00
|
|
|
/// Checks whether the given affine expression is a symbol expression.
|
|
|
|
MLIR_CAPI_EXPORTED bool mlirAffineExprIsASymbol(MlirAffineExpr affineExpr);
|
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Creates an affine symbol expression with 'position' in the context.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineSymbolExprGet(MlirContext ctx,
|
|
|
|
intptr_t position);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Returns the position of the given affine symbol expression.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED intptr_t
|
|
|
|
mlirAffineSymbolExprGetPosition(MlirAffineExpr affineExpr);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Affine Constant Expression.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2021-01-07 18:09:09 +08:00
|
|
|
/// Checks whether the given affine expression is a constant expression.
|
|
|
|
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAConstant(MlirAffineExpr affineExpr);
|
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Creates an affine constant expression with 'constant' in the context.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineConstantExprGet(MlirContext ctx,
|
|
|
|
int64_t constant);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Returns the value of the given affine constant expression.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED int64_t
|
|
|
|
mlirAffineConstantExprGetValue(MlirAffineExpr affineExpr);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Affine Add Expression.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given affine expression is an add expression.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAAdd(MlirAffineExpr affineExpr);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Creates an affine add expression with 'lhs' and 'rhs'.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineAddExprGet(MlirAffineExpr lhs,
|
|
|
|
MlirAffineExpr rhs);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Affine Mul Expression.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given affine expression is an mul expression.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAMul(MlirAffineExpr affineExpr);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Creates an affine mul expression with 'lhs' and 'rhs'.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineMulExprGet(MlirAffineExpr lhs,
|
|
|
|
MlirAffineExpr rhs);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Affine Mod Expression.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given affine expression is an mod expression.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAMod(MlirAffineExpr affineExpr);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Creates an affine mod expression with 'lhs' and 'rhs'.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineModExprGet(MlirAffineExpr lhs,
|
|
|
|
MlirAffineExpr rhs);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Affine FloorDiv Expression.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given affine expression is an floordiv expression.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAFloorDiv(MlirAffineExpr affineExpr);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Creates an affine floordiv expression with 'lhs' and 'rhs'.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineFloorDivExprGet(MlirAffineExpr lhs,
|
|
|
|
MlirAffineExpr rhs);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Affine CeilDiv Expression.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Checks whether the given affine expression is an ceildiv expression.
|
2020-11-30 10:31:11 +08:00
|
|
|
MLIR_CAPI_EXPORTED bool mlirAffineExprIsACeilDiv(MlirAffineExpr affineExpr);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Creates an affine ceildiv expression with 'lhs' and 'rhs'.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineCeilDivExprGet(MlirAffineExpr lhs,
|
|
|
|
MlirAffineExpr rhs);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Affine Binary Operation Expression.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2021-01-07 18:09:09 +08:00
|
|
|
/// Checks whether the given affine expression is binary.
|
|
|
|
MLIR_CAPI_EXPORTED bool mlirAffineExprIsABinary(MlirAffineExpr affineExpr);
|
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Returns the left hand side affine expression of the given affine binary
|
|
|
|
/// operation expression.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAffineExpr
|
|
|
|
mlirAffineBinaryOpExprGetLHS(MlirAffineExpr affineExpr);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Returns the right hand side affine expression of the given affine binary
|
|
|
|
/// operation expression.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirAffineExpr
|
|
|
|
mlirAffineBinaryOpExprGetRHS(MlirAffineExpr affineExpr);
|
2020-10-21 15:32:01 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // MLIR_C_AFFINEEXPR_H
|