aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
-rw-r--r--Makefile1
-rw-r--r--ir.c40
-rw-r--r--ir.h8
-rw-r--r--lib.c2
-rw-r--r--lib.h1
-rw-r--r--optimize.c3
6 files changed, 55 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 0b6c32cf..abe30e02 100644
--- a/Makefile
+++ b/Makefile
@@ -42,6 +42,7 @@ LIB_OBJS += expand.o
LIB_OBJS += expression.o
LIB_OBJS += flow.o
LIB_OBJS += inline.o
+LIB_OBJS += ir.o
LIB_OBJS += lib.o
LIB_OBJS += linearize.o
LIB_OBJS += liveness.o
diff --git a/ir.c b/ir.c
new file mode 100644
index 00000000..6684257c
--- /dev/null
+++ b/ir.c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: MIT
+
+#include "ir.h"
+#include "linearize.h"
+#include <stdlib.h>
+
+
+static int validate_insn(struct instruction *insn)
+{
+ int err = 0;
+
+ switch (insn->opcode) {
+ default:
+ break;
+ }
+
+ return err;
+}
+
+int ir_validate(struct entrypoint *ep)
+{
+ struct basic_block *bb;
+ int err = 0;
+
+ if (!dbg_ir || has_error)
+ return 0;
+
+ FOR_EACH_PTR(ep->bbs, bb) {
+ struct instruction *insn;
+ FOR_EACH_PTR(bb->insns, insn) {
+ if (!insn->bb)
+ continue;
+ err += validate_insn(insn);
+ } END_FOR_EACH_PTR(insn);
+ } END_FOR_EACH_PTR(bb);
+
+ if (err)
+ abort();
+ return err;
+}
diff --git a/ir.h b/ir.h
new file mode 100644
index 00000000..48760c25
--- /dev/null
+++ b/ir.h
@@ -0,0 +1,8 @@
+#ifndef _IR_H
+#define _IR_H
+
+#include "linearize.h"
+
+int ir_validate(struct entrypoint *ep);
+
+#endif
diff --git a/lib.c b/lib.c
index 5fab1933..d483f6f6 100644
--- a/lib.c
+++ b/lib.c
@@ -286,6 +286,7 @@ int dump_macro_defs = 0;
int dbg_compound = 0;
int dbg_dead = 0;
int dbg_entry = 0;
+int dbg_ir = 0;
unsigned long fdump_ir;
int fmem_report = 0;
@@ -762,6 +763,7 @@ static struct flag debugs[] = {
{ "compound", &dbg_compound},
{ "dead", &dbg_dead},
{ "entry", &dbg_entry},
+ { "ir", &dbg_ir},
};
diff --git a/lib.h b/lib.h
index e0b52a30..6c3f84cf 100644
--- a/lib.h
+++ b/lib.h
@@ -175,6 +175,7 @@ extern int dump_macro_defs;
extern int dbg_compound;
extern int dbg_dead;
extern int dbg_entry;
+extern int dbg_ir;
extern unsigned int fmax_warnings;
extern int fmem_report;
diff --git a/optimize.c b/optimize.c
index 5cde6a58..051c629f 100644
--- a/optimize.c
+++ b/optimize.c
@@ -11,6 +11,7 @@
#include "liveness.h"
#include "flow.h"
#include "cse.h"
+#include "ir.h"
int repeat_phase;
@@ -50,12 +51,14 @@ void optimize(struct entrypoint *ep)
* branches, kill dead basicblocks etc
*/
kill_unreachable_bbs(ep);
+ ir_validate(ep);
/*
* Turn symbols into pseudos
*/
if (fpasses & PASS_MEM2REG)
simplify_symbol_usage(ep);
+ ir_validate(ep);
if (fdump_ir & PASS_MEM2REG)
show_entry(ep);