[cfe-dev] Help required for adding a new attribute

Aaron Ballman via cfe-dev cfe-dev at lists.llvm.org
Mon Jul 11 05:33:10 PDT 2016


On Mon, Jul 11, 2016 at 6:47 AM, vivek pandya via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> Hello Clang Developers,
>
> I want to add a new attribute which is required to work with function
> declaration as shown in example given below:
>
> extern void foo(int param) __attribute__((regmask("R8,R11")));
>
> int foo2(int param) {
> foo(param);
> return param;
> }
>
> For this I have done following changes:
>
> Attr.td
>
> def RegMask : Attr {
>   let Spellings = [GNU<"regmask">];
>   let Args = [StringArgument<"ClobbersList">];
>   let Subjects = SubjectList<[Function]>;
>   let Documentation = [Undocumented];
> }
>
> lib/Sema/SemaDeclAttr.cpp
>
> static void handleRegMaskAttr(Sema &S, Decl *D, const AttributeList &Attr) {
>   // Make sure that there is a string literal as the annotation's single
>   // argument.
>   StringRef Str;
>   if (!S.checkStringLiteralArgumentAttr(Attr, 0, Str))
>     return;
>
>   D->addAttr(::new (S.Context)
>              AnnotateAttr(Attr.getRange(), S.Context, Str,
>                           Attr.getAttributeSpellingListIndex()));
>   llvm::dbgs() << "Reg Mask attribute : " << Str << "\n";
> }
>
> above method is very similar to handleAnnotateAttr
>
> and use this method inside ProcessDeclAttribute method as follows :
>
> // Attribute to help interprocedural register allocation
>   case AttributeList::AT_RegMask:
>     handleRegMaskAttr(S, D, Attr);
>     break;
>   }
>
> but this does not work for me, it works on function definitions but not with
> function declaration.
>
> Am I missing here any thing?

The attribute should inherit from InheritableAttr instead of just
Attr. That should cause it to be inherited by later redeclarations.

> Note: I want to parse this string at MI level if possible or at IR level to
> create a RegMask out of that.

How do you intend to report diagnostics to the user if the parsed
string contains something unexpected?

~Aaron

>
> Sincerely,
> Vivek
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>



More information about the cfe-dev mailing list