26 #include "llvm/IR/Constants.h" 27 #include "llvm/IR/DataLayout.h" 28 #include "llvm/IR/Function.h" 29 #include "llvm/IR/GlobalVariable.h" 30 using namespace clang;
31 using namespace CodeGen;
38 class ConstExprEmitter;
39 class ConstStructBuilder {
49 ConstExprEmitter *ExprEmitter,
50 llvm::ConstantStruct *
Base,
60 : CGM(emitter.CGM), Emitter(emitter), Packed(
false),
61 NextFieldOffsetInChars(
CharUnits::Zero()),
64 void AppendField(
const FieldDecl *Field, uint64_t FieldOffset,
65 llvm::Constant *InitExpr);
67 void AppendBytes(
CharUnits FieldOffsetInChars, llvm::Constant *InitCst);
69 void AppendBitField(
const FieldDecl *Field, uint64_t FieldOffset,
70 llvm::ConstantInt *InitExpr);
74 void AppendTailPadding(
CharUnits RecordSize);
76 void ConvertStructToPacked();
79 bool Build(ConstExprEmitter *Emitter, llvm::ConstantStruct *
Base,
83 llvm::Constant *Finalize(
QualType Ty);
85 CharUnits getAlignment(
const llvm::Constant *C)
const {
91 CharUnits getSizeInChars(
const llvm::Constant *C)
const {
97 void ConstStructBuilder::
98 AppendField(
const FieldDecl *Field, uint64_t FieldOffset,
99 llvm::Constant *InitCst) {
104 AppendBytes(FieldOffsetInChars, InitCst);
107 void ConstStructBuilder::
108 AppendBytes(
CharUnits FieldOffsetInChars, llvm::Constant *InitCst) {
110 assert(NextFieldOffsetInChars <= FieldOffsetInChars
111 &&
"Field offset mismatch!");
113 CharUnits FieldAlignment = getAlignment(InitCst);
116 CharUnits AlignedNextFieldOffsetInChars =
117 NextFieldOffsetInChars.
alignTo(FieldAlignment);
119 if (AlignedNextFieldOffsetInChars < FieldOffsetInChars) {
121 AppendPadding(FieldOffsetInChars - NextFieldOffsetInChars);
123 assert(NextFieldOffsetInChars == FieldOffsetInChars &&
124 "Did not add enough padding!");
126 AlignedNextFieldOffsetInChars =
127 NextFieldOffsetInChars.
alignTo(FieldAlignment);
130 if (AlignedNextFieldOffsetInChars > FieldOffsetInChars) {
131 assert(!Packed &&
"Alignment is wrong even with a packed struct!");
134 ConvertStructToPacked();
137 if (NextFieldOffsetInChars < FieldOffsetInChars) {
139 AppendPadding(FieldOffsetInChars - NextFieldOffsetInChars);
141 assert(NextFieldOffsetInChars == FieldOffsetInChars &&
142 "Did not add enough padding!");
144 AlignedNextFieldOffsetInChars = NextFieldOffsetInChars;
148 Elements.push_back(InitCst);
149 NextFieldOffsetInChars = AlignedNextFieldOffsetInChars +
150 getSizeInChars(InitCst);
154 "Packed struct not byte-aligned!");
156 LLVMStructAlignment =
std::max(LLVMStructAlignment, FieldAlignment);
159 void ConstStructBuilder::AppendBitField(
const FieldDecl *Field,
160 uint64_t FieldOffset,
161 llvm::ConstantInt *CI) {
164 uint64_t NextFieldOffsetInBits = Context.
toBits(NextFieldOffsetInChars);
165 if (FieldOffset > NextFieldOffsetInBits) {
168 llvm::alignTo(FieldOffset - NextFieldOffsetInBits,
171 AppendPadding(PadSize);
176 llvm::APInt FieldValue = CI->getValue();
182 if (FieldSize > FieldValue.getBitWidth())
183 FieldValue = FieldValue.zext(FieldSize);
186 if (FieldSize < FieldValue.getBitWidth())
187 FieldValue = FieldValue.trunc(FieldSize);
189 NextFieldOffsetInBits = Context.
toBits(NextFieldOffsetInChars);
190 if (FieldOffset < NextFieldOffsetInBits) {
193 assert(!Elements.empty() &&
"Elements can't be empty!");
195 unsigned BitsInPreviousByte = NextFieldOffsetInBits - FieldOffset;
197 bool FitsCompletelyInPreviousByte =
198 BitsInPreviousByte >= FieldValue.getBitWidth();
200 llvm::APInt Tmp = FieldValue;
202 if (!FitsCompletelyInPreviousByte) {
203 unsigned NewFieldWidth = FieldSize - BitsInPreviousByte;
206 Tmp.lshrInPlace(NewFieldWidth);
207 Tmp = Tmp.trunc(BitsInPreviousByte);
210 FieldValue = FieldValue.trunc(NewFieldWidth);
212 Tmp = Tmp.trunc(BitsInPreviousByte);
215 FieldValue.lshrInPlace(BitsInPreviousByte);
216 FieldValue = FieldValue.trunc(NewFieldWidth);
220 Tmp = Tmp.zext(CharWidth);
222 if (FitsCompletelyInPreviousByte)
223 Tmp = Tmp.shl(BitsInPreviousByte - FieldValue.getBitWidth());
225 Tmp = Tmp.shl(CharWidth - BitsInPreviousByte);
230 if (llvm::ConstantInt *Val = dyn_cast<llvm::ConstantInt>(LastElt))
231 Tmp |= Val->getValue();
233 assert(isa<llvm::UndefValue>(LastElt));
238 if (!isa<llvm::IntegerType>(LastElt->getType())) {
241 assert(isa<llvm::ArrayType>(LastElt->getType()) &&
242 "Expected array padding of undefs");
243 llvm::ArrayType *AT = cast<llvm::ArrayType>(LastElt->getType());
244 assert(AT->getElementType()->isIntegerTy(CharWidth) &&
245 AT->getNumElements() != 0 &&
246 "Expected non-empty array padding of undefs");
255 assert(isa<llvm::UndefValue>(Elements.back()) &&
256 Elements.back()->getType()->isIntegerTy(CharWidth) &&
257 "Padding addition didn't work right");
261 Elements.back() = llvm::ConstantInt::get(CGM.
getLLVMContext(), Tmp);
263 if (FitsCompletelyInPreviousByte)
267 while (FieldValue.getBitWidth() > CharWidth) {
273 FieldValue.lshr(FieldValue.getBitWidth() - CharWidth).
trunc(CharWidth);
276 Tmp = FieldValue.trunc(CharWidth);
278 FieldValue.lshrInPlace(CharWidth);
281 Elements.push_back(llvm::ConstantInt::get(CGM.
getLLVMContext(), Tmp));
282 ++NextFieldOffsetInChars;
284 FieldValue = FieldValue.trunc(FieldValue.getBitWidth() - CharWidth);
287 assert(FieldValue.getBitWidth() > 0 &&
288 "Should have at least one bit left!");
289 assert(FieldValue.getBitWidth() <= CharWidth &&
290 "Should not have more than a byte left!");
292 if (FieldValue.getBitWidth() < CharWidth) {
294 unsigned BitWidth = FieldValue.getBitWidth();
296 FieldValue = FieldValue.zext(CharWidth) << (CharWidth - BitWidth);
298 FieldValue = FieldValue.zext(CharWidth);
304 ++NextFieldOffsetInChars;
307 void ConstStructBuilder::AppendPadding(
CharUnits PadSize) {
313 Ty = llvm::ArrayType::get(Ty, PadSize.
getQuantity());
315 llvm::Constant *C = llvm::UndefValue::get(Ty);
316 Elements.push_back(C);
318 "Padding must have 1 byte alignment!");
320 NextFieldOffsetInChars += getSizeInChars(C);
323 void ConstStructBuilder::AppendTailPadding(
CharUnits RecordSize) {
324 assert(NextFieldOffsetInChars <= RecordSize &&
327 AppendPadding(RecordSize - NextFieldOffsetInChars);
330 void ConstStructBuilder::ConvertStructToPacked() {
334 for (
unsigned i = 0, e = Elements.size(); i != e; ++i) {
335 llvm::Constant *C = Elements[i];
340 ElementOffsetInChars.
alignTo(ElementAlign);
342 if (AlignedElementOffsetInChars > ElementOffsetInChars) {
345 AlignedElementOffsetInChars - ElementOffsetInChars;
349 Ty = llvm::ArrayType::get(Ty, NumChars.
getQuantity());
351 llvm::Constant *Padding = llvm::UndefValue::get(Ty);
352 PackedElements.push_back(Padding);
353 ElementOffsetInChars += getSizeInChars(Padding);
356 PackedElements.push_back(C);
357 ElementOffsetInChars += getSizeInChars(C);
360 assert(ElementOffsetInChars == NextFieldOffsetInChars &&
361 "Packing the struct changed its size!");
363 Elements.swap(PackedElements);
372 unsigned FieldNo = 0;
373 unsigned ElementNo = 0;
378 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
379 if (CXXRD->getNumBases())
383 FieldEnd = RD->
field_end(); Field != FieldEnd; ++Field, ++FieldNo) {
394 llvm::Constant *EltInit;
395 if (ElementNo < ILE->getNumInits())
409 if (
auto *CI = dyn_cast<llvm::ConstantInt>(EltInit)) {
425 : Decl(Decl), Offset(Offset), Index(Index) {
432 bool operator<(
const BaseInfo &O)
const {
return Offset < O.Offset; }
444 if (CD->isDynamicClass() && !IsPrimaryBase) {
445 llvm::Constant *VTableAddressPoint =
448 AppendBytes(Offset, VTableAddressPoint);
454 Bases.reserve(CD->getNumBases());
457 BaseEnd = CD->bases_end();
Base != BaseEnd; ++
Base, ++BaseNo) {
458 assert(!
Base->isVirtual() &&
"should not have virtual bases here");
461 Bases.push_back(BaseInfo(BD, BaseOffset, BaseNo));
463 std::stable_sort(Bases.begin(), Bases.end());
465 for (
unsigned I = 0, N = Bases.size(); I != N; ++I) {
466 BaseInfo &
Base = Bases[I];
469 Build(Val.
getStructBase(Base.Index), Base.Decl, IsPrimaryBase,
470 VTableClass, Offset + Base.Offset);
474 unsigned FieldNo = 0;
478 FieldEnd = RD->
field_end(); Field != FieldEnd; ++Field, ++FieldNo) {
490 llvm::Constant *EltInit =
497 AppendField(*Field, Layout.
getFieldOffset(FieldNo) + OffsetBits, EltInit);
500 AppendBitField(*Field, Layout.
getFieldOffset(FieldNo) + OffsetBits,
501 cast<llvm::ConstantInt>(EltInit));
508 llvm::Constant *ConstStructBuilder::Finalize(
QualType Ty) {
514 if (NextFieldOffsetInChars > LayoutSizeInChars) {
518 "Must have flexible array member if struct is bigger than type!");
524 NextFieldOffsetInChars.
alignTo(LLVMStructAlignment);
526 if (LLVMSizeInChars != LayoutSizeInChars)
527 AppendTailPadding(LayoutSizeInChars);
529 LLVMSizeInChars = NextFieldOffsetInChars.
alignTo(LLVMStructAlignment);
532 if (NextFieldOffsetInChars <= LayoutSizeInChars &&
533 LLVMSizeInChars > LayoutSizeInChars) {
534 assert(!Packed &&
"Size mismatch!");
536 ConvertStructToPacked();
537 assert(NextFieldOffsetInChars <= LayoutSizeInChars &&
538 "Converting to packed did not help!");
541 LLVMSizeInChars = NextFieldOffsetInChars.
alignTo(LLVMStructAlignment);
543 assert(LayoutSizeInChars == LLVMSizeInChars &&
544 "Tail padding mismatch!");
549 llvm::StructType *STy =
553 if (llvm::StructType *ValSTy = dyn_cast<llvm::StructType>(ValTy)) {
554 if (ValSTy->isLayoutIdentical(STy))
558 llvm::Constant *Result = llvm::ConstantStruct::get(STy, Elements);
560 assert(NextFieldOffsetInChars.alignTo(getAlignment(Result)) ==
561 getSizeInChars(Result) &&
567 llvm::Constant *ConstStructBuilder::BuildStruct(
ConstantEmitter &Emitter,
568 ConstExprEmitter *ExprEmitter,
569 llvm::ConstantStruct *Base,
572 ConstStructBuilder Builder(Emitter);
573 if (!Builder.Build(ExprEmitter, Base, Updater))
575 return Builder.Finalize(ValTy);
578 llvm::Constant *ConstStructBuilder::BuildStruct(
ConstantEmitter &Emitter,
581 ConstStructBuilder Builder(Emitter);
583 if (!Builder.Build(ILE))
586 return Builder.Finalize(ValTy);
589 llvm::Constant *ConstStructBuilder::BuildStruct(
ConstantEmitter &Emitter,
592 ConstStructBuilder Builder(Emitter);
599 return Builder.Finalize(ValTy);
611 if (llvm::GlobalVariable *Addr =
618 llvm::Constant *C = emitter.tryEmitForInitializer(E->
getInitializer(),
622 "file-scope compound literal did not have constant initializer!");
626 auto GV =
new llvm::GlobalVariable(CGM.
getModule(), C->getType(),
629 C,
".compoundliteral",
nullptr,
630 llvm::GlobalVariable::NotThreadLocal,
632 emitter.finalize(GV);
642 class ConstExprEmitter :
643 public StmtVisitor<ConstExprEmitter, llvm::Constant*, QualType> {
646 llvm::LLVMContext &VMContext;
649 : CGM(emitter.CGM), Emitter(emitter), VMContext(CGM.getLLVMContext()) {
684 if (
const auto *ECE = dyn_cast<ExplicitCastExpr>(E))
692 "Destination type is not union type!");
697 if (!C)
return nullptr;
699 auto destTy = ConvertType(destType);
700 if (C->getType() == destTy)
return C;
707 Types.push_back(C->getType());
708 unsigned CurSize = CGM.
getDataLayout().getTypeAllocSize(C->getType());
709 unsigned TotalSize = CGM.
getDataLayout().getTypeAllocSize(destTy);
711 assert(CurSize <= TotalSize &&
"Union size mismatch!");
712 if (
unsigned NumPadBytes = TotalSize - CurSize) {
715 Ty = llvm::ArrayType::get(Ty, NumPadBytes);
717 Elts.push_back(llvm::UndefValue::get(Ty));
721 llvm::StructType *STy = llvm::StructType::get(VMContext, Types,
false);
722 return llvm::ConstantStruct::get(STy, Elts);
725 case CK_AddressSpaceConversion: {
727 if (!C)
return nullptr;
735 case CK_LValueToRValue:
736 case CK_AtomicToNonAtomic:
737 case CK_NonAtomicToAtomic:
739 case CK_ConstructorConversion:
740 return Visit(subExpr, destType);
742 case CK_IntToOCLSampler:
743 llvm_unreachable(
"global sampler variables are not generated");
745 case CK_Dependent: llvm_unreachable(
"saw dependent cast!");
747 case CK_BuiltinFnToFnPtr:
748 llvm_unreachable(
"builtin functions are handled elsewhere");
750 case CK_ReinterpretMemberPointer:
751 case CK_DerivedToBaseMemberPointer:
752 case CK_BaseToDerivedMemberPointer: {
754 if (!C)
return nullptr;
759 case CK_ObjCObjectLValueCast:
760 case CK_ARCProduceObject:
761 case CK_ARCConsumeObject:
762 case CK_ARCReclaimReturnedObject:
763 case CK_ARCExtendBlockObject:
764 case CK_CopyAndAutoreleaseBlockObject:
772 case CK_LValueBitCast:
773 case CK_NullToMemberPointer:
774 case CK_UserDefinedConversion:
775 case CK_CPointerToObjCPointerCast:
776 case CK_BlockPointerToObjCPointerCast:
777 case CK_AnyPointerToBlockPointerCast:
778 case CK_ArrayToPointerDecay:
779 case CK_FunctionToPointerDecay:
780 case CK_BaseToDerived:
781 case CK_DerivedToBase:
782 case CK_UncheckedDerivedToBase:
783 case CK_MemberPointerToBoolean:
785 case CK_FloatingRealToComplex:
786 case CK_FloatingComplexToReal:
787 case CK_FloatingComplexToBoolean:
788 case CK_FloatingComplexCast:
789 case CK_FloatingComplexToIntegralComplex:
790 case CK_IntegralRealToComplex:
791 case CK_IntegralComplexToReal:
792 case CK_IntegralComplexToBoolean:
793 case CK_IntegralComplexCast:
794 case CK_IntegralComplexToFloatingComplex:
795 case CK_PointerToIntegral:
796 case CK_PointerToBoolean:
797 case CK_NullToPointer:
798 case CK_IntegralCast:
799 case CK_BooleanToSignedIntegral:
800 case CK_IntegralToPointer:
801 case CK_IntegralToBoolean:
802 case CK_IntegralToFloating:
803 case CK_FloatingToIntegral:
804 case CK_FloatingToBoolean:
805 case CK_FloatingCast:
806 case CK_ZeroToOCLEvent:
807 case CK_ZeroToOCLQueue:
810 llvm_unreachable(
"Invalid CastKind");
835 llvm::ArrayType *AType =
836 cast<llvm::ArrayType>(ConvertType(ILE->
getType()));
839 unsigned NumElements = AType->getNumElements();
843 unsigned NumInitableElts =
std::min(NumInitElements, NumElements);
848 llvm::Constant *fillC;
857 if (fillC->isNullValue() && !NumInitableElts)
858 return llvm::ConstantAggregateZero::get(AType);
862 Elts.reserve(NumInitableElts + NumElements);
864 bool RewriteType =
false;
865 for (
unsigned i = 0; i < NumInitableElts; ++i) {
870 RewriteType |= (C->getType() != ElemTy);
874 RewriteType |= (fillC->getType() != ElemTy);
875 Elts.resize(NumElements, fillC);
879 std::vector<llvm::Type*> Types;
880 Types.reserve(NumInitableElts + NumElements);
881 for (
unsigned i = 0, e = Elts.size(); i < e; ++i)
882 Types.push_back(Elts[i]->getType());
883 llvm::StructType *SType = llvm::StructType::get(AType->getContext(),
885 return llvm::ConstantStruct::get(SType, Elts);
888 return llvm::ConstantArray::get(AType, Elts);
892 return ConstStructBuilder::BuildStruct(Emitter, ILE, T);
905 return EmitArrayInitialization(ILE, T);
908 return EmitRecordInitialization(ILE, T);
913 llvm::Constant *EmitDesignatedInitUpdater(llvm::Constant *Base,
917 llvm::ArrayType *AType = cast<llvm::ArrayType>(ConvertType(destType));
918 llvm::Type *ElemType = AType->getElementType();
921 unsigned NumElements = AType->getNumElements();
923 std::vector<llvm::Constant *> Elts;
924 Elts.reserve(NumElements);
926 QualType destElemType = destAT->getElementType();
928 if (
auto DataArray = dyn_cast<llvm::ConstantDataArray>(Base))
929 for (
unsigned i = 0; i != NumElements; ++i)
930 Elts.push_back(DataArray->getElementAsConstant(i));
931 else if (
auto Array = dyn_cast<llvm::ConstantArray>(Base))
932 for (
unsigned i = 0; i != NumElements; ++i)
933 Elts.push_back(Array->getOperand(i));
937 llvm::Constant *fillC =
nullptr;
939 if (!isa<NoInitExpr>(filler))
941 bool RewriteType = (fillC && fillC->getType() != ElemType);
943 for (
unsigned i = 0; i != NumElements; ++i) {
944 Expr *Init =
nullptr;
945 if (i < NumInitElements)
950 else if (!Init || isa<NoInitExpr>(Init))
952 else if (
InitListExpr *ChildILE = dyn_cast<InitListExpr>(Init))
953 Elts[i] = EmitDesignatedInitUpdater(Elts[i], ChildILE, destElemType);
959 RewriteType |= (Elts[i]->getType() != ElemType);
963 std::vector<llvm::Type *> Types;
964 Types.reserve(NumElements);
965 for (
unsigned i = 0; i != NumElements; ++i)
966 Types.push_back(Elts[i]->getType());
967 llvm::StructType *SType = llvm::StructType::get(AType->getContext(),
969 return llvm::ConstantStruct::get(SType, Elts);
972 return llvm::ConstantArray::get(AType, Elts);
976 return ConstStructBuilder::BuildStruct(Emitter,
this,
977 dyn_cast<llvm::ConstantStruct>(Base), Updater, destType);
984 auto C = Visit(E->
getBase(), destType);
985 if (!C)
return nullptr;
986 return EmitDesignatedInitUpdater(C, E->
getUpdater(), destType);
1000 if (!RD->hasTrivialDestructor())
1007 assert(E->
getNumArgs() == 1 &&
"trivial ctor with > 1 argument");
1009 "trivial ctor has argument but isn't a copy/move ctor");
1013 "argument to copy ctor is of wrong type");
1015 return Visit(Arg, Ty);
1035 Str.resize(CAT->
getSize().getZExtValue(),
'\0');
1036 return llvm::ConstantDataArray::getString(VMContext, Str,
false);
1051 bool ConstStructBuilder::Build(ConstExprEmitter *ExprEmitter,
1052 llvm::ConstantStruct *Base,
1054 assert(Base &&
"base expression should not be empty");
1059 const llvm::StructLayout *BaseLayout = CGM.
getDataLayout().getStructLayout(
1061 unsigned FieldNo = -1;
1062 unsigned ElementNo = 0;
1067 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
1068 if (CXXRD->getNumBases())
1081 llvm::Constant *EltInit = Base->getOperand(ElementNo);
1087 BaseLayout->getElementOffsetInBits(ElementNo))
1092 Expr *Init =
nullptr;
1093 if (ElementNo < Updater->getNumInits())
1094 Init = Updater->
getInit(ElementNo);
1096 if (!Init || isa<NoInitExpr>(Init))
1098 else if (
InitListExpr *ChildILE = dyn_cast<InitListExpr>(Init))
1099 EltInit = ExprEmitter->EmitDesignatedInitUpdater(EltInit, ChildILE,
1111 else if (llvm::ConstantInt *CI = dyn_cast<llvm::ConstantInt>(EltInit))
1121 llvm::Constant *ConstantEmitter::validateAndPopAbstract(llvm::Constant *C,
1122 AbstractState saved) {
1123 Abstract = saved.OldValue;
1125 assert(saved.OldPlaceholdersSize == PlaceholderAddresses.size() &&
1126 "created a placeholder while doing an abstract emission?");
1135 auto state = pushAbstract();
1136 auto C = tryEmitPrivateForVarInit(D);
1137 return validateAndPopAbstract(C,
state);
1142 auto state = pushAbstract();
1143 auto C = tryEmitPrivate(E, destType);
1144 return validateAndPopAbstract(C,
state);
1149 auto state = pushAbstract();
1150 auto C = tryEmitPrivate(value, destType);
1151 return validateAndPopAbstract(C,
state);
1156 auto state = pushAbstract();
1157 auto C = tryEmitPrivate(E, destType);
1158 C = validateAndPopAbstract(C,
state);
1161 "internal error: could not emit constant value \"abstractly\"");
1170 auto state = pushAbstract();
1171 auto C = tryEmitPrivate(value, destType);
1172 C = validateAndPopAbstract(C,
state);
1175 "internal error: could not emit constant value \"abstractly\"");
1183 return markIfFailed(tryEmitPrivateForVarInit(D));
1189 initializeNonAbstract(destAddrSpace);
1190 return markIfFailed(tryEmitPrivateForMemory(E, destType));
1196 initializeNonAbstract(destAddrSpace);
1197 auto C = tryEmitPrivateForMemory(value, destType);
1198 assert(C &&
"couldn't emit constant value non-abstractly?");
1203 assert(!Abstract &&
"cannot get current address for abstract constant");
1209 auto global =
new llvm::GlobalVariable(CGM.
getModule(), CGM.
Int8Ty,
true,
1210 llvm::GlobalValue::PrivateLinkage,
1214 llvm::GlobalVariable::NotThreadLocal,
1217 PlaceholderAddresses.push_back(std::make_pair(
nullptr, global));
1223 llvm::GlobalValue *placeholder) {
1224 assert(!PlaceholderAddresses.empty());
1225 assert(PlaceholderAddresses.back().first ==
nullptr);
1226 assert(PlaceholderAddresses.back().second == placeholder);
1227 PlaceholderAddresses.back().first = signal;
1231 struct ReplacePlaceholders {
1235 llvm::Constant *
Base;
1239 llvm::DenseMap<llvm::Constant*, llvm::GlobalVariable*> PlaceholderAddresses;
1242 llvm::DenseMap<llvm::GlobalVariable*, llvm::Constant*> Locations;
1250 ReplacePlaceholders(
CodeGenModule &CGM, llvm::Constant *base,
1251 ArrayRef<std::pair<llvm::Constant*,
1252 llvm::GlobalVariable*>> addresses)
1253 : CGM(CGM),
Base(base),
1254 PlaceholderAddresses(addresses.begin(), addresses.end()) {
1257 void replaceInInitializer(llvm::Constant *init) {
1259 BaseValueTy = init->getType();
1262 Indices.push_back(0);
1263 IndexValues.push_back(
nullptr);
1266 findLocations(init);
1269 assert(IndexValues.size() == Indices.size() &&
"mismatch");
1270 assert(Indices.size() == 1 &&
"didn't pop all indices");
1273 assert(Locations.size() == PlaceholderAddresses.size() &&
1274 "missed a placeholder?");
1280 for (
auto &entry : Locations) {
1281 assert(entry.first->getParent() ==
nullptr &&
"not a placeholder!");
1282 entry.first->replaceAllUsesWith(entry.second);
1283 entry.first->eraseFromParent();
1288 void findLocations(llvm::Constant *init) {
1290 if (
auto agg = dyn_cast<llvm::ConstantAggregate>(init)) {
1291 for (
unsigned i = 0, e = agg->getNumOperands(); i != e; ++i) {
1292 Indices.push_back(i);
1293 IndexValues.push_back(
nullptr);
1295 findLocations(agg->getOperand(i));
1297 IndexValues.pop_back();
1305 auto it = PlaceholderAddresses.find(init);
1306 if (it != PlaceholderAddresses.end()) {
1307 setLocation(it->second);
1312 if (
auto expr = dyn_cast<llvm::ConstantExpr>(init)) {
1313 init =
expr->getOperand(0);
1320 void setLocation(llvm::GlobalVariable *placeholder) {
1321 assert(Locations.find(placeholder) == Locations.end() &&
1322 "already found location for placeholder!");
1327 assert(Indices.size() == IndexValues.size());
1328 for (
size_t i = Indices.size() - 1; i !=
size_t(-1); --i) {
1329 if (IndexValues[i]) {
1331 for (
size_t j = 0; j != i + 1; ++j) {
1332 assert(IndexValues[j] &&
1333 isa<llvm::ConstantInt>(IndexValues[j]) &&
1334 cast<llvm::ConstantInt>(IndexValues[j])->getZExtValue()
1341 IndexValues[i] = llvm::ConstantInt::get(CGM.
Int32Ty, Indices[i]);
1346 llvm::Constant *location =
1347 llvm::ConstantExpr::getInBoundsGetElementPtr(BaseValueTy,
1349 location = llvm::ConstantExpr::getBitCast(location,
1350 placeholder->getType());
1352 Locations.insert({placeholder, location});
1358 assert(InitializedNonAbstract &&
1359 "finalizing emitter that was used for abstract emission?");
1360 assert(!Finalized &&
"finalizing emitter multiple times");
1361 assert(global->getInitializer());
1366 if (!PlaceholderAddresses.empty()) {
1367 ReplacePlaceholders(CGM, global, PlaceholderAddresses)
1368 .replaceInInitializer(global->getInitializer());
1369 PlaceholderAddresses.clear();
1374 assert((!InitializedNonAbstract || Finalized || Failed) &&
1375 "not finalized after being initialized for non-abstract emission");
1376 assert(PlaceholderAddresses.empty() &&
"unhandled placeholders");
1395 dyn_cast_or_null<CXXConstructExpr>(D.
getInit())) {
1407 return tryEmitPrivateForMemory(*value, destType);
1420 assert(E &&
"No initializer to emit");
1424 ConstExprEmitter(*this).Visit(const_cast<Expr*>(E), nonMemoryDestType);
1425 return (C ? emitForMemory(C, destType) :
nullptr);
1431 auto C = tryEmitAbstract(E, nonMemoryDestType);
1432 return (C ? emitForMemory(C, destType) :
nullptr);
1439 auto C = tryEmitAbstract(value, nonMemoryDestType);
1440 return (C ? emitForMemory(C, destType) :
nullptr);
1446 llvm::Constant *C = tryEmitPrivate(E, nonMemoryDestType);
1447 return (C ? emitForMemory(C, destType) :
nullptr);
1453 auto C = tryEmitPrivate(value, nonMemoryDestType);
1454 return (C ? emitForMemory(C, destType) :
nullptr);
1462 QualType destValueType = AT->getValueType();
1463 C = emitForMemory(CGM, C, destValueType);
1467 if (innerSize == outerSize)
1470 assert(innerSize < outerSize &&
"emitted over-large constant for atomic");
1471 llvm::Constant *elts[] = {
1473 llvm::ConstantAggregateZero::get(
1474 llvm::ArrayType::get(CGM.
Int8Ty, (outerSize - innerSize) / 8))
1476 return llvm::ConstantStruct::getAnon(elts);
1480 if (C->getType()->isIntegerTy(1)) {
1482 return llvm::ConstantExpr::getZExt(C, boolTy);
1492 bool Success =
false;
1501 C = tryEmitPrivate(Result.
Val, destType);
1503 C = ConstExprEmitter(*this).Visit(const_cast<Expr*>(E), destType);
1509 return getTargetCodeGenInfo().getNullPointer(*
this, T, QT);
1515 struct ConstantLValue {
1516 llvm::Constant *
Value;
1517 bool HasOffsetApplied;
1519 ConstantLValue(llvm::Constant *value,
1520 bool hasOffsetApplied =
false)
1521 :
Value(value), HasOffsetApplied(
false) {}
1528 class ConstantLValueEmitter :
public ConstStmtVisitor<ConstantLValueEmitter,
1541 : CGM(emitter.
CGM), Emitter(emitter),
Value(value), DestType(destType) {}
1543 llvm::Constant *tryEmit();
1546 llvm::Constant *tryEmitAbsolute(
llvm::Type *destTy);
1549 ConstantLValue VisitStmt(
const Stmt *S) {
return nullptr; }
1556 ConstantLValue VisitCallExpr(
const CallExpr *E);
1557 ConstantLValue VisitBlockExpr(
const BlockExpr *E);
1560 ConstantLValue VisitMaterializeTemporaryExpr(
1563 bool hasNonZeroOffset()
const {
1568 llvm::Constant *getOffset() {
1569 return llvm::ConstantInt::get(CGM.
Int64Ty,
1574 llvm::Constant *applyOffset(llvm::Constant *C) {
1575 if (!hasNonZeroOffset())
1579 unsigned AS = origPtrTy->getPointerAddressSpace();
1581 C = llvm::ConstantExpr::getBitCast(C, charPtrTy);
1582 C = llvm::ConstantExpr::getGetElementPtr(CGM.
Int8Ty, C, getOffset());
1583 C = llvm::ConstantExpr::getPointerCast(C, origPtrTy);
1590 llvm::Constant *ConstantLValueEmitter::tryEmit() {
1597 if (DestType->isArrayType()) {
1598 assert(!hasNonZeroOffset() &&
"offset on array initializer");
1599 auto expr =
const_cast<Expr*
>(base.get<
const Expr*>());
1600 return ConstExprEmitter(Emitter).Visit(
expr, DestType);
1611 assert(isa<llvm::IntegerType>(destTy) || isa<llvm::PointerType>(destTy));
1616 return tryEmitAbsolute(destTy);
1620 ConstantLValue result = tryEmitBase(base);
1623 llvm::Constant *value = result.Value;
1624 if (!value)
return nullptr;
1627 if (!result.HasOffsetApplied) {
1628 value = applyOffset(value);
1633 if (isa<llvm::PointerType>(destTy))
1634 return llvm::ConstantExpr::getPointerCast(value, destTy);
1636 return llvm::ConstantExpr::getPtrToInt(value, destTy);
1642 ConstantLValueEmitter::tryEmitAbsolute(
llvm::Type *destTy) {
1643 auto offset = getOffset();
1646 if (
auto destPtrTy = cast<llvm::PointerType>(destTy)) {
1647 if (
Value.isNullPointer()) {
1655 auto intptrTy = CGM.
getDataLayout().getIntPtrType(destPtrTy);
1656 llvm::Constant *C = offset;
1657 C = llvm::ConstantExpr::getIntegerCast(getOffset(), intptrTy,
1659 C = llvm::ConstantExpr::getIntToPtr(C, destPtrTy);
1669 auto C = getOffset();
1670 C = llvm::ConstantExpr::getIntegerCast(C, destTy,
false);
1678 if (D->hasAttr<WeakRefAttr>())
1681 if (
auto FD = dyn_cast<FunctionDecl>(D))
1684 if (
auto VD = dyn_cast<VarDecl>(D)) {
1686 if (!VD->hasLocalStorage()) {
1687 if (VD->isFileVarDecl() || VD->hasExternalStorage())
1690 if (VD->isLocalVarDecl()) {
1701 return Visit(base.get<
const Expr*>());
1706 return tryEmitGlobalCompoundLiteral(CGM, Emitter.
CGF, E);
1710 ConstantLValueEmitter::VisitStringLiteral(
const StringLiteral *E) {
1715 ConstantLValueEmitter::VisitObjCEncodeExpr(
const ObjCEncodeExpr *E) {
1726 ConstantLValueEmitter::VisitPredefinedExpr(
const PredefinedExpr *E) {
1727 if (
auto CGF = Emitter.
CGF) {
1729 return cast<ConstantAddress>(Res.
getAddress());
1741 ConstantLValueEmitter::VisitAddrLabelExpr(
const AddrLabelExpr *E) {
1742 assert(Emitter.
CGF &&
"Invalid address of label expression outside function");
1744 Ptr = llvm::ConstantExpr::getBitCast(Ptr,
1750 ConstantLValueEmitter::VisitCallExpr(
const CallExpr *E) {
1752 if (builtin != Builtin::BI__builtin___CFStringMakeConstantString &&
1753 builtin != Builtin::BI__builtin___NSStringMakeConstantString)
1757 if (builtin == Builtin::BI__builtin___NSStringMakeConstantString) {
1766 ConstantLValueEmitter::VisitBlockExpr(
const BlockExpr *E) {
1767 StringRef functionName;
1768 if (
auto CGF = Emitter.
CGF)
1769 functionName = CGF->
CurFn->getName();
1771 functionName =
"global";
1777 ConstantLValueEmitter::VisitCXXTypeidExpr(
const CXXTypeidExpr *E) {
1787 ConstantLValueEmitter::VisitCXXUuidofExpr(
const CXXUuidofExpr *E) {
1792 ConstantLValueEmitter::VisitMaterializeTemporaryExpr(
1806 llvm_unreachable(
"Constant expressions should be initialized.");
1808 return ConstantLValueEmitter(*
this, Value, DestType).tryEmit();
1812 llvm::Constant *Complex[2];
1820 llvm::StructType *STy =
1821 llvm::StructType::get(Complex[0]->getType(), Complex[1]->getType());
1822 return llvm::ConstantStruct::get(STy, Complex);
1825 const llvm::APFloat &Init = Value.
getFloat();
1826 if (&Init.getSemantics() == &llvm::APFloat::IEEEhalf() &&
1830 Init.bitcastToAPInt());
1835 llvm::Constant *Complex[2];
1843 llvm::StructType *STy =
1844 llvm::StructType::get(Complex[0]->getType(), Complex[1]->getType());
1845 return llvm::ConstantStruct::get(STy, Complex);
1851 for (
unsigned I = 0; I != NumElts; ++I) {
1858 llvm_unreachable(
"unsupported vector element type");
1860 return llvm::ConstantVector::get(Inits);
1865 llvm::Constant *LHS = tryEmitPrivate(LHSExpr, LHSExpr->
getType());
1866 llvm::Constant *RHS = tryEmitPrivate(RHSExpr, RHSExpr->
getType());
1867 if (!LHS || !RHS)
return nullptr;
1871 LHS = llvm::ConstantExpr::getPtrToInt(LHS, CGM.
IntPtrTy);
1872 RHS = llvm::ConstantExpr::getPtrToInt(RHS, CGM.
IntPtrTy);
1873 llvm::Constant *AddrLabelDiff = llvm::ConstantExpr::getSub(LHS, RHS);
1878 return llvm::ConstantExpr::getTruncOrBitCast(AddrLabelDiff, ResultType);
1882 return ConstStructBuilder::BuildStruct(*
this, Value, DestType);
1889 llvm::Constant *Filler =
nullptr;
1899 if (Filler && Filler->isNullValue() && !NumInitElts) {
1900 llvm::ArrayType *AType =
1901 llvm::ArrayType::get(CommonElementType, NumElements);
1902 return llvm::ConstantAggregateZero::get(AType);
1906 Elts.reserve(NumElements);
1907 for (
unsigned I = 0; I < NumElements; ++I) {
1908 llvm::Constant *C = Filler;
1909 if (I < NumInitElts) {
1912 }
else if (!Filler) {
1914 "Missing filler for implicit elements of initializer");
1918 if (!C)
return nullptr;
1921 CommonElementType = C->getType();
1922 else if (C->getType() != CommonElementType)
1923 CommonElementType =
nullptr;
1927 if (!CommonElementType) {
1929 std::vector<llvm::Type*> Types;
1930 Types.reserve(NumElements);
1931 for (
unsigned i = 0, e = Elts.size(); i < e; ++i)
1932 Types.push_back(Elts[i]->getType());
1933 llvm::StructType *SType =
1935 return llvm::ConstantStruct::get(SType, Elts);
1938 llvm::ArrayType *AType =
1939 llvm::ArrayType::get(CommonElementType, NumElements);
1940 return llvm::ConstantArray::get(AType, Elts);
1945 llvm_unreachable(
"Unknown APValue kind");
1950 return EmittedCompoundLiterals.lookup(E);
1955 bool Ok = EmittedCompoundLiterals.insert(std::make_pair(CLE, GV)).second;
1957 assert(Ok &&
"CLE has already been emitted!");
1962 assert(E->
isFileScope() &&
"not a file-scope compound literal expr");
1963 return tryEmitGlobalCompoundLiteral(*
this,
nullptr, E);
1973 if (
const CXXMethodDecl *method = dyn_cast<CXXMethodDecl>(decl))
1974 return getCXXABI().EmitMemberFunctionPointer(method);
1977 uint64_t fieldOffset = getContext().getFieldOffset(decl);
1978 CharUnits chars = getContext().toCharUnitsFromBits((int64_t) fieldOffset);
1979 return getCXXABI().EmitMemberDataPointer(type, chars);
1988 bool asCompleteObject) {
1990 llvm::StructType *structure =
1994 unsigned numElements = structure->getNumElements();
1995 std::vector<llvm::Constant *> elements(numElements);
2000 for (
const auto &I : CXXR->bases()) {
2001 if (I.isVirtual()) {
2008 cast<CXXRecordDecl>(I.getType()->castAs<
RecordType>()->getDecl());
2017 llvm::Type *baseType = structure->getElementType(fieldIndex);
2023 for (
const auto *Field : record->
fields()) {
2035 if (
const auto *FieldRD =
2037 if (FieldRD->findFirstNamedDataMember())
2043 if (CXXR && asCompleteObject) {
2044 for (
const auto &I : CXXR->vbases()) {
2046 cast<CXXRecordDecl>(I.getType()->castAs<
RecordType>()->getDecl());
2055 if (elements[fieldIndex])
continue;
2057 llvm::Type *baseType = structure->getElementType(fieldIndex);
2063 for (
unsigned i = 0; i != numElements; ++i) {
2065 elements[i] = llvm::Constant::getNullValue(structure->getElementType(i));
2068 return llvm::ConstantStruct::get(structure, elements);
2079 return llvm::Constant::getNullValue(baseType);
2092 return getNullPointer(
2093 cast<llvm::PointerType>(getTypes().ConvertTypeForMem(T)), T);
2095 if (getTypes().isZeroInitializable(T))
2096 return llvm::Constant::getNullValue(getTypes().ConvertTypeForMem(T));
2099 llvm::ArrayType *ATy =
2100 cast<llvm::ArrayType>(getTypes().ConvertTypeForMem(T));
2104 llvm::Constant *Element =
2106 unsigned NumElements = CAT->
getSize().getZExtValue();
2108 return llvm::ConstantArray::get(ATy, Array);
2115 "Should only see pointers to data members here!");
const llvm::DataLayout & getDataLayout() 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.
bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const
EvaluateAsRValue - Return true if this is a constant which we can fold to an rvalue using any crazy t...
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.
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
CGRecordLayout - This class handles struct and union layout info while lowering AST types to LLVM typ...
bool isMemberDataPointerType() const
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.
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 Expr * getResultExpr() const
The generic selection's result expression.
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)
VarDecl - An instance of this class is created to represent 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>'.
unsigned getCharAlign() const
LangAS
Defines the address space values used by the address space qualifier of QualType. ...
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
getIdentifier - Get the identifier that names this declaration, if there is one.
RecordDecl - Represents a struct/union/class.
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
Expr * GetTemporaryExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
Address getAddress() const
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
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
StringLiteral * getString()
unsigned getNonVirtualBaseLLVMFieldNo(const CXXRecordDecl *RD) const
bool isReferenceType() const
unsigned getArraySize() const
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
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
IgnoreParenCasts - Ignore parentheses and casts.
ObjCStringLiteral, used for Objective-C string literals i.e.
field_iterator field_begin() const
unsigned getBitWidthValue(const ASTContext &Ctx) const
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.
A default argument (C++ [dcl.fct.default]).
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)
static CharUnits One()
One - Construct a CharUnits quantity of one.
ConstantAddress getElementBitCast(llvm::Type *ty) const
bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const
EvaluateAsLValue - Evaluate an expression to see if we can fold it to an lvalue with link time known ...
const TargetCodeGenInfo & getTargetCodeGenInfo()
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
APValue & getArrayFiller()
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.
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.
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Expr - This represents one expression.
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
bool hasLocalStorage() const
hasLocalStorage - Returns true if a variable with function scope is a non-static local variable...
const FunctionProtoType * T
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.
char __ovld __cnfn min(char x, char y)
Returns y if y < x, otherwise it returns x.
llvm::IntegerType * Int32Ty
llvm::GlobalValue::LinkageTypes getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant)
Returns LLVM linkage for a declarator.
TagDecl * getAsTagDecl() const
Retrieves the TagDecl that this type refers to, either because the type is a TagType or because it is...
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.
llvm::Constant * getOrCreateStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
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. ...
static QualType getNonMemoryType(CodeGenModule &CGM, QualType type)
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...
IdentType getIdentType() const
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
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
ConstantAddress GetAddrOfConstantCString(const std::string &Str, const char *GlobalName=nullptr)
Returns a pointer to a character array containing the literal and a terminating '\0' character...
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.
CharUnits getSize() const
getSize - Get the record size in characters.
[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
const Expr * getExpr() const
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.
llvm::PointerUnion< const ValueDecl *, const Expr * > LValueBase
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.
char __ovld __cnfn max(char x, char y)
Returns y if x < y, otherwise it returns x.
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.
CharUnits getNonVirtualSize() const
getNonVirtualSize - Get the non-virtual size (in chars) of an object, which is the size of the object...
unsigned kind
All of the diagnostics that can be emitted by the frontend.
unsigned getVirtualBaseIndex(const CXXRecordDecl *base) const
Return the LLVM field index corresponding to the given virtual base.
LValue EmitPredefinedLValue(const PredefinedExpr *E)
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)
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
LValue - This represents an lvalue references.
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
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.
CharUnits & getLValueOffset()
unsigned getLLVMFieldNo(const FieldDecl *FD) const
Return llvm::StructType element number that corresponds to the field FD.
unsigned getVectorLength() const