[llvm-dev] [Help] Add custom pragma

Sunghyun Park via llvm-dev llvm-dev at lists.llvm.org
Tue Oct 25 16:12:18 PDT 2016


Yes. I checked that file, but I wasn't sure whether that is right one to
look at.
What is *.td extension btw? When I google it, it says this is for Windows
Debug Simulator.
Why clang use this extension, which is limited to Windows environment?

On Tue, Oct 25, 2016 at 7:00 PM, Vedant Kumar <vsk at apple.com> wrote:

> That file is generated by the clang-tblgen tool:
>
>   COMMAND = cd /Users/vk/Desktop/llvm/DA-NoModules/tools/clang/include/clang/Sema
> && /Users/vk/Desktop/llvm/DA-NoModules/bin/clang-tblgen
> -gen-clang-attr-parsed-attr-list -I /Users/vk/Desktop/llvm/tools/
> clang/include/clang/Sema/../../ -I /Users/vk/Desktop/llvm/tools/clang/include/clang/Sema
> -I /Users/vk/Desktop/llvm/lib/Target -I /Users/vk/Desktop/llvm/include
> /Users/vk/Desktop/llvm/tools/clang/include/clang/Sema/../Basic/Attr.td -o
> /Users/vk/Desktop/llvm/DA-NoModules/tools/clang/include/
> clang/Sema/AttrParsedAttrList.inc.tmp
>
> Try looking include/clang/Basic/Attr.td?
>
> best,
> vedant
>
> > On Oct 25, 2016, at 2:54 PM, Sunghyun Park via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
> >
> > Hi, all.
> > I want to give programmer ability to tell LLVM that certain region of
> code is expected to get specialized optimization.
> > So, I'm trying to make custom pragma to mark certain region of code and
> pass this information to LLVM, in the similar way that '#pragma clang loop
> unroll_count(N)' works.
> >
> > By tracking the framework of loop unroll pragma, I found out it works in
> the way below.
> > (1) Detect pragma at lexer, parser.
> > (2) Create AttributeList and push it into AST.
> > (3) Once AST is built, consume AST and generate LLVM IR at CodeGeneration
> > (4) If attribute for loop unroll is found, put tag on LLVM IR with Meta
> data which indicates whether to unroll loop.
> >
> > Now I can detect my own pragma and figured it out how to create and tag
> custom metadata.
> > The problem is that creating custom AttributeList is somewhat hard to
> follow.
> >
> > As far as I know, the attribute for loop unroll pragma gets serviced at
> ProcessSmtAttrbute Function @ tools/clang/lib/Sema/SemaStmtAttr.cpp.
> > It contains switch statement like below.
> >
> > ProcessSmtAttrbute @ tools/clang/lib/Sema/SemaStmtAttr.cpp
> > // A : AttributeList - passed by argument
> > switch( A.getKind() ) {
> >   case AttributeList::UnknownAttribute:
> >     ~
> >   case AttributeList::AT_FallThrough:
> >     return ~
> >   case AttributeList::AT_LoopHint:
> >     return handleLoopHintAttr( ~ )
> >   case AttributeList::AT_OpenCLUnrollHint:
> >   ~
> >   ...
> > }
> >
> > As I want to define new attribute, I've tried to find where the
> definitions for AT_LoopHint, AT_FallThrough are done. This is what I found.
> >
> > class AttributeList @ tools/clang/include/clang/Sema/AttributeList.h
> >
> > enum Kind{
> >    #define PARSED ATTR(NAME) AT_##NAME,
> >    #include "clang/Sema/AttrParsedAttrList.inc"
> >    #undef PARSED_ATTR
> >    IgnoredAttribute,
> >    UnkownAttribute
> > };
> >
> > It looks like those are defined at this enum, but there's no such file,
> "clang/Sema/AttrParsedAttrList.inc".
> >
> > Anyone knows how those definitions are defined and how the kind of
> attributes are decided?
> > Thank you for your valuable time!
> >
> > --
> > Best, Sung
> > _______________________________________________
> > LLVM Developers mailing list
> > llvm-dev at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>


-- 
Best, Sung
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161025/2e98d9c2/attachment.html>


More information about the llvm-dev mailing list