21 #include "llvm/IR/Constants.h" 22 #include "llvm/IR/Function.h" 23 #include "llvm/IR/GlobalVariable.h" 24 #include "llvm/IR/Intrinsics.h" 25 using namespace clang;
26 using namespace CodeGen;
33 class AggExprEmitter :
public StmtVisitor<AggExprEmitter> {
44 bool shouldUseDestForReturnSlot()
const {
49 if (!shouldUseDestForReturnSlot())
67 : CGF(cgf), Builder(CGF.Builder), Dest(Dest),
68 IsResultUnused(IsResultUnused) { }
77 void EmitAggLoadOfLValue(
const Expr *E);
85 void EmitMoveFromReturnSlot(
const Expr *E,
RValue Src);
87 void EmitArrayInit(
Address DestPtr, llvm::ArrayType *AType,
91 if (CGF.
getLangOpts().getGC() && TypeRequiresGCollection(T))
96 bool TypeRequiresGCollection(
QualType T);
102 void Visit(
Expr *E) {
107 void VisitStmt(
Stmt *S) {
127 void VisitDeclRefExpr(
DeclRefExpr *E) { EmitAggLoadOfLValue(E); }
128 void VisitMemberExpr(
MemberExpr *ME) { EmitAggLoadOfLValue(ME); }
129 void VisitUnaryDeref(
UnaryOperator *E) { EmitAggLoadOfLValue(E); }
130 void VisitStringLiteral(
StringLiteral *E) { EmitAggLoadOfLValue(E); }
133 EmitAggLoadOfLValue(E);
136 EmitAggLoadOfLValue(E);
141 void VisitCallExpr(
const CallExpr *E);
142 void VisitStmtExpr(
const StmtExpr *E);
144 void VisitPointerToDataMemberBinaryOperator(
const BinaryOperator *BO);
150 EmitAggLoadOfLValue(E);
175 void VisitCXXTypeidExpr(
CXXTypeidExpr *E) { EmitAggLoadOfLValue(E); }
182 return EmitFinalDestCopy(E->
getType(), LV);
196 EmitFinalDestCopy(E->
getType(), Res);
208 void AggExprEmitter::EmitAggLoadOfLValue(
const Expr *E) {
217 EmitFinalDestCopy(E->
getType(), LV);
221 bool AggExprEmitter::TypeRequiresGCollection(
QualType T) {
224 if (!RecordTy)
return false;
228 if (isa<CXXRecordDecl>(Record) &&
229 (cast<CXXRecordDecl>(Record)->hasNonTrivialCopyConstructor() ||
230 !cast<CXXRecordDecl>(Record)->hasTrivialDestructor()))
247 void AggExprEmitter::EmitMoveFromReturnSlot(
const Expr *E,
RValue src) {
248 if (shouldUseDestForReturnSlot()) {
257 EmitFinalDestCopy(E->
getType(), src);
262 assert(src.
isAggregate() &&
"value must be aggregate value!");
264 EmitFinalDestCopy(type, srcLV);
268 void AggExprEmitter::EmitFinalDestCopy(
QualType type,
const LValue &src) {
279 EmitCopy(type, Dest, srcAgg);
313 assert(Array.
isSimple() &&
"initializer_list array not a simple lvalue");
318 assert(ArrayType &&
"std::initializer_list constructed from non-array");
329 if (!Field->getType()->isPointerType() ||
330 !Ctx.
hasSameType(Field->getType()->getPointeeType(),
342 Builder.CreateInBoundsGEP(ArrayPtr.getPointer(), IdxStart,
"arraystart");
353 if (Field->getType()->isPointerType() &&
354 Ctx.
hasSameType(Field->getType()->getPointeeType(),
359 Builder.CreateInBoundsGEP(ArrayPtr.getPointer(), IdxEnd,
"arrayend");
376 if (isa<ImplicitValueInitExpr>(E))
379 if (
auto *ILE = dyn_cast<InitListExpr>(E)) {
380 if (ILE->getNumInits())
385 if (
auto *Cons = dyn_cast_or_null<CXXConstructExpr>(E))
386 return Cons->getConstructor()->isDefaultConstructor() &&
387 Cons->getConstructor()->isTrivial();
394 void AggExprEmitter::EmitArrayInit(
Address DestPtr, llvm::ArrayType *AType,
398 uint64_t NumArrayElements = AType->getNumElements();
399 assert(NumInitElements <= NumArrayElements);
406 Builder.CreateInBoundsGEP(DestPtr.
getPointer(), indices,
"arrayinit.begin");
418 llvm::Instruction *cleanupDominator =
nullptr;
425 "arrayinit.endOfInit");
426 cleanupDominator = Builder.
CreateStore(begin, endOfInit);
447 for (uint64_t i = 0; i != NumInitElements; ++i) {
450 element = Builder.CreateInBoundsGEP(element, one,
"arrayinit.element");
460 EmitInitializationToLValue(E->
getInit(i), elementLV);
470 if (NumInitElements != NumArrayElements &&
471 !(Dest.
isZeroed() && hasTrivialFiller &&
478 if (NumInitElements) {
479 element = Builder.CreateInBoundsGEP(element, one,
"arrayinit.start");
484 llvm::Value *end = Builder.CreateInBoundsGEP(begin,
485 llvm::ConstantInt::get(CGF.
SizeTy, NumArrayElements),
488 llvm::BasicBlock *entryBB = Builder.GetInsertBlock();
493 llvm::PHINode *currentElement =
494 Builder.CreatePHI(element->getType(), 2,
"arrayinit.cur");
495 currentElement->addIncoming(element, entryBB);
508 EmitInitializationToLValue(filler, elementLV);
510 EmitNullInitializationToLValue(elementLV);
515 Builder.CreateInBoundsGEP(currentElement, one,
"arrayinit.next");
521 llvm::Value *done = Builder.CreateICmpEQ(nextElement, end,
524 Builder.CreateCondBr(done, endBB, bodyBB);
525 currentElement->addIncoming(nextElement, Builder.GetInsertBlock());
552 EmitAggLoadOfLValue(E);
565 if (
CastExpr *castE = dyn_cast<CastExpr>(op)) {
566 if (castE->getCastKind() ==
kind)
567 return castE->getSubExpr();
568 if (castE->getCastKind() == CK_NoOp)
575 void AggExprEmitter::VisitCastExpr(
CastExpr *E) {
576 if (
const auto *ECE = dyn_cast<ExplicitCastExpr>(E))
581 assert(isa<CXXDynamicCastExpr>(E) &&
"CK_Dynamic without a dynamic_cast?");
612 case CK_DerivedToBase:
613 case CK_BaseToDerived:
614 case CK_UncheckedDerivedToBase: {
615 llvm_unreachable(
"cannot perform hierarchy conversion in EmitAggExpr: " 616 "should have been unpacked before we got here");
619 case CK_NonAtomicToAtomic:
620 case CK_AtomicToNonAtomic: {
621 bool isToAtomic = (E->
getCastKind() == CK_NonAtomicToAtomic);
626 if (isToAtomic) std::swap(atomicType, valueType);
639 (isToAtomic ? CK_AtomicToNonAtomic : CK_NonAtomicToAtomic);
645 "peephole significantly changed types?");
684 return EmitFinalDestCopy(valueType, rvalue);
687 case CK_LValueToRValue:
698 case CK_UserDefinedConversion:
699 case CK_ConstructorConversion:
702 "Implicit cast types must be compatible");
706 case CK_LValueBitCast:
707 llvm_unreachable(
"should not be emitting lvalue bitcast as rvalue");
711 case CK_ArrayToPointerDecay:
712 case CK_FunctionToPointerDecay:
713 case CK_NullToPointer:
714 case CK_NullToMemberPointer:
715 case CK_BaseToDerivedMemberPointer:
716 case CK_DerivedToBaseMemberPointer:
717 case CK_MemberPointerToBoolean:
718 case CK_ReinterpretMemberPointer:
719 case CK_IntegralToPointer:
720 case CK_PointerToIntegral:
721 case CK_PointerToBoolean:
724 case CK_IntegralCast:
725 case CK_BooleanToSignedIntegral:
726 case CK_IntegralToBoolean:
727 case CK_IntegralToFloating:
728 case CK_FloatingToIntegral:
729 case CK_FloatingToBoolean:
730 case CK_FloatingCast:
731 case CK_CPointerToObjCPointerCast:
732 case CK_BlockPointerToObjCPointerCast:
733 case CK_AnyPointerToBlockPointerCast:
734 case CK_ObjCObjectLValueCast:
735 case CK_FloatingRealToComplex:
736 case CK_FloatingComplexToReal:
737 case CK_FloatingComplexToBoolean:
738 case CK_FloatingComplexCast:
739 case CK_FloatingComplexToIntegralComplex:
740 case CK_IntegralRealToComplex:
741 case CK_IntegralComplexToReal:
742 case CK_IntegralComplexToBoolean:
743 case CK_IntegralComplexCast:
744 case CK_IntegralComplexToFloatingComplex:
745 case CK_ARCProduceObject:
746 case CK_ARCConsumeObject:
747 case CK_ARCReclaimReturnedObject:
748 case CK_ARCExtendBlockObject:
749 case CK_CopyAndAutoreleaseBlockObject:
750 case CK_BuiltinFnToFnPtr:
751 case CK_ZeroToOCLEvent:
752 case CK_ZeroToOCLQueue:
753 case CK_AddressSpaceConversion:
754 case CK_IntToOCLSampler:
755 llvm_unreachable(
"cast kind invalid for aggregate types");
759 void AggExprEmitter::VisitCallExpr(
const CallExpr *E) {
761 EmitAggLoadOfLValue(E);
766 EmitMoveFromReturnSlot(E, RV);
771 EmitMoveFromReturnSlot(E, RV);
779 void AggExprEmitter::VisitStmtExpr(
const StmtExpr *E) {
784 void AggExprEmitter::VisitBinaryOperator(
const BinaryOperator *E) {
786 VisitPointerToDataMemberBinaryOperator(E);
791 void AggExprEmitter::VisitPointerToDataMemberBinaryOperator(
794 EmitFinalDestCopy(E->
getType(), LV);
804 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
806 return (var && var->
hasAttr<BlocksAttr>());
815 if (op->isAssignmentOp() || op->isPtrMemOp())
819 if (op->getOpcode() == BO_Comma)
827 = dyn_cast<AbstractConditionalOperator>(E)) {
833 = dyn_cast<OpaqueValueExpr>(E)) {
834 if (
const Expr *src = op->getSourceExpr())
841 }
else if (
const CastExpr *
cast = dyn_cast<CastExpr>(E)) {
842 if (
cast->getCastKind() == CK_LValueToRValue)
848 }
else if (
const UnaryOperator *uop = dyn_cast<UnaryOperator>(E)) {
852 }
else if (
const MemberExpr *mem = dyn_cast<MemberExpr>(E)) {
868 &&
"Invalid assignment");
884 if (LHS.getType()->isAtomicType() ||
923 EmitFinalDestCopy(E->
getType(), LHS);
926 void AggExprEmitter::
948 assert(CGF.
HaveInsertPoint() &&
"expression evaluation ended with no IP!");
949 CGF.
Builder.CreateBr(ContBlock);
965 void AggExprEmitter::VisitChooseExpr(
const ChooseExpr *CE) {
969 void AggExprEmitter::VisitVAArgExpr(
VAArgExpr *VE) {
994 if (!wasExternallyDestructed)
1004 void AggExprEmitter::VisitCXXInheritedCtorInitExpr(
1013 AggExprEmitter::VisitLambdaExpr(
LambdaExpr *E) {
1044 return IL->getValue() == 0;
1047 return FL->getValue().isPosZero();
1049 if ((isa<ImplicitValueInitExpr>(E) || isa<CXXScalarValueInitExpr>(E)) &&
1053 if (
const CastExpr *ICE = dyn_cast<CastExpr>(E))
1054 return ICE->getCastKind() == CK_NullToPointer &&
1058 return CL->getValue() == 0;
1066 AggExprEmitter::EmitInitializationToLValue(
Expr *E,
LValue LV) {
1073 }
else if (isa<ImplicitValueInitExpr>(E) || isa<CXXScalarValueInitExpr>(E)) {
1074 return EmitNullInitializationToLValue(LV);
1075 }
else if (isa<NoInitExpr>(E)) {
1102 llvm_unreachable(
"bad evaluation kind");
1105 void AggExprEmitter::EmitNullInitializationToLValue(
LValue lv) {
1132 void AggExprEmitter::VisitInitListExpr(
InitListExpr *E) {
1139 if (llvm::Constant* C = CGF.
CGM.EmitConstantExpr(E, E->
getType(), &CGF)) {
1140 llvm::GlobalVariable* GV =
1141 new llvm::GlobalVariable(CGF.
CGM.
getModule(), C->getType(),
true,
1163 EmitArrayInit(Dest.
getAddress(), AType, elementType, E);
1179 llvm::Instruction *cleanupDominator =
nullptr;
1181 unsigned curInitIndex = 0;
1184 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(record)) {
1185 assert(E->
getNumInits() >= CXXRD->getNumBases() &&
1186 "missing initializer for base class");
1187 for (
auto &
Base : CXXRD->bases()) {
1188 assert(!
Base.isVirtual() &&
"should not see vbases here");
1189 auto *BaseRD =
Base.getType()->getAsCXXRecordDecl();
1201 Base.getType().isDestructedType()) {
1220 for (
const auto *Field : record->
fields())
1221 assert(Field->isUnnamedBitfield() &&
"Only unnamed bitfields allowed");
1230 if (NumInitElements) {
1232 EmitInitializationToLValue(E->
getInit(0), FieldLoc);
1235 EmitNullInitializationToLValue(FieldLoc);
1243 for (
const auto *field : record->
fields()) {
1245 if (field->getType()->isIncompleteArrayType())
1249 if (field->isUnnamedBitfield())
1255 if (curInitIndex == NumInitElements && Dest.
isZeroed() &&
1264 if (curInitIndex < NumInitElements) {
1266 EmitInitializationToLValue(E->
getInit(curInitIndex++), LV);
1269 EmitNullInitializationToLValue(LV);
1275 bool pushedCleanup =
false;
1277 = field->getType().isDestructedType()) {
1280 if (!cleanupDominator)
1283 llvm::Constant::getNullValue(CGF.
Int8PtrTy),
1289 pushedCleanup =
true;
1295 if (!pushedCleanup && LV.
isSimple())
1296 if (llvm::GetElementPtrInst *GEP =
1297 dyn_cast<llvm::GetElementPtrInst>(LV.
getPointer()))
1298 if (GEP->use_empty())
1299 GEP->eraseFromParent();
1304 for (
unsigned i = cleanups.size(); i != 0; --i)
1308 if (cleanupDominator)
1309 cleanupDominator->eraseFromParent();
1318 uint64_t numElements = E->
getArraySize().getZExtValue();
1326 llvm::Value *begin = Builder.CreateInBoundsGEP(destPtr.getPointer(), indices,
1341 llvm::BasicBlock *entryBB = Builder.GetInsertBlock();
1346 llvm::PHINode *index =
1347 Builder.CreatePHI(zero->getType(), 2,
"arrayinit.index");
1348 index->addIncoming(zero, entryBB);
1349 llvm::Value *element = Builder.CreateInBoundsGEP(begin, index);
1355 if (outerBegin->getType() != element->getType())
1356 outerBegin = Builder.
CreateBitCast(outerBegin, element->getType());
1379 AggExprEmitter(CGF, elementSlot,
false)
1380 .VisitArrayInitLoopExpr(InnerLoop, outerBegin);
1382 EmitInitializationToLValue(E->
getSubExpr(), elementLV);
1387 index, llvm::ConstantInt::get(CGF.
SizeTy, 1),
"arrayinit.next");
1388 index->addIncoming(nextIndex, Builder.GetInsertBlock());
1392 nextIndex, llvm::ConstantInt::get(CGF.
SizeTy, numElements),
1395 Builder.CreateCondBr(done, endBB, bodyBB);
1408 EmitInitializationToLValue(E->
getBase(), DestLV);
1435 if (!RT->isUnionType()) {
1439 unsigned ILEElement = 0;
1440 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(SD))
1441 while (ILEElement != CXXRD->getNumBases())
1444 for (
const auto *Field : SD->
fields()) {
1447 if (Field->getType()->isIncompleteArrayType() ||
1450 if (Field->isUnnamedBitfield())
1456 if (Field->getType()->isReferenceType())
1463 return NumNonZeroBytes;
1469 for (
unsigned i = 0, e = ILE->
getNumInits(); i != e; ++i)
1471 return NumNonZeroBytes;
1488 const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
1501 if (NumNonZeroBytes*4 > Size)
1523 assert(E && hasAggregateEvaluationKind(E->
getType()) &&
1524 "Invalid aggregate expression to emit");
1526 "slot has bits but no address");
1531 AggExprEmitter(*
this, Slot, Slot.
isIgnored()).Visit(const_cast<Expr*>(E));
1535 assert(hasAggregateEvaluationKind(E->
getType()) &&
"Invalid argument!");
1547 bool isAssignment) {
1550 if (getLangOpts().CPlusPlus) {
1558 "Trying to aggregate-copy a type without a trivial copy/move " 1559 "constructor or assignment operator");
1581 std::pair<CharUnits, CharUnits>
TypeInfo;
1583 TypeInfo = getContext().getTypeInfoDataSizeInChars(Ty);
1585 TypeInfo = getContext().getTypeInfoInChars(Ty);
1588 if (TypeInfo.first.isZero()) {
1590 if (
auto *VAT = dyn_cast_or_null<VariableArrayType>(
1591 getContext().getAsArrayType(Ty))) {
1593 SizeVal = emitArrayLength(VAT, BaseEltTy, DestPtr);
1594 TypeInfo = getContext().getTypeInfoDataSizeInChars(BaseEltTy);
1595 std::pair<CharUnits, CharUnits> LastElementTypeInfo;
1597 LastElementTypeInfo = getContext().getTypeInfoInChars(BaseEltTy);
1598 assert(!TypeInfo.first.isZero());
1599 SizeVal = Builder.CreateNUWMul(
1601 llvm::ConstantInt::get(SizeTy, TypeInfo.first.getQuantity()));
1602 if (!isAssignment) {
1603 SizeVal = Builder.CreateNUWSub(
1605 llvm::ConstantInt::get(SizeTy, TypeInfo.first.getQuantity()));
1606 SizeVal = Builder.CreateNUWAdd(
1607 SizeVal, llvm::ConstantInt::get(
1608 SizeTy, LastElementTypeInfo.first.getQuantity()));
1613 SizeVal = llvm::ConstantInt::get(SizeTy, TypeInfo.first.getQuantity());
1638 CGM.getObjCRuntime().EmitGCMemmoveCollectable(*
this, DestPtr, SrcPtr,
1643 QualType BaseType = getContext().getBaseElementType(Ty);
1646 CGM.getObjCRuntime().EmitGCMemmoveCollectable(*
this, DestPtr, SrcPtr,
1653 auto Inst = Builder.
CreateMemCpy(DestPtr, SrcPtr, SizeVal, isVolatile);
1658 if (llvm::MDNode *TBAAStructTag = CGM.getTBAAStructInfo(Ty))
1659 Inst->setMetadata(llvm::LLVMContext::MD_tbaa_struct, TBAAStructTag);
ReturnValueSlot - Contains the address where the return value of a function can be stored...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Defines the clang::ASTContext interface.
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Address getAddress() const
void end(CodeGenFunction &CGF)
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
A (possibly-)qualified type.
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, llvm::BasicBlock *FalseBlock, uint64_t TrueCount)
EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g.
RValue EmitCoyieldExpr(const CoyieldExpr &E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
CompoundStmt * getSubStmt()
static AggValueSlot forLValue(const LValue &LV, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, IsZeroed_t isZeroed=IsNotZeroed)
const Expr * getInit(unsigned Init) const
Stmt - This represents one statement.
Address GetAddressOfDirectBaseInCompleteClass(Address Value, const CXXRecordDecl *Derived, const CXXRecordDecl *Base, bool BaseIsVirtual)
GetAddressOfBaseOfCompleteClass - Convert the given pointer to a complete class to the given direct b...
NeedsGCBarriers_t requiresGCollection() const
llvm::Value * getPointer() const
bool isRecordType() const
Address EmitVAArg(VAArgExpr *VE, Address &VAListAddr)
Generate code to get an argument from the passed in pointer and update it accordingly.
virtual void EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF, Address DestPtr, Address SrcPtr, llvm::Value *Size)=0
RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, AggValueSlot slot=AggValueSlot::ignored())
RValue EmitCoawaitExpr(const CoawaitExpr &E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic, and whose semantics are that of the sole contained initializer)?
Defines the C++ template declaration subclasses.
ParenExpr - This represents a parethesized expression, e.g.
Expr * getFalseExpr() const
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
EmitStoreThroughLValue - Store the specified rvalue into the specified lvalue, where both are guarant...
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
EmitComplexExprIntoLValue - Emit the given expression of complex type and place its result into the s...
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Represents a call to a C++ constructor.
bool hasTrivialMoveConstructor() const
Determine whether this class has a trivial move constructor (C++11 [class.copy]p12) ...
stable_iterator stable_begin() const
Create a stable reference to the top of the EH stack.
void setZeroed(bool V=true)
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
LValue EmitLValueForFieldInitialization(LValue Base, const FieldDecl *Field)
EmitLValueForFieldInitialization - Like EmitLValueForField, except that if the Field is a reference...
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
const Expr * getResultExpr() const
The generic selection's result expression.
IsAliased_t isPotentiallyAliased() const
void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit)
QualType getElementType() const
static bool isBlockVarRef(const Expr *E)
Is the value of the given expression possibly a reference to or into a __block variable?
static Expr * findPeephole(Expr *op, CastKind kind)
Attempt to look through various unimportant expressions to find a cast of the given kind...
VarDecl - An instance of this class is created to represent a variable declaration or definition...
CompoundLiteralExpr - [C99 6.5.2.5].
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
const T * getAs() const
Member-template getAs<specific type>'.
uint64_t getProfileCount(const Stmt *S)
Get the profiler's count for the given statement.
static bool isSimpleZero(const Expr *E, CodeGenFunction &CGF)
isSimpleZero - If emitting this value will obviously just cause a store of zero to memory...
IsZeroed_t isZeroed() const
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
llvm::Value * getPointer() const
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
A C++ throw-expression (C++ [except.throw]).
Represents an expression – generally a full-expression – that introduces cleanups to be run at the ...
void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, llvm::Value **Result=nullptr)
EmitStoreThroughBitfieldLValue - Store Src into Dst with same constraints as EmitStoreThroughLValue.
The collection of all-type qualifiers we support.
static CharUnits GetNumNonZeroBytesInInit(const Expr *E, CodeGenFunction &CGF)
GetNumNonZeroBytesInInit - Get an approximate count of the number of non-zero bytes that will be stor...
RecordDecl - Represents a struct/union/class.
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
const TargetInfo & getTarget() const
An object to manage conditionally-evaluated expressions.
IsDestructed_t isExternallyDestructed() const
Expr * GetTemporaryExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
Address getAddress() const
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
llvm::Value * EmitDynamicCast(Address V, const CXXDynamicCastExpr *DCE)
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
field_range fields() const
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
llvm::IntegerType * SizeTy
Represents a place-holder for an object not to be initialized by anything.
An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
bool isReferenceType() const
bool hasTrivialMoveAssignment() const
Determine whether this class has a trivial move assignment operator (C++11 [class.copy]p25)
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
bool isPaddedAtomicType(QualType type)
static bool isTrivialFiller(Expr *E)
Determine if E is a trivial array filler, that is, one that is equivalent to zero-initialization.
bool hadArrayRangeDesignator() const
void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, QualType Ty, AlignmentSource Source=AlignmentSource::Type, bool isInit=false, bool isNontemporal=false)
EmitStoreOfScalar - Store a scalar value to an address, taking care to appropriately convert from the...
void setNonGC(bool Value)
RValue EmitAnyExpr(const Expr *E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
EmitAnyExpr - Emit code to compute the specified expression which can have any type.
void EmitInheritedCXXConstructorCall(const CXXConstructorDecl *D, bool ForVirtualBase, Address This, bool InheritedFromVBase, const CXXInheritedCtorInitExpr *E)
Emit a call to a constructor inherited from a base class, passing the current constructor's arguments...
Describes an C or C++ initializer list.
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin, llvm::Value *arrayEnd, QualType elementType, CharUnits elementAlignment, Destroyer *destroyer)
pushRegularPartialArrayCleanup - Push an EH cleanup to destroy already-constructed elements of the gi...
static bool hasScalarEvaluationKind(QualType T)
Address CreateElementBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Cast the element type of the given address to a different type, preserving information like the align...
CharUnits - This is an opaque type for sizes expressed in character units.
CharUnits getAlignment() const
Return the alignment of this pointer.
A builtin binary operation expression such as "x + y" or "x <= y".
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
bool needsEHCleanup(QualType::DestructionKind kind)
Determines whether an EH cleanup is required to destroy a type with the given destruction kind...
bool constructsVBase() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
Scope - A scope is a transient data structure that is used while parsing the program.
field_iterator field_begin() const
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
void EmitIgnoredExpr(const Expr *E)
EmitIgnoredExpr - Emit an expression in a context which ignores the result.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Represents binding an expression to a temporary.
RValue EmitAtomicExpr(AtomicExpr *E)
CXXTemporary * getTemporary()
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
CharUnits getPointerAlign() const
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV=nullptr)
Increment the profiler's counter for the given statement by StepV.
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates an alloca and inserts it into the entry block if ArraySize is nullptr...
Address getAggregateAddress() const
getAggregateAddr() - Return the Value* of the address of the aggregate.
A default argument (C++ [dcl.fct.default]).
void begin(CodeGenFunction &CGF)
Checking the operand of a load. Must be suitably sized and aligned.
const Expr * getExpr() const
Get the initialization expression that will be used.
RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, ReturnValueSlot Return=ReturnValueSlot())
void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest)
static CharUnits One()
One - Construct a CharUnits quantity of one.
ASTContext & getContext() const
CastKind
CastKind - The kind of operation required for a conversion.
RValue - This trivial value class is used to represent the result of an expression that is evaluated...
InitListExpr * getUpdater() const
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Represents a call to the builtin function __builtin_va_arg.
bool isPointerZeroInitializable(QualType T)
Check if the pointer type can be zero-initialized (in the C++ sense) with an LLVM zeroinitializer...
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type...
Expr - This represents one expression.
Qualifiers getQualifiers() const
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited...
const FunctionProtoType * T
const T * castAs() const
Member-template castAs<specific type>.
Address EmitCompoundStmt(const CompoundStmt &S, bool GetLast=false, AggValueSlot AVS=AggValueSlot::ignored())
EmitCompoundStmt - Emit a compound statement {..} node.
unsigned getNumInits() const
Expr * getSubExpr() const
Get the initializer to use for each array element.
AggValueSlot CreateAggTemp(QualType T, const Twine &Name="tmp")
CreateAggTemp - Create a temporary memory object for the given aggregate type.
field_iterator field_end() const
llvm::PointerType * getType() const
Return the type of the pointer value.
bool isAnyComplexType() const
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
void EmitLambdaExpr(const LambdaExpr *E, AggValueSlot Dest)
An RAII object to record that we're evaluating a statement expression.
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
An expression that sends a message to the given Objective-C object or class.
llvm::CallInst * CreateMemSet(Address Dest, llvm::Value *Value, llvm::Value *Size, bool IsVolatile=false)
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
const AstTypeMatcher< AtomicType > atomicType
Matches atomic types.
Represents a reference to a non-type template parameter that has been substituted with a template arg...
The scope of a CXXDefaultInitExpr.
bool hasTrivialCopyConstructor() const
Determine whether this class has a trivial copy constructor (C++ [class.copy]p6, C++11 [class...
Expr * getTrueExpr() const
const Expr * getSubExpr() const
const Expr * getSubExpr() const
static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, IsZeroed_t isZeroed=IsNotZeroed)
forAddr - Make a slot for an aggregate value.
RValue EmitAtomicLoad(LValue LV, SourceLocation SL, AggValueSlot Slot=AggValueSlot::ignored())
RecordDecl * getDecl() const
The scope of an ArrayInitLoopExpr.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
Address CreateBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Represents a call to an inherited base class constructor from an inheriting constructor.
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
void pushDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
pushDestroy - Push the standard destructor for the given type as at least a normal cleanup...
bool inheritedFromVBase() const
Determine whether the inherited constructor is inherited from a virtual base of the object we constru...
bool hasTrivialCopyAssignment() const
Determine whether this class has a trivial copy assignment operator (C++ [class.copy]p11, C++11 [class.copy]p25)
bool LValueIsSuitableForInlineAtomic(LValue Src)
An LValue is a candidate for having its loads and stores be made atomic if we are operating under /vo...
A saved depth on the scope stack.
Expr * getSubExpr() const
LValue EmitCheckedLValue(const Expr *E, TypeCheckKind TCK)
Same as EmitLValue but additionally we generate checking code to guard against undefined behavior...
CastKind getCastKind() const
LValue EmitAggExprToLValue(const Expr *E)
EmitAggExprToLValue - Emit the computation of the specified expression of aggregate type into a tempo...
void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *DominatingIP)
DeactivateCleanupBlock - Deactivates the given cleanup block.
A scoped helper to set the current debug location to the specified location or preferred location of ...
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>, and corresponding __opencl_atomic_* for OpenCL 2.0.
void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType, Address Ptr)
Emits all the code to cause the given temporary to be cleaned up.
static void CheckAggExprForMemSetUse(AggValueSlot &Slot, const Expr *E, CodeGenFunction &CGF)
CheckAggExprForMemSetUse - If the initializer is large and has a lot of zeros in it, emit a memset and avoid storing the individual zeros.
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after...
LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E)
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
RValue EmitCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue=ReturnValueSlot())
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
void enterFullExpression(const ExprWithCleanups *E)
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
const Expr * getInitializer() const
void setExternallyDestructed(bool destructed=true)
Represents a C11 generic selection.
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type, returning the result.
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
void setVolatile(bool flag)
Dataflow Directional Tag Classes.
[C99 6.4.2.2] - A predefined identifier such as func.
static AggValueSlot ignored()
ignored - Returns an aggregate value slot indicating that the aggregate value is being ignored...
Address CreateStructGEP(Address Addr, unsigned Index, CharUnits Offset, const llvm::Twine &Name="")
A scope within which we are constructing the fields of an object which might use a CXXDefaultInitExpr...
llvm::LoadInst * CreateAlignedLoad(llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
LValue EmitPseudoObjectLValue(const PseudoObjectExpr *e)
bool hasUserDeclaredConstructor() const
Determine whether this class has any user-declared constructors.
Represents a 'co_yield' expression.
const Expr * getExpr() const
U cast(CodeGen::Address addr)
llvm::Constant * EmitNullConstant(QualType T)
Return the result of value-initializing the given type, i.e.
Checking the destination of a store. Must be suitably sized and aligned.
void EmitAggregateCopy(Address DestPtr, Address SrcPtr, QualType EltTy, bool isVolatile=false, bool isAssignment=false)
EmitAggregateCopy - Emit an aggregate copy.
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
llvm::Module & getModule() const
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type. ...
void EmitExplicitCastExprType(const ExplicitCastExpr *E, CodeGenFunction *CGF=nullptr)
Emit type info if type of an expression is a variably modified type.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
const LValue & getOpaqueLValueMapping(const OpaqueValueExpr *e)
getOpaqueLValueMapping - Given an opaque value expression (which must be mapped to an l-value)...
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
CodeGenTypes & getTypes() const
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
llvm::Type * getElementType() const
Return the type of the values stored in this address.
const llvm::APInt & getSize() const
bool isAtomicType() const
Represents a 'co_await' expression.
llvm::PointerType * Int8PtrTy
llvm::Value * getAggregatePointer() const
Expr * getReplacement() const
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
ObjCIvarRefExpr - A reference to an ObjC instance variable.
A use of a default initializer in a constructor or in aggregate initialization.
llvm::IntegerType * PtrDiffTy
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
void ErrorUnsupported(const Stmt *S, const char *Type)
ErrorUnsupported - Print out an error that codegen doesn't support the specified stmt yet...
Represents a C++ struct/union/class.
Represents a loop initializing the elements of an array.
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
llvm::Type * ConvertType(QualType T)
LValue EmitLValue(const Expr *E)
EmitLValue - Emit code to compute a designator that specifies the location of the expression...
unsigned kind
All of the diagnostics that can be emitted by the frontend.
StringLiteral - This represents a string literal expression, e.g.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
RetTy Visit(PTR(Stmt) S, ParamTys... P)
bool hasVolatileMember(QualType T)
hasVolatileMember - returns true if aggregate type has a volatile member.
A reference to a declared variable, function, enum, etc.
static RValue get(llvm::Value *V)
bool hasObjectMember() const
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
static RValue getAggregate(Address addr, bool isVolatile=false)
LValue - This represents an lvalue references.
const LangOptions & getLangOpts() const
llvm::APInt getArraySize() const
llvm::Value * getPointer() const
Represents the canonical version of C arrays with a specified constant size.
bool isZeroInitializable(QualType T)
IsZeroInitializable - Return whether a type can be zero-initialized (in the C++ sense) with an LLVM z...
Represents an implicitly-generated value initialization of an object of a given type.
void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint=true)
void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin, Address arrayEndPointer, QualType elementType, CharUnits elementAlignment, Destroyer *destroyer)
pushIrregularPartialArrayCleanup - Push an EH cleanup to destroy already-constructed elements of the ...
void EmitNullInitialization(Address DestPtr, QualType Ty)
EmitNullInitialization - Generate code to set a value of the given type to null, If the type contains...
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.