Revert "Remove threshold on object size for inserting lifetime begin / end"
Revert this patch while I investigate some sanitizer failures off-line.
llvm-svn: 219307
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index f943faf..24575ce 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -825,6 +825,19 @@
canEmitInitWithFewStoresAfterMemset(Init, StoreBudget);
}
+/// Should we use the LLVM lifetime intrinsics for the given local variable?
+static bool shouldUseLifetimeMarkers(CodeGenFunction &CGF, uint64_t Size) {
+ // For now, only in optimized builds.
+ if (CGF.CGM.getCodeGenOpts().OptimizationLevel == 0)
+ return false;
+
+ // Limit the size of marked objects to 32 bytes. We don't want to increase
+ // compile time by marking tiny objects.
+ unsigned SizeThreshold = 32;
+
+ return Size > SizeThreshold;
+}
+
/// EmitAutoVarDecl - Emit code and set up an entry in LocalDeclMap for a
/// variable declaration with auto, register, or no storage class specifier.
/// These turn into simple stack objects, or GlobalValues depending on target.
@@ -839,12 +852,7 @@
/// otherwise
llvm::Value *CodeGenFunction::EmitLifetimeStart(uint64_t Size,
llvm::Value *Addr) {
- // For now, only use the markers in optimized builds
- if (CGM.getCodeGenOpts().OptimizationLevel == 0)
- return nullptr;
-
- // Zero-sized objects do not need lifetime markers
- if (Size == 0)
+ if (!shouldUseLifetimeMarkers(*this, Size))
return nullptr;
llvm::Value *SizeV = llvm::ConstantInt::get(Int64Ty, Size);
@@ -955,10 +963,11 @@
// Emit a lifetime intrinsic if meaningful. There's no point
// in doing this if we don't have a valid insertion point (?).
uint64_t size = CGM.getDataLayout().getTypeAllocSize(LTy);
- if (HaveInsertPoint())
- emission.SizeForLifetimeMarkers = EmitLifetimeStart(size, Alloc);
- else
+ if (HaveInsertPoint() && EmitLifetimeStart(size, Alloc)) {
+ emission.SizeForLifetimeMarkers = llvm::ConstantInt::get(Int64Ty, size);
+ } else {
assert(!emission.useLifetimeMarkers());
+ }
}
} else {
EnsureInsertPoint();