summaryrefslogtreecommitdiffstats
path: root/lib/Sema/Scope.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2014-05-03 00:41:18 +0000
committerNick Lewycky <nicholas@mxc.ca>2014-05-03 00:41:18 +0000
commit130d63a029bc588cb61a6aaea2db6b9ed4c5cc56 (patch)
tree82f6cce36e08f27042b659e45b9fd5aa93419be3 /lib/Sema/Scope.cpp
parent3753e68d0a785dc92ee7317585d521e502f65a95 (diff)
Rewrite NRVO determination. Track NRVO candidates on the parser Scope and apply the NRVO candidate flag to all possible NRVO candidates here, and remove the flags in computeNRVO or upon template instantiation. A variable now has NRVO applied if and only if every return statement in that scope returns that variable. This is nearly optimal.
Performs NRVO roughly 7% more often in a bootstrap build of clang. Patch co-authored by Richard Smith. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207890 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/Scope.cpp')
-rw-r--r--lib/Sema/Scope.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/Sema/Scope.cpp b/lib/Sema/Scope.cpp
index 494768d66a..8e339d705f 100644
--- a/lib/Sema/Scope.cpp
+++ b/lib/Sema/Scope.cpp
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "clang/Sema/Scope.h"
+#include "clang/AST/Decl.h"
#include "llvm/Support/raw_ostream.h"
using namespace clang;
@@ -77,6 +78,7 @@ void Scope::Init(Scope *parent, unsigned flags) {
UsingDirectives.clear();
Entity = 0;
ErrorTrap.reset();
+ NRVO.setPointerAndInt(nullptr, 0);
}
bool Scope::containedInPrototypeScope() const {
@@ -103,6 +105,21 @@ void Scope::AddFlags(unsigned FlagsToSet) {
Flags |= FlagsToSet;
}
+void Scope::mergeNRVOIntoParent() {
+ if (VarDecl *Candidate = NRVO.getPointer()) {
+ if (isDeclScope(Candidate))
+ Candidate->setNRVOVariable(true);
+ }
+
+ if (getEntity())
+ return;
+
+ if (NRVO.getInt())
+ getParent()->setNoNRVO();
+ else if (NRVO.getPointer())
+ getParent()->addNRVOCandidate(NRVO.getPointer());
+}
+
void Scope::dump() const { dumpImpl(llvm::errs()); }
void Scope::dumpImpl(raw_ostream &OS) const {
@@ -176,4 +193,9 @@ void Scope::dumpImpl(raw_ostream &OS) const {
OS << "MSLocalManglingNumber: " << getMSLocalManglingNumber() << '\n';
if (const DeclContext *DC = getEntity())
OS << "Entity : (clang::DeclContext*)" << DC << '\n';
+
+ if (NRVO.getInt())
+ OS << "NRVO not allowed";
+ else if (NRVO.getPointer())
+ OS << "NRVO candidate : (clang::VarDecl*)" << NRVO.getPointer() << '\n';
}