[PATCH] Add NoDuplicate attribute to clang (2nd try)

Marcello Maggioni hayarms at gmail.com
Sat Feb 22 12:28:30 PST 2014


Thank you very much Aaron! :)

On Saturday, February 22, 2014, Aaron Ballman <aaron at aaronballman.com>
wrote:

> Thanks! I've applied your changes in r201941. I did have to change the
> codegen test so that it had a target triple, otherwise it was failing
> for me on Windows due to name mangling differences.
>
> ~Aaron
>
> On Fri, Feb 21, 2014 at 8:52 PM, Marcello Maggioni <hayarms at gmail.com>
> wrote:
> > Hi Aaron,
> > thanks for your comments! I addressed your concerns in these 2 new
> patches.
> > The answers are inline
> >
> > 2014-02-21 23:04 GMT+00:00 Aaron Ballman <aaron at aaronballman.com>:
> >
> >> A few mostly minor comments below:
> >>
> >> > diff --git a/docs/AttributeReference.rst b/docs/AttributeReference.rst
> >> > index 1d41cb3..3d718a4 100644
> >> > --- a/docs/AttributeReference.rst
> >> > +++ b/docs/AttributeReference.rst
> >> > @@ -558,6 +558,50 @@ caveats to this use of name mangling:
> >> >
> >> >  Query for this feature with
> >> > ``__has_extension(attribute_overloadable)``.
> >> >
> >> > +noduplicate
> >> > +-----------
> >> > +.. csv-table:: Supported Syntaxes
> >> > +   :header: "GNU", "C++11", "__declspec", "Keyword"
> >> > +
> >> > +   "X","X","",""
> >> > +
> >> > +The ``noduplicate`` attribute can be placed on function declarations
> to
> >> > control
> >> > +which overload whether function calls to this function can be
> >> > duplicated
> >> > +or not as a result of optimizations. This is required for the
> >> > implementation
> >> > +of functions with certain special requirements, like the OpenCL
> >> > "barrier",
> >> > +function that, depending on the hardware, might require to be run
> >> > concurrently
> >> > +by all the threads that are currently executing in lockstep on the
> >> > hardware.
> >> > +For example this attribute applied on the function "nodupfunc"
> >> > +avoids that this code:
> >> > +
> >> > +.. code-block:: c
> >> > +
> >> > +  void nodupfunc() __attribute__((noduplicate));
> >> > +  // Setting it as a C++11 attribute is also valid
> >> > +  // void nodupfunc() [[clang::noduplicate]];
> >> > +  void foo();
> >> > +  void bar();
> >> > +
> >> > +  nodupfunc();
> >> > +  if (a > n) {
> >> > +    foo();
> >> > +  } else {
> >> > +    bar();
> >> > +  }
> >> > +
> >> > +gets possibly modified by some optimization into code similar to
> this:
> >> > +
> >> > +.. code-block:: c
> >> > +
> >> > +  if (a > n) {
> >> > +    nodupfunc();
> >> > +    foo();
> >> > +  } else {
> >> > +    nodupfunc();
> >> > +    bar();
> >> > +  }
> >> > +
> >> > +where the barrier call is duplicated and sinked into the two branches
> >> > of the condition.
> >> >
> >> >  Variable Attributes
> >> >  ===================
> >> > diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td
> >> > index 3b70c4c..1368812 100644
> >> > --- a/include/clang/Basic/Attr.td
> >> > +++ b/include/clang/Basic/Attr.td
> >> > @@ -803,6 +803,12 @@ def NoDebug : InheritableAttr {
> >> >    let Documentation = [Undocumented];
> >> >  }
> >> >
> >> > +def NoDuplicate : InheritableAttr {
> >> > +  let Spellings = [GNU<"noduplicate">, CXX11<"clang",
> "noduplicate">];
> >> > +  let Subjects = SubjectList<[Function]>;
> >> > +  let Documentation = [NoDuplicateDocs];
> >> > +}
> >> > +
> >> >  def NoInline : InheritableAttr {
> >> >    let Spellings = [GCC<"noinline">, Declspec<"noinline">];
> >> >    let Subjects = SubjectList<[Function]>;
> >> > diff --git a/include/clang/Basic/AttrDocs.td
> >> > b/include/clang/Basic/AttrDocs.td
> >> > index a2476e4..d60de82 100644
> >> > --- a/include/clang/Basic/AttrDocs.td
> >> > +++ b/include/clang/Basic/AttrDocs.td
> >> > @@ -268,6 +268,49 @@ Query for thi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140222/b8ec727f/attachment.html>


More information about the cfe-commits mailing list