-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dialects: (cf) cond_br folding (#3283)
First two `cond_br` canonicalization patterns: - Constant folding (`cf.cond_br %true ^0 ^1` == `cf.br ^0`) - Passthrough (conditional branch to a branch with just a single `br` op gets forwarded)
- Loading branch information
Showing
5 changed files
with
155 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from xdsl.dialects import arith | ||
from xdsl.dialects.builtin import IntegerAttr | ||
from xdsl.ir import SSAValue | ||
|
||
|
||
def const_evaluate_operand(operand: SSAValue) -> int | None: | ||
""" | ||
Try to constant evaluate an SSA value, returning None on failure. | ||
""" | ||
if isinstance(op := operand.owner, arith.Constant) and isinstance( | ||
val := op.value, IntegerAttr | ||
): | ||
return val.value.data |