linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] sparse, llvm: group PHI nodes at the top of each BB
@ 2012-10-09 23:34 Jonathan Neuschäfer
  2012-10-09 23:34 ` [PATCH 2/2] sparse, llvm: Fix type of loaded values Jonathan Neuschäfer
  2012-10-10  0:12 ` [PATCH 1/2] sparse, llvm: group PHI nodes at the top of each BB Jeff Garzik
  0 siblings, 2 replies; 17+ messages in thread
From: Jonathan Neuschäfer @ 2012-10-09 23:34 UTC (permalink / raw)
  To: linux-sparse
  Cc: Jonathan Neuschäfer, Pekka Enberg, Christopher Li,
	Jeff Garzik, Linus Torvalds

This is required for producing valid LLVM bitcode.

Cc: Pekka Enberg <penberg@kernel.org>
Cc: Christopher Li <sparse@chrisli.org>
Cc: Jeff Garzik <jgarzik@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
---
 sparse-llvm.c              |   17 ++++++++++++++++-
 validation/backend/loop2.c |   13 +++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 validation/backend/loop2.c

diff --git a/sparse-llvm.c b/sparse-llvm.c
index 0fc0dae..2048a1b 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -1111,16 +1111,31 @@ static void output_insn(struct function *fn, struct instruction *insn)
 static void output_bb(struct function *fn, struct basic_block *bb, unsigned long generation)
 {
 	struct instruction *insn;
+	struct instruction_list *remaining = NULL;
 
 	bb->generation = generation;
 
+	/*
+	 * LLVM requires the phi instructions to be grouped at the top of each
+	 * basic block.
+	 */
+
 	FOR_EACH_PTR(bb->insns, insn) {
 		if (!insn->bb)
 			continue;
 
-		output_insn(fn, insn);
+		if (insn->opcode == OP_PHI)
+			output_insn(fn, insn);
+		else
+			add_instruction(&remaining, insn);
 	}
 	END_FOR_EACH_PTR(insn);
+
+	FOR_EACH_PTR(remaining, insn) {
+		output_insn(fn, insn);
+	} END_FOR_EACH_PTR(insn);
+
+	free_ptr_list(&remaining);
 }
 
 #define MAX_ARGS	64
diff --git a/validation/backend/loop2.c b/validation/backend/loop2.c
new file mode 100644
index 0000000..4e44a15
--- /dev/null
+++ b/validation/backend/loop2.c
@@ -0,0 +1,13 @@
+extern int op(void);
+
+static void test(void) {
+	int i;
+	for (i = 0; ; i++) {
+		op();
+	}
+}
+
+/*
+ * check-name: Loops with unused counter
+ * check-command: ./sparsec -c $file -o tmp.o
+ */
-- 
1.7.10.4

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

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2013-05-16  5:29 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-09 23:34 [PATCH 1/2] sparse, llvm: group PHI nodes at the top of each BB Jonathan Neuschäfer
2012-10-09 23:34 ` [PATCH 2/2] sparse, llvm: Fix type of loaded values Jonathan Neuschäfer
2012-10-10  0:13   ` Jeff Garzik
2012-10-10  6:34     ` Pekka Enberg
2012-10-10  0:12 ` [PATCH 1/2] sparse, llvm: group PHI nodes at the top of each BB Jeff Garzik
2012-10-10  6:31   ` Pekka Enberg
2012-10-10 16:33     ` Jonathan Neuschäfer
2012-10-12 18:25       ` Pekka Enberg
2012-10-16 17:59         ` Pekka Enberg
2012-10-16 20:14           ` Jonathan Neuschäfer
2012-10-16 20:53             ` Xi Wang
2012-10-17  6:48               ` Pekka Enberg
2012-10-17  6:53                 ` Xi Wang
2012-10-17 16:41                   ` Pekka Enberg
2012-10-17 17:44                     ` Jonathan Neuschäfer
2013-05-15 12:05               ` Pekka Enberg
2013-05-16  5:28                 ` Xi Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).