Navigation Menu

Skip to content

Commit

Permalink
Revert "[MLIR][Presburger] Improve unittest parsing"
Browse files Browse the repository at this point in the history
This reverts commit 84d07d0.

Reverted to fix a compilation issue on gcc8.
  • Loading branch information
Groverkss committed Sep 15, 2022
1 parent a53b56e commit 644dfba
Show file tree
Hide file tree
Showing 17 changed files with 1,026 additions and 899 deletions.
15 changes: 8 additions & 7 deletions mlir/include/mlir/AsmParser/AsmParser.h
Expand Up @@ -76,13 +76,14 @@ Type parseType(llvm::StringRef typeStr, MLIRContext *context);
/// returned in `numRead`.
Type parseType(llvm::StringRef typeStr, MLIRContext *context, size_t &numRead);

/// This parses a single IntegerSet/AffineMap to an MLIR context if it was
/// valid. If not, an error message is emitted through a new
/// SourceMgrDiagnosticHandler constructed from a new SourceMgr with a single
/// MemoryBuffer wrapping `str`. If the passed `str` has additional tokens that
/// were not part of the IntegerSet/AffineMap, a failure is returned.
AffineMap parseAffineMap(llvm::StringRef str, MLIRContext *context);
IntegerSet parseIntegerSet(llvm::StringRef str, MLIRContext *context);
/// This parses a single IntegerSet to an MLIR context if it was valid. If not,
/// an error message is emitted through a new SourceMgrDiagnosticHandler
/// constructed from a new SourceMgr with a single MemoryBuffer wrapping
/// `str`. If the passed `str` has additional tokens that were not part of the
/// IntegerSet, a failure is returned. Diagnostics are printed on failure if
/// `printDiagnosticInfo` is true.
IntegerSet parseIntegerSet(llvm::StringRef str, MLIRContext *context,
bool printDiagnosticInfo = true);

} // namespace mlir

Expand Down
8 changes: 0 additions & 8 deletions mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h
Expand Up @@ -32,10 +32,6 @@ class Value;
class MemRefType;
struct MutableAffineMap;

namespace presburger {
class MultiAffineFunction;
} // namespace presburger

/// FlatAffineValueConstraints represents an extension of IntegerPolyhedron
/// where each non-local variable can have an SSA Value attached to it.
class FlatAffineValueConstraints : public presburger::IntegerPolyhedron {
Expand Down Expand Up @@ -619,10 +615,6 @@ getFlattenedAffineExprs(IntegerSet set,
std::vector<SmallVector<int64_t, 8>> *flattenedExprs,
FlatAffineValueConstraints *cst = nullptr);

LogicalResult
getMultiAffineFunctionFromMap(AffineMap map,
presburger::MultiAffineFunction &multiAff);

/// Re-indexes the dimensions and symbols of an affine map with given `operands`
/// values to align with `dims` and `syms` values.
///
Expand Down
30 changes: 8 additions & 22 deletions mlir/lib/AsmParser/AffineParser.cpp
Expand Up @@ -734,8 +734,8 @@ Parser::parseAffineExprOfSSAIds(AffineExpr &expr,
.parseAffineExprOfSSAIds(expr);
}

static void parseAffineMapOrIntegerSet(StringRef inputStr, MLIRContext *context,
AffineMap &map, IntegerSet &set) {
IntegerSet mlir::parseIntegerSet(StringRef inputStr, MLIRContext *context,
bool printDiagnosticInfo) {
llvm::SourceMgr sourceMgr;
auto memBuffer = llvm::MemoryBuffer::getMemBuffer(
inputStr, /*BufferName=*/"<mlir_parser_buffer>",
Expand All @@ -747,31 +747,17 @@ static void parseAffineMapOrIntegerSet(StringRef inputStr, MLIRContext *context,
/*codeCompleteContext=*/nullptr);
Parser parser(state);

SourceMgrDiagnosticHandler handler(sourceMgr, context, llvm::errs());
if (parser.parseAffineMapOrIntegerSetReference(map, set))
return;
raw_ostream &os = printDiagnosticInfo ? llvm::errs() : llvm::nulls();
SourceMgrDiagnosticHandler handler(sourceMgr, context, os);
IntegerSet set;
if (parser.parseIntegerSetReference(set))
return IntegerSet();

Token endTok = parser.getToken();
if (endTok.isNot(Token::eof)) {
parser.emitError(endTok.getLoc(), "encountered unexpected token");
return;
return IntegerSet();
}
}

AffineMap mlir::parseAffineMap(StringRef inputStr, MLIRContext *context) {
AffineMap map;
IntegerSet set;
parseAffineMapOrIntegerSet(inputStr, context, map, set);
assert(!set &&
"expected string to represent AffineMap, but got IntegerSet instead");
return map;
}

IntegerSet mlir::parseIntegerSet(StringRef inputStr, MLIRContext *context) {
AffineMap map;
IntegerSet set;
parseAffineMapOrIntegerSet(inputStr, context, map, set);
assert(!map &&
"expected string to represent IntegerSet, but got AffineMap instead");
return set;
}
28 changes: 0 additions & 28 deletions mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp
Expand Up @@ -1801,31 +1801,3 @@ LogicalResult mlir::getRelationFromMap(const AffineValueMap &map,

return success();
}

LogicalResult
mlir::getMultiAffineFunctionFromMap(AffineMap map,
MultiAffineFunction &multiAff) {
FlatAffineValueConstraints cst;
std::vector<SmallVector<int64_t, 8>> flattenedExprs;
LogicalResult result = getFlattenedAffineExprs(map, &flattenedExprs, &cst);

if (result.failed())
return failure();

DivisionRepr divs = cst.getLocalReprs();
assert(divs.hasAllReprs() &&
"AffineMap cannot produce divs without local representation");

// TODO: We shouldn't have to do this conversion.
Matrix mat(map.getNumResults(), map.getNumInputs() + divs.getNumDivs() + 1);
for (unsigned i = 0, e = flattenedExprs.size(); i < e; ++i)
for (unsigned j = 0, f = flattenedExprs[i].size(); j < f; ++j)
mat(i, j) = flattenedExprs[i][j];

multiAff = MultiAffineFunction(
PresburgerSpace::getRelationSpace(map.getNumDims(), map.getNumResults(),
map.getNumSymbols(), divs.getNumDivs()),
mat, divs);

return success();
}
3 changes: 1 addition & 2 deletions mlir/unittests/Analysis/Presburger/CMakeLists.txt
Expand Up @@ -4,12 +4,11 @@ add_mlir_unittest(MLIRPresburgerTests
LinearTransformTest.cpp
MatrixTest.cpp
MPIntTest.cpp
Parser.h
ParserTest.cpp
PresburgerSetTest.cpp
PresburgerSpaceTest.cpp
PWMAFunctionTest.cpp
SimplexTest.cpp
../../Dialect/Affine/Analysis/AffineStructuresParser.cpp
)

target_link_libraries(MLIRPresburgerTests
Expand Down

0 comments on commit 644dfba

Please sign in to comment.