[Calyx] [NFC] Use stricter Block existence, not Region existence for IfOp.

This commit is contained in:
cgyurgyik 2021-09-28 18:54:31 -07:00
parent 360c4e7a0f
commit ef7bdd252d
3 changed files with 18 additions and 8 deletions

View File

@ -70,17 +70,27 @@ def IfOp : CalyxContainer<"if", [
let verifier = "return ::verify$cppClass(*this);";
let hasCanonicalizeMethod = true;
let extraClassDeclaration = [{
/// Checks whether the `then` region exists.
bool thenRegionExists() { return !getOperation()->getRegion(0).empty(); }
/// Checks whether the `else` region exists.
bool elseRegionExists() { return !getOperation()->getRegion(1).empty(); }
/// Checks whether the `then` body exists.
bool thenBodyExists() {
Region* region = &getOperation()->getRegion(0);
if (region == nullptr)
return false;
return !region->empty();
}
/// Checks whether the `else` body exists.
bool elseBodyExists() {
Region* region = &getOperation()->getRegion(1);
if (region == nullptr)
return false;
return !region->empty();
}
/// Gets the single basic block representing the `then` region.
Block *getThenBody() {
return &getOperation()->getRegion(0).front();
}
/// Gets the single basic block representing the `else` region.
Block *getElseBody() {
assert(elseRegionExists() && "Else region does not exist.");
assert(elseBodyExists() && "Else region does not exist.");
return &getOperation()->getRegion(1).front();
}
}];

View File

@ -1377,7 +1377,7 @@ static LogicalResult verifyIfOp(IfOp ifOp) {
if (ifOp.getThenBody()->empty())
return ifOp.emitError() << "empty 'then' region.";
if (ifOp.elseRegionExists() && ifOp.getElseBody()->empty())
if (ifOp.elseBodyExists() && ifOp.getElseBody()->empty())
return ifOp.emitError() << "empty 'else' region.";
Optional<StringRef> optGroupName = ifOp.groupName();
@ -1428,7 +1428,7 @@ static EnableOp getLastEnableOp(SeqOp parent) {
static LogicalResult eliminateCommonTailEnable(IfOp ifOp,
PatternRewriter &rewriter) {
// Check if the branches exist.
if (!ifOp.thenRegionExists() || !ifOp.elseRegionExists())
if (!ifOp.thenBodyExists() || !ifOp.elseBodyExists())
return failure();
auto &thenOpStructureOp = ifOp.getThenBody()->front();

View File

@ -406,7 +406,7 @@ private:
os << " with " << groupName.getValue();
emitCalyxBody([&]() { emitCalyxControl(op.getThenBody()); });
if (op.elseRegionExists())
if (op.elseBodyExists())
emitCalyxSection("else",
[&]() { emitCalyxControl(op.getElseBody()); });
})