clang 8.0.0

Functions
CGDecl.cpp File Reference
`#include "CGBlocks.h"`
`#include "CGCXXABI.h"`
`#include "CGCleanup.h"`
`#include "CGDebugInfo.h"`
`#include "CGOpenCLRuntime.h"`
`#include "CGOpenMPRuntime.h"`
`#include "CodeGenFunction.h"`
`#include "CodeGenModule.h"`
`#include "ConstantEmitter.h"`
`#include "TargetInfo.h"`
`#include "clang/AST/ASTContext.h"`
`#include "clang/AST/CharUnits.h"`
`#include "clang/AST/Decl.h"`
`#include "clang/AST/DeclObjC.h"`
`#include "clang/AST/DeclOpenMP.h"`
`#include "clang/Basic/CodeGenOptions.h"`
`#include "clang/Basic/SourceManager.h"`
`#include "clang/Basic/TargetInfo.h"`
`#include "clang/CodeGen/CGFunctionInfo.h"`
`#include "llvm/Analysis/ValueTracking.h"`
`#include "llvm/IR/DataLayout.h"`
`#include "llvm/IR/GlobalVariable.h"`
`#include "llvm/IR/Intrinsics.h"`
`#include "llvm/IR/Type.h"`
Include dependency graph for CGDecl.cpp:

Go to the source code of this file.

## Functions
static std::string | getStaticDeclName (CodeGenModule &CGM, const VarDecl &D)
static bool | hasNontrivialDestruction (QualType T)
| hasNontrivialDestruction - Determine whether a type's destruction is non-trivial. More...
static void | EmitAutoVarWithLifetime (CodeGenFunction &CGF, const VarDecl &var, Address addr, Qualifiers::ObjCLifetime lifetime)
| EmitAutoVarWithLifetime - Does the setup required for an automatic variable with lifetime. More...
static bool | isAccessedBy (const VarDecl &var, const Stmt *s)
static bool | isAccessedBy (const ValueDecl *decl, const Expr *e)
static bool | tryEmitARCCopyWeakInit (CodeGenFunction &CGF, const LValue &destLV, const Expr *init)
static void | drillIntoBlockVariable (CodeGenFunction &CGF, LValue &lvalue, const VarDecl *var)
static bool | canEmitInitWithFewStoresAfterBZero (llvm::Constant *Init, unsigned &NumStores)
| Decide whether we can emit the non-zero parts of the specified initializer with equal or fewer than NumStores scalar stores. More...
static void | emitStoresForInitAfterBZero (CodeGenModule &CGM, llvm::Constant *Init, Address Loc, bool isVolatile, CGBuilderTy &Builder)
| For inits that canEmitInitWithFewStoresAfterBZero returned true for, emit the scalar stores that would be required. More...
static bool | shouldUseBZeroPlusStoresToInitialize (llvm::Constant *Init, uint64_t GlobalSize)
| Decide whether we should use bzero plus some stores to initialize a local variable instead of using a memcpy from a constant global. More...
static llvm::Value * | shouldUseMemSetToInitialize (llvm::Constant *Init, uint64_t GlobalSize)
| Decide whether we should use memset to initialize a local variable instead of using a memcpy from a constant global. More...
static llvm::Constant * | patternFor (CodeGenModule &CGM, llvm::Type *Ty)
static Address | createUnnamedGlobalFrom (CodeGenModule &CGM, const VarDecl &D, CGBuilderTy &Builder, llvm::Constant *Constant, CharUnits Align)
static void | emitStoresForConstant (CodeGenModule &CGM, const VarDecl &D, Address Loc, bool isVolatile, CGBuilderTy &Builder, llvm::Constant *constant)
static void | emitStoresForZeroInit (CodeGenModule &CGM, const VarDecl &D, Address Loc, bool isVolatile, CGBuilderTy &Builder)
static void | emitStoresForPatternInit (CodeGenModule &CGM, const VarDecl &D, Address Loc, bool isVolatile, CGBuilderTy &Builder)
static bool | containsUndef (llvm::Constant *constant)
static llvm::Constant * | replaceUndef (llvm::Constant *constant)
static bool | isCapturedBy (const VarDecl &Var, const Expr *E)
| Determines whether the given __block variable is potentially captured by the given expression. More...
static bool | isCapturedBy (const VarDecl &Var, const Stmt *S)
| Determines whether the given __block variable is potentially captured by the given statement. More...
static void | emitPartialArrayDestroy (CodeGenFunction &CGF, llvm::Value *begin, llvm::Value *end, QualType type, CharUnits elementAlign, CodeGenFunction::Destroyer *destroyer)
| Perform partial array destruction as if in an EH cleanup. More...

