diff options
author | Guy Harris <guy@alum.mit.edu> | 2017-09-17 18:07:58 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2017-09-17 18:07:58 -0700 |
commit | 631428faa07b5e6d828228042e003a4384e349c7 (patch) | |
tree | f78db75cdc5b65e8747f7ff6c7022d3b50d6305b | |
parent | d7bdf180b158a11d116bb8a77674200e72baff44 (diff) |
Make it clearer where we're testing whether a value is unknown.
Add a #define of VAL_UNKNOWN for 0, and compare val[i] values against
that.
-rw-r--r-- | gencode.h | 5 | ||||
-rw-r--r-- | optimize.c | 9 |
2 files changed, 10 insertions, 4 deletions
@@ -266,6 +266,11 @@ struct block { int val[N_ATOMS]; }; +/* + * A value of 0 for val[i] means the value is unknown. + */ +#define VAL_UNKNOWN 0 + struct arth { struct block *b; /* protocol checks */ struct slist *s; /* stmt list */ @@ -578,7 +578,7 @@ F(opt_state_t *opt_state, int code, int v0, int v1) static inline void vstore(struct stmt *s, int *valp, int newval, int alter) { - if (alter && newval != 0 && *valp == newval) + if (alter && newval != VAL_UNKNOWN && *valp == newval) s->code = NOP; else *valp = newval; @@ -1242,8 +1242,9 @@ opt_blk(compiler_state_t *cstate, struct icode *ic, opt_state_t *opt_state, * block, can we eliminate it? */ if (do_stmts && - ((b->out_use == 0 && aval != 0 && b->val[A_ATOM] == aval && - xval != 0 && b->val[X_ATOM] == xval) || + ((b->out_use == 0 && + aval != VAL_UNKNOWN && b->val[A_ATOM] == aval && + xval != VAL_UNKNOWN && b->val[X_ATOM] == xval) || BPF_CLASS(b->s.code) == BPF_RET)) { if (b->stmts != 0) { b->stmts = 0; @@ -2275,7 +2276,7 @@ dot_dump_node(struct icode *ic, struct block *block, struct bpf_program *prog, } fprintf(out, "\" tooltip=\""); for (i = 0; i < BPF_MEMWORDS; i++) - if (block->val[i] != 0) + if (block->val[i] != VAL_UNKNOWN) fprintf(out, "val[%d]=%d ", i, block->val[i]); fprintf(out, "val[A]=%d ", block->val[A_ATOM]); fprintf(out, "val[X]=%d", block->val[X_ATOM]); |