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>
> Yes. I checked that file, but I wasn't sure whether that is right one to look at.It seems promising. I imagine you'd want something like the LoopHint attr.> What is *.td extension btw?The llvm project uses that extension to identify TableGen inputs (http://llvm.org/docs/TableGen/). vedant> On Oct 25, 2016, at 4:12 PM, Sunghyun Park <sunggg at umich.edu> wrote: > > 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
Yes. Exactly. So, I add my definition for custom attribute in 'include/clang/Basic/Attr.td', something like below. def MyHint : Attr { let Spellings = ~ let Args = ~ let AdditionalMembers = [{ void printPrettyPragma( ~ ) }]; let Documentation = [Undocumented]; } This is basically similar with "def LoopHint : Attr", which is attribute of loop unroll. But somehow it seems it doesn't work properly. It can not emit 'MyHintAttr' class as well as its elements like 'MyHintAttr::Spelling', 'MyHintAttr::CreateImplicit(~)'. My guess is there should be more things to do other than adding definition on Attr.td, so I'm trying to follow how those of LoopHIntAttr are emitted. Is there any reference, or advice where to look at? Instruction on clang is somewhat simpler than my need. It's my first time to hack this large program, so I'm stalling for hours at same status... Thanks, in advance! On Tue, Oct 25, 2016 at 7:22 PM, Vedant Kumar <vsk at apple.com> wrote:> > Yes. I checked that file, but I wasn't sure whether that is right one to > look at. > > It seems promising. I imagine you'd want something like the LoopHint attr. > > > What is *.td extension btw? > > The llvm project uses that extension to identify TableGen inputs > (http://llvm.org/docs/TableGen/). > > vedant > > > On Oct 25, 2016, at 4:12 PM, Sunghyun Park <sunggg at umich.edu> wrote: > > > > 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 > >-- Best, Sung -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161026/c9630937/attachment.html>