diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2014-05-03 00:41:18 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2014-05-03 00:41:18 +0000 |
commit | d78f92fbb26b388b30192dfa88fd614db35dbbad (patch) | |
tree | 3e07496fe683abf375a92778a2229b38ba7cfd55 /clang/lib/Sema/Scope.cpp | |
parent | e39ee215519e6189d56b345e21f2cee2ffeed3ab (diff) | |
download | bcm5719-llvm-d78f92fbb26b388b30192dfa88fd614db35dbbad.tar.gz bcm5719-llvm-d78f92fbb26b388b30192dfa88fd614db35dbbad.zip |
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.
llvm-svn: 207890
Diffstat (limited to 'clang/lib/Sema/Scope.cpp')
-rw-r--r-- | clang/lib/Sema/Scope.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/clang/lib/Sema/Scope.cpp b/clang/lib/Sema/Scope.cpp index 494768d66a6..8e339d705fb 100644 --- a/clang/lib/Sema/Scope.cpp +++ b/clang/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'; } |