18#include "mlir/IR/Attributes.h"
19#include "mlir/IR/BuiltinAttributeInterfaces.h"
20#include "mlir/IR/BuiltinAttributes.h"
32#include "llvm/ADT/ArrayRef.h"
33#include "llvm/ADT/STLExtras.h"
34#include "llvm/Support/ErrorHandling.h"
46class ConstExprEmitter;
54 return bld.
getConstArray(mlir::ArrayAttr::get(bld.getContext(), elts),
55 cir::ArrayType::get(eltTy, arSize));
58 return cir::ZeroAttr::get(eltTy);
62emitArrayConstant(
CIRGenModule &cgm, mlir::Type desiredType,
63 mlir::Type commonElementType,
unsigned arrayBound,
65 mlir::TypedAttr filler);
67struct ConstantAggregateBuilderUtils {
69 cir::CIRDataLayout dataLayout;
71 ConstantAggregateBuilderUtils(CIRGenModule &cgm)
72 : cgm(cgm), dataLayout{cgm.getModule()} {}
74 CharUnits getAlignment(
const mlir::TypedAttr
c)
const {
76 dataLayout.getAlignment(
c.getType(),
true));
79 CharUnits getSize(mlir::Type ty)
const {
83 CharUnits getSize(
const mlir::TypedAttr
c)
const {
84 return getSize(
c.getType());
87 mlir::TypedAttr getPadding(CharUnits size)
const {
88 return computePadding(cgm, size);
94class ConstantAggregateBuilder :
private ConstantAggregateBuilderUtils {
96 Element(mlir::TypedAttr element, CharUnits offset)
97 : element(element), offset(offset) {}
99 mlir::TypedAttr element;
110 llvm::SmallVector<Element, 32> elements;
119 bool naturalLayout =
true;
121 bool split(
size_t index, CharUnits hint);
122 std::optional<size_t> splitAt(CharUnits pos);
124 static mlir::Attribute buildFrom(CIRGenModule &cgm, ArrayRef<Element> elems,
125 CharUnits startOffset, CharUnits size,
126 bool naturalLayout, mlir::Type desiredTy,
127 bool allowOversized);
130 ConstantAggregateBuilder(CIRGenModule &cgm)
131 : ConstantAggregateBuilderUtils(cgm) {}
138 bool add(mlir::TypedAttr typedAttr, CharUnits offset,
bool allowOverwrite);
141 bool addBits(llvm::APInt bits, uint64_t offsetInBits,
bool allowOverwrite);
145 void condense(CharUnits offset, mlir::Type desiredTy);
152 mlir::Attribute build(mlir::Type desiredTy,
bool allowOversized)
const {
153 return buildFrom(cgm, elements,
CharUnits::Zero(), size, naturalLayout,
154 desiredTy, allowOversized);
158template <
typename Container,
typename Range = std::initializer_list<
159 typename Container::value_type>>
160static void replace(Container &
c,
size_t beginOff,
size_t endOff, Range vals) {
161 assert(beginOff <= endOff &&
"invalid replacement range");
162 llvm::replace(
c,
c.begin() + beginOff,
c.begin() + endOff, vals);
165bool ConstantAggregateBuilder::add(mlir::TypedAttr typedAttr,
CharUnits offset,
166 bool allowOverwrite) {
168 if (offset >= size) {
169 CharUnits
align = getAlignment(typedAttr);
170 CharUnits alignedSize = size.
alignTo(align);
171 if (alignedSize > offset || offset.
alignTo(align) != offset) {
172 naturalLayout =
false;
173 }
else if (alignedSize < offset) {
174 elements.emplace_back(getPadding(offset - size), size);
176 elements.emplace_back(typedAttr, offset);
177 size = offset + getSize(typedAttr);
182 cgm.
errorNYI(
"overlapping constants");
186bool ConstantAggregateBuilder::addBits(llvm::APInt bits, uint64_t offsetInBits,
187 bool allowOverwrite) {
194 unsigned offsetWithinChar = offsetInBits % charWidth;
198 for (CharUnits offsetInChars =
202 unsigned wantedBits =
203 std::min((uint64_t)bits.getBitWidth(), charWidth - offsetWithinChar);
207 llvm::APInt bitsThisChar = bits;
208 if (bitsThisChar.getBitWidth() < charWidth)
209 bitsThisChar = bitsThisChar.zext(charWidth);
213 int shift = bits.getBitWidth() - charWidth + offsetWithinChar;
215 bitsThisChar.lshrInPlace(shift);
217 bitsThisChar = bitsThisChar.shl(-shift);
219 bitsThisChar = bitsThisChar.shl(offsetWithinChar);
221 if (bitsThisChar.getBitWidth() > charWidth)
222 bitsThisChar = bitsThisChar.trunc(charWidth);
224 if (wantedBits == charWidth) {
226 add(cir::IntAttr::get(charTy, bitsThisChar), offsetInChars,
232 std::optional<size_t> firstElemToUpdate = splitAt(offsetInChars);
233 if (!firstElemToUpdate)
235 std::optional<size_t> lastElemToUpdate =
237 if (!lastElemToUpdate)
239 assert(*lastElemToUpdate - *firstElemToUpdate < 2 &&
240 "should have at most one element covering one byte");
243 llvm::APInt updateMask(charWidth, 0);
245 updateMask.setBits(charWidth - offsetWithinChar - wantedBits,
246 charWidth - offsetWithinChar);
248 updateMask.setBits(offsetWithinChar, offsetWithinChar + wantedBits);
249 bitsThisChar &= updateMask;
251 if (*firstElemToUpdate < elements.size()) {
252 auto firstEltToUpdate =
253 mlir::dyn_cast<cir::IntAttr>(elements[*firstElemToUpdate].element);
254 isNull = firstEltToUpdate && firstEltToUpdate.isNullValue();
257 if (*firstElemToUpdate == *lastElemToUpdate || isNull) {
259 add(cir::IntAttr::get(charTy, bitsThisChar), offsetInChars,
263 mlir::dyn_cast<cir::IntAttr>(elements[*firstElemToUpdate].element);
270 assert(ci.getBitWidth() == charWidth &&
"splitAt failed");
271 assert((!(ci.getValue() & updateMask) || allowOverwrite) &&
272 "unexpectedly overwriting bitfield");
273 bitsThisChar |= (ci.getValue() & ~updateMask);
274 elements[*firstElemToUpdate].element =
275 cir::IntAttr::get(charTy, bitsThisChar);
280 if (wantedBits == bits.getBitWidth())
285 bits.lshrInPlace(wantedBits);
286 bits = bits.trunc(bits.getBitWidth() - wantedBits);
289 offsetWithinChar = 0;
299std::optional<size_t> ConstantAggregateBuilder::splitAt(CharUnits pos) {
301 return elements.size();
306 llvm::upper_bound(elements, pos, [](CharUnits pos,
const Element &elt) {
307 return pos < elt.offset;
310 if (iter == elements.begin())
313 size_t index = iter - elements.begin() - 1;
314 const Element &elt = elements[index];
317 if (elt.offset == pos)
321 CharUnits eltEnd = elt.offset + getSize(elt.element);
326 if (!split(index, pos))
334bool ConstantAggregateBuilder::split(
size_t index, CharUnits hint) {
335 cgm.
errorNYI(
"split constant at index");
339void ConstantAggregateBuilder::condense(CharUnits offset,
340 mlir::Type desiredTy) {
341 CharUnits desiredSize = getSize(desiredTy);
343 std::optional<size_t> firstElemToReplace = splitAt(offset);
344 if (!firstElemToReplace)
346 size_t first = *firstElemToReplace;
348 std::optional<size_t> lastElemToReplace = splitAt(offset + desiredSize);
349 if (!lastElemToReplace)
351 size_t last = *lastElemToReplace;
353 size_t length = last - first;
357 if (
length == 1 && elements[first].offset == offset &&
358 getSize(elements[first].element) == desiredSize) {
359 cgm.
errorNYI(
"re-wrapping single element records");
364 SmallVector<Element> subElems(elements.begin() + first,
365 elements.begin() + last);
366 mlir::Attribute replacement =
367 buildFrom(cgm, subElems, offset, desiredSize,
368 false, desiredTy,
false);
371 Element newElt(mlir::cast<mlir::TypedAttr>(replacement), offset);
372 replace(elements, first, last, {newElt});
376ConstantAggregateBuilder::buildFrom(CIRGenModule &cgm, ArrayRef<Element> elems,
377 CharUnits startOffset, CharUnits size,
378 bool naturalLayout, mlir::Type desiredTy,
379 bool allowOversized) {
380 ConstantAggregateBuilderUtils utils(cgm);
383 return cir::UndefAttr::get(desiredTy);
387 if (mlir::isa<cir::ArrayType>(desiredTy)) {
388 cgm.
errorNYI(
"array aggregate constants");
395 CharUnits desiredSize = utils.getSize(desiredTy);
396 if (size > desiredSize) {
397 assert(allowOversized &&
"elems are oversized");
403 for (
auto [e, offset] : elems)
404 align = std::max(align, utils.getAlignment(e));
407 CharUnits alignedSize = size.
alignTo(align);
412 llvm::SmallVector<mlir::Attribute, 32> unpackedElems;
413 if (desiredSize < alignedSize || desiredSize.
alignTo(align) != desiredSize) {
414 naturalLayout =
false;
419 unpackedElems.reserve(elems.size() + 1);
420 llvm::transform(elems, std::back_inserter(unpackedElems),
421 std::mem_fn(&Element::element));
422 if (desiredSize > alignedSize)
423 unpackedElems.push_back(utils.getPadding(desiredSize - size));
429 llvm::SmallVector<mlir::Attribute, 32> packedElems;
430 packedElems.reserve(elems.size());
431 if (!naturalLayout) {
433 for (
auto [element, offset] : elems) {
434 CharUnits
align = utils.getAlignment(element);
435 CharUnits naturalOffset = sizeSoFar.
alignTo(align);
436 CharUnits desiredOffset = offset - startOffset;
437 assert(desiredOffset >= sizeSoFar &&
"elements out of order");
439 if (desiredOffset != naturalOffset)
441 if (desiredOffset != sizeSoFar)
442 packedElems.push_back(utils.getPadding(desiredOffset - sizeSoFar));
443 packedElems.push_back(element);
444 sizeSoFar = desiredOffset + utils.getSize(element);
449 assert(sizeSoFar <= desiredSize &&
450 "requested size is too small for contents");
452 if (sizeSoFar < desiredSize)
453 packedElems.push_back(utils.getPadding(desiredSize - sizeSoFar));
458 auto arrAttr = mlir::ArrayAttr::get(builder.getContext(),
459 packed ? packedElems : unpackedElems);
462 if (
auto desired = mlir::dyn_cast<cir::RecordType>(desiredTy))
473class ConstRecordBuilder {
475 ConstantEmitter &emitter;
476 ConstantAggregateBuilder &builder;
477 CharUnits startOffset;
480 static mlir::Attribute buildRecord(ConstantEmitter &emitter,
481 InitListExpr *ile, QualType valTy);
482 static mlir::Attribute buildRecord(ConstantEmitter &emitter,
483 const APValue &value, QualType valTy);
484 static bool updateRecord(ConstantEmitter &emitter,
485 ConstantAggregateBuilder &constant, CharUnits offset,
486 InitListExpr *updater);
489 ConstRecordBuilder(ConstantEmitter &emitter,
490 ConstantAggregateBuilder &builder, CharUnits startOffset)
491 : cgm(emitter.cgm), emitter(emitter), builder(builder),
492 startOffset(startOffset) {}
494 bool appendField(
const FieldDecl *field, uint64_t fieldOffset,
495 mlir::TypedAttr initCst,
bool allowOverwrite =
false);
497 bool appendBytes(CharUnits fieldOffsetInChars, mlir::TypedAttr initCst,
498 bool allowOverwrite =
false);
500 bool appendBitField(
const FieldDecl *field, uint64_t fieldOffset,
501 cir::IntAttr ci,
bool allowOverwrite =
false);
511 bool applyZeroInitPadding(
const ASTRecordLayout &layout,
unsigned fieldNo,
512 const FieldDecl &field,
bool allowOverwrite,
513 CharUnits &sizeSoFar,
bool &zeroFieldSize);
520 bool applyZeroInitPadding(
const ASTRecordLayout &layout,
bool allowOverwrite,
521 CharUnits &sizeSoFar);
523 bool build(InitListExpr *ile,
bool allowOverwrite);
524 bool build(
const APValue &val,
const RecordDecl *rd,
bool isPrimaryBase,
525 const CXXRecordDecl *vTableClass, CharUnits baseOffset);
527 mlir::Attribute
finalize(QualType ty);
530bool ConstRecordBuilder::appendField(
const FieldDecl *field,
531 uint64_t fieldOffset,
532 mlir::TypedAttr initCst,
533 bool allowOverwrite) {
538 return appendBytes(fieldOffsetInChars, initCst, allowOverwrite);
541bool ConstRecordBuilder::appendBytes(CharUnits fieldOffsetInChars,
542 mlir::TypedAttr initCst,
543 bool allowOverwrite) {
544 return builder.add(initCst, startOffset + fieldOffsetInChars, allowOverwrite);
547bool ConstRecordBuilder::appendBitField(
const FieldDecl *field,
548 uint64_t fieldOffset, cir::IntAttr ci,
549 bool allowOverwrite) {
550 const CIRGenRecordLayout &rl =
553 llvm::APInt fieldValue = ci.getValue();
559 if (info.
size > fieldValue.getBitWidth())
560 fieldValue = fieldValue.zext(info.
size);
563 if (info.
size < fieldValue.getBitWidth())
564 fieldValue = fieldValue.trunc(info.
size);
566 return builder.addBits(fieldValue,
571bool ConstRecordBuilder::applyZeroInitPadding(
572 const ASTRecordLayout &layout,
unsigned fieldNo,
const FieldDecl &field,
573 bool allowOverwrite, CharUnits &sizeSoFar,
bool &zeroFieldSize) {
575 CharUnits startOffset =
577 if (sizeSoFar < startOffset) {
578 if (!appendBytes(sizeSoFar, computePadding(cgm, startOffset - sizeSoFar),
584 CharUnits fieldSize =
586 sizeSoFar = startOffset + fieldSize;
587 zeroFieldSize = fieldSize.isZero();
589 const CIRGenRecordLayout &rl =
596 zeroFieldSize = info.
size == 0;
601bool ConstRecordBuilder::applyZeroInitPadding(
const ASTRecordLayout &layout,
603 CharUnits &sizeSoFar) {
604 CharUnits totalSize = layout.
getSize();
605 if (sizeSoFar < totalSize) {
606 if (!appendBytes(sizeSoFar, computePadding(cgm, totalSize - sizeSoFar),
610 sizeSoFar = totalSize;
614bool ConstRecordBuilder::build(InitListExpr *ile,
bool allowOverwrite) {
615 RecordDecl *rd = ile->
getType()
616 ->
castAs<clang::RecordType>()
618 ->getDefinitionOrSelf();
624 if (
auto *cxxrd = dyn_cast<CXXRecordDecl>(rd))
625 if (cxxrd->getNumBases())
629 bool zeroFieldSize =
false;
632 unsigned elementNo = 0;
633 for (
auto [index, field] : llvm::enumerate(rd->
fields())) {
646 Expr *init =
nullptr;
647 if (elementNo < ile->getNumInits())
648 init = ile->
getInit(elementNo++);
649 if (isa_and_nonnull<NoInitExpr>(init))
660 if (zeroInitPadding &&
661 !applyZeroInitPadding(layout, index, *field, allowOverwrite, sizeSoFar,
668 if (allowOverwrite &&
674 mlir::TypedAttr eltInit;
676 eltInit = mlir::cast<mlir::TypedAttr>(
692 if (field->
hasAttr<NoUniqueAddressAttr>())
693 allowOverwrite =
true;
696 if (
auto constInt = dyn_cast<cir::IntAttr>(eltInit)) {
697 if (!appendBitField(field, layout.
getFieldOffset(index), constInt,
708 return !zeroInitPadding ||
709 applyZeroInitPadding(layout, allowOverwrite, sizeSoFar);
714 BaseInfo(
const CXXRecordDecl *decl, CharUnits offset,
unsigned index)
715 : decl(decl), offset(offset), index(index) {}
717 const CXXRecordDecl *decl;
721 bool operator<(
const BaseInfo &o)
const {
return offset < o.offset; }
725bool ConstRecordBuilder::build(
const APValue &val,
const RecordDecl *rd,
727 const CXXRecordDecl *vTableClass,
730 if (
const CXXRecordDecl *cd = dyn_cast<CXXRecordDecl>(rd)) {
734 cir::GlobalOp vtable =
736 clang::VTableLayout::AddressPointLocation addressPoint =
741 mlir::ArrayAttr indices = builder.getArrayAttr({
742 builder.getI32IntegerAttr(addressPoint.
VTableIndex),
745 cir::GlobalViewAttr vtableInit =
747 if (!appendBytes(offset, vtableInit))
753 SmallVector<BaseInfo> bases;
754 bases.reserve(cd->getNumBases());
755 for (
auto [index, base] : llvm::enumerate(cd->bases())) {
756 assert(!base.isVirtual() &&
"should not have virtual bases here");
757 const CXXRecordDecl *bd = base.getType()->getAsCXXRecordDecl();
759 bases.push_back(BaseInfo(bd, baseOffset, index));
761#ifdef EXPENSIVE_CHECKS
762 assert(llvm::is_sorted(bases) &&
"bases not sorted by offset");
765 for (BaseInfo &base : bases) {
767 build(val.
getStructBase(base.index), base.decl, isPrimaryBase,
768 vTableClass, offset + base.offset);
774 bool allowOverwrite =
false;
775 for (
auto [index, field] : llvm::enumerate(rd->
fields())) {
787 mlir::TypedAttr eltInit = mlir::cast<mlir::TypedAttr>(
794 if (!appendField(field, layout.
getFieldOffset(index) + offsetBits,
795 eltInit, allowOverwrite))
799 if (field->
hasAttr<NoUniqueAddressAttr>())
800 allowOverwrite =
true;
803 if (
auto constInt = dyn_cast<cir::IntAttr>(eltInit)) {
804 if (!appendBitField(field, layout.
getFieldOffset(index) + offsetBits,
805 constInt, allowOverwrite))
818mlir::Attribute ConstRecordBuilder::finalize(QualType
type) {
820 RecordDecl *rd =
type->castAs<clang::RecordType>()
827mlir::Attribute ConstRecordBuilder::buildRecord(ConstantEmitter &emitter,
830 ConstantAggregateBuilder constant(emitter.
cgm);
833 if (!builder.build(ile,
false))
836 return builder.finalize(valTy);
839mlir::Attribute ConstRecordBuilder::buildRecord(ConstantEmitter &emitter,
842 ConstantAggregateBuilder constant(emitter.
cgm);
845 const RecordDecl *rd = valTy->
castAs<clang::RecordType>()
847 ->getDefinitionOrSelf();
848 const CXXRecordDecl *cd = dyn_cast<CXXRecordDecl>(rd);
852 return builder.finalize(valTy);
855bool ConstRecordBuilder::updateRecord(ConstantEmitter &emitter,
856 ConstantAggregateBuilder &constant,
857 CharUnits offset, InitListExpr *updater) {
858 return ConstRecordBuilder(emitter, constant, offset)
859 .build(updater,
true);
873class ConstExprEmitter
874 :
public StmtVisitor<ConstExprEmitter, mlir::Attribute, QualType> {
876 LLVM_ATTRIBUTE_UNUSED ConstantEmitter &emitter;
879 ConstExprEmitter(ConstantEmitter &emitter)
880 : cgm(emitter.cgm), emitter(emitter) {}
886 mlir::Attribute VisitStmt(Stmt *
s, QualType t) {
return {}; }
888 mlir::Attribute VisitConstantExpr(ConstantExpr *ce, QualType t) {
889 if (mlir::Attribute result = emitter.tryEmitConstantExpr(ce))
894 mlir::Attribute VisitParenExpr(ParenExpr *pe, QualType t) {
899 VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *pe,
904 mlir::Attribute VisitGenericSelectionExpr(GenericSelectionExpr *ge,
909 mlir::Attribute VisitChooseExpr(ChooseExpr *ce, QualType t) {
913 mlir::Attribute VisitCompoundLiteralExpr(CompoundLiteralExpr *e, QualType t) {
917 mlir::Attribute VisitCastExpr(
CastExpr *e, QualType destType) {
920 "ConstExprEmitter::VisitCastExpr explicit cast");
926 case CK_AddressSpaceConversion:
927 case CK_ReinterpretMemberPointer:
928 case CK_DerivedToBaseMemberPointer:
929 case CK_BaseToDerivedMemberPointer:
933 case CK_LValueToRValue:
934 case CK_AtomicToNonAtomic:
935 case CK_NonAtomicToAtomic:
937 case CK_ConstructorConversion:
938 return Visit(subExpr, destType);
940 case CK_IntToOCLSampler:
941 llvm_unreachable(
"global sampler variables are not generated");
944 llvm_unreachable(
"saw dependent cast!");
946 case CK_BuiltinFnToFnPtr:
947 llvm_unreachable(
"builtin functions are handled elsewhere");
950 case CK_ObjCObjectLValueCast:
951 case CK_ARCProduceObject:
952 case CK_ARCConsumeObject:
953 case CK_ARCReclaimReturnedObject:
954 case CK_ARCExtendBlockObject:
955 case CK_CopyAndAutoreleaseBlockObject:
963 case CK_LValueBitCast:
964 case CK_LValueToRValueBitCast:
965 case CK_NullToMemberPointer:
966 case CK_UserDefinedConversion:
967 case CK_CPointerToObjCPointerCast:
968 case CK_BlockPointerToObjCPointerCast:
969 case CK_AnyPointerToBlockPointerCast:
970 case CK_ArrayToPointerDecay:
971 case CK_FunctionToPointerDecay:
972 case CK_BaseToDerived:
973 case CK_DerivedToBase:
974 case CK_UncheckedDerivedToBase:
975 case CK_MemberPointerToBoolean:
977 case CK_FloatingRealToComplex:
978 case CK_FloatingComplexToReal:
979 case CK_FloatingComplexToBoolean:
980 case CK_FloatingComplexCast:
981 case CK_FloatingComplexToIntegralComplex:
982 case CK_IntegralRealToComplex:
983 case CK_IntegralComplexToReal:
984 case CK_IntegralComplexToBoolean:
985 case CK_IntegralComplexCast:
986 case CK_IntegralComplexToFloatingComplex:
987 case CK_PointerToIntegral:
988 case CK_PointerToBoolean:
989 case CK_NullToPointer:
990 case CK_IntegralCast:
991 case CK_BooleanToSignedIntegral:
992 case CK_IntegralToPointer:
993 case CK_IntegralToBoolean:
994 case CK_IntegralToFloating:
995 case CK_FloatingToIntegral:
996 case CK_FloatingToBoolean:
997 case CK_FloatingCast:
998 case CK_FloatingToFixedPoint:
999 case CK_FixedPointToFloating:
1000 case CK_FixedPointCast:
1001 case CK_FixedPointToBoolean:
1002 case CK_FixedPointToIntegral:
1003 case CK_IntegralToFixedPoint:
1004 case CK_ZeroToOCLOpaqueType:
1006 case CK_HLSLArrayRValue:
1007 case CK_HLSLVectorTruncation:
1008 case CK_HLSLElementwiseCast:
1009 case CK_HLSLAggregateSplatCast:
1012 llvm_unreachable(
"Invalid CastKind");
1015 mlir::Attribute VisitCXXDefaultInitExpr(CXXDefaultInitExpr *die, QualType t) {
1017 "ConstExprEmitter::VisitCXXDefaultInitExpr");
1021 mlir::Attribute VisitExprWithCleanups(ExprWithCleanups *e, QualType t) {
1026 mlir::Attribute VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *e,
1031 mlir::Attribute VisitImplicitValueInitExpr(ImplicitValueInitExpr *e,
1034 "ConstExprEmitter::VisitImplicitValueInitExpr");
1038 mlir::Attribute VisitInitListExpr(InitListExpr *ile, QualType t) {
1040 return Visit(ile->
getInit(0), t);
1050 return ConstRecordBuilder::buildRecord(emitter, ile, t);
1063 mlir::Attribute VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *e,
1064 QualType destType) {
1065 mlir::Attribute
c = Visit(e->
getBase(), destType);
1070 "ConstExprEmitter::VisitDesignatedInitUpdateExpr");
1074 mlir::Attribute VisitCXXConstructExpr(CXXConstructExpr *e, QualType ty) {
1081 mlir::Attribute VisitStringLiteral(StringLiteral *e, QualType t) {
1086 mlir::Attribute VisitObjCEncodeExpr(ObjCEncodeExpr *e, QualType t) {
1091 mlir::Attribute VisitUnaryExtension(
const UnaryOperator *e, QualType t) {
1096 mlir::Type convertType(QualType t) {
return cgm.
convertType(t); }
1101 if (
const auto *at =
type->getAs<AtomicType>()) {
1103 type.getQualifiers());
1108static mlir::Attribute
1109emitArrayConstant(CIRGenModule &cgm, mlir::Type desiredType,
1110 mlir::Type commonElementType,
unsigned arrayBound,
1111 SmallVectorImpl<mlir::TypedAttr> &elements,
1112 mlir::TypedAttr filler) {
1115 unsigned nonzeroLength = arrayBound;
1116 if (elements.size() < nonzeroLength && builder.
isNullValue(filler))
1117 nonzeroLength = elements.size();
1119 if (nonzeroLength == elements.size()) {
1120 while (nonzeroLength > 0 &&
1125 if (nonzeroLength == 0)
1126 return cir::ZeroAttr::get(desiredType);
1128 const unsigned trailingZeroes = arrayBound - nonzeroLength;
1131 if (trailingZeroes >= 8) {
1132 assert(elements.size() >= nonzeroLength &&
1133 "missing initializer for non-zero element");
1135 if (commonElementType && nonzeroLength >= 8) {
1139 SmallVector<mlir::Attribute> eles;
1140 eles.reserve(nonzeroLength);
1141 for (
const auto &element : elements)
1142 eles.push_back(element);
1143 auto initial = cir::ConstArrayAttr::get(
1144 cir::ArrayType::get(commonElementType, nonzeroLength),
1145 mlir::ArrayAttr::get(builder.getContext(), eles));
1147 elements[0] = initial;
1151 elements.resize(nonzeroLength + 1);
1154 mlir::Type fillerType =
1157 : mlir::cast<cir::ArrayType>(desiredType).getElementType();
1158 fillerType = cir::ArrayType::get(fillerType, trailingZeroes);
1159 elements.back() = cir::ZeroAttr::get(fillerType);
1160 commonElementType =
nullptr;
1161 }
else if (elements.size() != arrayBound) {
1162 elements.resize(arrayBound, filler);
1164 if (filler.getType() != commonElementType)
1165 commonElementType = {};
1168 if (commonElementType) {
1169 SmallVector<mlir::Attribute> eles;
1170 eles.reserve(elements.size());
1172 for (
const auto &element : elements)
1173 eles.push_back(element);
1175 return cir::ConstArrayAttr::get(
1176 cir::ArrayType::get(commonElementType, arrayBound),
1177 mlir::ArrayAttr::get(builder.getContext(), eles));
1180 SmallVector<mlir::Attribute> eles;
1181 eles.reserve(elements.size());
1182 for (
auto const &element : elements)
1183 eles.push_back(element);
1185 auto arrAttr = mlir::ArrayAttr::get(builder.getContext(), eles);
1198struct ConstantLValue {
1199 llvm::PointerUnion<mlir::Value, mlir::Attribute> value;
1200 bool hasOffsetApplied;
1202 ConstantLValue(std::nullptr_t)
1204 ConstantLValue(cir::GlobalViewAttr address)
1205 : value(address), hasOffsetApplied(
false) {}
1207 ConstantLValue() : value(
nullptr), hasOffsetApplied(
false) {}
1211class ConstantLValueEmitter
1212 :
public ConstStmtVisitor<ConstantLValueEmitter, ConstantLValue> {
1214 ConstantEmitter &emitter;
1219 friend StmtVisitorBase;
1222 ConstantLValueEmitter(ConstantEmitter &emitter,
const APValue &value,
1224 : cgm(emitter.cgm), emitter(emitter), value(value), destType(destType) {}
1226 mlir::Attribute tryEmit();
1229 mlir::Attribute tryEmitAbsolute(mlir::Type destTy);
1230 ConstantLValue tryEmitBase(
const APValue::LValueBase &base);
1232 ConstantLValue VisitStmt(
const Stmt *
s) {
return nullptr; }
1233 ConstantLValue VisitConstantExpr(
const ConstantExpr *e);
1234 ConstantLValue VisitCompoundLiteralExpr(
const CompoundLiteralExpr *e);
1235 ConstantLValue VisitStringLiteral(
const StringLiteral *e);
1236 ConstantLValue VisitObjCBoxedExpr(
const ObjCBoxedExpr *e);
1237 ConstantLValue VisitObjCEncodeExpr(
const ObjCEncodeExpr *e);
1238 ConstantLValue VisitObjCStringLiteral(
const ObjCStringLiteral *e);
1239 ConstantLValue VisitPredefinedExpr(
const PredefinedExpr *e);
1240 ConstantLValue VisitAddrLabelExpr(
const AddrLabelExpr *e);
1241 ConstantLValue VisitCallExpr(
const CallExpr *e);
1242 ConstantLValue VisitBlockExpr(
const BlockExpr *e);
1243 ConstantLValue VisitCXXTypeidExpr(
const CXXTypeidExpr *e);
1245 VisitMaterializeTemporaryExpr(
const MaterializeTemporaryExpr *e);
1248 mlir::ArrayAttr getOffset(mlir::Type ty) {
1250 cir::CIRDataLayout layout(cgm.
getModule());
1251 SmallVector<int64_t, 3> idxVec;
1255 llvm::SmallVector<mlir::Attribute, 3> indices;
1256 for (int64_t i : idxVec) {
1257 mlir::IntegerAttr intAttr = cgm.
getBuilder().getI32IntegerAttr(i);
1258 indices.push_back(intAttr);
1261 if (indices.empty())
1263 return cgm.
getBuilder().getArrayAttr(indices);
1267 ConstantLValue applyOffset(ConstantLValue &
c) {
1269 if (
auto attr = mlir::dyn_cast<mlir::Attribute>(
c.value)) {
1270 if (
auto gv = mlir::dyn_cast<cir::GlobalViewAttr>(attr)) {
1271 auto baseTy = mlir::cast<cir::PointerType>(gv.getType()).getPointee();
1273 assert(!gv.getIndices() &&
"Global view is already indexed");
1274 return cir::GlobalViewAttr::get(destTy, gv.getSymbol(),
1277 llvm_unreachable(
"Unsupported attribute type to offset");
1280 cgm.
errorNYI(
"ConstantLValue: non-attribute offset");
1287mlir::Attribute ConstantLValueEmitter::tryEmit() {
1298 assert(mlir::isa<cir::PointerType>(destTy));
1303 return tryEmitAbsolute(destTy);
1306 ConstantLValue result = tryEmitBase(base);
1309 llvm::PointerUnion<mlir::Value, mlir::Attribute> &value = result.value;
1314 if (!result.hasOffsetApplied)
1315 value = applyOffset(result).value;
1319 if (mlir::isa<cir::PointerType>(destTy)) {
1320 if (
auto attr = mlir::dyn_cast<mlir::Attribute>(value))
1322 cgm.
errorNYI(
"ConstantLValueEmitter: non-attribute pointer");
1326 cgm.
errorNYI(
"ConstantLValueEmitter: other?");
1332mlir::Attribute ConstantLValueEmitter::tryEmitAbsolute(mlir::Type destTy) {
1334 auto destPtrTy = mlir::cast<cir::PointerType>(destTy);
1336 destPtrTy, value.getLValueOffset().getQuantity());
1340ConstantLValueEmitter::tryEmitBase(
const APValue::LValueBase &base) {
1342 if (
const ValueDecl *d = base.
dyn_cast<
const ValueDecl *>()) {
1347 if (d->hasAttr<WeakRefAttr>()) {
1349 "ConstantLValueEmitter: emit pointer base for weakref");
1353 if (
auto *fd = dyn_cast<FunctionDecl>(d)) {
1356 mlir::MLIRContext *mlirContext = builder.getContext();
1357 return cir::GlobalViewAttr::get(
1359 mlir::FlatSymbolRefAttr::get(mlirContext, fop.getSymNameAttr()));
1362 if (
auto *vd = dyn_cast<VarDecl>(d)) {
1364 if (!vd->hasLocalStorage()) {
1365 if (vd->isFileVarDecl() || vd->hasExternalStorage())
1368 if (vd->isLocalVarDecl()) {
1370 "ConstantLValueEmitter: local var decl");
1381 "ConstantLValueEmitter: unhandled value decl");
1386 if (base.
dyn_cast<TypeInfoLValue>()) {
1387 cgm.
errorNYI(
"ConstantLValueEmitter: typeid");
1392 return Visit(base.
get<
const Expr *>());
1395ConstantLValue ConstantLValueEmitter::VisitConstantExpr(
const ConstantExpr *e) {
1401ConstantLValueEmitter::VisitCompoundLiteralExpr(
const CompoundLiteralExpr *e) {
1407ConstantLValueEmitter::VisitStringLiteral(
const StringLiteral *e) {
1412ConstantLValueEmitter::VisitObjCEncodeExpr(
const ObjCEncodeExpr *e) {
1418ConstantLValueEmitter::VisitObjCStringLiteral(
const ObjCStringLiteral *e) {
1420 "ConstantLValueEmitter: objc string literal");
1425ConstantLValueEmitter::VisitObjCBoxedExpr(
const ObjCBoxedExpr *e) {
1431ConstantLValueEmitter::VisitPredefinedExpr(
const PredefinedExpr *e) {
1437ConstantLValueEmitter::VisitAddrLabelExpr(
const AddrLabelExpr *e) {
1442ConstantLValue ConstantLValueEmitter::VisitCallExpr(
const CallExpr *e) {
1447ConstantLValue ConstantLValueEmitter::VisitBlockExpr(
const BlockExpr *e) {
1453ConstantLValueEmitter::VisitCXXTypeidExpr(
const CXXTypeidExpr *e) {
1458ConstantLValue ConstantLValueEmitter::VisitMaterializeTemporaryExpr(
1459 const MaterializeTemporaryExpr *e) {
1461 "ConstantLValueEmitter: materialize temporary expr");
1470 initializeNonAbstract();
1475 assert(initializedNonAbstract &&
1476 "finalizing emitter that was used for abstract emission?");
1477 assert(!finalized &&
"finalizing emitter multiple times");
1478 assert(!gv.isDeclaration());
1487 AbstractStateRAII state(*
this,
true);
1492 assert((!initializedNonAbstract || finalized || failed) &&
1493 "not finalized after being initialized for non-abstract emission");
1503 if (
const auto *e = dyn_cast_or_null<CXXConstructExpr>(d.
getInit())) {
1511 if (cxxrd->getNumBases() != 0) {
1514 cgm.errorNYI(
"tryEmitPrivateForVarInit: cxx record with bases");
1517 if (!
cgm.getTypes().isZeroInitializable(cxxrd)) {
1521 "tryEmitPrivateForVarInit: non-zero-initializable cxx record");
1524 return cir::ZeroAttr::get(
cgm.convertType(d.
getType()));
1532 assert(e &&
"No initializer to emit");
1538 if (mlir::Attribute
c = ConstExprEmitter(*this).Visit(
const_cast<Expr *
>(e),
1557 retType =
cgm.getASTContext().getLValueReferenceType(retType);
1568 return mlir::cast<mlir::TypedAttr>(
attr);
1582 AbstractStateRAII state{*
this,
true};
1583 mlir::Attribute
c = mlir::cast<mlir::Attribute>(
tryEmitPrivate(e, destType));
1586 "emitAbstract failed, emit null constaant");
1593 AbstractStateRAII state(*
this,
true);
1596 cgm.errorNYI(loc,
"emitAbstract failed, emit null constaant");
1603 cir::ConstantOp cstOp =
1604 cgm.emitNullConstant(t, loc).getDefiningOp<cir::ConstantOp>();
1605 assert(cstOp &&
"expected cir.const op");
1613 cgm.errorNYI(
"emitForMemory: atomic type");
1625 cgm.errorNYI(
"atomic constants");
1633 assert(!destType->
isVoidType() &&
"can't emit a void constant");
1635 if (mlir::Attribute
c =
1636 ConstExprEmitter(*this).Visit(
const_cast<Expr *
>(e), destType))
1637 return llvm::dyn_cast<mlir::TypedAttr>(
c);
1641 bool success =
false;
1651 return llvm::dyn_cast<mlir::TypedAttr>(
c);
1659 auto &builder =
cgm.getBuilder();
1663 cgm.errorNYI(
"ConstExprEmitter::tryEmitPrivate none or indeterminate");
1666 mlir::Type ty =
cgm.convertType(destType);
1667 if (mlir::isa<cir::BoolType>(ty))
1669 assert(mlir::isa<cir::IntType>(ty) &&
"expected integral type");
1670 return cir::IntAttr::get(ty, value.
getInt());
1673 const llvm::APFloat &init = value.
getFloat();
1674 if (&init.getSemantics() == &llvm::APFloat::IEEEhalf() &&
1675 !
cgm.getASTContext().getLangOpts().NativeHalfType &&
1676 cgm.getASTContext().getTargetInfo().useFP16ConversionIntrinsics()) {
1677 cgm.errorNYI(
"ConstExprEmitter::tryEmitPrivate half");
1681 mlir::Type ty =
cgm.convertType(destType);
1682 assert(mlir::isa<cir::FPTypeInterface>(ty) &&
1683 "expected floating-point type");
1684 return cir::FPAttr::get(ty, init);
1687 const ArrayType *arrayTy =
cgm.getASTContext().getAsArrayType(destType);
1692 mlir::Attribute filler;
1701 elements.reserve(numInitElts + 1);
1703 elements.reserve(numInitElts);
1705 mlir::Type commonElementType;
1706 for (
unsigned i = 0; i < numInitElts; ++i) {
1708 const mlir::Attribute element =
1713 const mlir::TypedAttr elementTyped = mlir::cast<mlir::TypedAttr>(element);
1715 commonElementType = elementTyped.getType();
1716 else if (elementTyped.getType() != commonElementType) {
1717 commonElementType = {};
1720 elements.push_back(elementTyped);
1723 mlir::TypedAttr typedFiller = llvm::cast_or_null<mlir::TypedAttr>(filler);
1724 if (filler && !typedFiller)
1725 cgm.errorNYI(
"array filler should always be typed");
1727 mlir::Type desiredType =
cgm.convertType(destType);
1728 return emitArrayConstant(
cgm, desiredType, commonElementType, numElements,
1729 elements, typedFiller);
1737 elements.reserve(numElements);
1739 for (
unsigned i = 0; i < numElements; ++i) {
1740 const mlir::Attribute element =
1744 elements.push_back(element);
1747 const auto desiredVecTy =
1748 mlir::cast<cir::VectorType>(
cgm.convertType(destType));
1750 return cir::ConstVectorAttr::get(
1752 mlir::ArrayAttr::get(
cgm.getBuilder().getContext(), elements));
1755 cgm.errorNYI(
"ConstExprEmitter::tryEmitPrivate member pointer");
1759 return ConstantLValueEmitter(*
this, value, destType).tryEmit();
1762 return ConstRecordBuilder::buildRecord(*
this, value, destType);
1765 mlir::Type desiredType =
cgm.convertType(destType);
1766 auto complexType = mlir::dyn_cast<cir::ComplexType>(desiredType);
1768 mlir::Type complexElemTy =
complexType.getElementType();
1772 return cir::ConstComplexAttr::get(builder.getContext(),
complexType,
1773 cir::IntAttr::get(complexElemTy, real),
1774 cir::IntAttr::get(complexElemTy, imag));
1778 "expected floating-point type");
1781 return cir::ConstComplexAttr::get(builder.getContext(),
complexType,
1782 cir::FPAttr::get(complexElemTy, real),
1783 cir::FPAttr::get(complexElemTy, imag));
1788 "ConstExprEmitter::tryEmitPrivate fixed point, addr label diff");
1791 llvm_unreachable(
"Unknown APValue kind");
1796 return builder.getNullPtr(
getTypes().convertTypeForMem(t), loc);
1799 if (
getTypes().isZeroInitializable(t))
1800 return builder.getNullValue(
getTypes().convertTypeForMem(t), loc);
1803 errorNYI(
"CIRGenModule::emitNullConstant ConstantArrayType");
1807 errorNYI(
"CIRGenModule::emitNullConstant RecordType");
1810 "Should only see pointers to data members here!");
1812 errorNYI(
"CIRGenModule::emitNullConstant unsupported type");
Defines the clang::ASTContext interface.
Defines enum values for all the target-independent builtin functions.
static QualType getNonMemoryType(CodeGenModule &CGM, QualType type)
__device__ __2f16 float __ockl_bool s
__device__ __2f16 float c
cir::GlobalViewAttr getGlobalViewAttr(cir::GlobalOp globalOp, mlir::ArrayAttr indices={})
Get constant address of a global variable as an MLIR attribute.
cir::BoolAttr getCIRBoolAttr(bool state)
cir::PointerType getPointerTo(mlir::Type ty)
mlir::TypedAttr getConstPtrAttr(mlir::Type type, int64_t value)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
bool hasArrayFiller() const
const LValueBase getLValueBase() const
APValue & getArrayInitializedElt(unsigned I)
APValue & getStructField(unsigned i)
const FieldDecl * getUnionField() const
APSInt & getComplexIntImag()
ValueKind getKind() const
unsigned getArrayInitializedElts() const
APValue & getUnionValue()
CharUnits & getLValueOffset()
APValue & getVectorElt(unsigned I)
APValue & getArrayFiller()
unsigned getVectorLength() const
unsigned getArraySize() const
@ Indeterminate
This object has an indeterminate value (C++ [basic.indet]).
@ None
There is no such object (it's outside its lifetime).
APSInt & getComplexIntReal()
APFloat & getComplexFloatImag()
APFloat & getComplexFloatReal()
APValue & getStructBase(unsigned i)
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
int64_t toBits(CharUnits CharSize) const
Convert a size in characters to a size in bits.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
uint64_t getCharWidth() const
Return the size of the character type, in bits.
bool hasOwnVFPtr() const
hasOwnVFPtr - Does this class provide its own virtual-function table pointer, rather than inheriting ...
CharUnits getSize() const
getSize - Get the record size in characters.
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
const CXXRecordDecl * getPrimaryBase() const
getPrimaryBase - Get the primary base for this record.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
cir::ConstRecordAttr getAnonConstRecord(mlir::ArrayAttr arrayAttr, bool packed=false, bool padded=false, mlir::Type ty={})
mlir::Attribute getConstRecordOrZeroAttr(mlir::ArrayAttr arrayAttr, bool packed=false, bool padded=false, mlir::Type type={})
bool isNullValue(mlir::Attribute attr) const
cir::RecordType getCompleteRecordType(mlir::ArrayAttr fields, bool packed=false, bool padded=false, llvm::StringRef name="")
void computeGlobalViewIndicesFromFlatOffset(int64_t offset, mlir::Type ty, cir::CIRDataLayout layout, llvm::SmallVectorImpl< int64_t > &indices)
cir::ConstArrayAttr getConstArray(mlir::Attribute attrs, cir::ArrayType arrayTy) const
cir::IntType getUIntNTy(int n)
virtual cir::GlobalOp getAddrOfVTable(const CXXRecordDecl *rd, CharUnits vptrOffset)=0
Get the address of the vtable for the given record decl which should be used for the vptr at the give...
This class organizes the cross-function state that is used while generating CIR code.
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
clang::ASTContext & getASTContext() const
mlir::Type convertType(clang::QualType type)
CIRGenBuilderTy & getBuilder()
ItaniumVTableContext & getItaniumVTableContext()
cir::FuncOp getAddrOfFunction(clang::GlobalDecl gd, mlir::Type funcType=nullptr, bool forVTable=false, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)
Return the address of the given function.
const cir::CIRDataLayout getDataLayout() const
cir::GlobalViewAttr getAddrOfGlobalVarAttr(const VarDecl *d)
Return the mlir::GlobalViewAttr for the address of the given global.
mlir::Location getLoc(clang::SourceLocation cLoc)
Helpers to convert the presumed location of Clang's SourceLocation to an MLIR Location.
mlir::Value emitNullConstant(QualType t, mlir::Location loc)
Return the result of value-initializing the given type, i.e.
mlir::ModuleOp getModule() const
CIRGenCXXABI & getCXXABI() const
cir::GlobalViewAttr getAddrOfConstantStringFromLiteral(const StringLiteral *s, llvm::StringRef name=".str")
Return a global symbol reference to a constant array for the given string literal.
bool shouldZeroInitPadding() const
mlir::Attribute getConstantArrayFromStringLiteral(const StringLiteral *e)
Return a constant array for the given string.
const CIRGenBitFieldInfo & getBitFieldInfo(const clang::FieldDecl *fd) const
Return the BitFieldInfo that corresponds to the field FD.
const CIRGenRecordLayout & getCIRGenRecordLayout(const clang::RecordDecl *rd)
Return record layout info for the given record decl.
mlir::Type convertTypeForMem(clang::QualType, bool forBitField=false)
Convert type T into an mlir::Type.
void finalize(cir::GlobalOp gv)
mlir::Attribute emitForMemory(mlir::Attribute c, QualType destType)
mlir::Attribute emitNullForMemory(mlir::Location loc, QualType t)
mlir::TypedAttr tryEmitPrivate(const Expr *e, QualType destType)
mlir::Attribute tryEmitPrivateForVarInit(const VarDecl &d)
mlir::Attribute tryEmitPrivateForMemory(const Expr *e, QualType destTy)
mlir::Attribute emitAbstract(const Expr *e, QualType destType)
Emit the result of the given expression as an abstract constant, asserting that it succeeded.
mlir::Attribute tryEmitForInitializer(const VarDecl &d)
Try to emit the initializer of the given declaration as an abstract constant.
mlir::Attribute tryEmitAbstractForInitializer(const VarDecl &d)
Try to emit the initializer of the given declaration as an abstract constant.
mlir::Attribute tryEmitConstantExpr(const ConstantExpr *ce)
SourceLocation getBeginLoc() const LLVM_READONLY
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Represents a C++ constructor within a class.
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
SourceLocation getBeginLoc() const
SourceRange getSourceRange() const LLVM_READONLY
CastKind getCastKind() const
CharUnits - This is an opaque type for sizes expressed in character units.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits One()
One - Construct a CharUnits quantity of one.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
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 ...
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
const Expr * getInitializer() const
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
APValue getAPValueResult() const
SourceLocation getBeginLoc() const LLVM_READONLY
bool hasAPValueResult() const
SourceLocation getBeginLoc() const LLVM_READONLY
This represents one expression.
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 ...
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...
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
bool isBitField() const
Determines whether this field is a bitfield.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
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...
bool isUnnamedBitField() const
Determines whether this is an unnamed bitfield.
const Expr * getSubExpr() const
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Expr * getResultExpr()
Return the result expression of this controlling expression.
SourceLocation getBeginLoc() const LLVM_READONLY
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic,...
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
const Expr * getInit(unsigned Init) const
const VTableLayout & getVTableLayout(const CXXRecordDecl *RD)
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation getBeginLoc() const LLVM_READONLY
const Expr * getSubExpr() const
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
bool hasFlexibleArrayMember() const
field_range fields() const
RecordDecl * getDefinitionOrSelf() const
Encodes a location in the source.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
Expr * getReplacement() const
CXXRecordDecl * castAsCXXRecordDecl() const
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isMemberDataPointerType() const
bool isVectorType() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
Expr * getSubExpr() const
AddressPointLocation getAddressPoint(BaseSubobject Base) const
Represents a variable declaration or definition.
APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
bool hasConstantInitialization() const
Determine whether this variable has constant initialization.
const Expr * getInit() const
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
Represents a GCC generic vector type.
const internal::VariadicAllOfMatcher< Attr > attr
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< ComplexType > complexType
const AstTypeMatcher< RecordType > recordType
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
void finalize(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema)
U cast(CodeGen::Address addr)
float __ovld __cnfn length(float)
Return the length of vector p, i.e., sqrt(p.x2 + p.y 2 + ...)
static bool addressPointerAuthInfo()
static bool constEmitterArrayILE()
static bool constEmitterVectorILE()
unsigned size
The total size of the bit-field, in bits.
mlir::Type UCharTy
ClangIR char.
EvalResult is a struct with detailed info about an evaluated expression.
APValue Val
Val - This is the value the expression can be folded to.
bool hasSideEffects() const
Return true if the evaluated expression has side effects.
unsigned AddressPointIndex