Skip to content

Commit

Permalink
[mlir][Analysis] Add batched version of FlatAffineConstraints::addId
Browse files Browse the repository at this point in the history
* Add batched version of all `addId` variants, so that multiple IDs can be added at a time.
* Rename `addId` and variants to `insertId` and `appendId`. Most external users call `appendId`. Splitting `addId` into two functions also makes it possible to provide batched version for both. (Otherwise, the overloads are ambigious when calling `addId`.)

Differential Revision: https://reviews.llvm.org/D108532
  • Loading branch information
matthias-springer committed Aug 30, 2021
1 parent 83e82ff commit eedc997
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 135 deletions.
77 changes: 45 additions & 32 deletions mlir/include/mlir/Analysis/AffineStructures.h
Expand Up @@ -243,19 +243,23 @@ class FlatAffineConstraints {
/// Swap the posA^th identifier with the posB^th identifier.
virtual void swapId(unsigned posA, unsigned posB);

/// Add identifiers of the specified kind - specified positions are relative
/// to the kind of identifier. The coefficient column corresponding to the
/// added identifier is initialized to zero.
void addDimId(unsigned pos);
void addSymbolId(unsigned pos);
void addLocalId(unsigned pos);
virtual unsigned addId(IdKind kind, unsigned pos);
/// Add identifiers of the specified kind at the end of the table. Return the
/// position of the column. The coefficient column corresponding to the
/// added identifier is initialized to zero.
unsigned addDimId();
unsigned addSymbolId();
unsigned addLocalId();
/// Insert `num` identifiers of the specified kind at position `pos`.
/// Positions are relative to the kind of identifier. The coefficient columns
/// corresponding to the added identifiers are initialized to zero. Return the
/// absolute column position (i.e., not relative to the kind of identifier)
/// of the first added identifier.
unsigned insertDimId(unsigned pos, unsigned num = 1);
unsigned insertSymbolId(unsigned pos, unsigned num = 1);
unsigned insertLocalId(unsigned pos, unsigned num = 1);
virtual unsigned insertId(IdKind kind, unsigned pos, unsigned num = 1);

/// Append `num` identifiers of the specified kind after the last identifier.
/// of that kind. Return the position of the first appended column. The
/// coefficient columns corresponding to the added identifiers are initialized
/// to zero.
unsigned appendDimId(unsigned num = 1);
unsigned appendSymbolId(unsigned num = 1);
unsigned appendLocalId(unsigned num = 1);

/// Composes an affine map whose dimensions and symbols match one to one with
/// the dimensions and symbols of this FlatAffineConstraints. The results of
Expand Down Expand Up @@ -655,22 +659,31 @@ class FlatAffineValueConstraints : public FlatAffineConstraints {
/// Swap the posA^th identifier with the posB^th identifier.
void swapId(unsigned posA, unsigned posB) override;

/// Add identifiers of the specified kind - specified positions are relative
/// to the kind of identifier. The coefficient column corresponding to the
/// added identifier is initialized to zero. `val` is the Value corresponding
/// to the identifier that can optionally be provided.
void addDimId(unsigned pos, Value val);
using FlatAffineConstraints::addDimId;
void addSymbolId(unsigned pos, Value val);
using FlatAffineConstraints::addSymbolId;
unsigned addId(IdKind kind, unsigned pos) override;
unsigned addId(IdKind kind, unsigned pos, Value val);
/// Add identifiers of the specified kind at the end of the table. Return the
/// position of the column. The coefficient column corresponding to the
/// added identifier is initialized to zero. `val` is the Value corresponding
/// to the identifier that can optionally be provided.
unsigned addDimId(Value val);
unsigned addSymbolId(Value val);
/// Insert identifiers of the specified kind at position `pos`. Positions are
/// relative to the kind of identifier. The coefficient columns corresponding
/// to the added identifiers are initialized to zero. `vals` are the Values
/// corresponding to the identifiers. Return the absolute column position
/// (i.e., not relative to the kind of identifier) of the first added
/// identifier.
///
/// Note: Empty Values are allowed in `vals`.
unsigned insertDimId(unsigned pos, ValueRange vals);
using FlatAffineConstraints::insertDimId;
unsigned insertSymbolId(unsigned pos, ValueRange vals);
using FlatAffineConstraints::insertSymbolId;
unsigned insertId(IdKind kind, unsigned pos, unsigned num = 1) override;
unsigned insertId(IdKind kind, unsigned pos, ValueRange vals);

/// Append identifiers of the specified kind after the last identifier of that
/// kind. The coefficient columns corresponding to the added identifiers are
/// initialized to zero. `vals` are the Values corresponding to the
/// identifiers. Return the position of the first added column.
///
/// Note: Empty Values are allowed in `vals`.
unsigned appendDimId(ValueRange vals);
using FlatAffineConstraints::appendDimId;
unsigned appendSymbolId(ValueRange vals);
using FlatAffineConstraints::appendSymbolId;

/// Add the specified values as a dim or symbol id depending on its nature, if
/// it already doesn't exist in the system. `val` has to be either a terminal
Expand Down Expand Up @@ -731,9 +744,9 @@ class FlatAffineValueConstraints : public FlatAffineConstraints {
/// by any of `other`'s identifiers that didn't appear in `this`. Local
/// identifiers of each system are by design separate/local and are placed
/// one after other (`this`'s followed by `other`'s).
// Eg: Input: `this` has (%i %j) [%M %N]
// `other` has (%k, %j) [%P, %N, %M]
// Output: both `this`, `other` have (%i, %j, %k) [%M, %N, %P]
// E.g.: Input: `this` has (%i, %j) [%M, %N]
// `other` has (%k, %j) [%P, %N, %M]
// Output: both `this`, `other` have (%i, %j, %k) [%M, %N, %P]
//
void mergeAndAlignIdsWithOther(unsigned offset,
FlatAffineValueConstraints *other);
Expand Down
8 changes: 2 additions & 6 deletions mlir/lib/Analysis/AffineAnalysis.cpp
Expand Up @@ -614,9 +614,7 @@ addMemRefAccessConstraints(const AffineValueMap &srcAccessMap,
unsigned srcNumLocalIds = srcLocalVarCst.getNumLocalIds();
unsigned dstNumLocalIds = destLocalVarCst.getNumLocalIds();
unsigned numLocalIdsToAdd = srcNumLocalIds + dstNumLocalIds;
for (unsigned i = 0; i < numLocalIdsToAdd; i++) {
dependenceDomain->addLocalId(dependenceDomain->getNumLocalIds());
}
dependenceDomain->appendLocalId(numLocalIdsToAdd);

unsigned numDims = dependenceDomain->getNumDimIds();
unsigned numSymbols = dependenceDomain->getNumSymbolIds();
Expand Down Expand Up @@ -859,9 +857,7 @@ static void computeDirectionVector(
unsigned numIdsToEliminate = dependenceDomain->getNumIds();
// Add new variables to 'dependenceDomain' to represent the direction
// constraints for each shared loop.
for (unsigned j = 0; j < numCommonLoops; ++j) {
dependenceDomain->addDimId(j);
}
dependenceDomain->insertDimId(/*pos=*/0, /*num=*/numCommonLoops);

// Add equality constraints for each common loop, setting newly introduced
// variable at column 'j' to the 'dst' IV minus the 'src IV.
Expand Down

0 comments on commit eedc997

Please sign in to comment.