-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor cond block to cond value in if blocks
- Loading branch information
alexander.nutz
committed
Feb 4, 2025
1 parent
a72d8ac
commit 9bf5a24
Showing
10 changed files
with
101 additions
and
57 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
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,44 @@ | ||
#include "../passes.h" | ||
|
||
// on the low level, it is better for if statements with only one case to only have an else body, not an if body. | ||
|
||
void vx_IrBlock_ll_if_invert(vx_CU* cu, vx_IrBlock *block) | ||
{ | ||
for (vx_IrOp* op = block->first; op; op = op->next) | ||
{ | ||
if (op->id != VX_IR_OP_IF) | ||
continue; | ||
|
||
vx_IrBlock *then = NULL; { | ||
vx_IrValue *val = vx_IrOp_param(op, VX_IR_NAME_COND_THEN); | ||
if (val) | ||
then = val->block; | ||
} | ||
|
||
vx_IrBlock *els = NULL; { | ||
vx_IrValue *val = vx_IrOp_param(op, VX_IR_NAME_COND_ELSE); | ||
if (val) | ||
els = val->block; | ||
} | ||
|
||
vx_IrValue cond_val = *vx_IrOp_param(op, VX_IR_NAME_COND); | ||
assert(cond_val.type = VX_IR_VAL_BLOCK); | ||
|
||
if (then && !els) | ||
{ | ||
// then => else and invert condition | ||
|
||
vx_IrType* condType = vx_IrValue_type(cu, vx_IrBlock_root(block), cond_val); | ||
assert(condType); | ||
vx_IrOp* inv = vx_IrBlock_insertOpCreateAfter(block, vx_IrOp_predecessor(op), VX_IR_OP_NOT); | ||
vx_IrVar invVar = vx_IrBlock_newVar(block, inv); | ||
vx_IrOp_addOut(inv, invVar, condType); | ||
vx_IrOp_addParam_s(inv, VX_IR_NAME_VALUE, cond_val); | ||
|
||
*vx_IrOp_param(op, VX_IR_NAME_COND) = VX_IR_VALUE_VAR(invVar); | ||
|
||
vx_IrOp_removeParam(op, VX_IR_NAME_COND_THEN); | ||
vx_IrOp_addParam_s(op, VX_IR_NAME_COND_ELSE, VX_IR_VALUE_BLK(then)); | ||
} | ||
} | ||
} |
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