Hi Chris, Thanks. I will see what I can do for this. Junjie On Wed, May 19, 2010 at 3:45 PM, Chris Lattner <clattner at apple.com> wrote:> > On May 19, 2010, at 2:38 PM, Junjie Gu wrote: > >> Many compilers support per-loop pragma, such as loop unrolling (ie >> #pragma unroll=2). Is there any LLVM project/effort going on >> in this area ? What is the expected way for implementing per-loop >> pragma, or general pragma ? Suggestions/comments ? > > Hi Junjie, > > I don't know of anyone working on it, but it seems like a natural application of the metadata support in mainline: > http://blog.llvm.org/2010/04/extensible-metadata-in-llvm-ir.html > > We'd want to tag something, perhaps the backedge branches with metadata, then have the loop canonicalization passes preserve them. > > -Chris
I'd like to add a pragma support in llvm. I am thinking about using a llvm intrinsic to represent each pragma, such as llvm.pragma (metadata, ...) where metadata describes a pragma. So if an application has: #pragma p1 .. #pragma p2... for (...) The llvm IR would be llvm.pragma (metadata..) // for p1 llvm.pragma (metadata..) // for p2 llvm IR for "for (...)" In this way, the pragma handling is quite general (for example, it can be used to support frequency hint for a branch, etc). And it should be easy for any frontend to generate. A possible issue might be that optimizations might make the association between pragmas and their loops (in this case) less obvious. Any suggestions/ideas ? Junjie On Wed, May 19, 2010 at 4:31 PM, Junjie Gu <jgu222 at gmail.com> wrote:> Hi Chris, > > Thanks. I will see what I can do for this. > > Junjie > > On Wed, May 19, 2010 at 3:45 PM, Chris Lattner <clattner at apple.com> wrote: >> >> On May 19, 2010, at 2:38 PM, Junjie Gu wrote: >> >>> Many compilers support per-loop pragma, such as loop unrolling (ie >>> #pragma unroll=2). Is there any LLVM project/effort going on >>> in this area ? What is the expected way for implementing per-loop >>> pragma, or general pragma ? Suggestions/comments ? >> >> Hi Junjie, >> >> I don't know of anyone working on it, but it seems like a natural application of the metadata support in mainline: >> http://blog.llvm.org/2010/04/extensible-metadata-in-llvm-ir.html >> >> We'd want to tag something, perhaps the backedge branches with metadata, then have the loop canonicalization passes preserve them. >> >> -Chris >
Hi Junjie,> In this way, the pragma handling is quite general (for example, it can > be used to support frequency hint for a branch, etc). > And it should be easy for any frontend to generate.since metadata can be attached to instructions, couldn't you just attach some metadata containing frequency information directly to the branch instruction? Ciao, Duncan.
On Tue, Jun 1, 2010 at 5:42 PM, Junjie Gu <jgu222 at gmail.com> wrote:> I'd like to add a pragma support in llvm. I am thinking about using a > llvm intrinsic to represent each pragma, such as > llvm.pragma (metadata, ...) > where metadata describes a pragma. So if an application has: > > #pragma p1 .. > #pragma p2... > for (...) > > The llvm IR would be > > llvm.pragma (metadata..) // for p1 > llvm.pragma (metadata..) // for p2 > llvm IR for "for (...)"This approach assumes that these two llvm.pragma intrinsics and the llvm IR for "for (...)" always stay together in same order all the time. This ordering is extremely hard to maintain. Using attached metadata, as suggested by others, is much better alternative. - Devang> In this way, the pragma handling is quite general (for example, it can > be used to support frequency hint for a branch, etc). > And it should be easy for any frontend to generate. > > A possible issue might be that optimizations might make the > association between pragmas and their loops (in this case) > less obvious. > > Any suggestions/ideas ? > > Junjie > > On Wed, May 19, 2010 at 4:31 PM, Junjie Gu <jgu222 at gmail.com> wrote: >> Hi Chris, >> >> Thanks. I will see what I can do for this. >> >> Junjie >> >> On Wed, May 19, 2010 at 3:45 PM, Chris Lattner <clattner at apple.com> wrote: >>> >>> On May 19, 2010, at 2:38 PM, Junjie Gu wrote: >>> >>>> Many compilers support per-loop pragma, such as loop unrolling (ie >>>> #pragma unroll=2). Is there any LLVM project/effort going on >>>> in this area ? What is the expected way for implementing per-loop >>>> pragma, or general pragma ? Suggestions/comments ? >>> >>> Hi Junjie, >>> >>> I don't know of anyone working on it, but it seems like a natural application of the metadata support in mainline: >>> http://blog.llvm.org/2010/04/extensible-metadata-in-llvm-ir.html >>> >>> We'd want to tag something, perhaps the backedge branches with metadata, then have the loop canonicalization passes preserve them. >>> >>> -Chris >> > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-- - Devang
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