MLIR 22.0.0git
FlatLinearValueConstraints.cpp File Reference
#include "mlir/Analysis//FlatLinearValueConstraints.h"
#include "mlir/Analysis/Presburger/PresburgerSpace.h"
#include "mlir/Analysis/Presburger/Simplex.h"
#include "mlir/Analysis/Presburger/Utils.h"
#include "mlir/IR/AffineExprVisitor.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/IntegerSet.h"
#include "mlir/Support/LLVM.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/InterleavedRange.h"
#include "llvm/Support/raw_ostream.h"
#include <optional>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "flat-value-constraints"

Functions

static LogicalResult getFlattenedAffineExprs (ArrayRef< AffineExpr > exprs, unsigned numDims, unsigned numSymbols, std::vector< SmallVector< int64_t, 8 > > *flattenedExprs, FlatLinearConstraints *localVarCst, bool addConservativeSemiAffineBounds=false)
static bool detectAsMod (const FlatLinearConstraints &cst, unsigned pos, unsigned offset, unsigned num, int64_t lbConst, int64_t ubConst, MLIRContext *context, SmallVectorImpl< AffineExpr > &memo)
static bool detectAsFloorDiv (const FlatLinearConstraints &cst, unsigned pos, MLIRContext *context, SmallVectorImpl< AffineExpr > &exprs)
 Check if the pos^th variable can be expressed as a floordiv of an affine function of other variables (where the divisor is a positive constant) given the initial set of expressions in exprs.
static bool detectAsExpr (const FlatLinearConstraints &cst, unsigned pos, unsigned idx, MLIRContext *context, SmallVectorImpl< AffineExpr > &exprs)
 Express the pos^th identifier of cst as an affine expression in terms of other identifiers, if they are available in exprs, using the equality at position idx in cst.
static void computeUnknownVars (const FlatLinearConstraints &cst, MLIRContext *context, unsigned offset, unsigned num, SmallVectorImpl< AffineExpr > &memo)
 Compute a representation of num identifiers starting at offset in cst as affine expressions involving other known identifiers.
static std::optional< AffineExprgetAsExpr (const FlatLinearConstraints &cst, unsigned pos, MLIRContext *context, ArrayRef< AffineExpr > exprs, unsigned idx, bool isEquality)
 Given an equality or inequality (isEquality used to disambiguate) of cst at idx, traverse and sum up AffineExprs of all known ids other than the posth.
static bool areVarsAligned (const FlatLinearValueConstraints &a, const FlatLinearValueConstraints &b)
 Checks if two constraint systems are in the same space, i.e., if they are associated with the same set of variables, appearing in the same order.
static bool areVarsUnique (const FlatLinearValueConstraints &cst, unsigned start, unsigned end)
 Checks if the SSA values associated with cst's variables in range [start, end) are unique.
static bool areVarsUnique (const FlatLinearValueConstraints &cst)
 Checks if the SSA values associated with cst's variables are unique.
static bool areVarsUnique (const FlatLinearValueConstraints &cst, VarKind kind)
 Checks if the SSA values associated with cst's variables of kind kind are unique.
static void mergeAndAlignVars (unsigned offset, FlatLinearValueConstraints *a, FlatLinearValueConstraints *b)
 Merge and align the variables of A and B starting at 'offset', so that both constraint systems get the union of the contained variables that is dimension-wise and symbol-wise unique; both constraint systems are updated so that they have the union of all variables, with A's original variables appearing first followed by any of B's variables that didn't appear in A.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "flat-value-constraints"

Definition at line 25 of file FlatLinearValueConstraints.cpp.

Function Documentation

◆ areVarsAligned()

◆ areVarsUnique() [1/3]

bool areVarsUnique ( const FlatLinearValueConstraints & cst)
static

Checks if the SSA values associated with cst's variables are unique.

Definition at line 1272 of file FlatLinearValueConstraints.cpp.

References areVarsUnique(), and mlir::presburger::IntegerRelation::getNumDimAndSymbolVars().

◆ areVarsUnique() [2/3]

bool areVarsUnique ( const FlatLinearValueConstraints & cst,
unsigned start,
unsigned end )
static

Checks if the SSA values associated with cst's variables in range [start, end) are unique.

Definition at line 1248 of file FlatLinearValueConstraints.cpp.

References mlir::FlatLinearValueConstraints::getMaybeValues(), and mlir::presburger::IntegerRelation::getNumDimAndSymbolVars().

Referenced by areVarsUnique(), and areVarsUnique().

◆ areVarsUnique() [3/3]

bool areVarsUnique ( const FlatLinearValueConstraints & cst,
VarKind kind )
static

Checks if the SSA values associated with cst's variables of kind kind are unique.

Definition at line 1279 of file FlatLinearValueConstraints.cpp.

