[PATCH] D47067: Update NRVO logic to support early return

Roman Lebedev via cfe-commits cfe-commits at lists.llvm.org
Fri May 18 10:56:07 PDT 2018


On Fri, May 18, 2018 at 8:47 PM, tzik via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
> Ah, sorry. It's still work in progress for now.
> I'll resend this soon after adding tests and updating comments there.
See Herald rules for exact syntax, but i think adding "[private]" into
the subject
would have prevented it from going live.

> 2018年5月19日(土) 2:41 Arthur O'Dwyer <arthur.j.odwyer at gmail.com>:
>>
>> https://reviews.llvm.org/D47067 is a "Restricted Differential Revision",
>> which I've never seen before!
>> Peanut gallery says: This sounds awesome. How does this change interact
>> with the diagnostics issued by -Wpessimizing-move and -Wreturn-std-move?
>> Should any new test cases be added for those diagnostics?
>>
>>
>> On Fri, May 18, 2018 at 7:12 AM, Taiju Tsuiki via Phabricator via
>> cfe-commits <cfe-commits at lists.llvm.org> wrote:
>>>
>>> tzik created this revision.
>>> Herald added a subscriber: cfe-commits.
>>>
>>> The previous implementation misses an opportunity to apply NRVO (Named
>>> Return Value
>>>
>>> Optimization) below. That discourages user to write early return code.
>>> ----------------------------------------------------------------------
>>>
>>> struct Foo {};
>>>
>>> Foo f(bool b) {
>>>
>>>   if (b)
>>>     return Foo();
>>>   Foo oo;
>>>   return oo;
>>>
>>> }
>>> -
>>>
>>> That is, we can/should apply RVO for a return statement if it refers a
>>> non-parameter local variable,
>>> and the variable is referred by all return statements reachable from the
>>> variable declaration.
>>> While, the previous implementation disables the RVO in a scope if there
>>> are multiple return
>>> statements that refers different variables.
>>>
>>> On the new algorithm, local variables are in NRVO_Candidate state at
>>> first, and a return
>>> statement changes it to NRVO_Disabled for all visible variables but the
>>> return statement refers.
>>> Then, at the end of the function AST traversal, NRVO is enabled for
>>> variables in NRVO_Candidate
>>> state and refers from at least one return statement.
>>>
>>>
>>> Repository:
>>>   rC Clang
>>>
>>> https://reviews.llvm.org/D47067
>>>
>>> Files:
>>>   include/clang/AST/Decl.h
>>>   include/clang/Sema/Scope.h
>>>   lib/Sema/Scope.cpp
>>>   lib/Sema/SemaDecl.cpp
>>>   lib/Sema/SemaStmt.cpp
>>>   lib/Serialization/ASTReaderDecl.cpp
>>>   lib/Serialization/ASTWriterDecl.cpp
>>>   test/CodeGenCXX/nrvo.cpp
>>>
>>>
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>


More information about the cfe-commits mailing list