Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnycase committed Feb 7, 2025
1 parent b9e5684 commit ac0b0e5
Showing 1 changed file with 9 additions and 45 deletions.
54 changes: 9 additions & 45 deletions src/Nncase.Diagnostics/Diagnostics/ILPrintVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ protected override string VisitConst(Const expr)
{
TensorConst tc => VisitTensorValue(tc.Value, tc.ValueType),
TupleConst tp => VisitValue(tp.Value),
ShapeConst sc => VisitShape(sc.Value),
DimensionConst dc => VisitDimension(dc.Value),
_ => throw new ArgumentOutOfRangeException(nameof(expr)),
};

Expand Down Expand Up @@ -528,57 +526,25 @@ protected override string VisitGrid(IR.Affine.Grid expr)
return name;
}

private string GetNextSSANumber()
{
if (_names.TryGetValue(expr, out var name))
{
return name;
}

_scope.Push();

// 1. Sequential signature
_scope.Append($"Sequential");
AppendCheckedType(expr.CheckedType, expr.Metadata.Range, " {", hasNewLine: true);

// 2. For Body
using (_scope.IndentUp())
{
foreach (var item in expr.Fields)
{
Visit(item);
}
}

// 3. For closing
_scope.IndWriteLine("}");

// 4. extact whole il
_scope.IndWrite(_scope.Pop());
return string.Empty;
}

private string AllocateTempVar(Expr expr)
{
var name = $"%{_localId++}";
_names.Add(expr, name);
return name;
}

private string VisitShape(Shape shape) =>
protected override string VisitShape(Shape shape) =>
shape.Kind switch
{
ShapeKind.Invalid => "Invalid",
ShapeKind.Unranked => "Unranked",
_ => $"[{string.Join(',', shape.Select(VisitDimension))}]",
};

private string GetNextSSANumber()
{
return $"%{_stackedSSANumbers[^1]++}";
}

private string VisitDimension(Dimension dimension) =>
dimension.Kind switch
{
DimensionKind.Any => "any",
DimensionKind.Unknown => "?",
DimensionKind.Fixed => $"{dimension.FixedValue}L",
DimensionKind.Unknown => VisitDimensionExpr(dimension.Value),
DimensionKind.Dynamic => VisitDimensionExpr(dimension.Value),
_ => throw new NotSupportedException(dimension.Kind.ToString()),
};

Expand All @@ -597,7 +563,7 @@ private string VisitDimensionExpr(Expr expr)

private void AppendCheckedType(IRType? type, ValueRange<double>? range, string end = "", bool hasNewLine = true)
{
var rangeText = range is not null ? $"[{range.Value.Min}, {range.Value.Max}]" : string.Empty;
var rangeText = range is not null ? $" [{range.Value.Min}, {range.Value.Max}]" : string.Empty;
if (type is not null)
{
if (hasNewLine)
Expand All @@ -621,8 +587,6 @@ private string VisitValue(IValue value)
{
TensorValue tv => VisitTensorValue(tv.AsTensor()),
TupleValue tp => $"({StringUtility.Join(",", tp.AsValueEnumerable().Select(VisitValue))})",
ShapeValue sv => $"[{StringUtility.Join(",", sv.Dimensions.AsValueEnumerable().Select(VisitDimension))}]",
DimensionValue dv => VisitDimension(dv.Dimension),
_ => throw new NotSupportedException(nameof(value)),
};
}
Expand Down

0 comments on commit ac0b0e5

Please sign in to comment.