Skip to content

Commit

Permalink
Enhance StreamRead/WriteOp verification error report
Browse files Browse the repository at this point in the history
  • Loading branch information
hanchenye committed Feb 19, 2024
1 parent 476e265 commit 18d8423
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
14 changes: 7 additions & 7 deletions include/scalehls/Dialect/HLS/IR/HLSTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,19 @@ def StreamType : HLSType<"Stream", []> {
/// represents.
SmallVector<int64_t> getShape() const;

/// Return whether the element type is a shaped type.
bool hasShapedElementType() const {
return getElementType().isa<ShapedType>();
}

/// Get the shaped element type if applicable. Return nullptr if the element
/// type is not a shaped type.
ShapedType getShapedElementType() const {
return getElementType().dyn_cast<ShapedType>();
}

/// Get the rank of the element type. Return 0 if the element type is not a
/// shaped type.
int64_t getElementRank() const {
if (auto shapedType = getShapedElementType())
return shapedType.getRank();
return 0;
}
/// Get the rank of the element type.
int64_t getElementRank() const { return getIterMap().getNumResults(); }

/// Return the dimension size of the element type. Return 1 if the element
/// type is not a shaped type.
Expand Down
20 changes: 13 additions & 7 deletions lib/Dialect/HLS/IR/HLSOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,21 +260,27 @@ static LogicalResult verifyTripCountsAndSteps(Operation *op, Value channel) {
if (!tripCounts || !steps)
return op->emitOpError("iteration trip counts or steps not available");

auto stripedTripCountsAndSteps =
auto stripedLoopInfo =
llvm::make_filter_range(llvm::zip(*tripCounts, *steps), [](auto tuple) {
return std::get<0>(tuple) != 1;
});

auto channelType = channel.getType().cast<StreamType>();
auto stripedIterTripCountsAndSteps = llvm::make_filter_range(
auto stripedIterInfo = llvm::make_filter_range(
llvm::zip(channelType.getIterTripCounts(), channelType.getIterSteps()),
[](auto tuple) { return std::get<0>(tuple) != 1; });

if (llvm::any_of(
llvm::zip(stripedTripCountsAndSteps, stripedIterTripCountsAndSteps),
[](auto tuple) { return std::get<0>(tuple) != std::get<1>(tuple); }))
return op->emitOpError("loop trip counts or steps doesn't align with "
"stream type's iteration trip counts or steps");
if (llvm::any_of(llvm::zip(stripedLoopInfo, stripedIterInfo), [](auto tuple) {
return std::get<0>(tuple) != std::get<1>(tuple);
})) {
auto diag = op->emitOpError("loop trip counts or steps doesn't align with "
"stream iteration trip counts or steps\n");
diag << "loop trip counts: " << *tripCounts << ", steps: " << *steps
<< "\n";
diag << "stream iteration trip counts: " << channelType.getIterTripCounts()
<< ", steps: " << channelType.getIterSteps();
return diag;
}
return success();
}

Expand Down

0 comments on commit 18d8423

Please sign in to comment.