summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGStmt.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-05-15 06:46:45 +0000
committerDouglas Gregor <dgregor@apple.com>2010-05-15 06:46:45 +0000
commit290c93ec0dea0188c4478a3d73ff48ae5b693498 (patch)
treef30376d4018b61f86e7dde8bdfe167eb3876762f /clang/lib/CodeGen/CGStmt.cpp
parent84ce2908220832675999a0d5be9f9b914c26ea66 (diff)
downloadbcm5719-llvm-290c93ec0dea0188c4478a3d73ff48ae5b693498.tar.gz
bcm5719-llvm-290c93ec0dea0188c4478a3d73ff48ae5b693498.zip
Implement a simple form of the C++ named return value optimization for
return statements. We perform NRVO only when all of the return statements in the function return the same variable. Fixes some link failures in Boost.Interprocess (which is relying on NRVO), and probably improves performance for some C++ applications. llvm-svn: 103867
Diffstat (limited to 'clang/lib/CodeGen/CGStmt.cpp')
-rw-r--r--clang/lib/CodeGen/CGStmt.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 772f640ed01..f51a899e7ff 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -607,7 +607,12 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) {
// FIXME: Clean this up by using an LValue for ReturnTemp,
// EmitStoreThroughLValue, and EmitAnyExpr.
- if (!ReturnValue) {
+ if (S.getNRVOCandidate() && S.getNRVOCandidate()->isNRVOVariable() &&
+ !Target.useGlobalsForAutomaticVariables()) {
+ // Apply the named return value optimization for this return statement,
+ // which means doing nothing: the appropriate result has already been
+ // constructed into the NRVO variable.
+ } else if (!ReturnValue) {
// Make sure not to return anything, but evaluate the expression
// for side effects.
if (RV)
OpenPOWER on IntegriCloud