@@ -354,7 +354,7 @@ static Value genSubscript(CodegenEnv &env, OpBuilder &builder, OpOperand *t,
354
354
const auto stt = getSparseTensorType (t->get ());
355
355
if (stt.hasEncoding ()) {
356
356
// For sparse tensors we only push the last-level's position onto `args`.
357
- const auto pos = env.emitter ().getPosits ()[ tid]. back ( );
357
+ const auto pos = env.emitter ().getValPosits ( tid);
358
358
assert (pos);
359
359
args.push_back (pos);
360
360
} else {
@@ -815,8 +815,7 @@ static Operation *genCoIteration(CodegenEnv &env, OpBuilder &builder,
815
815
Operation *loop = *env.genLoopBoundary ([&](MutableArrayRef<Value> reduc) {
816
816
// Construct while-loop with a parameter for each index.
817
817
return env.emitter ().enterCoIterationOverTensorsAtLvls (
818
- builder, env.op ().getLoc (), tidLvls, reduc, tryParallel,
819
- /* genDedup=*/ true , needsUniv);
818
+ builder, env.op ().getLoc (), tidLvls, reduc, tryParallel, needsUniv);
820
819
});
821
820
assert (loop);
822
821
return loop;
@@ -894,7 +893,7 @@ static scf::IfOp genIf(CodegenEnv &env, OpBuilder &builder, LoopId curr,
894
893
if (isCompressedLT (lt) || isSingletonLT (lt) ||
895
894
isLooseCompressedLT (lt) || is2OutOf4LT (lt)) {
896
895
assert (lvl.has_value ());
897
- const Value crd = env.emitter ().getCoords ()[ tid][ *lvl] ;
896
+ const Value crd = env.emitter ().getCoord ( tid, *lvl) ;
898
897
const Value lvar = env.getLoopVar (curr);
899
898
clause = builder.create <arith::CmpIOp>(loc, arith::CmpIPredicate::eq,
900
899
crd, lvar);
@@ -1032,10 +1031,14 @@ static bool getAllTidLvlsInLatPoints(
1032
1031
});
1033
1032
1034
1033
if (isDenseLT (env.lt (outTid, curr))) {
1035
- // Note that we generate dense indices of the output tensor
1036
- // unconditionally, since they may not appear in the lattice, but may be
1037
- // needed for linearized env.
1038
- callback (env.makeTensorLevel (outTid, *outLvl), nullptr );
1034
+ auto stt = getSparseTensorType (env.op ().getOutputs ().front ());
1035
+ // Note that we generate dense indices of the output tensor unconditionally,
1036
+ // since they may not appear in the lattice, but may be needed for
1037
+ // linearized env.
1038
+ // TODO: we should avoid introducing corner cases for all-dense sparse
1039
+ // tensors.
1040
+ if (stt.hasEncoding () && stt.isAllDense ())
1041
+ callback (env.makeTensorLevel (outTid, *outLvl), nullptr );
1039
1042
}
1040
1043
1041
1044
if (numloopCond == 0 ) {
@@ -1064,6 +1067,11 @@ static bool startLoopSeq(CodegenEnv &env, OpBuilder &builder, ExprId exp,
1064
1067
1065
1068
SmallVector<TensorLevel> tidLvls;
1066
1069
getAllTidLvlsInLatPoints (env, l0, curr, [&](TensorLevel tl, AffineExpr) {
1070
+ // TODO: remove this! The same tensor level might be added for multiple
1071
+ // times due to the special handling for all-dense "sparse" output tensor
1072
+ // (see L1038).
1073
+ if (llvm::find (tidLvls, tl) != tidLvls.end ())
1074
+ return ;
1067
1075
tidLvls.emplace_back (tl);
1068
1076
});
1069
1077
@@ -1096,7 +1104,7 @@ static void genConstantDenseAddressFromLevel(CodegenEnv &env,
1096
1104
for (Level l = startLvl; l < lvlRank; l++) {
1097
1105
AffineExpr lvlExpr = lvlExprs[l];
1098
1106
if (enc.isDenseLvl (l) && isa<AffineConstantExpr>(lvlExpr))
1099
- env.emitter ().genDenseAffineAddress (
1107
+ env.emitter ().locateLvlAtAffineAddress (
1100
1108
builder, loc, env.makeTensorLevel (tid, l), lvlExpr);
1101
1109
else
1102
1110
return ; // break on first non-dense non-constant level
@@ -1145,7 +1153,7 @@ static std::pair<Operation *, bool> startLoop(CodegenEnv &env,
1145
1153
Operation *loop = genLoop (env, builder, curr, needsUniv, tidLvls);
1146
1154
Location loc = env.op ().getLoc ();
1147
1155
for (auto [tidLvl, exp] : affineTidLvls) {
1148
- env.emitter ().genDenseAffineAddress (builder, loc, tidLvl, exp);
1156
+ env.emitter ().locateLvlAtAffineAddress (builder, loc, tidLvl, exp);
1149
1157
}
1150
1158
1151
1159
// Until now, we have entered every <tid, lvl> pair in {cond, extra,
0 commit comments