## Function Documentation

## ◆ canEmitInitWithFewStoresAfterBZero()

static bool canEmitInitWithFewStoresAfterBZero | ( | llvm::Constant * | Init,
|  | unsigned & | NumStores
| ) |  |
| static

Decide whether we can emit the non-zero parts of the specified initializer with equal or fewer than NumStores scalar stores.

Definition at line 859 of file CGDecl.cpp.

Referenced by shouldUseBZeroPlusStoresToInitialize().

## ◆ containsUndef()

static bool containsUndef | ( | llvm::Constant * | constant | ) |
| static

Definition at line 1162 of file CGDecl.cpp.

Referenced by replaceUndef().

## ◆ createUnnamedGlobalFrom()

static Address createUnnamedGlobalFrom | ( | CodeGenModule & | CGM,
|  | const VarDecl & | D,
|  | CGBuilderTy & | Builder,
|  | llvm::Constant * | Constant,
|  | CharUnits | Align
| ) |  |
| static

Definition at line 1051 of file CGDecl.cpp.

References clang::CodeGen::CGBuilderTy::CreateBitCast(), clang::CodeGen::CodeGenModule::getContext(), clang::CodeGen::CodeGenModule::getLLVMContext(), clang::CodeGen::CodeGenModule::getMangledName(), clang::CodeGen::CodeGenModule::getModule(), clang::NamedDecl::getName(), clang::Decl::getParentFunctionOrMethod(), clang::CharUnits::getQuantity(), clang::CodeGen::CodeGenModule::getStringLiteralAddressSpace(), clang::ASTContext::getTargetAddressSpace(), clang::CodeGen::Address::getType(), and clang::CodeGen::Type.

Referenced by clang::CodeGen::CodeGenFunction::EmitAutoVarInit(), and emitStoresForConstant().

## ◆ drillIntoBlockVariable()

static void drillIntoBlockVariable | ( | CodeGenFunction & | CGF,
|  | LValue & | lvalue,
|  | const VarDecl * | var
| ) |  |
| static

Definition at line 713 of file CGDecl.cpp.

References clang::CodeGen::CodeGenFunction::emitBlockByrefAddress(), clang::CodeGen::LValue::getAddress(), and clang::CodeGen::LValue::setAddress().

Referenced by clang::CodeGen::CodeGenFunction::EmitAutoVarInit(), clang::CodeGen::CodeGenFunction::EmitExprAsInit(), and clang::CodeGen::CodeGenFunction::EmitScalarInit().

## ◆ EmitAutoVarWithLifetime()

static void EmitAutoVarWithLifetime | ( | CodeGenFunction & | CGF,
|  | const VarDecl & | var,
|  | Address | addr,
|  | Qualifiers::ObjCLifetime | lifetime
| ) |  |
| static

EmitAutoVarWithLifetime - Does the setup required for an automatic variable with lifetime.

Definition at line 595 of file CGDecl.cpp.

References clang::CodeGen::CodeGenFunction::destroyARCStrongImprecise, clang::CodeGen::CodeGenFunction::destroyARCStrongPrecise, clang::CodeGen::CodeGenFunction::destroyARCWeak, clang::CodeGen::EHCleanup, clang::CodeGen::CodeGenFunction::getARCCleanupKind(), clang::ValueDecl::getType(), clang::Decl::hasAttr(), clang::CodeGen::NormalAndEHCleanup, clang::Qualifiers::OCL_Autoreleasing, clang::Qualifiers::OCL_ExplicitNone, clang::Qualifiers::OCL_None, clang::Qualifiers::OCL_Strong, clang::Qualifiers::OCL_Weak, and clang::CodeGen::CodeGenFunction::pushDestroy().

Referenced by clang::CodeGen::CodeGenFunction::EmitParmDecl().

## ◆ emitPartialArrayDestroy()

static void emitPartialArrayDestroy | ( | CodeGenFunction & | CGF,
|  | llvm::Value * | begin,
|  | llvm::Value * | end,
|  | QualType | type,
|  | CharUnits | elementAlign,
|  | CodeGenFunction::Destroyer * | destroyer
| ) |  |
| static

Perform partial array destruction as if in an EH cleanup.

Unlike emitArrayDestroy, the element type here may still be an array type.

Definition at line 2088 of file CGDecl.cpp.

