diff options
| author | WormHeamer | 2025-08-10 01:30:20 -0400 |
|---|---|---|
| committer | WormHeamer | 2025-08-10 01:30:20 -0400 |
| commit | 815d0b54b4cf09d7d2161f1be204f55db348927d (patch) | |
| tree | 6f9e966794ca92a17630ac158397591249af187f /peephole.c | |
| parent | 85e28cfad0260ebf206a1249f153942ccea9673d (diff) | |
convert node_op_* to just NodeMask #defines
Diffstat (limited to 'peephole.c')
| -rw-r--r-- | peephole.c | 39 |
1 files changed, 8 insertions, 31 deletions
@@ -6,32 +6,9 @@ extern int no_opt; -static inline int node_op_communative(NodeType t) { - return NMASK(t) & (NM_OP_ADD | NM_OP_MUL | NM_OP_AND | NM_OP_XOR | NM_OP_OR | NM_CMP_EQL | NM_CMP_NEQ); - /*NodeType ops[] = { N_OP_ADD, N_OP_MUL, N_OP_AND, N_OP_XOR, N_OP_OR, N_CMP_EQL, N_CMP_NEQ }; - for (unsigned i = 0; i < sizeof ops / sizeof *ops; i++) { - if (ops[i] == t) return 1; - } - return 0;*/ -} - -static inline int node_op_associative(NodeType t) { - /*NodeType ops[] = { N_OP_ADD, N_OP_MUL, N_OP_AND, N_OP_XOR, N_OP_OR }; - for (unsigned i = 0; i < sizeof ops / sizeof *ops; i++) { - if (ops[i] == t) return 1; - } - return 0;*/ - return NMASK(t) & (NM_OP_ADD | NM_OP_MUL | NM_OP_AND | NM_OP_XOR | NM_OP_OR); -} - -static inline int node_op_comparison(NodeType t) { - /*NodeType ops[] = { N_CMP_EQL, N_CMP_NEQ, N_CMP_LES, N_CMP_GTR, N_CMP_LTE, N_CMP_GTE }; - for (unsigned i = 0; i < sizeof ops / sizeof *ops; i++) { - if (ops[i] == t) return 1; - } - return 0;*/ - return NMASK(t) & (NM_CMP_EQL | NM_CMP_NEQ | NM_CMP_LES | NM_CMP_GTR | NM_CMP_LTE | NM_CMP_GTE); -} +#define NM_COMMUNATIVE (NM_OP_ADD | NM_OP_MUL | NM_OP_AND | NM_OP_XOR | NM_OP_OR | NM_CMP_EQL | NM_CMP_NEQ) +#define NM_ASSOCIATIVE (NM_OP_ADD | NM_OP_MUL | NM_OP_AND | NM_OP_XOR | NM_OP_OR) +#define NM_COMPARISON (NM_CMP_EQL | NM_CMP_NEQ | NM_CMP_LES | NM_CMP_GTR | NM_CMP_LTE | NM_CMP_GTE) /* when applied to the same input, at least one must be true */ static inline NodeType node_cmp_opposite(NodeType a) { @@ -206,7 +183,7 @@ static int node_equiv_input(Node *a, Node *b) { if (CTRL(a) != CTRL(b)) return 0; /* note that this means the order of inputs isn't guaranteed, so be * careful what you use this procedure for */ - if ((node_op_communative(a->op) || node_op_communative(b->op)) + if (((NMASK(a->op) | NMASK(b->op)) & NM_COMMUNATIVE) && node_equiv(CDR(a), CAR(b)) && node_equiv(CAR(a), CDR(b))) { /* assuming input count is 2 */ @@ -281,7 +258,7 @@ Node *node_idealize(Node *n, Proc *p, Lexer *l) { /* need to check for type compatibility */ #define C(a, b) type_base_eql(&(a)->type, &(b)->type) - if (node_op_communative(n->op)) { + if (NMASK(n->op) & NM_COMMUNATIVE) { /* op(lit, X) -> op(X, lit) */ if (T(CAR(n), N_LIT) && !T(CDR(n), N_LIT)) return OP(CDR(n), CAR(n)); @@ -298,7 +275,7 @@ Node *node_idealize(Node *n, Proc *p, Lexer *l) { } } - if (node_op_associative(n->op)) { + if (NMASK(n->op) & NM_ASSOCIATIVE) { /* op(X, op(Y,Z)) -> op(op(Y,Z), X) */ if (!T(CAR(n), n->op) && T(CDR(n), n->op) && C(CAR(n), CDAR(n))) return OP(CDR(n), CAR(n)); @@ -510,7 +487,7 @@ zero_no_effect: if (node_eql_i64(CAR(n), 0)) return CDR(n); break; } - if (node_op_comparison(n->op)) { + if (NMASK(n->op) & NM_COMPARISON) { /* cmp(2a, a + b) -> cmp(a, b) */ if (T(CAR(n), N_OP_SHL) && T(CDR(n), N_OP_ADD) && node_eql_i64(CADR(n), 1)) { if (node_equiv(CAAR(n), CDAR(n))) return NODE(n->op, CAAR(n), CDDR(n)); @@ -521,7 +498,7 @@ zero_no_effect: if (node_eql_i64(CAR(n), 0)) return CDR(n); if (node_equiv(CDAR(n), CADR(n))) return NODE(n->op, CDAR(n), CAAR(n)); } /* cmp(a + b, a + c) -> cmp(b, c) */ - if (node_op_associative(CAR(n)->op) && T(CAR(n), CDR(n)->op)) { + if ((NMASK(CAR(n)->op) & NM_ASSOCIATIVE) && T(CAR(n), CDR(n)->op)) { if (node_equiv(CAAR(n), CDAR(n))) return NODE(n->op, CADR(n), CDDR(n)); if (node_equiv(CADR(n), CDAR(n))) return NODE(n->op, CAAR(n), CDDR(n)); if (node_equiv(CAAR(n), CDDR(n))) return NODE(n->op, CADR(n), CDAR(n)); |
