diff options
author | Arnaud A. de Grandmaison <arnaud.degrandmaison@arm.com> | 2014-07-18 13:36:33 +0000 |
---|---|---|
committer | Arnaud A. de Grandmaison <arnaud.degrandmaison@arm.com> | 2014-07-18 13:36:33 +0000 |
commit | 1be89f4977724896289e6d706690ada275e9f451 (patch) | |
tree | a73ba745d323d0a58e41f059a8c39a49cea620d5 /clang/lib/CodeGen/CGExpr.cpp | |
parent | f8bfe21fad8f4c1ca41e583ef6fd7aae5b17e95e (diff) | |
download | bcm5719-llvm-1be89f4977724896289e6d706690ada275e9f451.tar.gz bcm5719-llvm-1be89f4977724896289e6d706690ada275e9f451.zip |
Emit lifetime.start / lifetime.end markers for unnamed temporary objects.
This will give more information to the optimizers so that they can reuse stack slots.
llvm-svn: 213379
Diffstat (limited to 'clang/lib/CodeGen/CGExpr.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 63731b7b7d0..1cb43ef6595 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -353,6 +353,17 @@ LValue CodeGenFunction::EmitMaterializeTemporaryExpr( // Create and initialize the reference temporary. llvm::Value *Object = createReferenceTemporary(*this, M, E); + + uint64_t size = + CGM.getDataLayout().getTypeStoreSize(ConvertTypeForMem(E->getType())); + llvm::Value *sizeV = nullptr; + llvm::AllocaInst *Alloca = dyn_cast<llvm::AllocaInst>(Object); + bool useLifetimeMarkers = Alloca && shouldUseLifetimeMarkers(size); + if (useLifetimeMarkers) { + sizeV = llvm::ConstantInt::get(Int64Ty, size); + EmitLifetimeStart(sizeV, Object); + } + if (auto *Var = dyn_cast<llvm::GlobalVariable>(Object)) { // If the temporary is a global and has a constant initializer, we may // have already initialized it. @@ -363,6 +374,10 @@ LValue CodeGenFunction::EmitMaterializeTemporaryExpr( } else { EmitAnyExprToMem(E, Object, Qualifiers(), /*IsInit*/true); } + + if (useLifetimeMarkers) + EHStack.pushCleanup<CallLifetimeEnd>(NormalAndEHCleanup, Object, sizeV); + pushTemporaryCleanup(*this, M, E, Object); // Perform derived-to-base casts and/or field accesses, to get from the |