From: Xi Wang <xi.wang@gmail.com>
To: "Jonathan Neuschäfer" <j.neuschaefer@gmx.net>
Cc: Pekka Enberg <penberg@kernel.org>,
Jeff Garzik <jgarzik@pobox.com>,
linux-sparse@vger.kernel.org, Christopher Li <sparse@chrisli.org>,
Jeff Garzik <jgarzik@redhat.com>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH 1/2] sparse, llvm: group PHI nodes at the top of each BB
Date: Tue, 16 Oct 2012 16:53:48 -0400 [thread overview]
Message-ID: <507DC95C.7010106@gmail.com> (raw)
In-Reply-To: <20121016201426.GD2932@debian.debian>
On 10/16/12 4:14 PM, Jonathan Neuschäfer wrote:
> Actually, the situation of Phi nodes in LLVM is actually slightly more
> complex: They require "one pair (of value and BB) for each predecessor
> basic block of the current block"[1]. This mean that we'll sometimes
> need to insert phi nodes into BBs that don't directly use a value.
I ran into the same problem before. I would suggest a simpler and safer
way: don't emit LLVM phi; instead emit load/store (of some alloca).
phi => load from some alloca
phisrc => store to some alloca
You can find sample code from splay here (emit_phi & emit_phisrc):
https://github.com/xiw/splay/blob/master/function.c#L356
> Consider the following piece of C code:
>
> extern int done(void);
> extern void foo(int);
>
> static void test(void) {
> int i;
> for (i = 0; ; i++) {
> if (done())
> break;
> foo(i);
> }
> }
This is what splay emits:
define internal void @test() {
entry:
%0 = alloca i32
store i32 0, i32* %0
br label %bb
bb: ; preds = %bb1, %entry
%1 = call i32 @done()
%2 = icmp ne i32 %1, 0
br i1 %2, label %bb2, label %bb1
bb1: ; preds = %bb
%3 = load i32* %0
call void @foo(i32 %3)
%4 = add nsw i32 %3, 1
store i32 %4, i32* %0
br label %bb
bb2: ; preds = %bb
ret void
}
After "-mem2reg" you get:
define internal void @test() {
entry:
br label %bb
bb: ; preds = %bb1, %entry
%.0 = phi i32 [ 0, %entry ], [ %2, %bb1 ]
%0 = call i32 @done()
%1 = icmp ne i32 %0, 0
br i1 %1, label %bb2, label %bb1
bb1: ; preds = %bb
call void @foo(i32 %.0)
%2 = add nsw i32 %.0, 1
br label %bb
bb2: ; preds = %bb
ret void
}
- xi
--
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
next prev parent reply other threads:[~2012-10-16 20:53 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=507DC95C.7010106@gmail.com \
--to=xi.wang@gmail.com \
--cc=j.neuschaefer@gmx.net \
--cc=jgarzik@pobox.com \
--cc=jgarzik@redhat.com \
--cc=linux-sparse@vger.kernel.org \
--cc=penberg@kernel.org \
--cc=sparse@chrisli.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.