<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=iso-8859-1"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        text-align:right;
        direction:rtl;
        unicode-bidi:embed;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
h1
        {mso-style-priority:9;
        mso-style-link:"Heading 1 Char";
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:24.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.Heading1Char
        {mso-style-name:"Heading 1 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 1";
        font-family:"Times New Roman","serif";
        font-weight:bold;}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:258492476;
        mso-list-template-ids:-846013604;}
@list l0:level1
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:36.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:72.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:"Courier New";
        mso-bidi-font-family:"Times New Roman";}
@list l0:level3
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:108.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Wingdings;}
@list l0:level4
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:144.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Wingdings;}
@list l0:level5
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:180.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Wingdings;}
@list l0:level6
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:216.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Wingdings;}
@list l0:level7
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:252.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Wingdings;}
@list l0:level8
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:288.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Wingdings;}
@list l0:level9
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:324.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Wingdings;}
@list l1
        {mso-list-id:1325163669;
        mso-list-type:hybrid;
        mso-list-template-ids:-9511386 -559004914 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l1:level1
        {mso-level-start-at:0;
        mso-level-number-format:bullet;
        mso-level-text:\F0D8;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:24.0pt;
        text-indent:-18.0pt;
        font-family:Wingdings;
        mso-fareast-font-family:"Times New Roman";
        mso-bidi-font-family:"Courier New";}
@list l1:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:60.0pt;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l1:level3
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:96.0pt;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l1:level4
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:132.0pt;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l1:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:168.0pt;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l1:level6
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:204.0pt;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l1:level7
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:240.0pt;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l1:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:276.0pt;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l1:level9
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:312.0pt;
        text-indent:-18.0pt;
        font-family:Wingdings;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal style='text-align:left;direction:ltr;unicode-bidi:embed'><span style='font-size:13.5pt;color:black'>Hi Gael,<o:p></o:p></span></p><p class=MsoNormal style='text-align:left;direction:ltr;unicode-bidi:embed'><span style='font-size:13.5pt;color:black'><o:p> </o:p></span></p><p class=MsoNormal style='text-align:left;direction:ltr;unicode-bidi:embed'><span style='font-size:13.5pt;color:black'>Thanks a lot for your response, it was very helpful!<o:p></o:p></span></p><p class=MsoNormal style='text-align:left;direction:ltr;unicode-bidi:embed'><span style='font-size:13.5pt;color:black'>How did you manage to access the argument value at the IR stage?<o:p></o:p></span></p><p class=MsoNormal style='text-align:left;direction:ltr;unicode-bidi:embed'><span style='font-size:13.5pt;color:black'><o:p> </o:p></span></p><p class=MsoNormal style='text-align:left;direction:ltr;unicode-bidi:embed'><span style='font-size:13.5pt;color:black'>Thanks again,<o:p></o:p></span></p><p class=MsoNormal style='text-align:left;direction:ltr;unicode-bidi:embed'><span style='font-size:13.5pt;color:black'>Tehila.</span><span lang=HE dir=RTL style='font-size:13.5pt;font-family:"Arial","sans-serif";color:black'><o:p></o:p></span></p><p class=MsoNormal style='text-align:left;direction:ltr;unicode-bidi:embed'><b><span style='font-size:13.5pt;color:black'><o:p> </o:p></span></b></p><p class=MsoNormal style='text-align:left;direction:ltr;unicode-bidi:embed'><b><span style='font-size:13.5pt;color:black'>Gaël Jobin via llvm-dev</span></b><span class=apple-converted-space><span style='font-size:13.5pt;color:black;background:white'> </span></span><a href="mailto:llvm-dev%40lists.llvm.org?Subject=Re%3A%20%5Bllvm-dev%5D%20Adding%20a%20function%20attribute%20with%20an%20argument&In-Reply-To=%3C1444291685.8458.15.camel%40switzerlandmail.ch%3E" title="[llvm-dev] Adding a function attribute with an argument"><span style='font-size:13.5pt'>llvm-dev at lists.llvm.org</span><span class=apple-converted-space><span style='font-size:13.5pt;color:blue;text-decoration:none'> </span></span></a><span style='font-size:13.5pt;color:black'><br><i>Thu Oct 8 01:08:05 PDT 2015</i></span><o:p></o:p></p><pre><span style='color:black'>>Hi Tehila,<o:p></o:p></span></pre><pre><span style='color:black'>>I recently added new function attributes to clang/llvm with arguments.<o:p></o:p></span></pre><pre><span style='color:black'>>What I did is the following:<o:p></o:p></span></pre><pre><span style='color:black'>>1. Add your attributes to tools/clang/include/clang/Basic/Attr.td<o:p></o:p></span></pre><pre><span style='color:black'>>def MYATTR : InheritableAttr {<o:p></o:p></span></pre><pre><span style='color:black'>>  let Spellings = [GNU<"myattr">, CXX11<"gnu", "myattr">];<o:p></o:p></span></pre><pre><span style='color:black'>>  let Args = [DefaultIntArgument<"myargument", 5>];<o:p></o:p></span></pre><pre><span style='color:black'>>  let Subjects = SubjectList<[Function]>;<o:p></o:p></span></pre><pre><span style='color:black'>>  let Documentation = [Undocumented];<o:p></o:p></span></pre><pre><span style='color:black'>>}<o:p></o:p></span></pre><pre><span style='color:black'>>2. Manage it in tools/clang/lib/CodeGen/CGCall.cpp...<o:p></o:p></span></pre><pre><span style='color:black'>>void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,<o:p></o:p></span></pre><pre><span style='color:black'>>                                           const Decl *TargetDecl,<o:p></o:p></span></pre><pre><span style='color:black'>>                                           AttributeListType &PAL,<o:p></o:p></span></pre><pre><span style='color:black'>>                                           unsigned &CallingConv,<o:p></o:p></span></pre><pre><span style='color:black'>>                                           bool AttrOnCallSite) {<o:p></o:p></span></pre><pre><span style='color:black'>>//other code...<o:p></o:p></span></pre><pre><span style='color:black'>>if (TargetDecl) {<o:p></o:p></span></pre><pre><span style='color:black'>>if (TargetDecl->hasAttr<MYEXAMPLEAttr>())<o:p></o:p></span></pre><pre><span style='color:black'>>       {<o:p></o:p></span></pre><pre><span style='color:black'>>               auto myexample = TargetDecl->getAttr<MYEXAMPLEAttr>();<o:p></o:p></span></pre><pre><span style='color:black'>>              FuncAttrs.addAttribute("myexample");<o:p></o:p></span></pre><pre><span style='color:black'>>              unsigned myargument = myexample->getMyargument();<o:p></o:p></span></pre><pre><span style='color:black'>><o:p> </o:p></span></pre><pre><span style='color:black'>><o:p> </o:p></span></pre><pre><span style='color:black'>>              FuncAttrs.addAttribute("myargument",<o:p></o:p></span></pre><pre><span style='color:black'>>llvm::utostr(myargument));<o:p></o:p></span></pre><pre><span style='color:black'>>       }<o:p></o:p></span></pre><pre><span style='color:black'>>//other code...<o:p></o:p></span></pre><pre><span style='color:black'>>}<o:p></o:p></span></pre><pre><span style='color:black'>>//other code...<o:p></o:p></span></pre><pre><span style='color:black'>>}<o:p></o:p></span></pre><pre><span style='color:black'>>3. ...and in tools/clang/lib/Sema/SemaDeclAttr.cpp<o:p></o:p></span></pre><pre><span style='color:black'>>static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,<o:p></o:p></span></pre><pre><span style='color:black'>>                                 const AttributeList &Attr,<o:p></o:p></span></pre><pre><span style='color:black'>>                                 bool IncludeCXX11Attributes) {<o:p></o:p></span></pre><pre><span style='color:black'>>//other code...<o:p></o:p></span></pre><pre><span style='color:black'>>switch (Attr.getKind()) {<o:p></o:p></span></pre><pre><span style='color:black'>>case AttributeList::AT_MYEXAMPLE:<o:p></o:p></span></pre><pre><span style='color:black'>>       handleMYEXAMPLEAttr(S, D, Attr);<o:p></o:p></span></pre><pre><span style='color:black'>>       break;<o:p></o:p></span></pre><pre><span style='color:black'>>//other code...<o:p></o:p></span></pre><pre><span style='color:black'>>}<o:p></o:p></span></pre><pre><span style='color:black'>><o:p> </o:p></span></pre><pre><span style='color:black'>><o:p> </o:p></span></pre><pre><span style='color:black'>>static void handleMYEXAMPLEAttr(Sema &S, Decl *D, const AttributeList<o:p></o:p></span></pre><pre><span style='color:black'>>&Attr) {<o:p></o:p></span></pre><pre><span style='color:black'>>       uint32_t myargument = AVMAttr::DefaultMyargument;<o:p></o:p></span></pre><pre><span style='color:black'>><o:p> </o:p></span></pre><pre><span style='color:black'>>       if (Attr.getNumArgs() && !checkUInt32Argument(S, Attr,<o:p></o:p></span></pre><pre><span style='color:black'>>Attr.getArgAsExpr(0), myargument))<o:p></o:p></span></pre><pre><span style='color:black'>>              return;<o:p></o:p></span></pre><pre><span style='color:black'>><o:p> </o:p></span></pre><pre><span style='color:black'>>       D->addAttr(::new (S.Context)<o:p></o:p></span></pre><pre><span style='color:black'>>                      AVMAttr(Attr.getRange(), S.Context, myargument,<o:p></o:p></span></pre><pre><span style='color:black'>>                              Attr.getAttributeSpellingListIndex()));<o:p></o:p></span></pre><pre><span style='color:black'>>}<o:p></o:p></span></pre><pre><span style='color:black'>>Then you should have access to it in LLVM IR.<o:p></o:p></span></pre><pre><span style='color:black'>>I may have forgotten some stuff but it should help you get started.<o:p></o:p></span></pre><pre><span style='color:black'>>Regards,<o:p></o:p></span></pre><pre><span style='color:black'>>Gael<o:p></o:p></span></pre><pre><span style='color:black'>>Le jeudi 08 octobre 2015 à 10:02 +0300, Tehila Mayzels via llvm-dev a<o:p></o:p></span></pre><pre><span style='color:black'>>écrit :<o:p></o:p></span></pre><pre><span style='color:black'>>><i> Hi,<o:p></o:p></i></span></pre><pre><span style='color:black'>>><i>  <o:p></o:p></i></span></pre><pre><span style='color:black'>>><i> I'm trying to add a function attribute to clang/llvm.<o:p></o:p></i></span></pre><pre><span style='color:black'>>><i> I need an attribute that will have an additional information of a<o:p></o:p></i></span></pre><pre><span style='color:black'>>><i> variable name.<o:p></o:p></i></span></pre><pre><span style='color:black'>>><i> e.g. I would like to add support for something like:<o:p></o:p></i></span></pre><pre><span style='color:black'>>><i>  <o:p></o:p></i></span></pre><pre><span style='color:black'>>><i> void foo() __attribute__ ((xyz(v)) {…}<o:p></o:p></i></span></pre><pre><span style='color:black'>>><i>  <o:p></o:p></i></span></pre><pre><span style='color:black'>>><i> such that on the IR stage I can realize that the function foo has the<o:p></o:p></i></span></pre><pre><span style='color:black'>>><i> attribute xyz and an argument v that  marks variable v (which is a<o:p></o:p></i></span></pre><pre><span style='color:black'>>><i> variable inside foo) for my needs.<o:p></o:p></i></span></pre><pre><span style='color:black'>>><i>  <o:p></o:p></i></span></pre><pre><span style='color:black'>>><i> I was able to add a function attribute without an argument, but I<o:p></o:p></i></span></pre><pre><span style='color:black'>>><i> don't understand how to parse/save/analyze the argument.<o:p></o:p></i></span></pre><pre><span style='color:black'>>><i>  <o:p></o:p></i></span></pre><pre><span style='color:black'>>><i> I would appreciate any ideas/examples/references.<o:p></o:p></i></span></pre><pre><span style='color:black'>>><i>  <o:p></o:p></i></span></pre><pre><span style='color:black'>>><i> Thanks a lot,<o:p></o:p></i></span></pre><pre><span style='color:black'>>><i> Tehila.<o:p></o:p></i></span></pre><pre><span style='color:black'>>><i>  <o:p></o:p></i></span></pre><pre><span style='color:black'>>><i>  <o:p></o:p></i></span></pre><pre><span style='color:black'>>><i> _______________________________________________<o:p></o:p></i></span></pre><pre><span style='color:black'>>><i> LLVM Developers mailing list<o:p></o:p></i></span></pre><pre><span style='color:black'>>><i> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">llvm-dev at lists.llvm.org</a><o:p></o:p></i></span></pre><pre><span style='color:black'>><i> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></i><o:p></o:p></span></pre><p class=MsoNormal dir=RTL><span dir=LTR><o:p> </o:p></span></p></div></body></html>