29#include "llvm/IR/Constants.h"
30#include "llvm/IR/Function.h"
31#include "llvm/IR/GlobalVariable.h"
32#include "llvm/IR/Instruction.h"
33#include "llvm/IR/IntrinsicInst.h"
34#include "llvm/IR/Intrinsics.h"
43class AggExprEmitter :
public StmtVisitor<AggExprEmitter> {
49 AggValueSlot EnsureSlot(QualType
T) {
54 void EnsureDest(QualType
T) {
66 void withReturnValueSlot(
const Expr *E,
67 llvm::function_ref<RValue(ReturnValueSlot)> Fn);
70 const FieldDecl *NextField);
73 AggExprEmitter(CodeGenFunction &cgf, AggValueSlot Dest,
bool IsResultUnused)
74 : CGF(cgf), Builder(CGF.Builder), Dest(Dest),
75 IsResultUnused(IsResultUnused) {}
84 void EmitAggLoadOfLValue(
const Expr *E);
88 void EmitFinalDestCopy(QualType
type,
const LValue &src,
91 void EmitFinalDestCopy(QualType
type, RValue src);
92 void EmitCopy(QualType
type,
const AggValueSlot &dest,
93 const AggValueSlot &src);
95 void EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, QualType ArrayQTy,
96 Expr *ExprToVisit, ArrayRef<Expr *> Args,
99 void EmitComparisonResult(
const Expr *E,
100 const ComparisonCategoryInfo &CmpInfo,
101 llvm::Value *ResultValue);
104 if (CGF.
getLangOpts().getGC() && TypeRequiresGCollection(
T))
109 bool TypeRequiresGCollection(QualType
T);
115 void Visit(Expr *E) {
116 ApplyDebugLocation DL(CGF, E);
117 StmtVisitor<AggExprEmitter>::Visit(E);
120 void VisitStmt(Stmt *S) { CGF.
ErrorUnsupported(S,
"aggregate expression"); }
121 void VisitParenExpr(ParenExpr *PE) { Visit(PE->
getSubExpr()); }
122 void VisitGenericSelectionExpr(GenericSelectionExpr *GE) {
123 Visit(
GE->getResultExpr());
125 void VisitCoawaitExpr(CoawaitExpr *E) {
128 void VisitCoyieldExpr(CoyieldExpr *E) {
131 void VisitUnaryCoawait(UnaryOperator *E) { Visit(E->
getSubExpr()); }
132 void VisitUnaryExtension(UnaryOperator *E) { Visit(E->
getSubExpr()); }
133 void VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E) {
137 void VisitConstantExpr(ConstantExpr *E) {
140 if (llvm::Value *
Result = ConstantEmitter(CGF).tryEmitConstantExpr(E)) {
143 llvm::TypeSize::getFixed(
153 void VisitDeclRefExpr(DeclRefExpr *E) { EmitAggLoadOfLValue(E); }
154 void VisitMemberExpr(MemberExpr *ME) { EmitAggLoadOfLValue(ME); }
155 void VisitUnaryDeref(UnaryOperator *E) { EmitAggLoadOfLValue(E); }
156 void VisitStringLiteral(StringLiteral *E) { EmitAggLoadOfLValue(E); }
157 void VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
158 void VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
159 EmitAggLoadOfLValue(E);
161 void VisitPredefinedExpr(
const PredefinedExpr *E) { EmitAggLoadOfLValue(E); }
165 void VisitCallExpr(
const CallExpr *E);
166 void VisitStmtExpr(
const StmtExpr *E);
167 void VisitBinaryOperator(
const BinaryOperator *BO);
168 void VisitPointerToDataMemberBinaryOperator(
const BinaryOperator *BO);
169 void VisitBinAssign(
const BinaryOperator *E);
170 void VisitBinComma(
const BinaryOperator *E);
171 void VisitBinCmp(
const BinaryOperator *E);
172 void VisitTypeTraitExpr(
const TypeTraitExpr *E);
173 void VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *E) {
177 void VisitObjCMessageExpr(ObjCMessageExpr *E);
178 void VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { EmitAggLoadOfLValue(E); }
180 void VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E);
181 void VisitAbstractConditionalOperator(
const AbstractConditionalOperator *CO);
182 void VisitChooseExpr(
const ChooseExpr *CE);
183 void VisitInitListExpr(InitListExpr *E);
184 void VisitCXXParenListOrInitListExpr(Expr *ExprToVisit, ArrayRef<Expr *> Args,
185 FieldDecl *InitializedFieldInUnion,
187 void VisitArrayInitLoopExpr(
const ArrayInitLoopExpr *E,
188 llvm::Value *outerBegin =
nullptr);
189 void VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
190 void VisitNoInitExpr(NoInitExpr *E) {}
191 void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) {
192 CodeGenFunction::CXXDefaultArgExprScope Scope(CGF, DAE);
195 void VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) {
196 CodeGenFunction::CXXDefaultInitExprScope Scope(CGF, DIE);
199 void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
200 void VisitCXXConstructExpr(
const CXXConstructExpr *E);
201 void VisitCXXInheritedCtorInitExpr(
const CXXInheritedCtorInitExpr *E);
203 void VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E);
204 void VisitExprWithCleanups(ExprWithCleanups *E);
205 void VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E);
206 void VisitCXXTypeidExpr(CXXTypeidExpr *E) { EmitAggLoadOfLValue(E); }
207 void VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E);
208 void VisitOpaqueValueExpr(OpaqueValueExpr *E);
210 void VisitPseudoObjectExpr(PseudoObjectExpr *E) {
213 return EmitFinalDestCopy(E->
getType(), LV);
216 AggValueSlot Slot = EnsureSlot(E->
getType());
217 bool NeedsDestruction =
220 if (NeedsDestruction)
223 if (NeedsDestruction)
228 void VisitVAArgExpr(VAArgExpr *E);
229 void VisitCXXParenListInitExpr(CXXParenListInitExpr *E);
231 void EmitInitializationToLValue(Expr *E, LValue Address);
232 void EmitNullInitializationToLValue(LValue Address);
235 void VisitAtomicExpr(AtomicExpr *E) {
237 EmitFinalDestCopy(E->
getType(), Res);
239 void VisitPackIndexingExpr(PackIndexingExpr *E) {
252void AggExprEmitter::EmitAggLoadOfLValue(
const Expr *E) {
265 EmitFinalDestCopy(E->
getType(), LV);
269bool AggExprEmitter::TypeRequiresGCollection(QualType
T) {
285void AggExprEmitter::withReturnValueSlot(
286 const Expr *E, llvm::function_ref<RValue(ReturnValueSlot)> EmitCall) {
288 bool RequiresDestruction =
304 bool CanAggregateCopy =
309 : RetTy.isTriviallyCopyableType(CGF.getContext());
310 bool DestASMismatch = !Dest.
isIgnored() && CanAggregateCopy &&
313 ->stripPointerCasts()
315 ->getPointerAddressSpace() != SRetAS;
317 (RequiresDestruction && Dest.
isIgnored()) || DestASMismatch;
321 EHScopeStack::stable_iterator LifetimeEndBlock;
322 llvm::IntrinsicInst *LifetimeStartInst =
nullptr;
325 if (RetAddr.isValid() && RetAddr.getAddressSpace() != SRetAS) {
326 llvm::Type *SRetPtrTy =
328 RetAddr = RetAddr.withPointer(
330 RetAddr.isKnownNonNull());
337 assert(LifetimeStartInst->getIntrinsicID() ==
338 llvm::Intrinsic::lifetime_start &&
339 "Last insertion wasn't a lifetime.start?");
348 EmitCall(ReturnValueSlot(RetAddr, Dest.
isVolatile(), IsResultUnused,
356 EmitFinalDestCopy(E->
getType(), Src);
358 if (!RequiresDestruction && LifetimeStartInst) {
368void AggExprEmitter::EmitFinalDestCopy(QualType
type, RValue src) {
369 assert(src.
isAggregate() &&
"value must be aggregate value!");
375void AggExprEmitter::EmitFinalDestCopy(
376 QualType
type,
const LValue &src,
410 EmitCopy(
type, Dest, srcAgg);
417void AggExprEmitter::EmitCopy(QualType
type,
const AggValueSlot &dest,
418 const AggValueSlot &src) {
438void AggExprEmitter::VisitCXXStdInitializerListExpr(
439 CXXStdInitializerListExpr *E) {
444 assert(
Array.isSimple() &&
"initializer_list array not a simple lvalue");
447 const ConstantArrayType *ArrayType =
449 assert(ArrayType &&
"std::initializer_list constructed from non-array");
453 assert(Field !=
Record->field_end() &&
456 "Expected std::initializer_list first field to be const E *");
459 AggValueSlot Dest = EnsureSlot(E->
getType());
465 assert(Field !=
Record->field_end() &&
466 "Expected std::initializer_list to have two fields");
468 llvm::Value *
Size = Builder.getInt(ArrayType->
getSize());
476 assert(
Field->getType()->isPointerType() &&
479 "Expected std::initializer_list second field to be const E *");
480 llvm::Value *
Zero = llvm::ConstantInt::get(CGF.
PtrDiffTy, 0);
481 llvm::Value *IdxEnd[] = {
Zero,
Size};
482 llvm::Value *ArrayEnd = Builder.CreateInBoundsGEP(
488 assert(++Field ==
Record->field_end() &&
489 "Expected std::initializer_list to only have two fields");
506 SrcTy = VT->getElementType();
507 assert(StoreList.size() <= VT->getNumElements() &&
508 "Cannot perform HLSL flat cast when vector source \
509 object has less elements than flattened destination \
513 for (
unsigned I = 0, Size = StoreList.size(); I < Size; I++) {
514 LValue DestLVal = StoreList[I];
534 assert(StoreList.size() <= LoadList.size() &&
535 "Cannot perform HLSL elementwise cast when flattened source object \
536 has less elements than flattened destination object.");
539 for (
unsigned I = 0, E = StoreList.size(); I < E; I++) {
540 LValue DestLVal = StoreList[I];
541 LValue SrcLVal = LoadList[I];
543 assert(RVal.
isScalar() &&
"All flattened source values should be scalars");
546 DestLVal.getType(), Loc);
553void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType,
554 QualType ArrayQTy, Expr *ExprToVisit,
555 ArrayRef<Expr *> Args, Expr *ArrayFiller) {
556 uint64_t NumInitElements = Args.size();
558 uint64_t NumArrayElements = AType->getNumElements();
559 for (
const auto *
Init : Args) {
560 if (
const auto *Embed = dyn_cast<EmbedExpr>(
Init->IgnoreParenImpCasts())) {
561 NumInitElements += Embed->getDataElementCount() - 1;
562 if (NumInitElements > NumArrayElements) {
563 NumInitElements = NumArrayElements;
569 assert(NumInitElements <= NumArrayElements);
571 QualType elementType =
574 CharUnits elementAlign =
581 if (NumInitElements * elementSize.
getQuantity() > 16 &&
583 CodeGen::CodeGenModule &CGM = CGF.
CGM;
584 ConstantEmitter Emitter(CGF);
589 if (llvm::Constant *
C =
590 Emitter.tryEmitForInitializer(ExprToVisit, AS, GVArrayQTy)) {
591 auto GV =
new llvm::GlobalVariable(
593 true, llvm::GlobalValue::PrivateLinkage,
C,
595 nullptr, llvm::GlobalVariable::NotThreadLocal,
597 Emitter.finalize(GV);
600 Address GVAddr(GV, GV->getValueType(), Align);
601 EmitFinalDestCopy(ArrayQTy, CGF.
MakeAddrLValue(GVAddr, GVArrayQTy));
611 CodeGenFunction::CleanupDeactivationScope deactivation(CGF);
615 CodeGenFunction::AllocaTrackerRAII allocaTracker(CGF);
620 llvm::Instruction *dominatingIP =
621 Builder.CreateFlagLoad(llvm::ConstantInt::getNullValue(CGF.
Int8PtrTy));
623 "arrayinit.endOfInit");
624 Builder.CreateStore(begin, endOfInit);
629 .AddAuxAllocas(allocaTracker.Take());
635 llvm::Value *one = llvm::ConstantInt::get(CGF.
SizeTy, 1);
638 llvm::Value *element = begin;
639 if (ArrayIndex > 0) {
641 element = Builder.CreateStructuredGEP(
642 AType, begin, llvm::ConstantInt::get(CGF.
SizeTy, ArrayIndex),
643 "arrayinit.element");
645 element = Builder.CreateInBoundsGEP(
646 llvmElementType, begin,
647 llvm::ConstantInt::get(CGF.
SizeTy, ArrayIndex),
648 "arrayinit.element");
654 Builder.CreateStore(element, endOfInit);
658 Address(element, llvmElementType, elementAlign), elementType);
659 EmitInitializationToLValue(
Init, elementLV);
663 unsigned ArrayIndex = 0;
665 for (
uint64_t i = 0; i != NumInitElements; ++i) {
666 if (ArrayIndex >= NumInitElements)
668 if (
auto *EmbedS = dyn_cast<EmbedExpr>(Args[i]->IgnoreParenImpCasts())) {
669 EmbedS->doForEachDataElement(Emit, ArrayIndex);
671 Emit(Args[i], ArrayIndex);
682 if (NumInitElements != NumArrayElements &&
683 !(Dest.
isZeroed() && hasTrivialFiller &&
690 llvm::Value *element = begin;
691 if (NumInitElements) {
692 element = Builder.CreateInBoundsGEP(
693 llvmElementType, element,
694 llvm::ConstantInt::get(CGF.
SizeTy, NumInitElements),
697 Builder.CreateStore(element, endOfInit);
701 llvm::Value *end = Builder.CreateInBoundsGEP(
702 llvmElementType, begin,
703 llvm::ConstantInt::get(CGF.
SizeTy, NumArrayElements),
"arrayinit.end");
705 llvm::BasicBlock *entryBB = Builder.GetInsertBlock();
710 llvm::PHINode *currentElement =
711 Builder.CreatePHI(element->getType(), 2,
"arrayinit.cur");
712 currentElement->addIncoming(element, entryBB);
724 CodeGenFunction::RunCleanupsScope CleanupsScope(CGF);
726 Address(currentElement, llvmElementType, elementAlign), elementType);
728 EmitInitializationToLValue(ArrayFiller, elementLV);
730 EmitNullInitializationToLValue(elementLV);
734 llvm::Value *nextElement = Builder.CreateInBoundsGEP(
735 llvmElementType, currentElement, one,
"arrayinit.next");
739 Builder.CreateStore(nextElement, endOfInit);
743 Builder.CreateICmpEQ(nextElement, end,
"arrayinit.done");
745 Builder.CreateCondBr(done, endBB, bodyBB);
746 currentElement->addIncoming(nextElement, Builder.GetInsertBlock());
759void AggExprEmitter::VisitMaterializeTemporaryExpr(
760 MaterializeTemporaryExpr *E) {
764void AggExprEmitter::VisitOpaqueValueExpr(OpaqueValueExpr *e) {
772void AggExprEmitter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
776 EmitAggLoadOfLValue(E);
780 AggValueSlot Slot = EnsureSlot(E->
getType());
801 if (
auto castE = dyn_cast<CastExpr>(op)) {
802 if (castE->getCastKind() ==
kind)
803 return castE->getSubExpr();
808void AggExprEmitter::VisitCastExpr(
CastExpr *E) {
809 if (
const auto *ECE = dyn_cast<ExplicitCastExpr>(E))
844 case CK_LValueToRValueBitCast: {
852 Address SourceAddress = SourceLV.getAddress().withElementType(CGF.
Int8Ty);
854 llvm::Value *SizeVal = llvm::ConstantInt::get(
857 Builder.CreateMemCpy(DestAddress, SourceAddress, SizeVal);
861 case CK_DerivedToBase: {
863 "Derived/Base casts in EmitAggExpr are only supported in HLSL");
874 AggValueSlot DestBaseSlot = Dest;
875 Dest = DerivedTmpSlot;
894 EmitCopy(E->
getType(), DestBaseSlot, SrcBaseSlot);
899 case CK_BaseToDerived:
900 case CK_UncheckedDerivedToBase: {
901 llvm_unreachable(
"cannot perform hierarchy conversion in EmitAggExpr: "
902 "should have been unpacked before we got here");
905 case CK_NonAtomicToAtomic:
906 case CK_AtomicToNonAtomic: {
907 bool isToAtomic = (E->
getCastKind() == CK_NonAtomicToAtomic);
911 QualType valueType = E->
getType();
917 valueType,
atomicType->castAs<AtomicType>()->getValueType()));
926 (isToAtomic ? CK_AtomicToNonAtomic : CK_NonAtomicToAtomic);
933 "peephole significantly changed types?");
940 AggValueSlot valueDest = Dest;
963 AggValueSlot atomicSlot =
969 return EmitFinalDestCopy(valueType, rvalue);
971 case CK_AddressSpaceConversion:
974 case CK_LValueToRValue:
995 case CK_HLSLArrayRValue:
1002 case CK_HLSLAggregateSplatCast: {
1004 QualType SrcTy = Src->
getType();
1010 "RHS of HLSL splat cast must be a scalar.");
1015 case CK_HLSLElementwiseCast: {
1017 QualType SrcTy = Src->
getType();
1025 "HLSL Elementwise cast doesn't handle splatting.");
1029 "Can't perform HLSL Aggregate cast on a complex type.");
1037 case CK_UserDefinedConversion:
1038 case CK_ConstructorConversion:
1041 "Implicit cast types must be compatible");
1045 case CK_LValueBitCast:
1046 llvm_unreachable(
"should not be emitting lvalue bitcast as rvalue");
1050 case CK_ArrayToPointerDecay:
1051 case CK_FunctionToPointerDecay:
1052 case CK_NullToPointer:
1053 case CK_NullToMemberPointer:
1054 case CK_BaseToDerivedMemberPointer:
1055 case CK_DerivedToBaseMemberPointer:
1056 case CK_MemberPointerToBoolean:
1057 case CK_ReinterpretMemberPointer:
1058 case CK_IntegralToPointer:
1059 case CK_PointerToIntegral:
1060 case CK_PointerToBoolean:
1062 case CK_VectorSplat:
1063 case CK_IntegralCast:
1064 case CK_BooleanToSignedIntegral:
1065 case CK_IntegralToBoolean:
1066 case CK_IntegralToFloating:
1067 case CK_FloatingToIntegral:
1068 case CK_FloatingToBoolean:
1069 case CK_FloatingCast:
1070 case CK_CPointerToObjCPointerCast:
1071 case CK_BlockPointerToObjCPointerCast:
1072 case CK_AnyPointerToBlockPointerCast:
1073 case CK_ObjCObjectLValueCast:
1074 case CK_FloatingRealToComplex:
1075 case CK_FloatingComplexToReal:
1076 case CK_FloatingComplexToBoolean:
1077 case CK_FloatingComplexCast:
1078 case CK_FloatingComplexToIntegralComplex:
1079 case CK_IntegralRealToComplex:
1080 case CK_IntegralComplexToReal:
1081 case CK_IntegralComplexToBoolean:
1082 case CK_IntegralComplexCast:
1083 case CK_IntegralComplexToFloatingComplex:
1084 case CK_ARCProduceObject:
1085 case CK_ARCConsumeObject:
1086 case CK_ARCReclaimReturnedObject:
1087 case CK_ARCExtendBlockObject:
1088 case CK_CopyAndAutoreleaseBlockObject:
1089 case CK_BuiltinFnToFnPtr:
1090 case CK_ZeroToOCLOpaqueType:
1092 case CK_HLSLVectorTruncation:
1093 case CK_HLSLMatrixTruncation:
1094 case CK_IntToOCLSampler:
1095 case CK_FloatingToFixedPoint:
1096 case CK_FixedPointToFloating:
1097 case CK_FixedPointCast:
1098 case CK_FixedPointToBoolean:
1099 case CK_FixedPointToIntegral:
1100 case CK_IntegralToFixedPoint:
1101 llvm_unreachable(
"cast kind invalid for aggregate types");
1105void AggExprEmitter::VisitCallExpr(
const CallExpr *E) {
1107 EmitAggLoadOfLValue(E);
1111 withReturnValueSlot(
1112 E, [&](ReturnValueSlot Slot) {
return CGF.
EmitCallExpr(E, Slot); });
1115void AggExprEmitter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
1116 withReturnValueSlot(E, [&](ReturnValueSlot Slot) {
1121void AggExprEmitter::VisitBinComma(
const BinaryOperator *E) {
1126void AggExprEmitter::VisitStmtExpr(
const StmtExpr *E) {
1127 CodeGenFunction::StmtExprEvaluation eval(CGF);
1140 const char *NameSuffix =
"") {
1143 ArgTy = CT->getElementType();
1147 "member pointers may only be compared for equality");
1149 CGF, LHS, RHS, MPT,
false);
1153 struct CmpInstInfo {
1155 llvm::CmpInst::Predicate FCmp;
1156 llvm::CmpInst::Predicate SCmp;
1157 llvm::CmpInst::Predicate UCmp;
1159 CmpInstInfo InstInfo = [&]() -> CmpInstInfo {
1160 using FI = llvm::FCmpInst;
1161 using II = llvm::ICmpInst;
1164 return {
"cmp.lt", FI::FCMP_OLT, II::ICMP_SLT, II::ICMP_ULT};
1166 return {
"cmp.gt", FI::FCMP_OGT, II::ICMP_SGT, II::ICMP_UGT};
1168 return {
"cmp.eq", FI::FCMP_OEQ, II::ICMP_EQ, II::ICMP_EQ};
1170 llvm_unreachable(
"Unrecognised CompareKind enum");
1174 return Builder.CreateFCmp(InstInfo.FCmp, LHS, RHS,
1175 llvm::Twine(InstInfo.Name) + NameSuffix);
1179 return Builder.CreateICmp(Inst, LHS, RHS,
1180 llvm::Twine(InstInfo.Name) + NameSuffix);
1183 llvm_unreachable(
"unsupported aggregate binary expression should have "
1184 "already been handled");
1187void AggExprEmitter::EmitComparisonResult(
const Expr *E,
1188 const ComparisonCategoryInfo &CmpInfo,
1189 llvm::Value *ResultValue) {
1202void AggExprEmitter::VisitBinCmp(
const BinaryOperator *E) {
1203 using llvm::BasicBlock;
1204 using llvm::PHINode;
1208 const ComparisonCategoryInfo &CmpInfo =
1211 "cannot copy non-trivially copyable aggregate");
1223 auto EmitOperand = [&](Expr *E) -> std::pair<Value *, Value *> {
1232 auto LHSValues = EmitOperand(E->
getLHS()),
1233 RHSValues = EmitOperand(E->
getRHS());
1237 K, IsComplex ?
".r" :
"");
1242 RHSValues.second, K,
".i");
1243 return Builder.CreateAnd(
Cmp, CmpImag,
"and.eq");
1245 auto EmitCmpRes = [&](
const ComparisonCategoryInfo::ValueInfo *VInfo) {
1246 return Builder.getInt(VInfo->getIntValue());
1254 Builder.CreateSelect(EmitCmp(
CK_Less), EmitCmpRes(CmpInfo.
getLess()),
1256 Select = Builder.CreateSelect(EmitCmp(
CK_Equal),
1258 SelectOne,
"sel.eq");
1260 Value *SelectEq = Builder.CreateSelect(
1265 SelectEq,
"sel.gt");
1266 Select = Builder.CreateSelect(
1267 EmitCmp(
CK_Less), EmitCmpRes(CmpInfo.
getLess()), SelectGT,
"sel.lt");
1270 EmitComparisonResult(E, CmpInfo, Select);
1273void AggExprEmitter::VisitTypeTraitExpr(
const TypeTraitExpr *E) {
1275 "expected a strong_ordering type trait with a stored value");
1277 const ComparisonCategoryInfo &CmpInfo =
1281 llvm::Value *ResultValue =
1284 EmitComparisonResult(E, CmpInfo, ResultValue);
1287void AggExprEmitter::VisitBinaryOperator(
const BinaryOperator *E) {
1289 VisitPointerToDataMemberBinaryOperator(E);
1294void AggExprEmitter::VisitPointerToDataMemberBinaryOperator(
1295 const BinaryOperator *E) {
1297 EmitFinalDestCopy(E->
getType(), LV);
1300void AggExprEmitter::VisitBinAssign(
const BinaryOperator *E) {
1306 "Invalid assignment");
1322 if (LHS.getType()->isAtomicType() ||
1341 if (LHS.getType()->isAtomicType() ||
1360 EmitFinalDestCopy(E->
getType(), LHS);
1368void AggExprEmitter::VisitAbstractConditionalOperator(
1369 const AbstractConditionalOperator *E) {
1375 CodeGenFunction::OpaqueValueMapping binding(CGF, E);
1377 CodeGenFunction::ConditionalEvaluation eval(CGF);
1383 bool destructNonTrivialCStruct =
1384 !isExternallyDestructed &&
1386 isExternallyDestructed |= destructNonTrivialCStruct;
1395 assert(CGF.
HaveInsertPoint() &&
"expression evaluation ended with no IP!");
1396 CGF.
Builder.CreateBr(ContBlock);
1410 if (destructNonTrivialCStruct)
1417void AggExprEmitter::VisitChooseExpr(
const ChooseExpr *CE) {
1421void AggExprEmitter::VisitVAArgExpr(VAArgExpr *VE) {
1432void AggExprEmitter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
1444 if (!wasExternallyDestructed)
1448void AggExprEmitter::VisitCXXConstructExpr(
const CXXConstructExpr *E) {
1449 AggValueSlot Slot = EnsureSlot(E->
getType());
1453void AggExprEmitter::VisitCXXInheritedCtorInitExpr(
1454 const CXXInheritedCtorInitExpr *E) {
1455 AggValueSlot Slot = EnsureSlot(E->
getType());
1461void AggExprEmitter::VisitLambdaExpr(
LambdaExpr *E) {
1462 AggValueSlot Slot = EnsureSlot(E->
getType());
1467 CodeGenFunction::CleanupDeactivationScope scope(CGF);
1472 i != e; ++i, ++CurField) {
1475 if (CurField->hasCapturedVLAType()) {
1480 EmitInitializationToLValue(*i, LV);
1484 CurField->getType().isDestructedType()) {
1485 assert(LV.isSimple());
1488 CurField->getType(),
1494void AggExprEmitter::VisitExprWithCleanups(ExprWithCleanups *E) {
1495 CodeGenFunction::RunCleanupsScope cleanups(CGF);
1499void AggExprEmitter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
1501 AggValueSlot Slot = EnsureSlot(
T);
1505void AggExprEmitter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
1507 AggValueSlot Slot = EnsureSlot(
T);
1511void AggExprEmitter::EmitInitializationToLValue(Expr *E, LValue LV) {
1512 QualType
type = LV.getType();
1519 return EmitNullInitializationToLValue(LV);
1523 }
else if (
type->isReferenceType()) {
1531void AggExprEmitter::EmitNullInitializationToLValue(LValue lv) {
1532 QualType
type = lv.getType();
1544 if (lv.isBitField()) {
1547 assert(lv.isSimple());
1558void AggExprEmitter::VisitCXXParenListInitExpr(CXXParenListInitExpr *E) {
1564void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
1571 VisitCXXParenListOrInitListExpr(
1575void AggExprEmitter::VisitCXXParenListOrInitListExpr(
1576 Expr *ExprToVisit, ArrayRef<Expr *> InitExprs,
1577 FieldDecl *InitializedFieldInUnion, Expr *ArrayFiller) {
1584 if (llvm::Constant *
C =
1585 CGF.
CGM.EmitConstantExpr(ExprToVisit, ExprToVisit->
getType(), &CGF)) {
1586 llvm::GlobalVariable* GV =
1587 new llvm::GlobalVariable(CGF.
CGM.
getModule(),
C->getType(),
true,
1588 llvm::GlobalValue::InternalLinkage,
C,
"");
1589 EmitFinalDestCopy(ExprToVisit->
getType(),
1607 AggValueSlot Dest = EnsureSlot(ExprToVisit->
getType());
1615 InitExprs, ArrayFiller);
1621 assert(InitExprs.size() == 0 &&
1622 "you can only use an empty initializer with VLAs");
1628 "Only support structs/unions here!");
1634 unsigned NumInitElements = InitExprs.size();
1639 CodeGenFunction::CleanupDeactivationScope DeactivateCleanups(CGF);
1641 unsigned curInitIndex = 0;
1644 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(record)) {
1645 assert(NumInitElements >= CXXRD->getNumBases() &&
1646 "missing initializer for base class");
1647 for (
auto &Base : CXXRD->bases()) {
1648 assert(!
Base.isVirtual() &&
"should not see vbases here");
1649 auto *BaseRD =
Base.getType()->getAsCXXRecordDecl();
1657 CGF.
EmitAggExpr(InitExprs[curInitIndex++], AggSlot);
1660 Base.getType().isDestructedType())
1666 CodeGenFunction::FieldConstructionScope FCS(CGF, Dest.
getAddress());
1668 const bool ZeroInitPadding =
1674 if (!InitializedFieldInUnion) {
1680 for (
const auto *Field : record->
fields())
1682 (
Field->isUnnamedBitField() ||
Field->isAnonymousStructOrUnion()) &&
1683 "Only unnamed bitfields or anonymous class allowed");
1689 FieldDecl *
Field = InitializedFieldInUnion;
1692 if (NumInitElements) {
1694 EmitInitializationToLValue(InitExprs[0], FieldLoc);
1695 if (ZeroInitPadding) {
1699 DoZeroInitPadding(FieldSize, TotalSize,
nullptr);
1703 if (ZeroInitPadding)
1704 EmitNullInitializationToLValue(DestLV);
1706 EmitNullInitializationToLValue(FieldLoc);
1716 for (
const auto *field : record->
fields()) {
1718 if (field->getType()->isIncompleteArrayType())
1722 if (field->isUnnamedBitField())
1728 if (curInitIndex == NumInitElements && Dest.
isZeroed() &&
1732 if (ZeroInitPadding)
1733 DoZeroInitPadding(PaddingStart,
1740 if (curInitIndex < NumInitElements) {
1742 EmitInitializationToLValue(InitExprs[curInitIndex++], LV);
1745 EmitNullInitializationToLValue(LV);
1752 field->getType().isDestructedType()) {
1753 assert(LV.isSimple());
1761 if (ZeroInitPadding) {
1764 DoZeroInitPadding(PaddingStart, TotalSize,
nullptr);
1768void AggExprEmitter::DoZeroInitPadding(
uint64_t &PaddingStart,
1770 const FieldDecl *NextField) {
1778 llvm::Constant *SizeVal = Builder.getInt64((End - Start).getQuantity());
1782 if (NextField !=
nullptr && NextField->
isBitField()) {
1785 const CGRecordLayout &RL =
1789 if (StorageStart + Info.
StorageSize > PaddingStart) {
1790 if (StorageStart > PaddingStart)
1791 InitBytes(PaddingStart, StorageStart);
1804 if (PaddingStart < PaddingEnd)
1805 InitBytes(PaddingStart, PaddingEnd);
1806 if (NextField !=
nullptr)
1811void AggExprEmitter::VisitArrayInitLoopExpr(
const ArrayInitLoopExpr *E,
1812 llvm::Value *outerBegin) {
1814 CodeGenFunction::OpaqueValueMapping binding(CGF, E->
getCommonExpr());
1823 llvm::Value *zero = llvm::ConstantInt::get(CGF.
SizeTy, 0);
1824 llvm::Value *indices[] = {zero, zero};
1825 llvm::Value *begin = Builder.CreateInBoundsGEP(destPtr.
getElementType(),
1827 indices,
"arrayinit.begin");
1833 ArrayInitLoopExpr *InnerLoop = dyn_cast<ArrayInitLoopExpr>(E->
getSubExpr());
1835 QualType elementType =
1838 CharUnits elementAlign =
1842 llvm::BasicBlock *entryBB = Builder.GetInsertBlock();
1847 llvm::PHINode *index =
1848 Builder.CreatePHI(zero->getType(), 2,
"arrayinit.index");
1849 index->addIncoming(zero, entryBB);
1850 llvm::Value *element =
1851 Builder.CreateInBoundsGEP(llvmElementType, begin, index);
1858 EHScopeStack::stable_iterator
cleanup;
1860 if (outerBegin->getType() != element->getType())
1861 outerBegin = Builder.CreateBitCast(outerBegin, element->getType());
1874 CodeGenFunction::RunCleanupsScope CleanupsScope(CGF);
1875 CodeGenFunction::ArrayInitLoopExprScope Scope(CGF, index);
1877 Address(element, llvmElementType, elementAlign), elementType);
1885 AggExprEmitter(CGF, elementSlot,
false)
1886 .VisitArrayInitLoopExpr(InnerLoop, outerBegin);
1888 EmitInitializationToLValue(E->
getSubExpr(), elementLV);
1892 llvm::Value *nextIndex = Builder.CreateNUWAdd(
1893 index, llvm::ConstantInt::get(CGF.
SizeTy, 1),
"arrayinit.next");
1894 index->addIncoming(nextIndex, Builder.GetInsertBlock());
1897 llvm::Value *done = Builder.CreateICmpEQ(
1898 nextIndex, llvm::ConstantInt::get(CGF.
SizeTy, numElements),
1901 Builder.CreateCondBr(done, endBB, bodyBB);
1913void AggExprEmitter::VisitDesignatedInitUpdateExpr(
1914 DesignatedInitUpdateExpr *E) {
1915 AggValueSlot Dest = EnsureSlot(E->
getType());
1918 EmitInitializationToLValue(E->
getBase(), DestLV);
1954 if (NumNonZeroBytes * 4 > Size)
1958 llvm::Constant *SizeVal = CGF.
Builder.getInt64(Size.getQuantity());
1973 "Invalid aggregate expression to emit");
1975 "slot has bits but no address");
1980 AggExprEmitter(*
this, Slot, Slot.
isIgnored()).Visit(
const_cast<Expr *
>(E));
1997 return AggExprEmitter(*
this, Dest, Dest.
isIgnored())
1998 .EmitFinalDestCopy(
Type, Src, SrcKind);
2041 getContext().getASTRecordLayout(BaseRD).getSize() <=
2059 assert((
Record->hasTrivialCopyConstructorForCall() ||
2060 Record->hasTrivialCopyAssignment() ||
2061 Record->hasTrivialMoveConstructorForCall() ||
2062 Record->hasTrivialMoveAssignment() ||
Record->isUnion() ||
2065 "Trying to aggregate-copy a type without a trivial copy/move "
2066 "constructor or assignment operator");
2075 if (
getTargetHooks().emitCUDADeviceBuiltinSurfaceDeviceCopy(*
this, Dest,
2079 if (
getTargetHooks().emitCUDADeviceBuiltinTextureDeviceCopy(*
this, Dest,
2086 "copies of aggregates in hlsl_constant address space should be "
2087 "handled earlier by the HLSL runtime");
2109 llvm::Value *SizeVal =
nullptr;
2112 if (
auto *VAT = dyn_cast_or_null<VariableArrayType>(
2118 SizeVal =
Builder.CreateNUWMul(
2147 if (
Record->hasObjectMember()) {
2148 CGM.getObjCRuntime().EmitGCMemmoveCollectable(*
this, DestPtr, SrcPtr,
2154 if (
const auto *
Record = BaseType->getAsRecordDecl()) {
2155 if (
Record->hasObjectMember()) {
2156 CGM.getObjCRuntime().EmitGCMemmoveCollectable(*
this, DestPtr, SrcPtr,
2163 auto *Inst =
Builder.CreateMemCpy(DestPtr, SrcPtr, SizeVal, isVolatile);
2170 if (llvm::MDNode *TBAAStructTag =
CGM.getTBAAStructInfo(Ty))
2171 Inst->setMetadata(llvm::LLVMContext::MD_tbaa_struct, TBAAStructTag);
2173 if (
CGM.getCodeGenOpts().NewStructPathTBAA) {
2176 CGM.DecorateInstructionWithTBAA(Inst, TBAAInfo);
Defines the clang::ASTContext interface.
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 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 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)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Result
Implement __builtin_bit_cast and related operations.
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...
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.
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 hasTrivialMoveAssignment() const
Determine whether this class has a trivial move assignment operator (C++11 [class....
bool isTriviallyCopyable() const
Determine whether this class is considered trivially copyable per (C++11 [class]p6).
bool hasTrivialMoveConstructor() const
Determine whether this class has a trivial move constructor (C++11 [class.copy]p12)
bool hasTrivialCopyConstructor() const
Determine whether this class has a trivial copy constructor (C++ [class.copy]p6, C++11 [class....
bool hasTrivialCopyAssignment() const
Determine whether this class has a trivial copy assignment operator (C++ [class.copy]p11,...
bool hasUserDeclaredConstructor() const
Determine whether this class has any user-declared constructors.
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.
path_iterator path_begin()
CastKind getCastKind() const
This is an opaque type for sizes expressed in character units.
bool isZero() const
Test whether the quantity equals zero.
llvm::Align getAsAlign() const
Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit bytes.
QuantityType getQuantity() const
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)
Construct a CharUnits quantity from a raw integer type.
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.
bool emitBufferCopy(CodeGenFunction &CGF, const Expr *E, const LValue &SrcLV, AggValueSlot &DestSlot)
bool emitGlobalResourceArray(CodeGenFunction &CGF, const Expr *E, AggValueSlot &DestSlot)
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 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.
llvm::Value * performAddrSpaceCast(llvm::Value *Src, llvm::Type *DestTy)
@ 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.
Address GetAddressOfBaseClass(Address Value, const CXXRecordDecl *Derived, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd, bool NullCheckValue, SourceLocation Loc)
GetAddressOfBaseClass - This function will add the necessary delta to the load of 'this' and returns ...
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)
SmallVector< llvm::ConvergenceControlInst *, 4 > ConvergenceTokenStack
Stack to track the controlled convergence tokens.
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 CreateCoercedStore(llvm::Value *Src, QualType SrcFETy, Address Dst, llvm::TypeSize DstSize, bool DstIsVolatile)
Create a store to.
llvm::ConvergenceControlInst * emitConvergenceLoopToken(llvm::BasicBlock *BB)
void EmitAggregateCopy(LValue Dest, LValue Src, QualType EltTy, AggValueSlot::Overlap_t MayOverlap, bool isVolatile=false)
EmitAggregateCopy - Emit an aggregate copy.
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.
llvm::Type * ConvertTypeForMem(QualType T)
RValue EmitAtomicExpr(AtomicExpr *E)
void emitPFPPostCopyUpdates(Address DestPtr, Address SrcPtr, QualType Ty)
Copy all PFP fields from SrcPtr to DestPtr while updating signatures, assuming that DestPtr was alrea...
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...
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.
bool shouldEmitConvergenceTokens() const
CGCXXABI & getCXXABI() const
ASTContext & getContext() const
const TargetCodeGenInfo & getTargetCodeGenInfo()
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...
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.
virtual LangAS getSRetAddrSpace(const CXXRecordDecl *RD) const
Get the address space for an indirect (sret) return of the given type.
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 * getValueInfo(ComparisonCategoryResult ValueKind) const
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.
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...
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
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.
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() const
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.
A pointer to member type per C++ 8.3.3 - Pointers to members.
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.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to 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
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
bool isStoredAsComparisonResult() const
const APValue & getAPValue() const
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.
CXXRecordDecl * castAsCXXRecordDecl() const
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
bool isHLSLResourceRecordArray() const
Expr * getSubExpr() const
Represents a GCC generic vector type.
bool isTrivialFiller(const Expr *E)
Check whether E is a trivial array filler, that is, one that is equivalent to zero-initialization.
bool isBlockVarRef(const Expr *E)
Check whether the value of E is possibly a reference to or into a __block variable.
CharUnits GetNumNonZeroBytesInInit(const Expr *E, CodeGenFunctionTy &CGF)
GetNumNonZeroBytesInInit - Get an approximate count of the number of non-zero bytes that will be stor...
bool isSimpleZero(const Expr *E, CodeGenFunctionTy &CGF)
isSimpleZero - If emitting this value will obviously just cause a store of zero to memory,...
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< AtomicType > atomicType
@ Address
A pointer to a ValueDecl.
bool GE(InterpState &S, CodePtr OpPC)
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
ComparisonCategoryResult
An enumeration representing the possible results of a three-way comparison.
@ 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)
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
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
llvm::APSInt getIntValue() const
Get the constant integer value used by this variable to represent the comparison category result type...