1 //===- MapRef.cpp - A dim2lvl/lvl2dim map reference wrapper ---------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "mlir/ExecutionEngine/SparseTensor/MapRef.h"
10 #include "mlir/Dialect/SparseTensor/IR/Enums.h"
12 mlir::sparse_tensor::MapRef::MapRef(uint64_t d
, uint64_t l
, const uint64_t *d2l
,
14 : dimRank(d
), lvlRank(l
), dim2lvl(d2l
), lvl2dim(l2d
),
15 isPermutation(isPermutationMap()) {
17 for (uint64_t l
= 0; l
< lvlRank
; l
++)
18 assert(lvl2dim
[dim2lvl
[l
]] == l
);
22 bool mlir::sparse_tensor::MapRef::isPermutationMap() const {
23 if (dimRank
!= lvlRank
)
25 std::vector
<bool> seen(dimRank
, false);
26 for (uint64_t l
= 0; l
< lvlRank
; l
++) {
27 const uint64_t d
= dim2lvl
[l
];
28 if (d
>= dimRank
|| seen
[d
])
35 bool mlir::sparse_tensor::MapRef::isFloor(uint64_t l
, uint64_t &i
,
37 if (isEncodedFloor(dim2lvl
[l
])) {
38 i
= decodeIndex(dim2lvl
[l
]);
39 c
= decodeConst(dim2lvl
[l
]);
45 bool mlir::sparse_tensor::MapRef::isMod(uint64_t l
, uint64_t &i
,
47 if (isEncodedMod(dim2lvl
[l
])) {
48 i
= decodeIndex(dim2lvl
[l
]);
49 c
= decodeConst(dim2lvl
[l
]);
55 bool mlir::sparse_tensor::MapRef::isMul(uint64_t d
, uint64_t &i
, uint64_t &c
,
57 if (isEncodedMul(lvl2dim
[d
])) {
58 i
= decodeIndex(lvl2dim
[d
]);
59 c
= decodeMulc(lvl2dim
[d
]);
60 ii
= decodeMuli(lvl2dim
[d
]);