[PATCH 2/4] ir-validate: add framework for IR validation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To be meaningful, the IR instructions and their relationships
must obey some constraints. This patch add the framework for
doing this kind of validation.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 Makefile   |  1 +
 ir.c       | 38 ++++++++++++++++++++++++++++++++++++++
 ir.h       |  8 ++++++++
 lib.c      |  2 ++
 lib.h      |  1 +
 optimize.c |  3 +++
 6 files changed, 53 insertions(+)
 create mode 100644 ir.c
 create mode 100644 ir.h

diff --git a/Makefile b/Makefile
index 0b6c32cf5..abe30e026 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 000000000..fe900b9ca
--- /dev/null
+++ b/ir.c
@@ -0,0 +1,38 @@
+#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 000000000..48760c258
--- /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 3ee7dc6b0..80fff8555 100644
--- a/lib.c
+++ b/lib.c
@@ -285,6 +285,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;
@@ -761,6 +762,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 e0b52a30d..6c3f84cf7 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 5cde6a58c..051c629f4 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);
 
-- 
2.17.1

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux