<div dir="ltr"><div style="font-size:12.8px"><div><div><div><div><div><div><div>Hi, all. <br></div><div>I want to give programmer ability to tell LLVM that certain region of code is expected to get specialized optimization.<br></div><div>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.<br></div><br></div>By tracking the framework of loop unroll pragma, I found out it works in the way below. <br></div>(1) Detect pragma at lexer, parser. <br></div>(2) Create AttributeList and push it into AST.<br></div>(3) Once AST is built, consume AST and generate LLVM IR at CodeGeneration<br></div>(4) If attribute for loop unroll is found, put tag on LLVM IR with Meta data which indicates whether to unroll loop.<br><br></div>Now I can detect my own pragma and figured it out how to create and tag custom metadata.<br></div><div style="font-size:12.8px">The problem is that creating custom AttributeList is somewhat hard to follow. <br><br></div><div style="font-size:12.8px">As far as I know, the attribute for loop unroll pragma gets serviced at ProcessSmtAttrbute Function @ tools/clang/lib/Sema/<wbr>SemaStmtAttr.cpp.<br></div><div style="font-size:12.8px">It contains switch statement like below.<br><br>ProcessSmtAttrbute @ tools/clang/lib/Sema/<wbr>SemaStmtAttr.cpp<br></div><div style="font-size:12.8px">// A : AttributeList - passed by argument<br></div><div style="font-size:12.8px">switch( A.getKind() ) {<br></div><div style="font-size:12.8px">  case AttributeList::<wbr>UnknownAttribute:<br>    ~<br></div><div style="font-size:12.8px">  case AttributeList::AT_FallThrough:<br></div><div style="font-size:12.8px">    return ~<br></div><div style="font-size:12.8px">  case AttributeList::AT_LoopHint: <br></div><div style="font-size:12.8px">    return handleLoopHintAttr( ~ )<br></div><div style="font-size:12.8px">  case AttributeList::AT_<wbr>OpenCLUnrollHint:<br>  ~<br>  ...<br></div><div style="font-size:12.8px">}<br><br></div><div style="font-size:12.8px">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.<br><br>class AttributeList @ tools/clang/include/clang/<wbr>Sema/AttributeList.h<br><br></div><div style="font-size:12.8px">enum Kind{<br></div><div style="font-size:12.8px">   #define PARSED ATTR(NAME) AT_##NAME,<br></div><div style="font-size:12.8px">   #include "clang/Sema/<wbr>AttrParsedAttrList.inc"<br></div><div style="font-size:12.8px">   #undef PARSED_ATTR<br></div><div style="font-size:12.8px">   IgnoredAttribute,<br></div><div style="font-size:12.8px">   UnkownAttribute<br>};<br><br></div><div style="font-size:12.8px">It looks like those are defined at this enum, but there's no such file, "clang/Sema/<wbr>AttrParsedAttrList.inc".<br><br></div><div style="font-size:12.8px">Anyone knows how those definitions are defined and how the kind of attributes are decided?<br></div><div style="font-size:12.8px">Thank you for your valuable time!</div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr">Best, Sung<br></div></div></div></div>
</div>