[CodeGen] Move shouldEmitLifetimeMarkers into more convenient place

Summary: D24693 will need access to it from other places

Reviewers: eugenis

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D24695

llvm-svn: 285158
This commit is contained in:
Vitaly Buka 2016-10-26 01:59:57 +00:00
parent 8b6af7a9d3
commit 1c94332e7a
3 changed files with 31 additions and 28 deletions

View File

@ -885,29 +885,12 @@ void CodeGenFunction::EmitAutoVarDecl(const VarDecl &D) {
EmitAutoVarCleanups(emission); EmitAutoVarCleanups(emission);
} }
/// shouldEmitLifetimeMarkers - Decide whether we need emit the life-time
/// markers.
static bool shouldEmitLifetimeMarkers(const CodeGenOptions &CGOpts,
const LangOptions &LangOpts) {
// Asan uses markers for use-after-scope checks.
if (CGOpts.SanitizeAddressUseAfterScope)
return true;
// Disable lifetime markers in msan builds.
// FIXME: Remove this when msan works with lifetime markers.
if (LangOpts.Sanitize.has(SanitizerKind::Memory))
return false;
// For now, only in optimized builds.
return CGOpts.OptimizationLevel != 0;
}
/// Emit a lifetime.begin marker if some criteria are satisfied. /// Emit a lifetime.begin marker if some criteria are satisfied.
/// \return a pointer to the temporary size Value if a marker was emitted, null /// \return a pointer to the temporary size Value if a marker was emitted, null
/// otherwise /// otherwise
llvm::Value *CodeGenFunction::EmitLifetimeStart(uint64_t Size, llvm::Value *CodeGenFunction::EmitLifetimeStart(uint64_t Size,
llvm::Value *Addr) { llvm::Value *Addr) {
if (!shouldEmitLifetimeMarkers(CGM.getCodeGenOpts(), getLangOpts())) if (!ShouldEmitLifetimeMarkers)
return nullptr; return nullptr;
llvm::Value *SizeV = llvm::ConstantInt::get(Int64Ty, Size); llvm::Value *SizeV = llvm::ConstantInt::get(Int64Ty, Size);

View File

@ -38,20 +38,35 @@
using namespace clang; using namespace clang;
using namespace CodeGen; using namespace CodeGen;
/// shouldEmitLifetimeMarkers - Decide whether we need emit the life-time
/// markers.
static bool shouldEmitLifetimeMarkers(const CodeGenOptions &CGOpts,
const LangOptions &LangOpts) {
// Asan uses markers for use-after-scope checks.
if (CGOpts.SanitizeAddressUseAfterScope)
return true;
// Disable lifetime markers in msan builds.
// FIXME: Remove this when msan works with lifetime markers.
if (LangOpts.Sanitize.has(SanitizerKind::Memory))
return false;
// For now, only in optimized builds.
return CGOpts.OptimizationLevel != 0;
}
CodeGenFunction::CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext) CodeGenFunction::CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext)
: CodeGenTypeCache(cgm), CGM(cgm), Target(cgm.getTarget()), : CodeGenTypeCache(cgm), CGM(cgm), Target(cgm.getTarget()),
Builder(cgm, cgm.getModule().getContext(), llvm::ConstantFolder(), Builder(cgm, cgm.getModule().getContext(), llvm::ConstantFolder(),
CGBuilderInserterTy(this)), CGBuilderInserterTy(this)),
CurFn(nullptr), ReturnValue(Address::invalid()), CurFn(nullptr), ReturnValue(Address::invalid()),
CapturedStmtInfo(nullptr), CapturedStmtInfo(nullptr), SanOpts(CGM.getLangOpts().Sanitize),
SanOpts(CGM.getLangOpts().Sanitize), IsSanitizerScope(false), IsSanitizerScope(false), CurFuncIsThunk(false), AutoreleaseResult(false),
CurFuncIsThunk(false), AutoreleaseResult(false), SawAsmBlock(false), SawAsmBlock(false), IsOutlinedSEHHelper(false), BlockInfo(nullptr),
IsOutlinedSEHHelper(false), BlockPointer(nullptr), LambdaThisCaptureField(nullptr),
BlockInfo(nullptr), BlockPointer(nullptr), NormalCleanupDest(nullptr), NextCleanupDestIndex(1),
LambdaThisCaptureField(nullptr), NormalCleanupDest(nullptr), FirstBlockInfo(nullptr), EHResumeBlock(nullptr), ExceptionSlot(nullptr),
NextCleanupDestIndex(1), FirstBlockInfo(nullptr), EHResumeBlock(nullptr), EHSelectorSlot(nullptr), DebugInfo(CGM.getModuleDebugInfo()),
ExceptionSlot(nullptr), EHSelectorSlot(nullptr),
DebugInfo(CGM.getModuleDebugInfo()),
DisableDebugInfo(false), DidCallStackSave(false), IndirectBranch(nullptr), DisableDebugInfo(false), DidCallStackSave(false), IndirectBranch(nullptr),
PGO(cgm), SwitchInsn(nullptr), SwitchWeights(nullptr), PGO(cgm), SwitchInsn(nullptr), SwitchWeights(nullptr),
CaseRangeBlock(nullptr), UnreachableBlock(nullptr), NumReturnExprs(0), CaseRangeBlock(nullptr), UnreachableBlock(nullptr), NumReturnExprs(0),
@ -60,7 +75,9 @@ CodeGenFunction::CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext)
CXXStructorImplicitParamDecl(nullptr), CXXStructorImplicitParamDecl(nullptr),
CXXStructorImplicitParamValue(nullptr), OutermostConditional(nullptr), CXXStructorImplicitParamValue(nullptr), OutermostConditional(nullptr),
CurLexicalScope(nullptr), TerminateLandingPad(nullptr), CurLexicalScope(nullptr), TerminateLandingPad(nullptr),
TerminateHandler(nullptr), TrapBB(nullptr) { TerminateHandler(nullptr), TrapBB(nullptr),
ShouldEmitLifetimeMarkers(
shouldEmitLifetimeMarkers(CGM.getCodeGenOpts(), CGM.getLangOpts())) {
if (!suppressNewContext) if (!suppressNewContext)
CGM.getCXXABI().getMangleContext().startNewFunction(); CGM.getCXXABI().getMangleContext().startNewFunction();

View File

@ -1186,6 +1186,9 @@ private:
llvm::BasicBlock *TerminateHandler; llvm::BasicBlock *TerminateHandler;
llvm::BasicBlock *TrapBB; llvm::BasicBlock *TrapBB;
/// True if we need emit the life-time markers.
const bool ShouldEmitLifetimeMarkers;
/// Add a kernel metadata node to the named metadata node 'opencl.kernels'. /// Add a kernel metadata node to the named metadata node 'opencl.kernels'.
/// In the kernel metadata node, reference the kernel function and metadata /// In the kernel metadata node, reference the kernel function and metadata
/// nodes for its optional attribute qualifiers (OpenCL 1.1 6.7.2): /// nodes for its optional attribute qualifiers (OpenCL 1.1 6.7.2):