clang 22.0.0git
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 "CodeGenPGO.h"
#include "ConstantEmitter.h"
#include "EHScopeStack.h"
#include "PatternInit.h"
#include "TargetInfo.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Attr.h"
#include "clang/AST/CharUnits.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclOpenACC.h"
#include "clang/AST/DeclOpenMP.h"
#include "clang/Basic/CodeGenOptions.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/CodeGen/CGFunctionInfo.h"
#include "clang/Sema/Sema.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Type.h"
#include <optional>

Go to the source code of this file.

Enumerations

enum class  IsPattern { No , Yes }

Functions

static std::string getStaticDeclName (CodeGenModule &CGM, const VarDecl &D)
static void EmitAutoVarWithLifetime (CodeGenFunction &CGF, const VarDecl &var, Address addr, Qualifiers::ObjCLifetime lifetime)
 EmitAutoVarWithLifetime - Does the setup required for an automatic variable with lifetime.
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.
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.
static llvm::ValueshouldUseMemSetToInitialize (llvm::Constant *Init, uint64_t GlobalSize, const llvm::DataLayout &DL)
 Decide whether we should use memset to initialize a local variable instead of using a memcpy from a constant global.
static bool shouldSplitConstantStore (CodeGenModule &CGM, uint64_t GlobalByteSize)
 Decide whether we want to split a constant structure or array store into a sequence of its fields' stores.
static llvm::Constant * patternOrZeroFor (CodeGenModule &CGM, IsPattern isPattern, llvm::Type *Ty)
 Generate a constant filled with either a pattern or zeroes.
static llvm::Constant * constWithPadding (CodeGenModule &CGM, IsPattern isPattern, llvm::Constant *constant)
 Replace all padding bytes in a given constant with either a pattern byte or 0x00.
static llvm::Constant * constStructWithPadding (CodeGenModule &CGM, IsPattern isPattern, llvm::StructType *STy, llvm::Constant *constant)
 Helper function for constWithPadding() to deal with padding in structures.
static Address createUnnamedGlobalForMemcpyFrom (CodeGenModule &CGM, const VarDecl &D, CGBuilderTy &Builder, llvm::Constant *Constant, CharUnits Align)
static bool containsUndef (llvm::Constant *constant)
static llvm::Constant * replaceUndef (CodeGenModule &CGM, IsPattern isPattern, llvm::Constant *constant)
static uint64_t maxFakeUseAggregateSize (const ASTContext &C)
 Return the maximum size of an aggregate for which we generate a fake use intrinsic when -fextend-variable-liveness is in effect.
static bool shouldExtendLifetime (const ASTContext &Context, const Decl *FuncDecl, const VarDecl &D, ImplicitParamDecl *CXXABIThisDecl)
static bool isCapturedBy (const VarDecl &Var, const Expr *E)
 Determines whether the given __block variable is potentially captured by the given expression.
static bool isCapturedBy (const VarDecl &Var, const Stmt *S)
 Determines whether the given __block variable is potentially captured by the given statement.
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.

Enumeration Type Documentation

◆ IsPattern

enum class IsPattern
strong
Enumerator
No 
Yes 

Definition at line 1039 of file CGDecl.cpp.

Function Documentation

◆ canEmitInitWithFewStoresAfterBZero()

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 910 of file CGDecl.cpp.

References canEmitInitWithFewStoresAfterBZero(), clang::cast(), clang::Init, and clang::isa().

Referenced by canEmitInitWithFewStoresAfterBZero(), and shouldUseBZeroPlusStoresToInitialize().

◆ constStructWithPadding()

llvm::Constant * constStructWithPadding ( CodeGenModule & CGM,
IsPattern isPattern,
llvm::StructType * STy,
llvm::Constant * constant )
static

Helper function for constWithPadding() to deal with padding in structures.

Definition at line 1054 of file CGDecl.cpp.

References clang::cast(), constWithPadding(), clang::CodeGen::CodeGenModule::getDataLayout(), clang::CodeGen::CodeGenModule::getLLVMContext(), and patternOrZeroFor().

Referenced by constWithPadding().

◆ constWithPadding()

llvm::Constant * constWithPadding ( CodeGenModule & CGM,
IsPattern isPattern,
llvm::Constant * constant )
static

Replace all padding bytes in a given constant with either a pattern byte or 0x00.

Definition at line 1094 of file CGDecl.cpp.

References constStructWithPadding(), and constWithPadding().

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

◆ containsUndef()

bool containsUndef ( llvm::Constant * constant)
static

Definition at line 1313 of file CGDecl.cpp.

References clang::cast(), containsUndef(), and clang::isa().

Referenced by containsUndef(), and replaceUndef().

◆ createUnnamedGlobalForMemcpyFrom()

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

◆ drillIntoBlockVariable()

◆ EmitAutoVarWithLifetime()

◆ emitPartialArrayDestroy()

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

◆ getStaticDeclName()

◆ isAccessedBy() [1/2]

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

Definition at line 702 of file CGDecl.cpp.

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

◆ isAccessedBy() [2/2]

◆ isCapturedBy() [1/2]

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 1759 of file CGDecl.cpp.

References clang::Block, clang::CompoundStmt::body(), clang::Stmt::children(), clang::Expr::IgnoreParenCasts(), clang::Init, and isCapturedBy().

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

◆ isCapturedBy() [2/2]

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 1748 of file CGDecl.cpp.

References clang::Stmt::children(), and isCapturedBy().

◆ maxFakeUseAggregateSize()

uint64_t maxFakeUseAggregateSize ( const ASTContext & C)
static

Return the maximum size of an aggregate for which we generate a fake use intrinsic when -fextend-variable-liveness is in effect.

Definition at line 1449 of file CGDecl.cpp.

References clang::C.

Referenced by shouldExtendLifetime().

◆ patternOrZeroFor()

llvm::Constant * patternOrZeroFor ( CodeGenModule & CGM,
IsPattern isPattern,
llvm::Type * Ty )
static

Generate a constant filled with either a pattern or zeroes.

Definition at line 1042 of file CGDecl.cpp.

References clang::CodeGen::initializationPatternFor(), and Yes.

Referenced by constStructWithPadding(), and replaceUndef().

◆ replaceUndef()

llvm::Constant * replaceUndef ( CodeGenModule & CGM,
IsPattern isPattern,
llvm::Constant * constant )
static

◆ shouldExtendLifetime()

◆ shouldSplitConstantStore()

bool shouldSplitConstantStore ( CodeGenModule & CGM,
uint64_t GlobalByteSize )
static

Decide whether we want to split a constant structure or array store into a sequence of its fields' stores.

This may cost us code size and compilation speed, but plays better with store optimizations.

Definition at line 1028 of file CGDecl.cpp.

References clang::CodeGen::CodeGenModule::getCodeGenOpts().

◆ shouldUseBZeroPlusStoresToInitialize()

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 995 of file CGDecl.cpp.

References canEmitInitWithFewStoresAfterBZero(), clang::Init, and clang::isa().

◆ shouldUseMemSetToInitialize()

llvm::Value * shouldUseMemSetToInitialize ( llvm::Constant * Init,
uint64_t GlobalSize,
const llvm::DataLayout & DL )
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 1016 of file CGDecl.cpp.

References clang::Init.

◆ tryEmitARCCopyWeakInit()