[PATCH] D47067: Update NRVO logic to support early return
Taiju Tsuiki via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri May 18 07:12:16 PDT 2018
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47067.147497.patch
Type: text/x-patch
Size: 9098 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180518/d74be3f9/attachment-0001.bin>
More information about the cfe-commits
mailing list