aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-04-03 16:00:15 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-04-03 16:00:15 +0300
commit36de4f902c4eec9f8d918e00cf0bf89d6b670cf5 (patch)
tree6fc1a8f172ac018411f54b24b2d989992b20fe40 /include
parenta7cb592efa9ec72c4c5e9d3c1e7469203a4b47e2 (diff)
downloadqbt-36de4f902c4eec9f8d918e00cf0bf89d6b670cf5.tar.gz
qbt-36de4f902c4eec9f8d918e00cf0bf89d6b670cf5.zip
add ssa form
Diffstat (limited to 'include')
-rw-r--r--include/qbt/nodes.h34
-rw-r--r--include/qbt/unreachable.h2
2 files changed, 33 insertions, 3 deletions
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 <qbt/nodes.h>
-void unreachable(struct fn *f);
+void remove_unvisited(struct fn *f, int visited);
#endif /* UNREACHABLE_H */