On Tue, Jun 1, 2010 at 5:42 PM, Junjie Gu <jgu222 at gmail.com> wrote:> Any suggestions/ideas ?IIUC, Chris suggested something like following ... header: br i1 %x, label %then, %label endif then: ... br i1 %y, label %loop_exit, label %header, !loop_pragma !1 endif: ... br i1 %z, label %loop_exit, label %header, !loop_pragma !2 loop_exit: ret i32 1 Where !1 and !2 are the metadata for your loop pragma. - Devang
Thanks for comments/suggestions. Yes, attaching metadata to instructions will be good choices for many cases. But for loops, attaching metadata to back-edges requires that the front end to build loops, which is an additional task for the front end. And this task is really a backend's job, not the front end's. If the only concern is that it is hard for pragma intrinsics to stay with their associated code, another choice is to process pragma intrinsic at the beginning of optimizer and associates them to instructions by either attaching metadata to instructions and some kind maps (between instructions/BB to metadata, etc). Junjie On Wed, Jun 2, 2010 at 9:48 AM, Devang Patel <devang.patel at gmail.com> wrote:> On Tue, Jun 1, 2010 at 5:42 PM, Junjie Gu <jgu222 at gmail.com> wrote: >> Any suggestions/ideas ? > > IIUC, Chris suggested something like following ... > > header: > br i1 %x, label %then, %label endif > then: > ... > br i1 %y, label %loop_exit, label %header, !loop_pragma !1 > endif: > ... > br i1 %z, label %loop_exit, label %header, !loop_pragma !2 > loop_exit: > ret i32 1 > > > Where !1 and !2 are the metadata for your loop pragma. > > - > Devang >
If LLVM would like to support OpenMP pragma in the future, not sure if attaching metadata to instructions is still a good choice. Junjie On Wed, Jun 2, 2010 at 11:08 AM, Junjie Gu <jgu222 at gmail.com> wrote:> Thanks for comments/suggestions. > > Yes, attaching metadata to instructions will be good choices for many > cases. But for loops, > attaching metadata to back-edges requires that the front end to build > loops, which is an > additional task for the front end. And this task is really a backend's > job, not the front end's. > > If the only concern is that it is hard for pragma intrinsics to stay > with their associated code, > another choice is to process pragma intrinsic at the beginning of > optimizer and associates > them to instructions by either attaching metadata to instructions and > some kind maps (between > instructions/BB to metadata, etc). > > Junjie > > On Wed, Jun 2, 2010 at 9:48 AM, Devang Patel <devang.patel at gmail.com> wrote: >> On Tue, Jun 1, 2010 at 5:42 PM, Junjie Gu <jgu222 at gmail.com> wrote: >>> Any suggestions/ideas ? >> >> IIUC, Chris suggested something like following ... >> >> header: >> br i1 %x, label %then, %label endif >> then: >> ... >> br i1 %y, label %loop_exit, label %header, !loop_pragma !1 >> endif: >> ... >> br i1 %z, label %loop_exit, label %header, !loop_pragma !2 >> loop_exit: >> ret i32 1 >> >> >> Where !1 and !2 are the metadata for your loop pragma. >> >> - >> Devang >> >
On Wed, Jun 2, 2010 at 11:08 AM, Junjie Gu <jgu222 at gmail.com> wrote:> Thanks for comments/suggestions. > > Yes, attaching metadata to instructions will be good choices for many > cases. But for loops, > attaching metadata to back-edges requires that the front end to build > loops, which is an > additional task for the front end. And this task is really a backend's > job, not the front end's.The front-ends (llvm-gcc and clang) typically lower their internal AST into llvm IR. The front-end's will have to do a job of attaching pragma to respective AST node any way. Which node will it chose to annotate #pragma, irrespective of how it is annotated ?> If the only concern is that it is hard for pragma intrinsics to stay > with their associated code, > another choice is to process pragma intrinsic at the beginning of > optimizer and associates > them to instructions by either attaching metadata to instructions and > some kind maps (between > instructions/BB to metadata, etc).Note, The loop optimizer may not be the first thing run by the optimizer. If you wait until loop optimizer to form loop then it may be too late. Whoever is converting llvm.pragma intrinsic into attached metadata will likely attach metadata to immediate next instruction anyway. - Devang