[PATCH] Have 'this'-returning constructors and destructors to take advantage of the new backend 'returned' attribute
John McCall
rjmccall at apple.com
Thu May 2 14:09:45 PDT 2013
On May 2, 2013, at 1:59 PM, Stephen Lin <swlin at post.harvard.edu> wrote:
> On Thu, May 2, 2013 at 2:28 PM, John McCall <rjmccall at apple.com> wrote:
>> On May 1, 2013, at 7:56 AM, Stephen Lin <swlin at post.harvard.edu> wrote:
>>> This patch converts the implementation of 'this'-returning
>>> constructors and destructors (in ARM and MS C++ ABIs) to use the new
>>> 'returned' attribute.
>>>
>>> It does so by adding a new flag to FunctionType::ExtInfo and other
>>> associated classes which indicates that a function returns its first
>>> argument; only a single bit is used currently since the only use cases
>>> for this attribute are for the first parameter, but the API is
>>> designed to theoretically allow the the attribute on any parameter if
>>> needed later by increasing the number of reserved flag bits for the
>>> field.
>>
>> This optimization is definitely not worth the complexity cost of raising it into
>> the formal type system. Just find a way to add the new function attribute to
>> the LLVM function declaration when creating a constructor or destructor.
>>
>> If we added a user-level attribute, that's how we'd handle it as well.
>>
>> LLVM has existing built-in knowledge of specific functions like memcpy;
>> it can be responsible for adding this annotation as appropriate to them
>> (when allowed).
>>
>> John.
>
> Thanks for the reply and feedback. To clarify, so you mean to avoid
> putting it in FunctionType::ExtInfo? I was hesistant to add it there
> for the complexity cost you mentioned but couldn't figure out a better
> place to put it: the information seems to have to get to
> CodeGenModule::ConstructAttributeList somehow, or is there another
> convenient place to add attributes to a parameter of a function
> declaration?
CodeGenModule::ConstructAttributeList gets the Decl; just have it
check for a ctor or dtor and ask the CXXABI whether that Decl
promises to return 'this'.
John.
More information about the cfe-commits
mailing list