From patchwork Tue Oct 9 23:34:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?J=2E_Neusch=C3=A4fer?= X-Patchwork-Id: 1571821 Return-Path: X-Original-To: patchwork-linux-sparse@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 6F7D840135 for ; Tue, 9 Oct 2012 23:35:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751538Ab2JIXfL (ORCPT ); Tue, 9 Oct 2012 19:35:11 -0400 Received: from mailout-de.gmx.net ([213.165.64.22]:59004 "HELO mailout-de.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751335Ab2JIXfK (ORCPT ); Tue, 9 Oct 2012 19:35:10 -0400 Received: (qmail invoked by alias); 09 Oct 2012 23:35:08 -0000 Received: from dslb-084-060-229-125.pools.arcor-ip.net (EHLO debian.debian) [84.60.229.125] by mail.gmx.net (mp028) with SMTP; 10 Oct 2012 01:35:08 +0200 X-Authenticated: #41721828 X-Provags-ID: V01U2FsdGVkX18yBlUcezUydhEsgpoLAjMmwZtP8ua0Wf+bf3Qux0 mgyTS3ovHwoCLo From: =?UTF-8?q?Jonathan=20Neusch=C3=A4fer?= To: linux-sparse@vger.kernel.org Cc: =?UTF-8?q?Jonathan=20Neusch=C3=A4fer?= , Pekka Enberg , Christopher Li , Jeff Garzik , Linus Torvalds Subject: [PATCH 1/2] sparse, llvm: group PHI nodes at the top of each BB Date: Wed, 10 Oct 2012 01:34:35 +0200 Message-Id: <1349825676-1713-1-git-send-email-j.neuschaefer@gmx.net> X-Mailer: git-send-email 1.7.10.4 MIME-Version: 1.0 X-Y-GMX-Trusted: 0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org This is required for producing valid LLVM bitcode. Cc: Pekka Enberg Cc: Christopher Li Cc: Jeff Garzik Cc: Linus Torvalds Signed-off-by: Jonathan Neuschäfer --- 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 + */