References areVarsUnique(), mlir::presburger::IntegerRelation::getNumDimAndSymbolVars(), and mlir::presburger::IntegerRelation::getNumDimVars().

◆ computeUnknownVars()

void computeUnknownVars ( const FlatLinearConstraints & cst,
MLIRContext * context,
unsigned offset,
unsigned num,
SmallVectorImpl< AffineExpr > & memo )
static

◆ detectAsExpr()

bool detectAsExpr ( const FlatLinearConstraints & cst,
unsigned pos,
unsigned idx,
MLIRContext * context,
SmallVectorImpl< AffineExpr > & exprs )
static

Express the pos^th identifier of cst as an affine expression in terms of other identifiers, if they are available in exprs, using the equality at position idx in cst.

Populates exprs with such an expression if possible, and return true. Returns false otherwise.

Definition at line 587 of file FlatLinearValueConstraints.cpp.

References mlir::presburger::IntegerRelation::atEq64(), mlir::getAffineConstantExpr(), and mlir::presburger::IntegerRelation::getNumVars().

Referenced by computeUnknownVars(), and mlir::FlatLinearConstraints::getConstantBoundOnDimSize().

◆ detectAsFloorDiv()

bool detectAsFloorDiv ( const FlatLinearConstraints & cst,
unsigned pos,
MLIRContext * context,
SmallVectorImpl< AffineExpr > & exprs )
static

Check if the pos^th variable can be expressed as a floordiv of an affine function of other variables (where the divisor is a positive constant) given the initial set of expressions in exprs.

If it can be, the corresponding position in exprs is set as the detected affine expr. For eg: 4q <= i + j <= 4q + 3 <=> q = (i + j) floordiv 4. An equality can also yield a floordiv: eg. 4q = i + j <=> q = (i + j) floordiv 4. 32q + 28 <= i <= 32q + 31 => q = i floordiv 32.

Definition at line 417 of file FlatLinearValueConstraints.cpp.

References mlir::presburger::computeSingleVarRepr(), mlir::getAffineConstantExpr(), mlir::presburger::IntegerRelation::getNumCols(), and mlir::presburger::IntegerRelation::getNumVars().

Referenced by mlir::FlatLinearConstraints::computeLocalVars(), and computeUnknownVars().

◆ detectAsMod()

◆ getAsExpr()

std::optional< AffineExpr > getAsExpr ( const FlatLinearConstraints & cst,
unsigned pos,
MLIRContext * context,
ArrayRef< AffineExpr > exprs,
unsigned idx,
bool isEquality )
static

Given an equality or inequality (isEquality used to disambiguate) of cst at idx, traverse and sum up AffineExprs of all known ids other than the posth.

Known AffineExprs are given in exprs (unknowns are null). If the equality/inequality contains any unknown id, return None. Otherwise return sum as AffineExpr.

Definition at line 913 of file FlatLinearValueConstraints.cpp.

References mlir::getAffineConstantExpr(), mlir::presburger::IntegerRelation::getEquality64(), mlir::presburger::IntegerRelation::getInequality64(), and mlir::presburger::IntegerRelation::getNumVars().

Referenced by mlir::FlatLinearConstraints::getConstantBoundOnDimSize().

◆ getFlattenedAffineExprs()

LogicalResult getFlattenedAffineExprs ( ArrayRef< AffineExpr > exprs,
unsigned numDims,
unsigned numSymbols,
std::vector< SmallVector< int64_t, 8 > > * flattenedExprs,
FlatLinearConstraints * localVarCst,
bool addConservativeSemiAffineBounds = false )
static

◆ mergeAndAlignVars()

void mergeAndAlignVars ( unsigned offset,
FlatLinearValueConstraints * a,
FlatLinearValueConstraints * b )
static

Merge and align the variables of A and B starting at 'offset', so that both constraint systems get the union of the contained variables that is dimension-wise and symbol-wise unique; both constraint systems are updated so that they have the union of all variables, with A's original variables appearing first followed by any of B's variables that didn't appear in A.

Local variables in B that have the same division representation as local variables in A are merged into one. We allow A and B to have non-unique values for their variables; in such cases, they are still aligned with the variables appearing first aligned with those appearing first in the other system from left to right.

Definition at line 1301 of file FlatLinearValueConstraints.cpp.

References mlir::FlatLinearValueConstraints::appendDimVar(), areVarsAligned(), b, mlir::FlatLinearValueConstraints::getMaybeValues(), mlir::presburger::IntegerRelation::getNumDimVars(), mlir::FlatLinearValueConstraints::getValues(), mlir::presburger::IntegerRelation::mergeLocalVars(), and mlir::FlatLinearValueConstraints::mergeSymbolVars().

Referenced by mlir::FlatLinearValueConstraints::mergeAndAlignVarsWithOther(), and mlir::FlatLinearValueConstraints::unionBoundingBox().