diff options
author | Taiju Tsuiki <tzik@google.com> | 2018-05-30 03:53:16 +0000 |
---|---|---|
committer | Taiju Tsuiki <tzik@google.com> | 2018-05-30 03:53:16 +0000 |
commit | 44f9c585b94ed9f15bd64f6c2fc32bbd397ff4af (patch) | |
tree | d837c1d976e080268135c1304ca5985510362ee0 /llvm/lib/Support/SmallVector.cpp | |
parent | e9ce661e3294dd5581d0d124e69d191112e24776 (diff) | |
download | bcm5719-llvm-44f9c585b94ed9f15bd64f6c2fc32bbd397ff4af.tar.gz bcm5719-llvm-44f9c585b94ed9f15bd64f6c2fc32bbd397ff4af.zip |
Update NRVO logic to support early return
Summary:
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 local variable if:
* It's directly returned by at least one return statement.
* And, all reachable return statements in its scope returns the variable directly.
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.
Reviewers: rsmith
Reviewed By: rsmith
Subscribers: xbolva00, Quuxplusone, arthur.j.odwyer, cfe-commits
Differential Revision: https://reviews.llvm.org/D47067
llvm-svn: 333500
Diffstat (limited to 'llvm/lib/Support/SmallVector.cpp')
0 files changed, 0 insertions, 0 deletions