Skip to content

Commit

Permalink
[StaticLogic] Add a helper to get a pipeline stage number.
Browse files Browse the repository at this point in the history
The stage number is computed as its index in the stages block. This is
useful to passes that may want to give a stage a meaningful name.
  • Loading branch information
mikeurbach committed Dec 24, 2021
1 parent fba1ab7 commit 7bdd9da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/circt/Dialect/StaticLogic/StaticLogic.td
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def PipelineStageOp : Op<StaticLogic_Dialect, "pipeline.stage",

let extraClassDeclaration = [{
Block &getBodyBlock() { return body().front(); }
unsigned getStageNumber();
}];
}

Expand Down
12 changes: 12 additions & 0 deletions lib/Dialect/StaticLogic/StaticLogicOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,18 @@ static LogicalResult verifyPipelineRegisterOp(PipelineRegisterOp op) {
return success();
}

unsigned PipelineStageOp::getStageNumber() {
unsigned number = 0;
auto *op = getOperation();
auto parent = op->getParentOfType<PipelineWhileOp>();
Operation *stage = &parent.getStagesBlock().front();
while (stage != op && stage->getNextNode()) {
++number;
stage = stage->getNextNode();
}
return number;
}

//===----------------------------------------------------------------------===//
// PipelineTerminatorOp
//===----------------------------------------------------------------------===//
Expand Down

0 comments on commit 7bdd9da

Please sign in to comment.