Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions mlir/include/mlir/IR/BuiltinAttributeInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def MemRefLayoutAttrInterface : AttrInterface<"MemRefLayoutAttrInterface"> {

let methods = [
InterfaceMethod<
"Get the MemRef layout as an AffineMap, the method must not return NULL",
"Get the MemRef layout as an AffineMap, returns NULL if cannot be expressed as affine map",
"::mlir::AffineMap", "getAffineMap", (ins)
>,

Expand All @@ -495,7 +495,8 @@ def MemRefLayoutAttrInterface : AttrInterface<"MemRefLayoutAttrInterface"> {
"bool", "isIdentity", (ins),
[{}],
[{
return $_attr.getAffineMap().isIdentity();
AffineMap map = $_attr.getAffineMap();
return map && $_attr.getAffineMap().isIdentity();
}]
>,

Expand Down
6 changes: 5 additions & 1 deletion mlir/lib/IR/BuiltinAttributeInterfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ uint64_t ElementsAttr::getFlattenedIndex(Type type, ArrayRef<uint64_t> index) {
LogicalResult mlir::detail::verifyAffineMapAsLayout(
AffineMap m, ArrayRef<int64_t> shape,
function_ref<InFlightDiagnostic()> emitError) {
if (!m) {
return success();
}
if (m.getNumDims() != shape.size())
return emitError() << "memref layout mismatch between rank and affine map: "
<< shape.size() << " != " << m.getNumDims();
Expand Down Expand Up @@ -204,7 +207,8 @@ LogicalResult mlir::detail::getAffineMapStridesAndOffset(
int64_t &offset) {
AffineExpr offsetExpr;
SmallVector<AffineExpr, 4> strideExprs;
if (failed(::getStridesAndOffset(map, shape, strideExprs, offsetExpr)))
if (!map ||
failed(::getStridesAndOffset(map, shape, strideExprs, offsetExpr)))
return failure();
if (auto cst = llvm::dyn_cast<AffineConstantExpr>(offsetExpr))
offset = cst.getValue();
Expand Down