References clang::ast_matchers::arrayType, clang::CodeGen::CodeGenFunction::Builder, clang::CodeGen::CGBuilderTy::CreateLoad(), clang::CodeGen::CodeGenFunction::emitArrayDestroy(), clang::ASTContext::getAsArrayType(), clang::CodeGen::CodeGenFunction::getContext(), and clang::CodeGen::CodeGenTypeCache::SizeTy.

## ◆ emitStoresForConstant()

static void emitStoresForConstant | ( | CodeGenModule & | CGM,
|  | const VarDecl & | D,
|  | Address | Loc,
|  | bool | isVolatile,
|  | CGBuilderTy & | Builder,
|  | llvm::Constant * | constant
| ) |  |
| static

Definition at line 1094 of file CGDecl.cpp.

References clang::CodeGen::CGBuilderTy::CreateBitCast(), clang::CodeGen::CGBuilderTy::CreateMemCpy(), clang::CodeGen::CGBuilderTy::CreateMemSet(), clang::CodeGen::CGBuilderTy::CreateStore(), createUnnamedGlobalFrom(), emitStoresForInitAfterBZero(), clang::CodeGen::Address::getAddressSpace(), clang::CodeGen::Address::getAlignment(), clang::CodeGen::CodeGenModule::getDataLayout(), clang::CodeGen::CodeGenModule::getLLVMContext(), getValue(), clang::CodeGen::CodeGenTypeCache::Int8Ty, clang::CodeGen::CodeGenTypeCache::IntPtrTy, shouldUseBZeroPlusStoresToInitialize(), and shouldUseMemSetToInitialize().

Referenced by emitStoresForPatternInit(), and emitStoresForZeroInit().

## ◆ emitStoresForInitAfterBZero()

static void emitStoresForInitAfterBZero | ( | CodeGenModule & | CGM,
|  | llvm::Constant * | Init,
|  | Address | Loc,
|  | bool | isVolatile,
|  | CGBuilderTy & | Builder
| ) |  |
| static

For inits that canEmitInitWithFewStoresAfterBZero returned true for, emit the scalar stores that would be required.

Definition at line 897 of file CGDecl.cpp.

References clang::CodeGen::CGBuilderTy::CreateConstInBoundsGEP2_32(), clang::CodeGen::CGBuilderTy::CreateStore(), and clang::CodeGen::CodeGenModule::getDataLayout().

Referenced by emitStoresForConstant().

## ◆ emitStoresForPatternInit()

static void emitStoresForPatternInit | ( | CodeGenModule & | CGM,
|  | const VarDecl & | D,
|  | Address | Loc,
|  | bool | isVolatile,
|  | CGBuilderTy & | Builder
| ) |  |
| static

Definition at line 1153 of file CGDecl.cpp.

References emitStoresForConstant(), clang::CodeGen::Address::getElementType(), patternFor(), and clang::CodeGen::Type.

Referenced by clang::CodeGen::CodeGenFunction::EmitAutoVarInit().

## ◆ emitStoresForZeroInit()

static void emitStoresForZeroInit | ( | CodeGenModule & | CGM,
|  | const VarDecl & | D,
|  | Address | Loc,
|  | bool | isVolatile,
|  | CGBuilderTy & | Builder
| ) |  |
| static

Definition at line 1145 of file CGDecl.cpp.

References emitStoresForConstant(), clang::CodeGen::Address::getElementType(), and clang::CodeGen::Type.

Referenced by clang::CodeGen::CodeGenFunction::EmitAutoVarInit().

## ◆ getStaticDeclName()

static std::string getStaticDeclName | ( | CodeGenModule & | CGM,
|  | const VarDecl & | D
| ) |  |
| static

Definition at line 188 of file CGDecl.cpp.

References clang::CodeGen::CodeGenModule::getBlockMangledName(), clang::Decl::getDeclContext(), clang::CodeGen::CodeGenModule::getLangOpts(), clang::CodeGen::CodeGenModule::getMangledName(), clang::NamedDecl::getNameAsString(), and clang::NamedDecl::isExternallyVisible().

## ◆ hasNontrivialDestruction()

static bool hasNontrivialDestruction | ( | QualType | T | ) |
| static

hasNontrivialDestruction - Determine whether a type's destruction is non-trivial.

If so, and the variable uses static initialization, we must register its destructor to run on exit.

Definition at line 304 of file CGDecl.cpp.

References clang::Type::getAsCXXRecordDecl(), clang::Type::getBaseElementTypeUnsafe(), and clang::CXXRecordDecl::hasTrivialDestructor().

Referenced by clang::CodeGen::CodeGenFunction::AddInitializerToStaticVarDecl().

