From 36de4f902c4eec9f8d918e00cf0bf89d6b670cf5 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Wed, 3 Apr 2024 16:00:15 +0300 Subject: add ssa form --- include/qbt/nodes.h | 34 ++++++++++++++++++++++++++++++++-- include/qbt/unreachable.h | 2 +- 2 files changed, 33 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/qbt/nodes.h b/include/qbt/nodes.h index 63bbc58..d3ddc5f 100644 --- a/include/qbt/nodes.h +++ b/include/qbt/nodes.h @@ -125,11 +125,17 @@ struct blk { struct blk *s1; struct blk *s2; struct vec insns; + /* input parameters, tmp values effectively */ + struct vec params; + /* arguments for s1 */ + struct vec args1; + /* arguments for s2 (if any) */ + struct vec args2; /* used to temporarily store label targets */ const char *to; - /* used by reachability analysis */ - bool reachable; + /* used by some algorithms to mark visited */ + int visited; }; struct fn { @@ -206,6 +212,24 @@ static inline struct val tmp_val(int64_t t) }; } +static inline bool same_val(struct val v1, struct val v2) +{ + if (v1.class != v2.class) + return false; + + switch (v1.class) { + case REG: return v1.r == v2.r; + case TMP: return v1.r == v2.r; + case IMM: return v1.v == v2.v; + case MEM: return v1.v == v2.v; + case REF: return v1.r == v2.r && v1.v == v2.v; + case NOCLASS: return true; + } + + /* shouldn't be reachable */ + return false; +} + static inline struct insn insn_create(enum insn_type o, enum val_type t, struct val r, struct val a0, struct val a1) { return (struct insn) { @@ -264,6 +288,12 @@ struct label_map { #define foreach_blk(iter, blocks)\ foreach_vec(iter, blocks) +#define foreach_blk_param(iter, block_params)\ + foreach_vec(iter, block_params) + +#define blk_param_at(v, i)\ + vect_at(struct val, v, i) + #define label_at(v, i)\ vect_at(struct label_map, v, i) diff --git a/include/qbt/unreachable.h b/include/qbt/unreachable.h index 0f0c39e..8ad152e 100644 --- a/include/qbt/unreachable.h +++ b/include/qbt/unreachable.h @@ -3,6 +3,6 @@ #include -void unreachable(struct fn *f); +void remove_unvisited(struct fn *f, int visited); #endif /* UNREACHABLE_H */ -- cgit v1.3