Skip to content

Commit

Permalink
Support to bufferize task op with new destination-style semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
hanchenye committed Mar 24, 2024
1 parent cd66c16 commit 6696640
Show file tree
Hide file tree
Showing 5 changed files with 418 additions and 127 deletions.
13 changes: 10 additions & 3 deletions include/scalehls/Dialect/HLS/IR/HLSOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,22 @@ def TaskOp : HLSOp<"task", [SingleBlockImplicitTerminator<"YieldOp">]> {
let hasCanonicalizer = 1;

let extraClassDeclaration = [{
/// Return true if this task op contains nested sub-tasks.
bool hasHierarchy() {
return walk([&](Operation *op) {
/// Return whether this task op is a leaf task.
bool isLeafTask() {
return !walk([&](Operation *op) {
if (isa<TaskOp, func::CallOp>(op) && op != *this)
return WalkResult::interrupt();
return WalkResult::advance();
}).wasInterrupted();
}

/// Return whether this task is the single task in the parent block.
bool isSingleTask() {
return llvm::hasSingleElement(
llvm::make_filter_range((*this)->getBlock()->getOperations(),
[](Operation &op) { return isa<TaskOp, func::CallOp>(op); }));
}

/// Return the yield op of this task op.
YieldOp getYieldOp();

Expand Down
10 changes: 4 additions & 6 deletions lib/Dialect/HLS/IR/HLSOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,8 @@ struct FoldTaskIterArgs : public OpRewritePattern<hls::TaskOp> {
task.getLoc(), TypeRange(newIterArgs), newIterArgs);
newtask->setAttrs(task->getAttrs());
Block *newBlock = rewriter.createBlock(
&newtask.getBody(), newtask.getBody().begin(), TypeRange(newIterArgs));
&newtask.getBody(), newtask.getBody().begin(), TypeRange(newIterArgs),
llvm::map_to_vector(newIterArgs, [&](Value v) { return v.getLoc(); }));
rewriter.setInsertionPointToEnd(newBlock);
rewriter.create<hls::YieldOp>(task.getLoc(), newYieldValues);

Expand Down Expand Up @@ -518,11 +519,8 @@ struct InlineTask : public OpRewritePattern<hls::TaskOp> {
void TaskOp::getCanonicalizationPatterns(RewritePatternSet &results,
MLIRContext *context) {
results.add<FoldTaskIterArgs>(context);
results.add<InlineTask>(context, [](TaskOp task) {
return llvm::hasSingleElement(
llvm::make_filter_range(task->getBlock()->getOperations(),
[](Operation &op) { return isa<TaskOp>(op); }));
});
results.add<InlineTask>(context,
[](TaskOp task) { return task.isSingleTask(); });
}

LogicalResult TaskOp::verify() {
Expand Down
Loading

0 comments on commit 6696640

Please sign in to comment.