## ◆ isAccessedBy() [1/2]

static bool isAccessedBy | ( | const VarDecl & | var,
|  | const Stmt * | s
| ) |  |
| static

Definition at line 631 of file CGDecl.cpp.

References clang::BlockDecl::captures(), and clang::Stmt::children().

Referenced by clang::CodeGen::CodeGenFunction::EmitScalarInit(), and isAccessedBy().

## ◆ isAccessedBy() [2/2]

static bool isAccessedBy | ( | const ValueDecl * | decl,
|  | const Expr * | e
| ) |  |
| static

Definition at line 656 of file CGDecl.cpp.

References clang::ast_matchers::decl, and isAccessedBy().

## ◆ isCapturedBy() [1/2]

static bool isCapturedBy | ( | const VarDecl & | Var,
|  | const Expr * | E
| ) |  |
| static

Determines whether the given __block variable is potentially captured by the given expression.

Definition at line 1515 of file CGDecl.cpp.

References clang::CompoundStmt::body(), clang::BlockDecl::captures(), clang::Stmt::children(), and clang::Expr::IgnoreParenCasts().

Referenced by clang::CodeGen::CodeGenFunction::EmitAutoVarInit().

## ◆ isCapturedBy() [2/2]

static bool isCapturedBy | ( | const VarDecl & | Var,
|  | const Stmt * | S
| ) |  |
| static

Determines whether the given __block variable is potentially captured by the given statement.

Definition at line 1504 of file CGDecl.cpp.

## ◆ patternFor()

static llvm::Constant* patternFor | ( | CodeGenModule & | CGM,
|  | llvm::Type * | Ty
| ) |  |
| static

Definition at line 972 of file CGDecl.cpp.

References clang::CodeGen::CodeGenModule::getContext(), clang::CodeGen::CodeGenModule::getLLVMContext(), clang::TargetInfo::getPointerWidth(), clang::ASTContext::getTargetInfo(), clang::CodeGen::CodeGenTypeCache::IntTy, and clang::CodeGen::Type.

Referenced by clang::CodeGen::CodeGenFunction::EmitAutoVarInit(), and emitStoresForPatternInit().

## ◆ replaceUndef()

static llvm::Constant* replaceUndef | ( | llvm::Constant * | constant | ) |
| static

Definition at line 1173 of file CGDecl.cpp.

References containsUndef().

## ◆ shouldUseBZeroPlusStoresToInitialize()

static bool shouldUseBZeroPlusStoresToInitialize | ( | llvm::Constant * | Init,
|  | uint64_t | GlobalSize
| ) |  |
| static

Decide whether we should use bzero plus some stores to initialize a local variable instead of using a memcpy from a constant global.

It is beneficial to use bzero if the global is all zeros, or mostly zeros and large.

Definition at line 943 of file CGDecl.cpp.

References canEmitInitWithFewStoresAfterBZero().

Referenced by emitStoresForConstant().

## ◆ shouldUseMemSetToInitialize()

static llvm::Value* shouldUseMemSetToInitialize | ( | llvm::Constant * | Init,
|  | uint64_t | GlobalSize
| ) |  |
| static

Decide whether we should use memset to initialize a local variable instead of using a memcpy from a constant global.

Assumes we've already decided to not user bzero. FIXME We could be more clever, as we are for bzero above, and generate memset followed by stores. It's unclear that's worth the effort.

Definition at line 964 of file CGDecl.cpp.

Referenced by emitStoresForConstant().

## ◆ tryEmitARCCopyWeakInit()

static bool tryEmitARCCopyWeakInit | ( | CodeGenFunction & | CGF,
|  | const LValue & | destLV,
|  | const Expr * | init
| ) |  |
| static

Definition at line 663 of file CGDecl.cpp.

References clang::CodeGen::CodeGenFunction::Builder, clang::ast_matchers::castExpr, clang::CodeGen::CGBuilderTy::CreateElementBitCast(), clang::CodeGen::CodeGenFunction::EmitARCCopyWeak(), clang::CodeGen::CodeGenFunction::EmitARCMoveWeak(), clang::CodeGen::CodeGenFunction::EmitLValue(), clang::CodeGen::LValue::getAddress(), clang::CodeGen::Address::getElementType(), clang::QualType::getObjCLifetime(), clang::Expr::getType(), clang::Expr::getValueKind(), clang::Expr::IgnoreParens(), clang::Qualifiers::OCL_Weak, clang::VK_LValue, and clang::VK_XValue.

Referenced by clang::CodeGen::CodeGenFunction::EmitScalarInit().