25 #include "llvm/ADT/Sequence.h" 26 #include "llvm/ADT/STLExtras.h" 27 #include "llvm/IR/Constants.h" 28 #include "llvm/IR/DataLayout.h" 29 #include "llvm/IR/Function.h" 30 #include "llvm/IR/GlobalVariable.h" 31 using namespace clang;
32 using namespace CodeGen;
39 class ConstExprEmitter;
41 struct ConstantAggregateBuilderUtils {
44 ConstantAggregateBuilderUtils(
CodeGenModule &CGM) : CGM(CGM) {}
46 CharUnits getAlignment(
const llvm::Constant *C)
const {
55 CharUnits getSize(
const llvm::Constant *C)
const {
56 return getSize(C->getType());
59 llvm::Constant *getPadding(
CharUnits PadSize)
const {
62 Ty = llvm::ArrayType::get(Ty, PadSize.
getQuantity());
63 return llvm::UndefValue::get(Ty);
66 llvm::Constant *getZeroes(
CharUnits ZeroSize)
const {
68 return llvm::ConstantAggregateZero::get(Ty);
74 class ConstantAggregateBuilder :
private ConstantAggregateBuilderUtils {
93 bool NaturalLayout =
true;
103 bool AllowOversized);
107 : ConstantAggregateBuilderUtils(CGM) {}
117 bool addBits(llvm::APInt Bits, uint64_t OffsetInBits,
bool AllowOverwrite);
128 llvm::Constant *build(
llvm::Type *DesiredTy,
bool AllowOversized)
const {
130 NaturalLayout, DesiredTy, AllowOversized);
134 template<
typename Container,
typename Range = std::initializer_list<
135 typename Container::value_type>>
136 static void replace(Container &C,
size_t BeginOff,
size_t EndOff, Range Vals) {
137 assert(BeginOff <= EndOff &&
"invalid replacement range");
138 llvm::replace(C, C.begin() + BeginOff, C.begin() + EndOff, Vals);
141 bool ConstantAggregateBuilder::add(llvm::Constant *C,
CharUnits Offset,
142 bool AllowOverwrite) {
144 if (Offset >= Size) {
148 NaturalLayout =
false;
149 else if (AlignedSize < Offset) {
150 Elems.push_back(getPadding(Offset - Size));
151 Offsets.push_back(Size);
154 Offsets.push_back(Offset);
155 Size = Offset + getSize(C);
161 if (!FirstElemToReplace)
166 if (!LastElemToReplace)
169 assert((FirstElemToReplace == LastElemToReplace || AllowOverwrite) &&
170 "unexpectedly overwriting field");
172 replace(Elems, *FirstElemToReplace, *LastElemToReplace, {C});
173 replace(Offsets, *FirstElemToReplace, *LastElemToReplace, {Offset});
174 Size =
std::max(Size, Offset + CSize);
175 NaturalLayout =
false;
179 bool ConstantAggregateBuilder::addBits(llvm::APInt Bits, uint64_t OffsetInBits,
180 bool AllowOverwrite) {
186 unsigned OffsetWithinChar = OffsetInBits % CharWidth;
194 unsigned WantedBits =
195 std::min((uint64_t)Bits.getBitWidth(), CharWidth - OffsetWithinChar);
199 llvm::APInt BitsThisChar = Bits;
200 if (BitsThisChar.getBitWidth() < CharWidth)
201 BitsThisChar = BitsThisChar.zext(CharWidth);
205 int Shift = Bits.getBitWidth() - CharWidth + OffsetWithinChar;
207 BitsThisChar.lshrInPlace(Shift);
209 BitsThisChar = BitsThisChar.shl(-Shift);
211 BitsThisChar = BitsThisChar.shl(OffsetWithinChar);
213 if (BitsThisChar.getBitWidth() > CharWidth)
214 BitsThisChar = BitsThisChar.trunc(CharWidth);
216 if (WantedBits == CharWidth) {
219 OffsetInChars, AllowOverwrite);
225 if (!FirstElemToUpdate)
229 if (!LastElemToUpdate)
231 assert(*LastElemToUpdate - *FirstElemToUpdate < 2 &&
232 "should have at most one element covering one byte");
235 llvm::APInt UpdateMask(CharWidth, 0);
237 UpdateMask.setBits(CharWidth - OffsetWithinChar - WantedBits,
238 CharWidth - OffsetWithinChar);
240 UpdateMask.setBits(OffsetWithinChar, OffsetWithinChar + WantedBits);
241 BitsThisChar &= UpdateMask;
243 if (*FirstElemToUpdate == *LastElemToUpdate ||
244 Elems[*FirstElemToUpdate]->isNullValue() ||
245 isa<llvm::UndefValue>(Elems[*FirstElemToUpdate])) {
248 OffsetInChars,
true);
250 llvm::Constant *&ToUpdate = Elems[*FirstElemToUpdate];
253 auto *CI = dyn_cast<llvm::ConstantInt>(ToUpdate);
258 assert(CI->getBitWidth() == CharWidth &&
"splitAt failed");
259 assert((!(CI->getValue() & UpdateMask) || AllowOverwrite) &&
260 "unexpectedly overwriting bitfield");
261 BitsThisChar |= (CI->getValue() & ~UpdateMask);
262 ToUpdate = llvm::ConstantInt::get(CGM.
getLLVMContext(), BitsThisChar);
267 if (WantedBits == Bits.getBitWidth())
272 Bits.lshrInPlace(WantedBits);
273 Bits = Bits.trunc(Bits.getBitWidth() - WantedBits);
276 OffsetWithinChar = 0;
288 return Offsets.size();
291 auto FirstAfterPos = llvm::upper_bound(Offsets, Pos);
292 if (FirstAfterPos == Offsets.begin())
296 size_t LastAtOrBeforePosIndex = FirstAfterPos - Offsets.begin() - 1;
297 if (Offsets[LastAtOrBeforePosIndex] == Pos)
298 return LastAtOrBeforePosIndex;
301 if (Offsets[LastAtOrBeforePosIndex] +
302 getSize(Elems[LastAtOrBeforePosIndex]) <= Pos)
303 return LastAtOrBeforePosIndex + 1;
306 if (!split(LastAtOrBeforePosIndex, Pos))
314 bool ConstantAggregateBuilder::split(
size_t Index,
CharUnits Hint) {
315 NaturalLayout =
false;
316 llvm::Constant *C = Elems[Index];
319 if (
auto *CA = dyn_cast<llvm::ConstantAggregate>(C)) {
320 replace(Elems, Index, Index + 1,
321 llvm::map_range(llvm::seq(0u, CA->getNumOperands()),
322 [&](
unsigned Op) {
return CA->getOperand(Op); }));
323 if (
auto *Seq = dyn_cast<llvm::SequentialType>(CA->getType())) {
325 CharUnits ElemSize = getSize(Seq->getElementType());
327 Offsets, Index, Index + 1,
328 llvm::map_range(llvm::seq(0u, CA->getNumOperands()),
329 [&](
unsigned Op) {
return Offset + Op * ElemSize; }));
332 auto *ST = cast<llvm::StructType>(CA->getType());
333 const llvm::StructLayout *Layout =
335 replace(Offsets, Index, Index + 1,
337 llvm::seq(0u, CA->getNumOperands()), [&](
unsigned Op) {
339 Layout->getElementOffset(Op));
345 if (
auto *CDS = dyn_cast<llvm::ConstantDataSequential>(C)) {
347 CharUnits ElemSize = getSize(CDS->getElementType());
348 replace(Elems, Index, Index + 1,
349 llvm::map_range(llvm::seq(0u, CDS->getNumElements()),
351 return CDS->getElementAsConstant(Elem);
353 replace(Offsets, Index, Index + 1,
355 llvm::seq(0u, CDS->getNumElements()),
356 [&](
unsigned Elem) {
return Offset + Elem * ElemSize; }));
360 if (isa<llvm::ConstantAggregateZero>(C)) {
362 assert(Hint > Offset && Hint < Offset + ElemSize &&
"nothing to split");
363 replace(Elems, Index, Index + 1,
364 {getZeroes(Hint - Offset), getZeroes(Offset + ElemSize - Hint)});
365 replace(Offsets, Index, Index + 1, {
Offset, Hint});
369 if (isa<llvm::UndefValue>(C)) {
370 replace(Elems, Index, Index + 1, {});
371 replace(Offsets, Index, Index + 1, {});
382 static llvm::Constant *
383 EmitArrayConstant(
CodeGenModule &CGM, llvm::ArrayType *DesiredType,
384 llvm::Type *CommonElementType,
unsigned ArrayBound,
386 llvm::Constant *Filler);
388 llvm::Constant *ConstantAggregateBuilder::buildFrom(
391 bool NaturalLayout,
llvm::Type *DesiredTy,
bool AllowOversized) {
392 ConstantAggregateBuilderUtils Utils(CGM);
395 return llvm::UndefValue::get(DesiredTy);
397 auto Offset = [&](
size_t I) {
return Offsets[I] - StartOffset; };
401 if (llvm::ArrayType *ATy = dyn_cast<llvm::ArrayType>(DesiredTy)) {
402 assert(!AllowOversized &&
"oversized array emission not supported");
404 bool CanEmitArray =
true;
406 llvm::Constant *Filler = llvm::Constant::getNullValue(CommonType);
407 CharUnits ElemSize = Utils.getSize(ATy->getElementType());
409 for (
size_t I = 0; I != Elems.size(); ++I) {
411 if (Elems[I]->isNullValue())
415 if (Elems[I]->getType() != CommonType ||
416 Offset(I) % ElemSize != 0) {
417 CanEmitArray =
false;
420 ArrayElements.resize(
Offset(I) / ElemSize + 1, Filler);
421 ArrayElements.back() = Elems[I];
425 return EmitArrayConstant(CGM, ATy, CommonType, ATy->getNumElements(),
426 ArrayElements, Filler);
432 CharUnits DesiredSize = Utils.getSize(DesiredTy);
434 for (llvm::Constant *C : Elems)
435 Align =
std::max(Align, Utils.getAlignment(C));
441 if ((DesiredSize < AlignedSize && !AllowOversized) ||
442 DesiredSize.alignTo(Align) != DesiredSize) {
444 NaturalLayout =
false;
446 }
else if (DesiredSize > AlignedSize) {
448 UnpackedElemStorage.assign(Elems.begin(), Elems.end());
449 UnpackedElemStorage.push_back(Utils.getPadding(DesiredSize - Size));
450 UnpackedElems = UnpackedElemStorage;
457 if (!NaturalLayout) {
459 for (
size_t I = 0; I != Elems.size(); ++I) {
460 CharUnits Align = Utils.getAlignment(Elems[I]);
463 assert(DesiredOffset >= SizeSoFar &&
"elements out of order");
465 if (DesiredOffset != NaturalOffset)
467 if (DesiredOffset != SizeSoFar)
468 PackedElems.push_back(Utils.getPadding(DesiredOffset - SizeSoFar));
469 PackedElems.push_back(Elems[I]);
470 SizeSoFar = DesiredOffset + Utils.getSize(Elems[I]);
475 assert((SizeSoFar <= DesiredSize || AllowOversized) &&
476 "requested size is too small for contents");
477 if (SizeSoFar < DesiredSize)
478 PackedElems.push_back(Utils.getPadding(DesiredSize - SizeSoFar));
482 llvm::StructType *STy = llvm::ConstantStruct::getTypeForElements(
483 CGM.
getLLVMContext(), Packed ? PackedElems : UnpackedElems, Packed);
487 if (llvm::StructType *DesiredSTy = dyn_cast<llvm::StructType>(DesiredTy)) {
488 if (DesiredSTy->isLayoutIdentical(STy))
492 return llvm::ConstantStruct::get(STy, Packed ? PackedElems : UnpackedElems);
495 void ConstantAggregateBuilder::condense(
CharUnits Offset,
500 if (!FirstElemToReplace)
502 size_t First = *FirstElemToReplace;
505 if (!LastElemToReplace)
507 size_t Last = *LastElemToReplace;
509 size_t Length = Last - First;
513 if (Length == 1 && Offsets[First] == Offset &&
514 getSize(Elems[First]) == Size) {
517 auto *STy = dyn_cast<llvm::StructType>(DesiredTy);
518 if (STy && STy->getNumElements() == 1 &&
519 STy->getElementType(0) == Elems[First]->getType())
520 Elems[First] = llvm::ConstantStruct::get(STy, Elems[First]);
524 llvm::Constant *Replacement = buildFrom(
525 CGM, makeArrayRef(Elems).slice(First, Length),
526 makeArrayRef(Offsets).slice(First, Length), Offset, getSize(DesiredTy),
527 false, DesiredTy,
false);
528 replace(Elems, First, Last, {Replacement});
529 replace(Offsets, First, Last, {Offset});
536 class ConstStructBuilder {
539 ConstantAggregateBuilder &Builder;
548 ConstantAggregateBuilder &Const,
CharUnits Offset,
553 ConstantAggregateBuilder &Builder,
CharUnits StartOffset)
554 : CGM(Emitter.CGM), Emitter(Emitter), Builder(Builder),
555 StartOffset(StartOffset) {}
557 bool AppendField(
const FieldDecl *Field, uint64_t FieldOffset,
558 llvm::Constant *InitExpr,
bool AllowOverwrite =
false);
560 bool AppendBytes(
CharUnits FieldOffsetInChars, llvm::Constant *InitCst,
561 bool AllowOverwrite =
false);
563 bool AppendBitField(
const FieldDecl *Field, uint64_t FieldOffset,
564 llvm::ConstantInt *InitExpr,
bool AllowOverwrite =
false);
569 llvm::Constant *Finalize(
QualType Ty);
572 bool ConstStructBuilder::AppendField(
573 const FieldDecl *Field, uint64_t FieldOffset, llvm::Constant *InitCst,
574 bool AllowOverwrite) {
579 return AppendBytes(FieldOffsetInChars, InitCst, AllowOverwrite);
582 bool ConstStructBuilder::AppendBytes(
CharUnits FieldOffsetInChars,
583 llvm::Constant *InitCst,
584 bool AllowOverwrite) {
585 return Builder.add(InitCst, StartOffset + FieldOffsetInChars, AllowOverwrite);
588 bool ConstStructBuilder::AppendBitField(
589 const FieldDecl *Field, uint64_t FieldOffset, llvm::ConstantInt *CI,
590 bool AllowOverwrite) {
592 llvm::APInt FieldValue = CI->getValue();
598 if (FieldSize > FieldValue.getBitWidth())
599 FieldValue = FieldValue.zext(FieldSize);
602 if (FieldSize < FieldValue.getBitWidth())
603 FieldValue = FieldValue.trunc(FieldSize);
605 return Builder.addBits(FieldValue,
611 ConstantAggregateBuilder &Const,
615 return ConstStructBuilder::UpdateStruct(Emitter, Const, Offset, Updater);
620 QualType ElemType = CAT->getElementType();
624 llvm::Constant *FillC =
nullptr;
626 if (!isa<NoInitExpr>(Filler)) {
633 unsigned NumElementsToUpdate =
634 FillC ? CAT->getSize().getZExtValue() : Updater->
getNumInits();
635 for (
unsigned I = 0; I != NumElementsToUpdate; ++I, Offset += ElemSize) {
636 Expr *Init =
nullptr;
637 if (I < Updater->getNumInits())
640 if (!Init && FillC) {
641 if (!Const.add(FillC, Offset,
true))
643 }
else if (!Init || isa<NoInitExpr>(Init)) {
645 }
else if (
InitListExpr *ChildILE = dyn_cast<InitListExpr>(Init)) {
646 if (!EmitDesignatedInitUpdater(Emitter, Const, Offset, ElemType,
650 Const.condense(Offset, ElemTy);
653 if (!Const.add(Val, Offset,
true))
661 bool ConstStructBuilder::Build(
InitListExpr *ILE,
bool AllowOverwrite) {
665 unsigned FieldNo = -1;
666 unsigned ElementNo = 0;
671 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
672 if (CXXRD->getNumBases())
689 Expr *Init =
nullptr;
690 if (ElementNo < ILE->getNumInits())
691 Init = ILE->
getInit(ElementNo++);
692 if (Init && isa<NoInitExpr>(Init))
698 if (AllowOverwrite &&
700 if (
auto *SubILE = dyn_cast<InitListExpr>(Init)) {
703 if (!EmitDesignatedInitUpdater(Emitter, Builder, StartOffset + Offset,
708 Builder.condense(StartOffset + Offset,
714 llvm::Constant *EltInit =
727 if (Field->
hasAttr<NoUniqueAddressAttr>())
728 AllowOverwrite =
true;
731 if (
auto *CI = dyn_cast<llvm::ConstantInt>(EltInit)) {
749 : Decl(Decl), Offset(Offset), Index(Index) {
756 bool operator<(
const BaseInfo &O)
const {
return Offset < O.Offset; }
768 if (CD->isDynamicClass() && !IsPrimaryBase) {
769 llvm::Constant *VTableAddressPoint =
772 if (!AppendBytes(Offset, VTableAddressPoint))
779 Bases.reserve(CD->getNumBases());
782 BaseEnd = CD->bases_end();
Base != BaseEnd; ++
Base, ++BaseNo) {
783 assert(!
Base->isVirtual() &&
"should not have virtual bases here");
786 Bases.push_back(BaseInfo(BD, BaseOffset, BaseNo));
788 llvm::stable_sort(Bases);
790 for (
unsigned I = 0, N = Bases.size(); I != N; ++I) {
791 BaseInfo &
Base = Bases[I];
794 Build(Val.
getStructBase(Base.Index), Base.Decl, IsPrimaryBase,
795 VTableClass, Offset + Base.Offset);
799 unsigned FieldNo = 0;
802 bool AllowOverwrite =
false;
804 FieldEnd = RD->
field_end(); Field != FieldEnd; ++Field, ++FieldNo) {
816 llvm::Constant *EltInit =
823 if (!AppendField(*Field, Layout.
getFieldOffset(FieldNo) + OffsetBits,
824 EltInit, AllowOverwrite))
828 if (Field->
hasAttr<NoUniqueAddressAttr>())
829 AllowOverwrite =
true;
832 if (!AppendBitField(*Field, Layout.
getFieldOffset(FieldNo) + OffsetBits,
833 cast<llvm::ConstantInt>(EltInit), AllowOverwrite))
841 llvm::Constant *ConstStructBuilder::Finalize(
QualType Type) {
847 llvm::Constant *ConstStructBuilder::BuildStruct(
ConstantEmitter &Emitter,
850 ConstantAggregateBuilder Const(Emitter.
CGM);
853 if (!Builder.Build(ILE,
false))
856 return Builder.Finalize(ValTy);
859 llvm::Constant *ConstStructBuilder::BuildStruct(
ConstantEmitter &Emitter,
862 ConstantAggregateBuilder Const(Emitter.
CGM);
870 return Builder.Finalize(ValTy);
874 ConstantAggregateBuilder &Const,
876 return ConstStructBuilder(Emitter, Const, Offset)
877 .Build(Updater,
true);
888 if (llvm::GlobalVariable *Addr =
895 llvm::Constant *C = emitter.tryEmitForInitializer(E->
getInitializer(),
899 "file-scope compound literal did not have constant initializer!");
903 auto GV =
new llvm::GlobalVariable(CGM.
getModule(), C->getType(),
906 C,
".compoundliteral",
nullptr,
907 llvm::GlobalVariable::NotThreadLocal,
909 emitter.finalize(GV);
915 static llvm::Constant *
916 EmitArrayConstant(
CodeGenModule &CGM, llvm::ArrayType *DesiredType,
917 llvm::Type *CommonElementType,
unsigned ArrayBound,
919 llvm::Constant *Filler) {
921 unsigned NonzeroLength = ArrayBound;
922 if (Elements.size() < NonzeroLength && Filler->isNullValue())
923 NonzeroLength = Elements.size();
924 if (NonzeroLength == Elements.size()) {
925 while (NonzeroLength > 0 && Elements[NonzeroLength - 1]->isNullValue())
929 if (NonzeroLength == 0)
930 return llvm::ConstantAggregateZero::get(DesiredType);
933 unsigned TrailingZeroes = ArrayBound - NonzeroLength;
934 if (TrailingZeroes >= 8) {
935 assert(Elements.size() >= NonzeroLength &&
936 "missing initializer for non-zero element");
940 if (CommonElementType && NonzeroLength >= 8) {
941 llvm::Constant *Initial = llvm::ConstantArray::get(
942 llvm::ArrayType::get(CommonElementType, NonzeroLength),
943 makeArrayRef(Elements).take_front(NonzeroLength));
945 Elements[0] = Initial;
947 Elements.resize(NonzeroLength + 1);
951 CommonElementType ? CommonElementType : DesiredType->getElementType();
952 FillerType = llvm::ArrayType::get(FillerType, TrailingZeroes);
953 Elements.back() = llvm::ConstantAggregateZero::get(FillerType);
954 CommonElementType =
nullptr;
955 }
else if (Elements.size() != ArrayBound) {
957 Elements.resize(ArrayBound, Filler);
958 if (Filler->getType() != CommonElementType)
959 CommonElementType =
nullptr;
963 if (CommonElementType)
964 return llvm::ConstantArray::get(
965 llvm::ArrayType::get(CommonElementType, ArrayBound), Elements);
969 Types.reserve(Elements.size());
970 for (llvm::Constant *Elt : Elements)
971 Types.push_back(Elt->getType());
972 llvm::StructType *SType =
974 return llvm::ConstantStruct::get(SType, Elements);
983 class ConstExprEmitter :
984 public StmtVisitor<ConstExprEmitter, llvm::Constant*, QualType> {
987 llvm::LLVMContext &VMContext;
990 : CGM(emitter.CGM), Emitter(emitter), VMContext(CGM.getLLVMContext()) {
1029 if (
const auto *ECE = dyn_cast<ExplicitCastExpr>(E))
1037 "Destination type is not union type!");
1042 if (!C)
return nullptr;
1044 auto destTy = ConvertType(destType);
1045 if (C->getType() == destTy)
return C;
1052 Types.push_back(C->getType());
1053 unsigned CurSize = CGM.
getDataLayout().getTypeAllocSize(C->getType());
1054 unsigned TotalSize = CGM.
getDataLayout().getTypeAllocSize(destTy);
1056 assert(CurSize <= TotalSize &&
"Union size mismatch!");
1057 if (
unsigned NumPadBytes = TotalSize - CurSize) {
1059 if (NumPadBytes > 1)
1060 Ty = llvm::ArrayType::get(Ty, NumPadBytes);
1062 Elts.push_back(llvm::UndefValue::get(Ty));
1063 Types.push_back(Ty);
1066 llvm::StructType *STy = llvm::StructType::get(VMContext, Types,
false);
1067 return llvm::ConstantStruct::get(STy, Elts);
1070 case CK_AddressSpaceConversion: {
1072 if (!C)
return nullptr;
1080 case CK_LValueToRValue:
1081 case CK_AtomicToNonAtomic:
1082 case CK_NonAtomicToAtomic:
1084 case CK_ConstructorConversion:
1085 return Visit(subExpr, destType);
1087 case CK_IntToOCLSampler:
1088 llvm_unreachable(
"global sampler variables are not generated");
1090 case CK_Dependent: llvm_unreachable(
"saw dependent cast!");
1092 case CK_BuiltinFnToFnPtr:
1093 llvm_unreachable(
"builtin functions are handled elsewhere");
1095 case CK_ReinterpretMemberPointer:
1096 case CK_DerivedToBaseMemberPointer:
1097 case CK_BaseToDerivedMemberPointer: {
1099 if (!C)
return nullptr;
1104 case CK_ObjCObjectLValueCast:
1105 case CK_ARCProduceObject:
1106 case CK_ARCConsumeObject:
1107 case CK_ARCReclaimReturnedObject:
1108 case CK_ARCExtendBlockObject:
1109 case CK_CopyAndAutoreleaseBlockObject:
1117 case CK_LValueBitCast:
1118 case CK_LValueToRValueBitCast:
1119 case CK_NullToMemberPointer:
1120 case CK_UserDefinedConversion:
1121 case CK_CPointerToObjCPointerCast:
1122 case CK_BlockPointerToObjCPointerCast:
1123 case CK_AnyPointerToBlockPointerCast:
1124 case CK_ArrayToPointerDecay:
1125 case CK_FunctionToPointerDecay:
1126 case CK_BaseToDerived:
1127 case CK_DerivedToBase:
1128 case CK_UncheckedDerivedToBase:
1129 case CK_MemberPointerToBoolean:
1130 case CK_VectorSplat:
1131 case CK_FloatingRealToComplex:
1132 case CK_FloatingComplexToReal:
1133 case CK_FloatingComplexToBoolean:
1134 case CK_FloatingComplexCast:
1135 case CK_FloatingComplexToIntegralComplex:
1136 case CK_IntegralRealToComplex:
1137 case CK_IntegralComplexToReal:
1138 case CK_IntegralComplexToBoolean:
1139 case CK_IntegralComplexCast:
1140 case CK_IntegralComplexToFloatingComplex:
1141 case CK_PointerToIntegral:
1142 case CK_PointerToBoolean:
1143 case CK_NullToPointer:
1144 case CK_IntegralCast:
1145 case CK_BooleanToSignedIntegral:
1146 case CK_IntegralToPointer:
1147 case CK_IntegralToBoolean:
1148 case CK_IntegralToFloating:
1149 case CK_FloatingToIntegral:
1150 case CK_FloatingToBoolean:
1151 case CK_FloatingCast:
1152 case CK_FixedPointCast:
1153 case CK_FixedPointToBoolean:
1154 case CK_FixedPointToIntegral:
1155 case CK_IntegralToFixedPoint:
1156 case CK_ZeroToOCLOpaqueType:
1159 llvm_unreachable(
"Invalid CastKind");
1165 return Visit(DIE->
getExpr(), T);
1181 assert(CAT &&
"can't emit array init for non-constant-bound array");
1183 unsigned NumElements = CAT->getSize().getZExtValue();
1187 unsigned NumInitableElts =
std::min(NumInitElements, NumElements);
1189 QualType EltType = CAT->getElementType();
1192 llvm::Constant *fillC =
nullptr;
1201 if (fillC && fillC->isNullValue())
1202 Elts.reserve(NumInitableElts + 1);
1204 Elts.reserve(NumElements);
1207 for (
unsigned i = 0;
i < NumInitableElts; ++
i) {
1213 CommonElementType = C->getType();
1214 else if (C->getType() != CommonElementType)
1215 CommonElementType =
nullptr;
1219 llvm::ArrayType *Desired =
1221 return EmitArrayConstant(CGM, Desired, CommonElementType, NumElements, Elts,
1226 return ConstStructBuilder::BuildStruct(Emitter, ILE, T);
1236 return Visit(ILE->
getInit(0), T);
1239 return EmitArrayInitialization(ILE, T);
1242 return EmitRecordInitialization(ILE, T);
1249 auto C = Visit(E->
getBase(), destType);
1253 ConstantAggregateBuilder Const(CGM);
1256 if (!EmitDesignatedInitUpdater(Emitter, Const,
CharUnits::Zero(), destType,
1261 bool HasFlexibleArray =
false;
1263 HasFlexibleArray = RT->getDecl()->hasFlexibleArrayMember();
1264 return Const.build(ValTy, HasFlexibleArray);
1278 if (!RD->hasTrivialDestructor())
1285 assert(E->
getNumArgs() == 1 &&
"trivial ctor with > 1 argument");
1287 "trivial ctor has argument but isn't a copy/move ctor");
1291 "argument to copy ctor is of wrong type");
1293 return Visit(Arg, Ty);
1314 Str.resize(CAT->
getSize().getZExtValue(),
'\0');
1315 return llvm::ConstantDataArray::getString(VMContext, Str,
false);
1330 llvm::Constant *ConstantEmitter::validateAndPopAbstract(llvm::Constant *C,
1331 AbstractState saved) {
1332 Abstract = saved.OldValue;
1334 assert(saved.OldPlaceholdersSize == PlaceholderAddresses.size() &&
1335 "created a placeholder while doing an abstract emission?");
1344 auto state = pushAbstract();
1345 auto C = tryEmitPrivateForVarInit(D);
1346 return validateAndPopAbstract(C,
state);
1351 auto state = pushAbstract();
1352 auto C = tryEmitPrivate(E, destType);
1353 return validateAndPopAbstract(C,
state);
1358 auto state = pushAbstract();
1359 auto C = tryEmitPrivate(value, destType);
1360 return validateAndPopAbstract(C,
state);
1365 auto state = pushAbstract();
1366 auto C = tryEmitPrivate(E, destType);
1367 C = validateAndPopAbstract(C,
state);
1370 "internal error: could not emit constant value \"abstractly\"");
1379 auto state = pushAbstract();
1380 auto C = tryEmitPrivate(value, destType);
1381 C = validateAndPopAbstract(C,
state);
1384 "internal error: could not emit constant value \"abstractly\"");
1392 return markIfFailed(tryEmitPrivateForVarInit(D));
1398 initializeNonAbstract(destAddrSpace);
1399 return markIfFailed(tryEmitPrivateForMemory(E, destType));
1405 initializeNonAbstract(destAddrSpace);
1406 auto C = tryEmitPrivateForMemory(value, destType);
1407 assert(C &&
"couldn't emit constant value non-abstractly?");
1412 assert(!Abstract &&
"cannot get current address for abstract constant");
1418 auto global =
new llvm::GlobalVariable(CGM.
getModule(), CGM.
Int8Ty,
true,
1419 llvm::GlobalValue::PrivateLinkage,
1423 llvm::GlobalVariable::NotThreadLocal,
1426 PlaceholderAddresses.push_back(std::make_pair(
nullptr, global));
1432 llvm::GlobalValue *placeholder) {
1433 assert(!PlaceholderAddresses.empty());
1434 assert(PlaceholderAddresses.back().first ==
nullptr);
1435 assert(PlaceholderAddresses.back().second == placeholder);
1436 PlaceholderAddresses.back().first = signal;
1440 struct ReplacePlaceholders {
1444 llvm::Constant *Base;
1448 llvm::DenseMap<llvm::Constant*, llvm::GlobalVariable*> PlaceholderAddresses;
1451 llvm::DenseMap<llvm::GlobalVariable*, llvm::Constant*> Locations;
1459 ReplacePlaceholders(
CodeGenModule &CGM, llvm::Constant *base,
1460 ArrayRef<std::pair<llvm::Constant*,
1461 llvm::GlobalVariable*>> addresses)
1462 : CGM(CGM), Base(base),
1463 PlaceholderAddresses(addresses.begin(), addresses.end()) {
1466 void replaceInInitializer(llvm::Constant *init) {
1468 BaseValueTy = init->getType();
1471 Indices.push_back(0);
1472 IndexValues.push_back(
nullptr);
1475 findLocations(init);
1478 assert(IndexValues.size() == Indices.size() &&
"mismatch");
1479 assert(Indices.size() == 1 &&
"didn't pop all indices");
1482 assert(Locations.size() == PlaceholderAddresses.size() &&
1483 "missed a placeholder?");
1489 for (
auto &entry : Locations) {
1490 assert(entry.first->getParent() ==
nullptr &&
"not a placeholder!");
1491 entry.first->replaceAllUsesWith(entry.second);
1492 entry.first->eraseFromParent();
1497 void findLocations(llvm::Constant *init) {
1499 if (
auto agg = dyn_cast<llvm::ConstantAggregate>(init)) {
1500 for (
unsigned i = 0, e = agg->getNumOperands();
i != e; ++
i) {
1501 Indices.push_back(
i);
1502 IndexValues.push_back(
nullptr);
1504 findLocations(agg->getOperand(
i));
1506 IndexValues.pop_back();
1514 auto it = PlaceholderAddresses.find(init);
1515 if (it != PlaceholderAddresses.end()) {
1516 setLocation(it->second);
1521 if (
auto expr = dyn_cast<llvm::ConstantExpr>(init)) {
1522 init =
expr->getOperand(0);
1529 void setLocation(llvm::GlobalVariable *placeholder) {
1530 assert(Locations.find(placeholder) == Locations.end() &&
1531 "already found location for placeholder!");
1536 assert(Indices.size() == IndexValues.size());
1537 for (
size_t i = Indices.size() - 1;
i !=
size_t(-1); --
i) {
1538 if (IndexValues[
i]) {
1540 for (
size_t j = 0; j != i + 1; ++j) {
1541 assert(IndexValues[j] &&
1542 isa<llvm::ConstantInt>(IndexValues[j]) &&
1543 cast<llvm::ConstantInt>(IndexValues[j])->getZExtValue()
1550 IndexValues[
i] = llvm::ConstantInt::get(CGM.
Int32Ty, Indices[i]);
1555 llvm::Constant *location =
1556 llvm::ConstantExpr::getInBoundsGetElementPtr(BaseValueTy,
1558 location = llvm::ConstantExpr::getBitCast(location,
1559 placeholder->getType());
1561 Locations.insert({placeholder, location});
1567 assert(InitializedNonAbstract &&
1568 "finalizing emitter that was used for abstract emission?");
1569 assert(!Finalized &&
"finalizing emitter multiple times");
1570 assert(global->getInitializer());
1575 if (!PlaceholderAddresses.empty()) {
1576 ReplacePlaceholders(CGM, global, PlaceholderAddresses)
1577 .replaceInInitializer(global->getInitializer());
1578 PlaceholderAddresses.clear();
1583 assert((!InitializedNonAbstract || Finalized || Failed) &&
1584 "not finalized after being initialized for non-abstract emission");
1585 assert(PlaceholderAddresses.empty() &&
"unhandled placeholders");
1604 dyn_cast_or_null<CXXConstructExpr>(D.
getInit())) {
1609 InConstantContext =
true;
1617 return tryEmitPrivateForMemory(*value, destType);
1630 assert(E &&
"No initializer to emit");
1634 ConstExprEmitter(*this).Visit(const_cast<Expr*>(E), nonMemoryDestType);
1635 return (C ? emitForMemory(C, destType) :
nullptr);
1641 auto C = tryEmitAbstract(E, nonMemoryDestType);
1642 return (C ? emitForMemory(C, destType) :
nullptr);
1649 auto C = tryEmitAbstract(value, nonMemoryDestType);
1650 return (C ? emitForMemory(C, destType) :
nullptr);
1656 llvm::Constant *C = tryEmitPrivate(E, nonMemoryDestType);
1657 return (C ? emitForMemory(C, destType) :
nullptr);
1663 auto C = tryEmitPrivate(value, nonMemoryDestType);
1664 return (C ? emitForMemory(C, destType) :
nullptr);
1672 QualType destValueType = AT->getValueType();
1673 C = emitForMemory(CGM, C, destValueType);
1677 if (innerSize == outerSize)
1680 assert(innerSize < outerSize &&
"emitted over-large constant for atomic");
1681 llvm::Constant *elts[] = {
1683 llvm::ConstantAggregateZero::get(
1684 llvm::ArrayType::get(CGM.
Int8Ty, (outerSize - innerSize) / 8))
1686 return llvm::ConstantStruct::getAnon(elts);
1690 if (C->getType()->isIntegerTy(1)) {
1692 return llvm::ConstantExpr::getZExt(C, boolTy);
1702 bool Success =
false;
1711 C = tryEmitPrivate(Result.
Val, destType);
1713 C = ConstExprEmitter(*this).Visit(const_cast<Expr*>(E), destType);
1719 return getTargetCodeGenInfo().getNullPointer(*
this, T, QT);
1725 struct ConstantLValue {
1726 llvm::Constant *
Value;
1727 bool HasOffsetApplied;
1729 ConstantLValue(llvm::Constant *value,
1730 bool hasOffsetApplied =
false)
1731 :
Value(value), HasOffsetApplied(
false) {}
1738 class ConstantLValueEmitter :
public ConstStmtVisitor<ConstantLValueEmitter,
1751 : CGM(emitter.
CGM), Emitter(emitter),
Value(value), DestType(destType) {}
1753 llvm::Constant *tryEmit();
1756 llvm::Constant *tryEmitAbsolute(
llvm::Type *destTy);
1759 ConstantLValue VisitStmt(
const Stmt *S) {
return nullptr; }
1760 ConstantLValue VisitConstantExpr(
const ConstantExpr *E);
1768 ConstantLValue VisitCallExpr(
const CallExpr *E);
1769 ConstantLValue VisitBlockExpr(
const BlockExpr *E);
1772 ConstantLValue VisitMaterializeTemporaryExpr(
1775 bool hasNonZeroOffset()
const {
1780 llvm::Constant *getOffset() {
1781 return llvm::ConstantInt::get(CGM.
Int64Ty,
1786 llvm::Constant *applyOffset(llvm::Constant *C) {
1787 if (!hasNonZeroOffset())
1791 unsigned AS = origPtrTy->getPointerAddressSpace();
1793 C = llvm::ConstantExpr::getBitCast(C, charPtrTy);
1794 C = llvm::ConstantExpr::getGetElementPtr(CGM.
Int8Ty, C, getOffset());
1795 C = llvm::ConstantExpr::getPointerCast(C, origPtrTy);
1802 llvm::Constant *ConstantLValueEmitter::tryEmit() {
1813 assert(isa<llvm::IntegerType>(destTy) || isa<llvm::PointerType>(destTy));
1818 return tryEmitAbsolute(destTy);
1822 ConstantLValue
result = tryEmitBase(base);
1825 llvm::Constant *value = result.Value;
1826 if (!value)
return nullptr;
1829 if (!result.HasOffsetApplied) {
1830 value = applyOffset(value);
1835 if (isa<llvm::PointerType>(destTy))
1836 return llvm::ConstantExpr::getPointerCast(value, destTy);
1838 return llvm::ConstantExpr::getPtrToInt(value, destTy);
1844 ConstantLValueEmitter::tryEmitAbsolute(
llvm::Type *destTy) {
1846 auto destPtrTy = cast<llvm::PointerType>(destTy);
1847 if (
Value.isNullPointer()) {
1855 auto intptrTy = CGM.
getDataLayout().getIntPtrType(destPtrTy);
1857 C = llvm::ConstantExpr::getIntegerCast(getOffset(), intptrTy,
1859 C = llvm::ConstantExpr::getIntToPtr(C, destPtrTy);
1867 if (D->hasAttr<WeakRefAttr>())
1870 if (
auto FD = dyn_cast<FunctionDecl>(D))
1873 if (
auto VD = dyn_cast<VarDecl>(D)) {
1875 if (!VD->hasLocalStorage()) {
1876 if (VD->isFileVarDecl() || VD->hasExternalStorage())
1879 if (VD->isLocalVarDecl()) {
1895 if (TypeInfo->getType() != StdTypeInfoPtrTy)
1896 TypeInfo = llvm::ConstantExpr::getBitCast(TypeInfo, StdTypeInfoPtrTy);
1901 return Visit(base.
get<
const Expr*>());
1905 ConstantLValueEmitter::VisitConstantExpr(
const ConstantExpr *E) {
1911 return tryEmitGlobalCompoundLiteral(CGM, Emitter.
CGF, E);
1915 ConstantLValueEmitter::VisitStringLiteral(
const StringLiteral *E) {
1920 ConstantLValueEmitter::VisitObjCEncodeExpr(
const ObjCEncodeExpr *E) {
1937 ConstantLValueEmitter::VisitObjCBoxedExpr(
const ObjCBoxedExpr *E) {
1939 "this boxed expression can't be emitted as a compile-time constant");
1945 ConstantLValueEmitter::VisitPredefinedExpr(
const PredefinedExpr *E) {
1950 ConstantLValueEmitter::VisitAddrLabelExpr(
const AddrLabelExpr *E) {
1951 assert(Emitter.
CGF &&
"Invalid address of label expression outside function");
1953 Ptr = llvm::ConstantExpr::getBitCast(Ptr,
1959 ConstantLValueEmitter::VisitCallExpr(
const CallExpr *E) {
1961 if (builtin != Builtin::BI__builtin___CFStringMakeConstantString &&
1962 builtin != Builtin::BI__builtin___NSStringMakeConstantString)
1966 if (builtin == Builtin::BI__builtin___NSStringMakeConstantString) {
1975 ConstantLValueEmitter::VisitBlockExpr(
const BlockExpr *E) {
1976 StringRef functionName;
1977 if (
auto CGF = Emitter.
CGF)
1978 functionName = CGF->
CurFn->getName();
1980 functionName =
"global";
1986 ConstantLValueEmitter::VisitCXXTypeidExpr(
const CXXTypeidExpr *E) {
1996 ConstantLValueEmitter::VisitCXXUuidofExpr(
const CXXUuidofExpr *E) {
2001 ConstantLValueEmitter::VisitMaterializeTemporaryExpr(
2019 return ConstantLValueEmitter(*
this, Value, DestType).tryEmit();
2034 llvm::StructType *STy =
2035 llvm::StructType::get(Complex[0]->getType(), Complex[1]->getType());
2036 return llvm::ConstantStruct::get(STy, Complex);
2039 const llvm::APFloat &Init = Value.
getFloat();
2040 if (&Init.getSemantics() == &llvm::APFloat::IEEEhalf() &&
2044 Init.bitcastToAPInt());
2057 llvm::StructType *STy =
2058 llvm::StructType::get(Complex[0]->getType(), Complex[1]->getType());
2059 return llvm::ConstantStruct::get(STy, Complex);
2065 for (
unsigned I = 0; I != NumElts; ++I) {
2072 llvm_unreachable(
"unsupported vector element type");
2074 return llvm::ConstantVector::get(Inits);
2079 llvm::Constant *LHS = tryEmitPrivate(LHSExpr, LHSExpr->
getType());
2080 llvm::Constant *RHS = tryEmitPrivate(RHSExpr, RHSExpr->
getType());
2081 if (!LHS || !RHS)
return nullptr;
2085 LHS = llvm::ConstantExpr::getPtrToInt(LHS, CGM.
IntPtrTy);
2086 RHS = llvm::ConstantExpr::getPtrToInt(RHS, CGM.
IntPtrTy);
2087 llvm::Constant *AddrLabelDiff = llvm::ConstantExpr::getSub(LHS, RHS);
2092 return llvm::ConstantExpr::getTruncOrBitCast(AddrLabelDiff, ResultType);
2096 return ConstStructBuilder::BuildStruct(*
this, Value, DestType);
2104 llvm::Constant *Filler =
nullptr;
2114 if (Filler && Filler->isNullValue())
2115 Elts.reserve(NumInitElts + 1);
2117 Elts.reserve(NumElements);
2120 for (
unsigned I = 0; I < NumInitElts; ++I) {
2121 llvm::Constant *C = tryEmitPrivateForMemory(
2123 if (!C)
return nullptr;
2126 CommonElementType = C->getType();
2127 else if (C->getType() != CommonElementType)
2128 CommonElementType =
nullptr;
2134 if (CAT ==
nullptr && CommonElementType ==
nullptr && !NumInitElts) {
2137 llvm::ArrayType *AType = llvm::ArrayType::get(CommonElementType,
2139 return llvm::ConstantAggregateZero::get(AType);
2142 llvm::ArrayType *Desired =
2144 return EmitArrayConstant(CGM, Desired, CommonElementType, NumElements, Elts,
2150 llvm_unreachable(
"Unknown APValue kind");
2155 return EmittedCompoundLiterals.lookup(E);
2160 bool Ok = EmittedCompoundLiterals.insert(std::make_pair(CLE, GV)).second;
2162 assert(Ok &&
"CLE has already been emitted!");
2167 assert(E->
isFileScope() &&
"not a file-scope compound literal expr");
2168 return tryEmitGlobalCompoundLiteral(*
this,
nullptr, E);
2178 if (
const CXXMethodDecl *method = dyn_cast<CXXMethodDecl>(decl))
2179 return getCXXABI().EmitMemberFunctionPointer(method);
2182 uint64_t fieldOffset = getContext().getFieldOffset(decl);
2183 CharUnits chars = getContext().toCharUnitsFromBits((int64_t) fieldOffset);
2184 return getCXXABI().EmitMemberDataPointer(type, chars);
2193 bool asCompleteObject) {
2195 llvm::StructType *structure =
2199 unsigned numElements = structure->getNumElements();
2200 std::vector<llvm::Constant *> elements(numElements);
2205 for (
const auto &I : CXXR->bases()) {
2206 if (I.isVirtual()) {
2213 cast<CXXRecordDecl>(I.getType()->castAs<
RecordType>()->getDecl());
2222 llvm::Type *baseType = structure->getElementType(fieldIndex);
2228 for (
const auto *Field : record->
fields()) {
2241 if (FieldRD->findFirstNamedDataMember())
2247 if (CXXR && asCompleteObject) {
2248 for (
const auto &I : CXXR->vbases()) {
2250 cast<CXXRecordDecl>(I.getType()->castAs<
RecordType>()->getDecl());
2259 if (elements[fieldIndex])
continue;
2261 llvm::Type *baseType = structure->getElementType(fieldIndex);
2267 for (
unsigned i = 0;
i != numElements; ++
i) {
2269 elements[
i] = llvm::Constant::getNullValue(structure->getElementType(i));
2272 return llvm::ConstantStruct::get(structure, elements);
2283 return llvm::Constant::getNullValue(baseType);
2296 return getNullPointer(
2297 cast<llvm::PointerType>(getTypes().ConvertTypeForMem(T)), T);
2299 if (getTypes().isZeroInitializable(T))
2300 return llvm::Constant::getNullValue(getTypes().ConvertTypeForMem(T));
2303 llvm::ArrayType *ATy =
2304 cast<llvm::ArrayType>(getTypes().ConvertTypeForMem(T));
2308 llvm::Constant *Element =
2310 unsigned NumElements = CAT->
getSize().getZExtValue();
2312 return llvm::ConstantArray::get(ATy, Array);
2319 "Should only see pointers to data members here!");
const llvm::DataLayout & getDataLayout() const
const Expr * getSubExpr() const
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Defines the clang::ASTContext interface.
CharUnits alignTo(const CharUnits &Align) const
alignTo - Returns the next integer (mod 2**64) that is greater than or equal to this quantity and is ...
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
virtual llvm::Constant * EmitMemberPointer(const APValue &MP, QualType MPT)
Create a member pointer for the given member pointer constant.
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
CodeGenTypes & getTypes()
llvm::Constant * emitForInitializer(const APValue &value, LangAS destAddrSpace, QualType destType)
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr *> &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
CGRecordLayout - This class handles struct and union layout info while lowering AST types to LLVM typ...
bool isMemberDataPointerType() const
llvm::APSInt getValue() const
Expr * getResultExpr()
Return the result expression of this controlling expression.
llvm::Constant * getMemberPointerConstant(const UnaryOperator *e)
llvm::LLVMContext & getLLVMContext()
const Expr * getInit(unsigned Init) const
ConstantAddress GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *)
Return a pointer to a constant array for the given ObjCEncodeExpr node.
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D...
Stmt - This represents one statement.
llvm::Constant * tryEmitForInitializer(const VarDecl &D)
Try to emit the initiaizer of the given declaration as an abstract constant.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
bool isRecordType() const
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Decl - This represents one declaration (or definition), e.g.
llvm::Constant * emitForMemory(llvm::Constant *C, QualType T)
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic, and whose semantics are that of the sole contained initializer)?
ParenExpr - This represents a parethesized expression, e.g.
The base class of the type hierarchy.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Represents a call to a C++ constructor.
bool isZero() const
isZero - Test whether the quantity equals zero.
const TargetInfo & getTargetInfo() const
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Represents a C++ constructor within a class.
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
const AddrLabelExpr * getAddrLabelDiffLHS() const
QualType getElementType() const
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
llvm::Constant * tryEmitPrivateForVarInit(const VarDecl &D)
Represents a variable declaration or definition.
CompoundLiteralExpr - [C99 6.5.2.5].
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
APFloat & getComplexFloatReal()
const T * getAs() const
Member-template getAs<specific type>'.
LangAS
Defines the address space values used by the address space qualifier of QualType. ...
QualType getTypeInfoType() const
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
Expr * getExprOperand() const
Represents an expression – generally a full-expression – that introduces cleanups to be run at the ...
bool isZeroInitializableAsBase() const
Check whether this struct can be C++ zero-initialized with a zeroinitializer when considered as a bas...
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Represents a struct/union/class.
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
Expr * GetTemporaryExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
bool cleanupsHaveSideEffects() const
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
virtual llvm::Constant * getVTableAddressPointForConstExpr(BaseSubobject Base, const CXXRecordDecl *VTableClass)=0
Get the address point of the vtable for the given base subobject while building a constexpr...
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
llvm::Constant * tryEmitAbstractForInitializer(const VarDecl &D)
Try to emit the initializer of the given declaration as an abstract constant.
llvm::IntegerType * Int64Ty
field_range fields() const
Represents a member of a struct/union/class.
StringLiteral * getString()
unsigned getNonVirtualBaseLLVMFieldNo(const CXXRecordDecl *RD) const
bool isReferenceType() const
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
unsigned getArraySize() const
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
__DEVICE__ int max(int __a, int __b)
Symbolic representation of typeid(T) for some type T.
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final * state
llvm::Constant * GetConstantArrayFromStringLiteral(const StringLiteral *E)
Return a constant array for the given string.
Describes an C or C++ initializer list.
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
bool isBitField() const
Determines whether this field is a bitfield.
CharUnits - This is an opaque type for sizes expressed in character units.
APValue Val
Val - This is the value the expression can be folded to.
llvm::Constant * tryEmitPrivate(const Expr *E, QualType T)
llvm::StructType * getBaseSubobjectLLVMType() const
Return the "base subobject" LLVM type associated with this record.
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
ObjCStringLiteral, used for Objective-C string literals i.e.
field_iterator field_begin() const
unsigned getBitWidthValue(const ASTContext &Ctx) const
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
APSInt & getComplexIntReal()
llvm::GlobalValue * getCurrentAddrPrivate()
Get the address of the current location.
virtual llvm::Value * performAddrSpaceCast(CodeGen::CodeGenFunction &CGF, llvm::Value *V, LangAS SrcAddr, LangAS DestAddr, llvm::Type *DestTy, bool IsNonNull=false) const
Perform address space cast of an expression of pointer type.
bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor)
isTypeConstant - Determine whether an object of this type can be emitted as a constant.
const Expr * getExpr() const
Get the initialization expression that will be used.
APValue & getVectorElt(unsigned I)
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
static CharUnits One()
One - Construct a CharUnits quantity of one.
ConstantAddress getElementBitCast(llvm::Type *ty) const
const TargetCodeGenInfo & getTargetCodeGenInfo()
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
APValue & getArrayFiller()
bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsLValue - Evaluate an expression to see if we can fold it to an lvalue with link time known ...
llvm::Constant * getNullPointer(llvm::PointerType *T, QualType QT)
Get target specific null pointer.
InitListExpr * getUpdater() const
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
bool hasArrayFiller() const
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
This represents one expression.
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
llvm::Constant * GetAddrOfGlobalVar(const VarDecl *D, llvm::Type *Ty=nullptr, ForDefinition_t IsForDefinition=NotForDefinition)
Return the llvm::Constant for the address of the given global variable.
const T * castAs() const
Member-template castAs<specific type>.
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
unsigned getNumInits() const
field_iterator field_end() const
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
const CXXRecordDecl * getPrimaryBase() const
getPrimaryBase - Get the primary base for this record.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
llvm::IntegerType * Int32Ty
llvm::GlobalValue::LinkageTypes getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant)
Returns LLVM linkage for a declarator.
APValue & getStructField(unsigned i)
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
QualType getEncodedType() const
ConstantAddress GetAddrOfUuidDescriptor(const CXXUuidofExpr *E)
Get the address of a uuid descriptor .
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
QualType getTypeOperand(ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
Represents a reference to a non-type template parameter that has been substituted with a template arg...
APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
APSInt & getComplexIntImag()
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
const Expr * getSubExpr() const
ASTContext & getContext() const
const FieldDecl * getUnionField() const
ConstantAddress GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E, const Expr *Inner)
Returns a pointer to a global variable representing a temporary with static or thread storage duratio...
unsigned getBuiltinCallee() const
getBuiltinCallee - If this is a call to a builtin, return the builtin ID of the callee.
The l-value was considered opaque, so the alignment was determined from a type.
RecordDecl * getDecl() const
APValue & getStructBase(unsigned i)
virtual bool useFP16ConversionIntrinsics() const
Check whether llvm intrinsics such as llvm.convert.to.fp16 should be used to convert to and from __fp...
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
static ConstantLValue emitConstantObjCStringLiteral(const StringLiteral *S, QualType T, CodeGenModule &CGM)
llvm::Constant * getOrCreateStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsRValue - Return true if this is a constant which we can fold to an rvalue using any crazy t...
APValue & getArrayInitializedElt(unsigned I)
virtual llvm::Value * EmitMemberPointerConversion(CodeGenFunction &CGF, const CastExpr *E, llvm::Value *Src)
Perform a derived-to-base, base-to-derived, or bitcast member pointer conversion. ...
This object has an indeterminate value (C++ [basic.indet]).
static QualType getNonMemoryType(CodeGenModule &CGM, QualType type)
bool isExpressibleAsConstantInitializer() const
StringLiteral * getFunctionName()
Encodes a location in the source.
const AddrLabelExpr * getAddrLabelDiffRHS() const
LangAS getAddressSpace() const
Return the address space of this type.
virtual ConstantAddress GenerateConstantString(const StringLiteral *)=0
Generate a constant string object.
Expr * getSubExpr() const
ConstantAddress GetAddrOfConstantCFString(const StringLiteral *Literal)
Return a pointer to a constant CFString object for the given string.
CastKind getCastKind() const
APValue & getUnionValue()
bool isUnnamedBitfield() const
Determines whether this is an unnamed bitfield.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
Represents a static or instance method of a struct/union/class.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
ConstantAddress GetAddrOfConstantStringFromLiteral(const StringLiteral *S, StringRef Name=".str")
Return a pointer to a constant array for the given string literal.
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
llvm::Constant * EmitNullConstantForBase(const CXXRecordDecl *Record)
Return a null constant appropriate for zero-initializing a base class with the given type...
llvm::Constant * GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH=false)
Get the address of the RTTI descriptor for the given type.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
llvm::Constant * emitAbstract(const Expr *E, QualType T)
Emit the result of the given expression as an abstract constant, asserting that it succeeded...
ConstantAddress GetWeakRefReference(const ValueDecl *VD)
Get a reference to the target of VD.
void registerCurrentAddrPrivate(llvm::Constant *signal, llvm::GlobalValue *placeholder)
Register a 'signal' value with the emitter to inform it where to resolve a placeholder.
llvm::GlobalVariable * getAddrOfConstantCompoundLiteralIfEmitted(const CompoundLiteralExpr *E)
If it's been emitted already, returns the GlobalVariable corresponding to a compound literal...
constexpr XRayInstrMask None
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
ObjCBoxedExpr - used for generalized expression boxing.
void Error(SourceLocation loc, StringRef error)
Emit a general error that something can't be done.
llvm::Constant * emitNullForMemory(QualType T)
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
bool hasFlexibleArrayMember() const
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
const Expr * getInitializer() const
Represents a C11 generic selection.
AddrLabelExpr - The GNU address of label extension, representing &&label.
const FieldDecl * getTargetUnionField() const
This class organizes the cross-function state that is used while generating LLVM code.
bool isTypeOperand() const
Dataflow Directional Tag Classes.
[C99 6.4.2.2] - A predefined identifier such as func.
EvalResult is a struct with detailed info about an evaluated expression.
const Expr * getInit() const
static llvm::Constant * EmitNullConstantForBase(CodeGenModule &CGM, llvm::Type *baseType, const CXXRecordDecl *base)
Emit the null constant for a base subobject.
llvm::Constant * getPointer() const
llvm::IntegerType * IntPtrTy
unsigned getArrayInitializedElts() const
llvm::Constant * EmitNullConstant(QualType T)
Return the result of value-initializing the given type, i.e.
A pointer to member type per C++ 8.3.3 - Pointers to members.
llvm::Module & getModule() const
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
LabelDecl * getLabel() const
llvm::Constant * tryEmitPrivateForMemory(const Expr *E, QualType T)
void EmitExplicitCastExprType(const ExplicitCastExpr *E, CodeGenFunction *CGF=nullptr)
Emit type info if type of an expression is a variably modified type.
bool HasSideEffects
Whether the evaluated expression has side effects.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
StmtVisitorBase - This class implements a simple visitor for Stmt subclasses.
ObjCEncodeExpr, used for @encode in Objective-C.
const llvm::APInt & getSize() const
uint64_t getCharWidth() const
Return the size of the character type, in bits.
void getObjCEncodingForType(QualType T, std::string &S, const FieldDecl *Field=nullptr, QualType *NotEncodedT=nullptr) const
Emit the Objective-CC type encoding for the given type T into S.
Expr * getReplacement() const
Expr * getArg(unsigned Arg)
Return the specified argument.
llvm::StructType * getLLVMType() const
Return the "complete object" LLVM type associated with this record.
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=nullptr, bool ForVTable=false, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the given function.
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
ConstantAddress GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr *E)
Returns a pointer to a constant global variable for the given file-scope compound literal expression...
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
Represents a base class of a C++ class.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
A use of a default initializer in a constructor or in aggregate initialization.
void setAddrOfConstantCompoundLiteral(const CompoundLiteralExpr *CLE, llvm::GlobalVariable *GV)
Notes that CLE's GlobalVariable is GV.
static llvm::Constant * EmitNullConstant(CodeGenModule &CGM, const RecordDecl *record, bool asCompleteObject)
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
int64_t toBits(CharUnits CharSize) const
Convert a size in characters to a size in bits.
ValueKind getKind() const
APFloat & getComplexFloatImag()
Represents a C++ struct/union/class.
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
A specialization of Address that requires the address to be an LLVM Constant.
There is no such object (it's outside its lifetime).
CharUnits getNonVirtualSize() const
getNonVirtualSize - Get the non-virtual size (in chars) of an object, which is the size of the object...
unsigned getVirtualBaseIndex(const CXXRecordDecl *base) const
Return the LLVM field index corresponding to the given virtual base.
__DEVICE__ int min(int __a, int __b)
StringLiteral - This represents a string literal expression, e.g.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
void finalize(llvm::GlobalVariable *global)
llvm::Constant * tryEmitAbstract(const Expr *E, QualType T)
Try to emit the result of the given expression as an abstract constant.
static ConstantAddress invalid()
CGCXXABI & getCXXABI() const
llvm::Constant * tryEmitAbstractForMemory(const Expr *E, QualType T)
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
llvm::Constant * GetAddrOfGlobalBlock(const BlockExpr *BE, StringRef Name)
Gets the address of a block which requires no captures.
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
llvm::BlockAddress * GetAddrOfLabel(const LabelDecl *L)
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
unsigned getTargetAddressSpace(QualType T) const
bool isZeroSize(const ASTContext &Ctx) const
Determine if this field is a subobject of zero size, that is, either a zero-length bit-field or a fie...
const CGRecordLayout & getCGRecordLayout(const RecordDecl *)
getCGRecordLayout - Return record layout info for the given record decl.
const LangOptions & getLangOpts() const
Represents the canonical version of C arrays with a specified constant size.
Defines enum values for all the target-independent builtin functions.
Represents an implicitly-generated value initialization of an object of a given type.
APFixedPoint & getFixedPoint()
CharUnits & getLValueOffset()
unsigned getLLVMFieldNo(const FieldDecl *FD) const
Return llvm::StructType element number that corresponds to the field FD.
unsigned getVectorLength() const