28#include "llvm/IR/Constants.h"
29#include "llvm/IR/Function.h"
30#include "llvm/IR/GlobalVariable.h"
31#include "llvm/IR/Instruction.h"
32#include "llvm/IR/IntrinsicInst.h"
33#include "llvm/IR/Intrinsics.h"
42class AggExprEmitter :
public StmtVisitor<AggExprEmitter> {
48 AggValueSlot EnsureSlot(QualType
T) {
53 void EnsureDest(QualType
T) {
65 void withReturnValueSlot(
const Expr *E,
66 llvm::function_ref<RValue(ReturnValueSlot)> Fn);
68 void DoZeroInitPadding(uint64_t &PaddingStart, uint64_t PaddingEnd,
69 const FieldDecl *NextField);
72 AggExprEmitter(CodeGenFunction &cgf, AggValueSlot Dest,
bool IsResultUnused)
73 : CGF(cgf), Builder(CGF.Builder), Dest(Dest),
74 IsResultUnused(IsResultUnused) {}
83 void EmitAggLoadOfLValue(
const Expr *E);
87 void EmitFinalDestCopy(QualType
type,
const LValue &src,
90 void EmitFinalDestCopy(QualType
type, RValue src);
91 void EmitCopy(QualType
type,
const AggValueSlot &dest,
92 const AggValueSlot &src);
94 void EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, QualType ArrayQTy,
95 Expr *ExprToVisit, ArrayRef<Expr *> Args,
99 if (CGF.
getLangOpts().getGC() && TypeRequiresGCollection(
T))
104 bool TypeRequiresGCollection(QualType
T);
110 void Visit(Expr *E) {
111 ApplyDebugLocation DL(CGF, E);
112 StmtVisitor<AggExprEmitter>::Visit(E);
115 void VisitStmt(Stmt *S) { CGF.
ErrorUnsupported(S,
"aggregate expression"); }
116 void VisitParenExpr(ParenExpr *PE) { Visit(PE->
getSubExpr()); }
117 void VisitGenericSelectionExpr(GenericSelectionExpr *GE) {
118 Visit(
GE->getResultExpr());
120 void VisitCoawaitExpr(CoawaitExpr *E) {
123 void VisitCoyieldExpr(CoyieldExpr *E) {
126 void VisitUnaryCoawait(UnaryOperator *E) { Visit(E->
getSubExpr()); }
127 void VisitUnaryExtension(UnaryOperator *E) { Visit(E->
getSubExpr()); }
128 void VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E) {
132 void VisitConstantExpr(ConstantExpr *E) {
135 if (llvm::Value *
Result = ConstantEmitter(CGF).tryEmitConstantExpr(E)) {
138 llvm::TypeSize::getFixed(
148 void VisitDeclRefExpr(DeclRefExpr *E) { EmitAggLoadOfLValue(E); }
149 void VisitMemberExpr(MemberExpr *ME) { EmitAggLoadOfLValue(ME); }
150 void VisitUnaryDeref(UnaryOperator *E) { EmitAggLoadOfLValue(E); }
151 void VisitStringLiteral(StringLiteral *E) { EmitAggLoadOfLValue(E); }
152 void VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
153 void VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
154 EmitAggLoadOfLValue(E);
156 void VisitPredefinedExpr(
const PredefinedExpr *E) { EmitAggLoadOfLValue(E); }
160 void VisitCallExpr(
const CallExpr *E);
161 void VisitStmtExpr(
const StmtExpr *E);
162 void VisitBinaryOperator(
const BinaryOperator *BO);
163 void VisitPointerToDataMemberBinaryOperator(
const BinaryOperator *BO);
164 void VisitBinAssign(
const BinaryOperator *E);
165 void VisitBinComma(
const BinaryOperator *E);
166 void VisitBinCmp(
const BinaryOperator *E);
167 void VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *E) {
171 void VisitObjCMessageExpr(ObjCMessageExpr *E);
172 void VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { EmitAggLoadOfLValue(E); }
174 void VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E);
175 void VisitAbstractConditionalOperator(
const AbstractConditionalOperator *CO);
176 void VisitChooseExpr(
const ChooseExpr *CE);
177 void VisitInitListExpr(InitListExpr *E);
178 void VisitCXXParenListOrInitListExpr(Expr *ExprToVisit, ArrayRef<Expr *> Args,
179 FieldDecl *InitializedFieldInUnion,
181 void VisitArrayInitLoopExpr(
const ArrayInitLoopExpr *E,
182 llvm::Value *outerBegin =
nullptr);
183 void VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
184 void VisitNoInitExpr(NoInitExpr *E) {}
185 void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) {
186 CodeGenFunction::CXXDefaultArgExprScope Scope(CGF, DAE);
189 void VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) {
190 CodeGenFunction::CXXDefaultInitExprScope Scope(CGF, DIE);
193 void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
194 void VisitCXXConstructExpr(
const CXXConstructExpr *E);
195 void VisitCXXInheritedCtorInitExpr(
const CXXInheritedCtorInitExpr *E);
197 void VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E);
198 void VisitExprWithCleanups(ExprWithCleanups *E);
199 void VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E);
200 void VisitCXXTypeidExpr(CXXTypeidExpr *E) { EmitAggLoadOfLValue(E); }
201 void VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E);
202 void VisitOpaqueValueExpr(OpaqueValueExpr *E);
204 void VisitPseudoObjectExpr(PseudoObjectExpr *E) {
207 return EmitFinalDestCopy(E->
getType(), LV);
210 AggValueSlot Slot = EnsureSlot(E->
getType());
211 bool NeedsDestruction =
214 if (NeedsDestruction)
217 if (NeedsDestruction)
222 void VisitVAArgExpr(VAArgExpr *E);
223 void VisitCXXParenListInitExpr(CXXParenListInitExpr *E);
224 void VisitCXXParenListOrInitListExpr(Expr *ExprToVisit, ArrayRef<Expr *> Args,
227 void EmitInitializationToLValue(Expr *E, LValue Address);
228 void EmitNullInitializationToLValue(LValue Address);
231 void VisitAtomicExpr(AtomicExpr *E) {
233 EmitFinalDestCopy(E->
getType(), Res);
235 void VisitPackIndexingExpr(PackIndexingExpr *E) {
248void AggExprEmitter::EmitAggLoadOfLValue(
const Expr *E) {
257 EmitFinalDestCopy(E->
getType(), LV);
261bool AggExprEmitter::TypeRequiresGCollection(QualType
T) {
277void AggExprEmitter::withReturnValueSlot(
278 const Expr *E, llvm::function_ref<RValue(ReturnValueSlot)> EmitCall) {
280 bool RequiresDestruction =
290 (RequiresDestruction && Dest.
isIgnored());
294 EHScopeStack::stable_iterator LifetimeEndBlock;
295 llvm::IntrinsicInst *LifetimeStartInst =
nullptr;
303 assert(LifetimeStartInst->getIntrinsicID() ==
304 llvm::Intrinsic::lifetime_start &&
305 "Last insertion wasn't a lifetime.start?");
314 EmitCall(ReturnValueSlot(RetAddr, Dest.
isVolatile(), IsResultUnused,
322 EmitFinalDestCopy(E->
getType(), Src);
324 if (!RequiresDestruction && LifetimeStartInst) {
334void AggExprEmitter::EmitFinalDestCopy(QualType
type, RValue src) {
335 assert(src.
isAggregate() &&
"value must be aggregate value!");
341void AggExprEmitter::EmitFinalDestCopy(
342 QualType
type,
const LValue &src,
376 EmitCopy(
type, Dest, srcAgg);
383void AggExprEmitter::EmitCopy(QualType
type,
const AggValueSlot &dest,
384 const AggValueSlot &src) {
404void AggExprEmitter::VisitCXXStdInitializerListExpr(
405 CXXStdInitializerListExpr *E) {
410 assert(Array.isSimple() &&
"initializer_list array not a simple lvalue");
411 Address ArrayPtr = Array.getAddress();
413 const ConstantArrayType *ArrayType =
415 assert(ArrayType &&
"std::initializer_list constructed from non-array");
419 assert(Field !=
Record->field_end() &&
422 "Expected std::initializer_list first field to be const E *");
425 AggValueSlot Dest = EnsureSlot(E->
getType());
431 assert(Field !=
Record->field_end() &&
432 "Expected std::initializer_list to have two fields");
434 llvm::Value *
Size = Builder.getInt(ArrayType->
getSize());
442 assert(
Field->getType()->isPointerType() &&
445 "Expected std::initializer_list second field to be const E *");
446 llvm::Value *
Zero = llvm::ConstantInt::get(CGF.
PtrDiffTy, 0);
447 llvm::Value *IdxEnd[] = {
Zero,
Size};
448 llvm::Value *ArrayEnd = Builder.CreateInBoundsGEP(
454 assert(++Field ==
Record->field_end() &&
455 "Expected std::initializer_list to only have two fields");
467 if (
auto *ILE = dyn_cast<InitListExpr>(E)) {
468 if (ILE->getNumInits())
473 if (
auto *Cons = dyn_cast_or_null<CXXConstructExpr>(E))
474 return Cons->getConstructor()->isDefaultConstructor() &&
475 Cons->getConstructor()->isTrivial();
495 SrcTy = VT->getElementType();
496 assert(StoreList.size() <= VT->getNumElements() &&
497 "Cannot perform HLSL flat cast when vector source \
498 object has less elements than flattened destination \
502 for (
unsigned I = 0, Size = StoreList.size(); I < Size; I++) {
503 LValue DestLVal = StoreList[I];
523 assert(StoreList.size() <= LoadList.size() &&
524 "Cannot perform HLSL elementwise cast when flattened source object \
525 has less elements than flattened destination object.");
528 for (
unsigned I = 0, E = StoreList.size(); I < E; I++) {
529 LValue DestLVal = StoreList[I];
530 LValue SrcLVal = LoadList[I];
532 assert(RVal.
isScalar() &&
"All flattened source values should be scalars");
535 DestLVal.getType(), Loc);
542void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType,
543 QualType ArrayQTy, Expr *ExprToVisit,
544 ArrayRef<Expr *> Args, Expr *ArrayFiller) {
545 uint64_t NumInitElements = Args.size();
547 uint64_t NumArrayElements = AType->getNumElements();
548 for (
const auto *
Init : Args) {
549 if (
const auto *Embed = dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
550 NumInitElements += Embed->getDataElementCount() - 1;
551 if (NumInitElements > NumArrayElements) {
552 NumInitElements = NumArrayElements;
558 assert(NumInitElements <= NumArrayElements);
560 QualType elementType =
563 CharUnits elementAlign =
570 if (NumInitElements * elementSize.
getQuantity() > 16 &&
572 CodeGen::CodeGenModule &CGM = CGF.
CGM;
573 ConstantEmitter Emitter(CGF);
578 if (llvm::Constant *
C =
579 Emitter.tryEmitForInitializer(ExprToVisit, AS, GVArrayQTy)) {
580 auto GV =
new llvm::GlobalVariable(
582 true, llvm::GlobalValue::PrivateLinkage,
C,
584 nullptr, llvm::GlobalVariable::NotThreadLocal,
586 Emitter.finalize(GV);
589 Address GVAddr(GV, GV->getValueType(), Align);
590 EmitFinalDestCopy(ArrayQTy, CGF.
MakeAddrLValue(GVAddr, GVArrayQTy));
600 CodeGenFunction::CleanupDeactivationScope deactivation(CGF);
604 CodeGenFunction::AllocaTrackerRAII allocaTracker(CGF);
609 llvm::Instruction *dominatingIP =
610 Builder.CreateFlagLoad(llvm::ConstantInt::getNullValue(CGF.
Int8PtrTy));
612 "arrayinit.endOfInit");
613 Builder.CreateStore(begin, endOfInit);
618 .AddAuxAllocas(allocaTracker.Take());
624 llvm::Value *one = llvm::ConstantInt::get(CGF.
SizeTy, 1);
627 llvm::Value *element = begin;
628 if (ArrayIndex > 0) {
629 element = Builder.CreateInBoundsGEP(
630 llvmElementType, begin,
631 llvm::ConstantInt::get(CGF.
SizeTy, ArrayIndex),
"arrayinit.element");
637 Builder.CreateStore(element, endOfInit);
641 Address(element, llvmElementType, elementAlign), elementType);
642 EmitInitializationToLValue(
Init, elementLV);
646 unsigned ArrayIndex = 0;
648 for (uint64_t i = 0; i != NumInitElements; ++i) {
649 if (ArrayIndex >= NumInitElements)
651 if (
auto *EmbedS = dyn_cast<EmbedExpr>(Args[i]->IgnoreParenImpCasts())) {
652 EmbedS->doForEachDataElement(Emit, ArrayIndex);
654 Emit(Args[i], ArrayIndex);
665 if (NumInitElements != NumArrayElements &&
666 !(Dest.
isZeroed() && hasTrivialFiller &&
673 llvm::Value *element = begin;
674 if (NumInitElements) {
675 element = Builder.CreateInBoundsGEP(
676 llvmElementType, element,
677 llvm::ConstantInt::get(CGF.
SizeTy, NumInitElements),
680 Builder.CreateStore(element, endOfInit);
684 llvm::Value *end = Builder.CreateInBoundsGEP(
685 llvmElementType, begin,
686 llvm::ConstantInt::get(CGF.
SizeTy, NumArrayElements),
"arrayinit.end");
688 llvm::BasicBlock *entryBB = Builder.GetInsertBlock();
693 llvm::PHINode *currentElement =
694 Builder.CreatePHI(element->getType(), 2,
"arrayinit.cur");
695 currentElement->addIncoming(element, entryBB);
704 CodeGenFunction::RunCleanupsScope CleanupsScope(CGF);
706 Address(currentElement, llvmElementType, elementAlign), elementType);
708 EmitInitializationToLValue(ArrayFiller, elementLV);
710 EmitNullInitializationToLValue(elementLV);
714 llvm::Value *nextElement = Builder.CreateInBoundsGEP(
715 llvmElementType, currentElement, one,
"arrayinit.next");
719 Builder.CreateStore(nextElement, endOfInit);
723 Builder.CreateICmpEQ(nextElement, end,
"arrayinit.done");
725 Builder.CreateCondBr(done, endBB, bodyBB);
726 currentElement->addIncoming(nextElement, Builder.GetInsertBlock());
736void AggExprEmitter::VisitMaterializeTemporaryExpr(
737 MaterializeTemporaryExpr *E) {
741void AggExprEmitter::VisitOpaqueValueExpr(OpaqueValueExpr *e) {
749void AggExprEmitter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
753 EmitAggLoadOfLValue(E);
757 AggValueSlot Slot = EnsureSlot(E->
getType());
779 if (
auto castE = dyn_cast<CastExpr>(op)) {
780 if (castE->getCastKind() ==
kind)
781 return castE->getSubExpr();
786void AggExprEmitter::VisitCastExpr(
CastExpr *E) {
787 if (
const auto *ECE = dyn_cast<ExplicitCastExpr>(E))
822 case CK_LValueToRValueBitCast: {
830 Address SourceAddress = SourceLV.getAddress().withElementType(CGF.
Int8Ty);
832 llvm::Value *SizeVal = llvm::ConstantInt::get(
835 Builder.CreateMemCpy(DestAddress, SourceAddress, SizeVal);
839 case CK_DerivedToBase:
840 case CK_BaseToDerived:
841 case CK_UncheckedDerivedToBase: {
842 llvm_unreachable(
"cannot perform hierarchy conversion in EmitAggExpr: "
843 "should have been unpacked before we got here");
846 case CK_NonAtomicToAtomic:
847 case CK_AtomicToNonAtomic: {
848 bool isToAtomic = (E->
getCastKind() == CK_NonAtomicToAtomic);
852 QualType valueType = E->
getType();
858 valueType,
atomicType->castAs<AtomicType>()->getValueType()));
867 (isToAtomic ? CK_AtomicToNonAtomic : CK_NonAtomicToAtomic);
874 "peephole significantly changed types?");
881 AggValueSlot valueDest = Dest;
904 AggValueSlot atomicSlot =
908 Address valueAddr = Builder.CreateStructGEP(atomicSlot.
getAddress(), 0);
910 return EmitFinalDestCopy(valueType, rvalue);
912 case CK_AddressSpaceConversion:
915 case CK_LValueToRValue:
936 case CK_HLSLArrayRValue:
939 case CK_HLSLAggregateSplatCast: {
941 QualType SrcTy = Src->
getType();
947 "RHS of HLSL splat cast must be a scalar.");
952 case CK_HLSLElementwiseCast: {
954 QualType SrcTy = Src->
getType();
962 "HLSL Elementwise cast doesn't handle splatting.");
966 "Can't perform HLSL Aggregate cast on a complex type.");
974 case CK_UserDefinedConversion:
975 case CK_ConstructorConversion:
978 "Implicit cast types must be compatible");
982 case CK_LValueBitCast:
983 llvm_unreachable(
"should not be emitting lvalue bitcast as rvalue");
987 case CK_ArrayToPointerDecay:
988 case CK_FunctionToPointerDecay:
989 case CK_NullToPointer:
990 case CK_NullToMemberPointer:
991 case CK_BaseToDerivedMemberPointer:
992 case CK_DerivedToBaseMemberPointer:
993 case CK_MemberPointerToBoolean:
994 case CK_ReinterpretMemberPointer:
995 case CK_IntegralToPointer:
996 case CK_PointerToIntegral:
997 case CK_PointerToBoolean:
1000 case CK_IntegralCast:
1001 case CK_BooleanToSignedIntegral:
1002 case CK_IntegralToBoolean:
1003 case CK_IntegralToFloating:
1004 case CK_FloatingToIntegral:
1005 case CK_FloatingToBoolean:
1006 case CK_FloatingCast:
1007 case CK_CPointerToObjCPointerCast:
1008 case CK_BlockPointerToObjCPointerCast:
1009 case CK_AnyPointerToBlockPointerCast:
1010 case CK_ObjCObjectLValueCast:
1011 case CK_FloatingRealToComplex:
1012 case CK_FloatingComplexToReal:
1013 case CK_FloatingComplexToBoolean:
1014 case CK_FloatingComplexCast:
1015 case CK_FloatingComplexToIntegralComplex:
1016 case CK_IntegralRealToComplex:
1017 case CK_IntegralComplexToReal:
1018 case CK_IntegralComplexToBoolean:
1019 case CK_IntegralComplexCast:
1020 case CK_IntegralComplexToFloatingComplex:
1021 case CK_ARCProduceObject:
1022 case CK_ARCConsumeObject:
1023 case CK_ARCReclaimReturnedObject:
1024 case CK_ARCExtendBlockObject:
1025 case CK_CopyAndAutoreleaseBlockObject:
1026 case CK_BuiltinFnToFnPtr:
1027 case CK_ZeroToOCLOpaqueType:
1029 case CK_HLSLVectorTruncation:
1030 case CK_HLSLMatrixTruncation:
1031 case CK_IntToOCLSampler:
1032 case CK_FloatingToFixedPoint:
1033 case CK_FixedPointToFloating:
1034 case CK_FixedPointCast:
1035 case CK_FixedPointToBoolean:
1036 case CK_FixedPointToIntegral:
1037 case CK_IntegralToFixedPoint:
1038 llvm_unreachable(
"cast kind invalid for aggregate types");
1042void AggExprEmitter::VisitCallExpr(
const CallExpr *E) {
1044 EmitAggLoadOfLValue(E);
1048 withReturnValueSlot(
1049 E, [&](ReturnValueSlot Slot) {
return CGF.
EmitCallExpr(E, Slot); });
1052void AggExprEmitter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
1053 withReturnValueSlot(E, [&](ReturnValueSlot Slot) {
1058void AggExprEmitter::VisitBinComma(
const BinaryOperator *E) {
1063void AggExprEmitter::VisitStmtExpr(
const StmtExpr *E) {
1064 CodeGenFunction::StmtExprEvaluation eval(CGF);
1077 const char *NameSuffix =
"") {
1080 ArgTy = CT->getElementType();
1084 "member pointers may only be compared for equality");
1086 CGF, LHS, RHS, MPT,
false);
1090 struct CmpInstInfo {
1092 llvm::CmpInst::Predicate FCmp;
1093 llvm::CmpInst::Predicate SCmp;
1094 llvm::CmpInst::Predicate UCmp;
1096 CmpInstInfo InstInfo = [&]() -> CmpInstInfo {
1097 using FI = llvm::FCmpInst;
1098 using II = llvm::ICmpInst;
1101 return {
"cmp.lt", FI::FCMP_OLT, II::ICMP_SLT, II::ICMP_ULT};
1103 return {
"cmp.gt", FI::FCMP_OGT, II::ICMP_SGT, II::ICMP_UGT};
1105 return {
"cmp.eq", FI::FCMP_OEQ, II::ICMP_EQ, II::ICMP_EQ};
1107 llvm_unreachable(
"Unrecognised CompareKind enum");
1111 return Builder.CreateFCmp(InstInfo.FCmp, LHS, RHS,
1112 llvm::Twine(InstInfo.Name) + NameSuffix);
1116 return Builder.CreateICmp(Inst, LHS, RHS,
1117 llvm::Twine(InstInfo.Name) + NameSuffix);
1120 llvm_unreachable(
"unsupported aggregate binary expression should have "
1121 "already been handled");
1124void AggExprEmitter::VisitBinCmp(
const BinaryOperator *E) {
1125 using llvm::BasicBlock;
1126 using llvm::PHINode;
1130 const ComparisonCategoryInfo &CmpInfo =
1133 "cannot copy non-trivially copyable aggregate");
1145 auto EmitOperand = [&](Expr *E) -> std::pair<Value *, Value *> {
1154 auto LHSValues = EmitOperand(E->
getLHS()),
1155 RHSValues = EmitOperand(E->
getRHS());
1158 Value *Cmp =
EmitCompare(Builder, CGF, E, LHSValues.first, RHSValues.first,
1159 K, IsComplex ?
".r" :
"");
1164 RHSValues.second, K,
".i");
1165 return Builder.CreateAnd(Cmp, CmpImag,
"and.eq");
1167 auto EmitCmpRes = [&](
const ComparisonCategoryInfo::ValueInfo *VInfo) {
1168 return Builder.getInt(VInfo->getIntValue());
1176 Builder.CreateSelect(EmitCmp(
CK_Less), EmitCmpRes(CmpInfo.
getLess()),
1178 Select = Builder.CreateSelect(EmitCmp(
CK_Equal),
1180 SelectOne,
"sel.eq");
1182 Value *SelectEq = Builder.CreateSelect(
1187 SelectEq,
"sel.gt");
1188 Select = Builder.CreateSelect(
1189 EmitCmp(
CK_Less), EmitCmpRes(CmpInfo.
getLess()), SelectGT,
"sel.lt");
1204void AggExprEmitter::VisitBinaryOperator(
const BinaryOperator *E) {
1206 VisitPointerToDataMemberBinaryOperator(E);
1211void AggExprEmitter::VisitPointerToDataMemberBinaryOperator(
1212 const BinaryOperator *E) {
1214 EmitFinalDestCopy(E->
getType(), LV);
1224 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
1225 const VarDecl *var = dyn_cast<VarDecl>(DRE->getDecl());
1226 return (var && var->hasAttr<BlocksAttr>());
1235 if (op->isAssignmentOp() || op->isPtrMemOp())
1239 if (op->getOpcode() == BO_Comma)
1247 dyn_cast<AbstractConditionalOperator>(E)) {
1252 }
else if (
const OpaqueValueExpr *op = dyn_cast<OpaqueValueExpr>(E)) {
1253 if (
const Expr *src = op->getSourceExpr())
1260 }
else if (
const CastExpr *
cast = dyn_cast<CastExpr>(E)) {
1261 if (
cast->getCastKind() == CK_LValueToRValue)
1267 }
else if (
const UnaryOperator *uop = dyn_cast<UnaryOperator>(E)) {
1271 }
else if (
const MemberExpr *mem = dyn_cast<MemberExpr>(E)) {
1282void AggExprEmitter::VisitBinAssign(
const BinaryOperator *E) {
1288 "Invalid assignment");
1304 if (LHS.getType()->isAtomicType() ||
1323 if (LHS.getType()->isAtomicType() ||
1342 EmitFinalDestCopy(E->
getType(), LHS);
1350void AggExprEmitter::VisitAbstractConditionalOperator(
1351 const AbstractConditionalOperator *E) {
1357 CodeGenFunction::OpaqueValueMapping binding(CGF, E);
1359 CodeGenFunction::ConditionalEvaluation eval(CGF);
1365 bool destructNonTrivialCStruct =
1366 !isExternallyDestructed &&
1368 isExternallyDestructed |= destructNonTrivialCStruct;
1377 assert(CGF.
HaveInsertPoint() &&
"expression evaluation ended with no IP!");
1378 CGF.
Builder.CreateBr(ContBlock);
1392 if (destructNonTrivialCStruct)
1399void AggExprEmitter::VisitChooseExpr(
const ChooseExpr *CE) {
1403void AggExprEmitter::VisitVAArgExpr(VAArgExpr *VE) {
1414void AggExprEmitter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
1426 if (!wasExternallyDestructed)
1430void AggExprEmitter::VisitCXXConstructExpr(
const CXXConstructExpr *E) {
1431 AggValueSlot Slot = EnsureSlot(E->
getType());
1435void AggExprEmitter::VisitCXXInheritedCtorInitExpr(
1436 const CXXInheritedCtorInitExpr *E) {
1437 AggValueSlot Slot = EnsureSlot(E->
getType());
1443void AggExprEmitter::VisitLambdaExpr(
LambdaExpr *E) {
1444 AggValueSlot Slot = EnsureSlot(E->
getType());
1449 CodeGenFunction::CleanupDeactivationScope scope(CGF);
1454 i != e; ++i, ++CurField) {
1457 if (CurField->hasCapturedVLAType()) {
1462 EmitInitializationToLValue(*i, LV);
1466 CurField->getType().isDestructedType()) {
1467 assert(LV.isSimple());
1470 CurField->getType(),
1476void AggExprEmitter::VisitExprWithCleanups(ExprWithCleanups *E) {
1477 CodeGenFunction::RunCleanupsScope cleanups(CGF);
1481void AggExprEmitter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
1483 AggValueSlot Slot = EnsureSlot(
T);
1487void AggExprEmitter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
1489 AggValueSlot Slot = EnsureSlot(
T);
1500 case CK_UserDefinedConversion:
1501 case CK_ConstructorConversion:
1507 case CK_BooleanToSignedIntegral:
1508 case CK_FloatingCast:
1509 case CK_FloatingComplexCast:
1510 case CK_FloatingComplexToBoolean:
1511 case CK_FloatingComplexToIntegralComplex:
1512 case CK_FloatingComplexToReal:
1513 case CK_FloatingRealToComplex:
1514 case CK_FloatingToBoolean:
1515 case CK_FloatingToIntegral:
1516 case CK_IntegralCast:
1517 case CK_IntegralComplexCast:
1518 case CK_IntegralComplexToBoolean:
1519 case CK_IntegralComplexToFloatingComplex:
1520 case CK_IntegralComplexToReal:
1521 case CK_IntegralRealToComplex:
1522 case CK_IntegralToBoolean:
1523 case CK_IntegralToFloating:
1525 case CK_IntegralToPointer:
1526 case CK_PointerToIntegral:
1528 case CK_VectorSplat:
1530 case CK_NonAtomicToAtomic:
1531 case CK_AtomicToNonAtomic:
1532 case CK_HLSLVectorTruncation:
1533 case CK_HLSLMatrixTruncation:
1534 case CK_HLSLElementwiseCast:
1535 case CK_HLSLAggregateSplatCast:
1538 case CK_BaseToDerivedMemberPointer:
1539 case CK_DerivedToBaseMemberPointer:
1540 case CK_MemberPointerToBoolean:
1541 case CK_NullToMemberPointer:
1542 case CK_ReinterpretMemberPointer:
1546 case CK_AnyPointerToBlockPointerCast:
1547 case CK_BlockPointerToObjCPointerCast:
1548 case CK_CPointerToObjCPointerCast:
1549 case CK_ObjCObjectLValueCast:
1550 case CK_IntToOCLSampler:
1551 case CK_ZeroToOCLOpaqueType:
1555 case CK_FixedPointCast:
1556 case CK_FixedPointToBoolean:
1557 case CK_FixedPointToFloating:
1558 case CK_FixedPointToIntegral:
1559 case CK_FloatingToFixedPoint:
1560 case CK_IntegralToFixedPoint:
1564 case CK_AddressSpaceConversion:
1565 case CK_BaseToDerived:
1566 case CK_DerivedToBase:
1568 case CK_NullToPointer:
1569 case CK_PointerToBoolean:
1574 case CK_ARCConsumeObject:
1575 case CK_ARCExtendBlockObject:
1576 case CK_ARCProduceObject:
1577 case CK_ARCReclaimReturnedObject:
1578 case CK_CopyAndAutoreleaseBlockObject:
1579 case CK_ArrayToPointerDecay:
1580 case CK_FunctionToPointerDecay:
1581 case CK_BuiltinFnToFnPtr:
1583 case CK_LValueBitCast:
1584 case CK_LValueToRValue:
1585 case CK_LValueToRValueBitCast:
1586 case CK_UncheckedDerivedToBase:
1587 case CK_HLSLArrayRValue:
1590 llvm_unreachable(
"Unhandled clang::CastKind enum");
1598 while (
auto *CE = dyn_cast<CastExpr>(E)) {
1606 return IL->getValue() == 0;
1609 return FL->getValue().isPosZero();
1615 if (
const CastExpr *ICE = dyn_cast<CastExpr>(E))
1616 return ICE->getCastKind() == CK_NullToPointer &&
1621 return CL->getValue() == 0;
1627void AggExprEmitter::EmitInitializationToLValue(Expr *E, LValue LV) {
1628 QualType
type = LV.getType();
1635 return EmitNullInitializationToLValue(LV);
1639 }
else if (
type->isReferenceType()) {
1647void AggExprEmitter::EmitNullInitializationToLValue(LValue lv) {
1648 QualType
type = lv.getType();
1660 if (lv.isBitField()) {
1663 assert(lv.isSimple());
1674void AggExprEmitter::VisitCXXParenListInitExpr(CXXParenListInitExpr *E) {
1680void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
1687 VisitCXXParenListOrInitListExpr(
1691void AggExprEmitter::VisitCXXParenListOrInitListExpr(
1692 Expr *ExprToVisit, ArrayRef<Expr *> InitExprs,
1693 FieldDecl *InitializedFieldInUnion, Expr *ArrayFiller) {
1700 if (llvm::Constant *
C =
1701 CGF.
CGM.EmitConstantExpr(ExprToVisit, ExprToVisit->
getType(), &CGF)) {
1702 llvm::GlobalVariable* GV =
1703 new llvm::GlobalVariable(CGF.
CGM.
getModule(),
C->getType(),
true,
1704 llvm::GlobalValue::InternalLinkage,
C,
"");
1705 EmitFinalDestCopy(ExprToVisit->
getType(),
1723 AggValueSlot Dest = EnsureSlot(ExprToVisit->
getType());
1731 InitExprs, ArrayFiller);
1737 assert(InitExprs.size() == 0 &&
1738 "you can only use an empty initializer with VLAs");
1744 "Only support structs/unions here!");
1750 unsigned NumInitElements = InitExprs.size();
1755 CodeGenFunction::CleanupDeactivationScope DeactivateCleanups(CGF);
1757 unsigned curInitIndex = 0;
1760 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(record)) {
1761 assert(NumInitElements >= CXXRD->getNumBases() &&
1762 "missing initializer for base class");
1763 for (
auto &Base : CXXRD->bases()) {
1764 assert(!
Base.isVirtual() &&
"should not see vbases here");
1765 auto *BaseRD =
Base.getType()->getAsCXXRecordDecl();
1773 CGF.
EmitAggExpr(InitExprs[curInitIndex++], AggSlot);
1776 Base.getType().isDestructedType())
1782 CodeGenFunction::FieldConstructionScope FCS(CGF, Dest.
getAddress());
1784 const bool ZeroInitPadding =
1790 if (!InitializedFieldInUnion) {
1796 for (
const auto *Field : record->
fields())
1798 (
Field->isUnnamedBitField() ||
Field->isAnonymousStructOrUnion()) &&
1799 "Only unnamed bitfields or anonymous class allowed");
1805 FieldDecl *
Field = InitializedFieldInUnion;
1808 if (NumInitElements) {
1810 EmitInitializationToLValue(InitExprs[0], FieldLoc);
1811 if (ZeroInitPadding) {
1815 DoZeroInitPadding(FieldSize, TotalSize,
nullptr);
1819 if (ZeroInitPadding)
1820 EmitNullInitializationToLValue(DestLV);
1822 EmitNullInitializationToLValue(FieldLoc);
1832 for (
const auto *field : record->
fields()) {
1834 if (field->getType()->isIncompleteArrayType())
1838 if (field->isUnnamedBitField())
1844 if (curInitIndex == NumInitElements && Dest.
isZeroed() &&
1848 if (ZeroInitPadding)
1849 DoZeroInitPadding(PaddingStart,
1856 if (curInitIndex < NumInitElements) {
1858 EmitInitializationToLValue(InitExprs[curInitIndex++], LV);
1861 EmitNullInitializationToLValue(LV);
1868 field->getType().isDestructedType()) {
1869 assert(LV.isSimple());
1877 if (ZeroInitPadding) {
1880 DoZeroInitPadding(PaddingStart, TotalSize,
nullptr);
1884void AggExprEmitter::DoZeroInitPadding(uint64_t &PaddingStart,
1885 uint64_t PaddingEnd,
1886 const FieldDecl *NextField) {
1894 llvm::Constant *SizeVal = Builder.getInt64((End - Start).getQuantity());
1898 if (NextField !=
nullptr && NextField->
isBitField()) {
1901 const CGRecordLayout &RL =
1905 if (StorageStart + Info.
StorageSize > PaddingStart) {
1906 if (StorageStart > PaddingStart)
1907 InitBytes(PaddingStart, StorageStart);
1920 if (PaddingStart < PaddingEnd)
1921 InitBytes(PaddingStart, PaddingEnd);
1922 if (NextField !=
nullptr)
1927void AggExprEmitter::VisitArrayInitLoopExpr(
const ArrayInitLoopExpr *E,
1928 llvm::Value *outerBegin) {
1930 CodeGenFunction::OpaqueValueMapping binding(CGF, E->
getCommonExpr());
1932 Address destPtr = EnsureSlot(E->
getType()).getAddress();
1939 llvm::Value *zero = llvm::ConstantInt::get(CGF.
SizeTy, 0);
1940 llvm::Value *indices[] = {zero, zero};
1941 llvm::Value *begin = Builder.CreateInBoundsGEP(destPtr.
getElementType(),
1943 indices,
"arrayinit.begin");
1949 ArrayInitLoopExpr *InnerLoop = dyn_cast<ArrayInitLoopExpr>(E->
getSubExpr());
1951 QualType elementType =
1954 CharUnits elementAlign =
1958 llvm::BasicBlock *entryBB = Builder.GetInsertBlock();
1963 llvm::PHINode *index =
1964 Builder.CreatePHI(zero->getType(), 2,
"arrayinit.index");
1965 index->addIncoming(zero, entryBB);
1966 llvm::Value *element =
1967 Builder.CreateInBoundsGEP(llvmElementType, begin, index);
1971 EHScopeStack::stable_iterator
cleanup;
1973 if (outerBegin->getType() != element->getType())
1974 outerBegin = Builder.CreateBitCast(outerBegin, element->getType());
1987 CodeGenFunction::RunCleanupsScope CleanupsScope(CGF);
1988 CodeGenFunction::ArrayInitLoopExprScope Scope(CGF, index);
1990 Address(element, llvmElementType, elementAlign), elementType);
1998 AggExprEmitter(CGF, elementSlot,
false)
1999 .VisitArrayInitLoopExpr(InnerLoop, outerBegin);
2001 EmitInitializationToLValue(E->
getSubExpr(), elementLV);
2005 llvm::Value *nextIndex = Builder.CreateNUWAdd(
2006 index, llvm::ConstantInt::get(CGF.
SizeTy, 1),
"arrayinit.next");
2007 index->addIncoming(nextIndex, Builder.GetInsertBlock());
2010 llvm::Value *done = Builder.CreateICmpEQ(
2011 nextIndex, llvm::ConstantInt::get(CGF.
SizeTy, numElements),
2014 Builder.CreateCondBr(done, endBB, bodyBB);
2023void AggExprEmitter::VisitDesignatedInitUpdateExpr(
2024 DesignatedInitUpdateExpr *E) {
2025 AggValueSlot Dest = EnsureSlot(E->
getType());
2028 EmitInitializationToLValue(E->
getBase(), DestLV);
2040 if (
auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
2041 E = MTE->getSubExpr();
2052 ILE = dyn_cast<InitListExpr>(ILE->
getInit(0));
2060 if (!RT->isUnionType()) {
2064 unsigned ILEElement = 0;
2065 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(SD))
2066 while (ILEElement != CXXRD->getNumBases())
2069 for (
const auto *Field : SD->
fields()) {
2072 if (Field->getType()->isIncompleteArrayType() ||
2075 if (Field->isUnnamedBitField())
2081 if (Field->getType()->isReferenceType())
2088 return NumNonZeroBytes;
2094 for (
unsigned i = 0, e = ILE->
getNumInits(); i != e; ++i)
2096 return NumNonZeroBytes;
2115 if (RD->hasUserDeclaredConstructor())
2127 if (NumNonZeroBytes * 4 > Size)
2131 llvm::Constant *SizeVal = CGF.
Builder.getInt64(Size.getQuantity());
2146 "Invalid aggregate expression to emit");
2148 "slot has bits but no address");
2153 AggExprEmitter(*
this, Slot, Slot.
isIgnored()).Visit(
const_cast<Expr *
>(E));
2170 return AggExprEmitter(*
this, Dest, Dest.
isIgnored())
2171 .EmitFinalDestCopy(
Type, Src, SrcKind);
2214 getContext().getASTRecordLayout(BaseRD).getSize() <=
2232 assert((
Record->hasTrivialCopyConstructor() ||
2233 Record->hasTrivialCopyAssignment() ||
2234 Record->hasTrivialMoveConstructor() ||
2235 Record->hasTrivialMoveAssignment() ||
2236 Record->hasAttr<TrivialABIAttr>() ||
Record->isUnion()) &&
2237 "Trying to aggregate-copy a type without a trivial copy/move "
2238 "constructor or assignment operator");
2247 if (
getTargetHooks().emitCUDADeviceBuiltinSurfaceDeviceCopy(*
this, Dest,
2251 if (
getTargetHooks().emitCUDADeviceBuiltinTextureDeviceCopy(*
this, Dest,
2258 if (
CGM.getHLSLRuntime().emitBufferCopy(*
this, DestPtr, SrcPtr, Ty))
2281 llvm::Value *SizeVal =
nullptr;
2284 if (
auto *VAT = dyn_cast_or_null<VariableArrayType>(
2290 SizeVal =
Builder.CreateNUWMul(
2319 if (
Record->hasObjectMember()) {
2320 CGM.getObjCRuntime().EmitGCMemmoveCollectable(*
this, DestPtr, SrcPtr,
2326 if (
const auto *
Record = BaseType->getAsRecordDecl()) {
2327 if (
Record->hasObjectMember()) {
2328 CGM.getObjCRuntime().EmitGCMemmoveCollectable(*
this, DestPtr, SrcPtr,
2335 auto *Inst =
Builder.CreateMemCpy(DestPtr, SrcPtr, SizeVal, isVolatile);
2341 if (llvm::MDNode *TBAAStructTag =
CGM.getTBAAStructInfo(Ty))
2342 Inst->setMetadata(llvm::LLVMContext::MD_tbaa_struct, TBAAStructTag);
2344 if (
CGM.getCodeGenOpts().NewStructPathTBAA) {
2347 CGM.DecorateInstructionWithTBAA(Inst, TBAAInfo);
Defines the clang::ASTContext interface.
static CharUnits GetNumNonZeroBytesInInit(const Expr *E, CodeGenFunction &CGF)
GetNumNonZeroBytesInInit - Get an approximate count of the number of non-zero bytes that will be stor...
static Expr * findPeephole(Expr *op, CastKind kind, const ASTContext &ctx)
Attempt to look through various unimportant expressions to find a cast of the given kind.
static bool isBlockVarRef(const Expr *E)
Is the value of the given expression possibly a reference to or into a __block variable?
static bool isSimpleZero(const Expr *E, CodeGenFunction &CGF)
isSimpleZero - If emitting this value will obviously just cause a store of zero to memory,...
static llvm::Value * EmitCompare(CGBuilderTy &Builder, CodeGenFunction &CGF, const BinaryOperator *E, llvm::Value *LHS, llvm::Value *RHS, CompareKind Kind, const char *NameSuffix="")
static void EmitHLSLElementwiseCast(CodeGenFunction &CGF, LValue DestVal, LValue SrcVal, SourceLocation Loc)
static bool castPreservesZero(const CastExpr *CE)
Determine whether the given cast kind is known to always convert values with all zero bits in their v...
static void CheckAggExprForMemSetUse(AggValueSlot &Slot, const Expr *E, CodeGenFunction &CGF)
CheckAggExprForMemSetUse - If the initializer is large and has a lot of zeros in it,...
static void EmitHLSLScalarElementwiseAndSplatCasts(CodeGenFunction &CGF, LValue DestVal, llvm::Value *SrcVal, QualType SrcTy, SourceLocation Loc)
static bool isTrivialFiller(Expr *e)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
llvm::MachO::Record Record
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
static bool isVector(QualType QT, QualType ElementType)
This helper function returns true if QT is a vector type that has element type ElementType.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const ConstantArrayType * getAsConstantArrayType(QualType T) const
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
ComparisonCategories CompCategories
Types and expressions required to build C++2a three-way comparisons using operator<=>,...
QualType removeAddrSpaceQualType(QualType T) const
Remove any existing address space on the type and returns the type with qualifiers intact (or that's ...
int64_t toBits(CharUnits CharSize) const
Convert a size in characters to a size in bits.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
static bool hasSameType(QualType T1, QualType T2)
Determine whether the given types T1 and T2 are equivalent.
QualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const
Return the uniqued reference to the type for an address space qualified type with the specified type ...
unsigned getTargetAddressSpace(LangAS AS) const
static bool hasSameUnqualifiedType(QualType T1, QualType T2)
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
CharUnits getNonVirtualSize() const
getNonVirtualSize - Get the non-virtual size (in chars) of an object, which is the size of the object...
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
llvm::APInt getArraySize() const
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Expr * getSubExpr() const
Get the initializer to use for each array element.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
QualType getElementType() const
A builtin binary operation expression such as "x + y" or "x <= y".
CXXTemporary * getTemporary()
const Expr * getSubExpr() const
Expr * getExpr()
Get the initialization expression that will be used.
bool constructsVBase() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
bool inheritedFromVBase() const
Determine whether the inherited constructor is inherited from a virtual base of the object we constru...
MutableArrayRef< Expr * > getInitExprs()
FieldDecl * getInitializedFieldInUnion()
Represents a C++ struct/union/class.
bool isTriviallyCopyable() const
Determine whether this class is considered trivially copyable per (C++11 [class]p6).
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
CastKind getCastKind() const
CharUnits - This is an opaque type for sizes expressed in character units.
bool isZero() const
isZero - Test whether the quantity equals zero.
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
llvm::Value * getBasePointer() const
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
CharUnits getAlignment() const
llvm::Type * getElementType() const
Return the type of the values stored in this address.
Address withElementType(llvm::Type *ElemTy) const
Return address with different element type, but same pointer and alignment.
void setVolatile(bool flag)
static AggValueSlot ignored()
ignored - Returns an aggregate value slot indicating that the aggregate value is being ignored.
Address getAddress() const
CharUnits getPreferredSize(ASTContext &Ctx, QualType Type) const
Get the preferred size to use when storing a value to this slot.
NeedsGCBarriers_t requiresGCollection() const
void setExternallyDestructed(bool destructed=true)
void setZeroed(bool V=true)
IsZeroed_t isZeroed() const
Qualifiers getQualifiers() const
static AggValueSlot forLValue(const LValue &LV, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
IsAliased_t isPotentiallyAliased() const
static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
forAddr - Make a slot for an aggregate value.
IsDestructed_t isExternallyDestructed() const
Overlap_t mayOverlap() const
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
llvm::CallInst * CreateMemSet(Address Dest, llvm::Value *Value, llvm::Value *Size, bool IsVolatile=false)
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
virtual llvm::Value * EmitMemberPointerComparison(CodeGenFunction &CGF, llvm::Value *L, llvm::Value *R, const MemberPointerType *MPT, bool Inequality)
Emit a comparison between two member pointers. Returns an i1.
void emitInitListOpaqueValues(CodeGenFunction &CGF, InitListExpr *E)
virtual void EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF, Address DestPtr, Address SrcPtr, llvm::Value *Size)=0
const CGBitFieldInfo & getBitFieldInfo(const FieldDecl *FD) const
Return the BitFieldInfo that corresponds to the field FD.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
void CreateCoercedStore(llvm::Value *Src, Address Dst, llvm::TypeSize DstSize, bool DstIsVolatile)
Create a store to.
void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, llvm::BasicBlock *FalseBlock, uint64_t TrueCount, Stmt::Likelihood LH=Stmt::LH_None, const Expr *ConditionalOp=nullptr, const VarDecl *ConditionalDecl=nullptr)
EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g.
RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, ReturnValueSlot Return=ReturnValueSlot())
void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest)
AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *FD)
Determine whether a field initialization may overlap some other object.
@ UseSkipPath
Skip (false)
void callCStructMoveConstructor(LValue Dst, LValue Src)
void EmitNullInitialization(Address DestPtr, QualType Ty)
EmitNullInitialization - Generate code to set a value of the given type to null, If the type contains...
static bool hasScalarEvaluationKind(QualType T)
llvm::Type * ConvertType(QualType T)
void EmitAggFinalDestCopy(QualType Type, AggValueSlot Dest, const LValue &Src, ExprValueKind SrcKind)
EmitAggFinalDestCopy - Emit copy of the specified aggregate into destination address.
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...
void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint=true)
void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, llvm::Value **Result=nullptr)
EmitStoreThroughBitfieldLValue - Store Src into Dst with same constraints as EmitStoreThroughLValue.
bool hasVolatileMember(QualType T)
hasVolatileMember - returns true if aggregate type has a volatile member.
llvm::SmallVector< DeferredDeactivateCleanup > DeferredDeactivationCleanupStack
RValue EmitVAArg(VAArgExpr *VE, Address &VAListAddr, AggValueSlot Slot=AggValueSlot::ignored())
Generate code to get an argument from the passed in pointer and update it accordingly.
RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, AggValueSlot slot=AggValueSlot::ignored())
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
void addInstToCurrentSourceAtom(llvm::Instruction *KeyInstruction, llvm::Value *Backup)
See CGDebugInfo::addInstToCurrentSourceAtom.
AggValueSlot::Overlap_t getOverlapForBaseInit(const CXXRecordDecl *RD, const CXXRecordDecl *BaseRD, bool IsVirtual)
Determine whether a base class initialization may overlap some other object.
const LangOptions & getLangOpts() const
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E)
void pushDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
pushDestroy - Push the standard destructor for the given type as at least a normal cleanup.
@ TCK_Store
Checking the destination of a store. Must be suitably sized and aligned.
@ TCK_Load
Checking the operand of a load. Must be suitably sized and aligned.
void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin, Address arrayEndPointer, QualType elementType, CharUnits elementAlignment, Destroyer *destroyer)
pushIrregularPartialArrayCleanup - Push a NormalAndEHCleanup to destroy already-constructed elements ...
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
LValue EmitPseudoObjectLValue(const PseudoObjectExpr *e)
void EmitAggregateCopy(LValue Dest, LValue Src, QualType EltTy, AggValueSlot::Overlap_t MayOverlap, bool isVolatile=false)
EmitAggregateCopy - Emit an aggregate copy.
const TargetInfo & getTarget() const
void EmitIgnoredExpr(const Expr *E)
EmitIgnoredExpr - Emit an expression in a context which ignores the result.
RValue EmitCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue=ReturnValueSlot(), llvm::CallBase **CallOrInvoke=nullptr)
RValue EmitLoadOfLValue(LValue V, SourceLocation Loc)
EmitLoadOfLValue - Given an expression that represents a value lvalue, this method emits the address ...
void pushDestroyAndDeferDeactivation(QualType::DestructionKind dtorKind, Address addr, QualType type)
void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *DominatingIP)
DeactivateCleanupBlock - Deactivates the given cleanup block.
void callCStructCopyAssignmentOperator(LValue Dst, LValue Src)
void pushFullExprCleanup(CleanupKind kind, As... A)
pushFullExprCleanup - Push a cleanup to be run at the end of the current full-expression.
LValue EmitAggExprToLValue(const Expr *E)
EmitAggExprToLValue - Emit the computation of the specified expression of aggregate type into a tempo...
RValue EmitCoyieldExpr(const CoyieldExpr &E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
AggValueSlot CreateAggTemp(QualType T, const Twine &Name="tmp", RawAddress *Alloca=nullptr)
CreateAggTemp - Create a temporary memory object for the given aggregate type.
llvm::Value * emitArrayLength(const ArrayType *arrayType, QualType &baseType, Address &addr)
emitArrayLength - Compute the length of an array, even if it's a VLA, and drill down to the base elem...
void callCStructCopyConstructor(LValue Dst, LValue Src)
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
RValue EmitAtomicLoad(LValue LV, SourceLocation SL, AggValueSlot Slot=AggValueSlot::ignored())
CGDebugInfo * getDebugInfo()
llvm::Value * getTypeSize(QualType Ty)
Returns calculated size of the specified type.
bool EmitLifetimeStart(llvm::Value *Addr)
Emit a lifetime.begin marker if some criteria are satisfied.
LValue EmitLValueForFieldInitialization(LValue Base, const FieldDecl *Field)
EmitLValueForFieldInitialization - Like EmitLValueForField, except that if the Field is a reference,...
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...
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...
LValue getOrCreateOpaqueLValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its LValue mapping if it exists, otherwise create one.
const TargetCodeGenInfo & getTargetHooks() const
void EmitLifetimeEnd(llvm::Value *Addr)
RawAddress CreateMemTempWithoutCast(QualType T, const Twine &Name="tmp")
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen without...
void callCStructMoveAssignmentOperator(LValue Dst, LValue Src)
ASTContext & getContext() const
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
EmitStoreThroughLValue - Store the specified rvalue into the specified lvalue, where both are guarant...
void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
Address EmitCompoundStmt(const CompoundStmt &S, bool GetLast=false, AggValueSlot AVS=AggValueSlot::ignored())
EmitCompoundStmt - Emit a compound statement {..} node.
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.
bool needsEHCleanup(QualType::DestructionKind kind)
Determines whether an EH cleanup is required to destroy a type with the given destruction kind.
CleanupKind getCleanupKind(QualType::DestructionKind kind)
llvm::Type * ConvertTypeForMem(QualType T)
RValue EmitAtomicExpr(AtomicExpr *E)
CodeGenTypes & getTypes() const
void FlattenAccessAndTypeLValue(LValue LVal, SmallVectorImpl< LValue > &AccessList)
RValue EmitCoawaitExpr(const CoawaitExpr &E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType, Address Ptr)
Emits all the code to cause the given temporary to be cleaned up.
bool LValueIsSuitableForInlineAtomic(LValue Src)
An LValue is a candidate for having its loads and stores be made atomic if we are operating under /vo...
LValue EmitCheckedLValue(const Expr *E, TypeCheckKind TCK)
Same as EmitLValue but additionally we generate checking code to guard against undefined behavior.
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...
RawAddress CreateMemTemp(QualType T, const Twine &Name="tmp", RawAddress *Alloca=nullptr)
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen and cas...
void EmitInitializationToLValue(const Expr *E, LValue LV, AggValueSlot::IsZeroed_t IsZeroed=AggValueSlot::IsNotZeroed)
EmitInitializationToLValue - Emit an initializer to an LValue.
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type.
static bool hasAggregateEvaluationKind(QualType T)
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
void EmitLambdaVLACapture(const VariableArrayType *VAT, LValue LV)
void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit)
uint64_t getProfileCount(const Stmt *S)
Get the profiler's count for the given statement.
void ErrorUnsupported(const Stmt *S, const char *Type)
ErrorUnsupported - Print out an error that codegen doesn't support the specified stmt yet.
LValue EmitLValue(const Expr *E, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
EmitLValue - Emit code to compute a designator that specifies the location of the expression.
llvm::LLVMContext & getLLVMContext()
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV=nullptr)
Increment the profiler's counter for the given statement by StepV.
llvm::Value * EmitScalarConversion(llvm::Value *Src, QualType SrcTy, QualType DstTy, SourceLocation Loc)
Emit a conversion from the specified type to the specified destination type, both of which are LLVM s...
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...
llvm::Value * EmitDynamicCast(Address V, const CXXDynamicCastExpr *DCE)
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
void EmitExplicitCastExprType(const ExplicitCastExpr *E, CodeGenFunction *CGF=nullptr)
Emit type info if type of an expression is a variably modified type.
CGHLSLRuntime & getHLSLRuntime()
Return a reference to the configured HLSL runtime.
llvm::Module & getModule() const
bool isPaddedAtomicType(QualType type)
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
CGCXXABI & getCXXABI() const
ASTContext & getContext() const
bool shouldZeroInitPadding() const
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
llvm::Constant * EmitNullConstant(QualType T)
Return the result of value-initializing the given type, i.e.
LangAS GetGlobalConstantAddressSpace() const
Return the AST address space of constant literal, which is used to emit the constant literal as globa...
bool isPointerZeroInitializable(QualType T)
Check if the pointer type can be zero-initialized (in the C++ sense) with an LLVM zeroinitializer.
const CGRecordLayout & getCGRecordLayout(const RecordDecl *)
getCGRecordLayout - Return record layout info for the given record decl.
bool isZeroInitializable(QualType T)
IsZeroInitializable - Return whether a type can be zero-initialized (in the C++ sense) with an LLVM z...
stable_iterator stable_begin() const
Create a stable reference to the top of the EH stack.
iterator find(stable_iterator save) const
Turn a stable reference to a scope depth into a unstable pointer to the EH stack.
LValue - This represents an lvalue references.
Address getAddress() const
TBAAAccessInfo getTBAAInfo() const
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
llvm::Value * getAggregatePointer(QualType PointeeType, CodeGenFunction &CGF) const
static RValue get(llvm::Value *V)
static RValue getAggregate(Address addr, bool isVolatile=false)
Convert an Address to an RValue.
Address getAggregateAddress() const
getAggregateAddr() - Return the Value* of the address of the aggregate.
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
std::pair< llvm::Value *, llvm::Value * > getComplexVal() const
getComplexVal - Return the real/imag components of this complex value.
const ComparisonCategoryInfo & getInfoForType(QualType Ty) const
Return the comparison category information as specified by getCategoryForType(Ty).
bool isPartial() const
True iff the comparison is not totally ordered.
const ValueInfo * getLess() const
const ValueInfo * getUnordered() const
const CXXRecordDecl * Record
The declaration for the comparison category type from the standard library.
const ValueInfo * getGreater() const
const ValueInfo * getEqualOrEquiv() const
Complex values, per C99 6.2.5p11.
const Expr * getInitializer() const
llvm::APInt getSize() const
Return the constant array size as an APInt.
A reference to a declared variable, function, enum, etc.
InitListExpr * getUpdater() const
This represents one expression.
Expr * IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY
Skip past any parentheses and casts which do not change the value (including ptr->int casts of the sa...
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Represents a member of a struct/union/class.
bool isBitField() const
Determines whether this field is a bitfield.
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
const Expr * getSubExpr() const
Describes an C or C++ initializer list.
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic,...
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
unsigned getNumInits() const
bool hadArrayRangeDesignator() const
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
const Expr * getInit(unsigned Init) const
ArrayRef< Expr * > inits()
capture_init_iterator capture_init_end()
Retrieve the iterator pointing one past the last initialization argument for this lambda expression.
Expr *const * const_capture_init_iterator
Const iterator that walks over the capture initialization arguments.
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
A pointer to member type per C++ 8.3.3 - Pointers to members.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Expr * getSelectedExpr() const
const Expr * getSubExpr() const
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
bool isTriviallyCopyableType(const ASTContext &Context) const
Return true if this is a trivially copyable type (C++0x [basic.types]p9)
LangAS getAddressSpace() const
Return the address space of this type.
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
@ PCK_Struct
The type is a struct containing a field whose type is neither PCK_Trivial nor PCK_VolatileTrivial.
Represents a struct/union/class.
bool hasObjectMember() const
field_range fields() const
specific_decl_iterator< FieldDecl > field_iterator
RecordDecl * getDefinitionOrSelf() const
field_iterator field_begin() const
Encodes a location in the source.
CompoundStmt * getSubStmt()
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Expr * getReplacement() const
uint64_t getPointerWidth(LangAS AddrSpace) const
Return the width of pointers on this target, for the specified address space.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isConstantArrayType() const
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isPointerType() const
bool isReferenceType() const
bool isScalarType() const
bool isVariableArrayType() const
bool isCUDADeviceBuiltinSurfaceType() const
Check if the type is the CUDA device builtin surface type.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
RecordDecl * castAsRecordDecl() const
bool isAnyComplexType() const
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g....
bool isMemberPointerType() const
bool isCUDADeviceBuiltinTextureType() const
Check if the type is the CUDA device builtin texture type.
bool hasFloatingRepresentation() const
Determine whether this type has a floating-point representation of some sort, e.g....
bool isVectorType() const
bool isRealFloatingType() const
Floating point categories.
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
const T * getAs() const
Member-template getAs<specific type>'.
bool isNullPtrType() const
bool isRecordType() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Expr * getSubExpr() const
Represents a variable declaration or definition.
Represents a GCC generic vector type.
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
@ EHCleanup
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< AtomicType > atomicType
bool GE(InterpState &S, CodePtr OpPC)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
@ Result
The result type of a method or function.
const FunctionProtoType * T
LangAS
Defines the address space values used by the address space qualifier of QualType.
CastKind
CastKind - The kind of operation required for a conversion.
U cast(CodeGen::Address addr)
CharUnits StorageOffset
The offset of the bitfield storage from the start of the struct.
unsigned StorageSize
The storage size in bits which should be used when accessing this bitfield.
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
llvm::IntegerType * CharTy
char
llvm::IntegerType * SizeTy
llvm::PointerType * Int8PtrTy
llvm::IntegerType * PtrDiffTy
CharUnits getPointerAlign() const