13#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
16#include "mlir/IR/Attributes.h"
17#include "mlir/IR/DialectImplementation.h"
18#include "llvm/ADT/TypeSwitch.h"
26 mlir::ArrayAttr &members);
33 cir::IntTypeInterface ty);
36 cir::IntTypeInterface ty);
43static mlir::ParseResult
45 mlir::FailureOr<llvm::APFloat> &value,
46 cir::FPTypeInterface fpType);
49 mlir::IntegerAttr &value);
53static mlir::ParseResult
55 mlir::DenseI32ArrayAttr &memberPath);
58 mlir::DenseI32ArrayAttr memberPath);
60#define GET_ATTRDEF_CLASSES
61#include "clang/CIR/Dialect/IR/CIROpsAttributes.cpp.inc"
71bool LangAddressSpaceAttr::isValidLoad(
72 mlir::Type type, mlir::ptr::AtomicOrdering ordering,
73 std::optional<int64_t> alignment,
const mlir::DataLayout *dataLayout,
74 llvm::function_ref<mlir::InFlightDiagnostic()> emitError)
const {
75 llvm_unreachable(
"isValidLoad for LangAddressSpaceAttr NYI");
78bool LangAddressSpaceAttr::isValidStore(
79 mlir::Type type, mlir::ptr::AtomicOrdering ordering,
80 std::optional<int64_t> alignment,
const mlir::DataLayout *dataLayout,
81 llvm::function_ref<mlir::InFlightDiagnostic()> emitError)
const {
82 llvm_unreachable(
"isValidStore for LangAddressSpaceAttr NYI");
85bool LangAddressSpaceAttr::isValidAtomicOp(
86 mlir::ptr::AtomicBinOp op, mlir::Type type,
87 mlir::ptr::AtomicOrdering ordering, std::optional<int64_t> alignment,
88 const mlir::DataLayout *dataLayout,
89 llvm::function_ref<mlir::InFlightDiagnostic()> emitError)
const {
90 llvm_unreachable(
"isValidAtomicOp for LangAddressSpaceAttr NYI");
93bool LangAddressSpaceAttr::isValidAtomicXchg(
94 mlir::Type type, mlir::ptr::AtomicOrdering successOrdering,
95 mlir::ptr::AtomicOrdering failureOrdering, std::optional<int64_t> alignment,
96 const mlir::DataLayout *dataLayout,
97 llvm::function_ref<mlir::InFlightDiagnostic()> emitError)
const {
98 llvm_unreachable(
"isValidAtomicXchg for LangAddressSpaceAttr NYI");
101bool LangAddressSpaceAttr::isValidAddrSpaceCast(
102 mlir::Type tgt, mlir::Type src,
103 llvm::function_ref<mlir::InFlightDiagnostic()> emitError)
const {
104 llvm_unreachable(
"isValidAddrSpaceCast for LangAddressSpaceAttr NYI");
107bool LangAddressSpaceAttr::isValidPtrIntCast(
108 mlir::Type intLikeTy, mlir::Type ptrLikeTy,
109 llvm::function_ref<mlir::InFlightDiagnostic()> emitError)
const {
110 llvm_unreachable(
"isValidPtrIntCast for LangAddressSpaceAttr NYI");
113bool TargetAddressSpaceAttr::isValidLoad(
114 mlir::Type type, mlir::ptr::AtomicOrdering ordering,
115 std::optional<int64_t> alignment,
const mlir::DataLayout *dataLayout,
116 llvm::function_ref<mlir::InFlightDiagnostic()> emitError)
const {
117 llvm_unreachable(
"isValidLoad for TargetAddressSpaceAttr NYI");
120bool TargetAddressSpaceAttr::isValidStore(
121 mlir::Type type, mlir::ptr::AtomicOrdering ordering,
122 std::optional<int64_t> alignment,
const mlir::DataLayout *dataLayout,
123 llvm::function_ref<mlir::InFlightDiagnostic()> emitError)
const {
124 llvm_unreachable(
"isValidStore for TargetAddressSpaceAttr NYI");
127bool TargetAddressSpaceAttr::isValidAtomicOp(
128 mlir::ptr::AtomicBinOp op, mlir::Type type,
129 mlir::ptr::AtomicOrdering ordering, std::optional<int64_t> alignment,
130 const mlir::DataLayout *dataLayout,
131 llvm::function_ref<mlir::InFlightDiagnostic()> emitError)
const {
132 llvm_unreachable(
"isValidAtomicOp for TargetAddressSpaceAttr NYI");
135bool TargetAddressSpaceAttr::isValidAtomicXchg(
136 mlir::Type type, mlir::ptr::AtomicOrdering successOrdering,
137 mlir::ptr::AtomicOrdering failureOrdering, std::optional<int64_t> alignment,
138 const mlir::DataLayout *dataLayout,
139 llvm::function_ref<mlir::InFlightDiagnostic()> emitError)
const {
140 llvm_unreachable(
"isValidAtomicXchg for TargetAddressSpaceAttr NYI");
143bool TargetAddressSpaceAttr::isValidAddrSpaceCast(
144 mlir::Type tgt, mlir::Type src,
145 llvm::function_ref<mlir::InFlightDiagnostic()> emitError)
const {
146 llvm_unreachable(
"isValidAddrSpaceCast for TargetAddressSpaceAttr NYI");
149bool TargetAddressSpaceAttr::isValidPtrIntCast(
150 mlir::Type intLikeTy, mlir::Type ptrLikeTy,
151 llvm::function_ref<mlir::InFlightDiagnostic()> emitError)
const {
152 llvm_unreachable(
"isValidPtrIntCast for TargetAddressSpaceAttr NYI");
159LogicalResult PtrSpecAttr::verify(function_ref<InFlightDiagnostic()> emitError,
162 constexpr unsigned kBitsInByte = 8;
163 if (size % kBitsInByte != 0)
164 return emitError() <<
"size entry must be divisible by 8";
165 if (abi % kBitsInByte != 0)
166 return emitError() <<
"abi entry must be divisible by 8";
167 if (preferred % kBitsInByte != 0)
168 return emitError() <<
"preferred entry must be divisible by 8";
169 if (index != kOptionalSpecValue && index % kBitsInByte != 0)
170 return emitError() <<
"index entry must be divisible by 8";
172 return emitError() <<
"preferred alignment is expected to be at least "
173 "as large as ABI alignment";
182BitFieldDeclAttr::verify(function_ref<InFlightDiagnostic()> emitError,
183 mlir::Type declaredType, uint64_t width,
185 if (width == 0 && !isUnnamed)
186 return emitError() <<
"zero-width bit-field cannot be named";
195 mlir::ArrayAttr members) {
197 llvm::interleaveComma(members, printer);
202 mlir::ArrayAttr &members) {
205 auto delimiter = AsmParser::Delimiter::Braces;
206 auto result = parser.parseCommaSeparatedList(delimiter, [&]() {
207 mlir::TypedAttr attr;
208 if (parser.parseAttribute(attr).failed())
209 return mlir::failure();
210 elts.push_back(attr);
211 return mlir::success();
215 return mlir::failure();
217 members = mlir::ArrayAttr::get(parser.getContext(), elts);
218 return mlir::success();
226ConstRecordAttr::verify(function_ref<InFlightDiagnostic()> emitError,
227 mlir::Type type, ArrayAttr members) {
228 auto sTy = mlir::dyn_cast_if_present<cir::RecordType>(type);
230 return emitError() <<
"expected !cir.struct or !cir.union type";
235 if (members.size() != 1)
236 return emitError() <<
"union constant must have exactly one element, got "
238 auto m = mlir::cast<mlir::TypedAttr>(members[0]);
240 if (!llvm::any_of(sTy.getMembers(), [&](mlir::Type memberTy) {
241 return cir::memberStorageType(memberTy) == m.getType();
243 return emitError() <<
"union element type " << m.getType()
244 <<
" is not a member of " << sTy;
252 for (mlir::Type memberTy : sTy.getMembers())
256 if (storedMembers.size() != members.size())
257 return emitError() <<
"number of elements must match";
259 for (
const auto &[attrIdx, member] : llvm::enumerate(storedMembers)) {
260 auto m = mlir::cast<mlir::TypedAttr>(members[attrIdx]);
265 if (attrIdx == storedMembers.size() - 1) {
266 auto memArrayTy = dyn_cast<cir::ArrayType>(member);
267 if (memArrayTy && memArrayTy.getSize() == 0) {
270 if (!isa<cir::ArrayType>(m.getType()))
272 <<
"element at index " << attrIdx <<
" has type "
273 << m.getType() <<
" but the expected type for this element is "
276 cir::ArrayType initArrayTy = cast<cir::ArrayType>(m.getType());
278 if (initArrayTy.getElementType() != memArrayTy.getElementType())
280 <<
"flexible array member at index " << attrIdx <<
" has type "
282 <<
" which doesn't match the expected element type of member "
288 if (member != m.getType())
289 return emitError() <<
"element at index " << attrIdx <<
" has type "
291 <<
" but the expected type for this element is "
302LogicalResult OptInfoAttr::verify(function_ref<InFlightDiagnostic()> emitError,
303 unsigned level,
unsigned size) {
306 <<
"optimization level must be between 0 and 3 inclusive";
309 <<
"size optimization level must be between 0 and 2 inclusive";
319static ParseResult
parseConstPtr(AsmParser &parser, mlir::IntegerAttr &value) {
321 if (parser.parseOptionalKeyword(
"null").succeeded()) {
322 value = parser.getBuilder().getI64IntegerAttr(0);
326 return parser.parseAttribute(value);
337 mlir::DenseI32ArrayAttr &memberPath) {
338 if (parser.parseOptionalKeyword(
"null").succeeded())
341 auto parsed = mlir::FieldParser<mlir::DenseI32ArrayAttr>::parse(parser);
342 if (mlir::failed(parsed))
344 memberPath = *parsed;
349 mlir::DenseI32ArrayAttr memberPath) {
353 p.printStrippedAttrOrType(memberPath);
361 cir::IntTypeInterface ty) {
362 llvm::SMLoc loc = parser.getCurrentLocation();
364 mlir::OptionalParseResult result = parser.parseOptionalInteger(parsed);
365 if (!result.has_value() || failed(*result))
366 return parser.emitError(loc,
"expected integer value");
368 const unsigned width = ty.getWidth();
370 ty.isSigned() ? parsed.getSignificantBits() <= width
371 : !parsed.isNegative() && parsed.getActiveBits() <= width;
373 return parser.emitError(loc,
"integer value too large for the given type");
375 value = ty.isSigned() ? parsed.sextOrTrunc(width) : parsed.zextOrTrunc(width);
380 cir::IntTypeInterface ty) {
382 value.toString(str, 10, ty.isSigned());
386LogicalResult IntAttr::verify(function_ref<InFlightDiagnostic()> emitError,
387 cir::IntTypeInterface type, llvm::APInt value) {
388 if (value.getBitWidth() != type.getWidth())
389 return emitError() <<
"type and value bitwidth mismatch: "
390 << type.getWidth() <<
" != " << value.getBitWidth();
403 FailureOr<APFloat> &value,
404 cir::FPTypeInterface fpType) {
406 APFloat parsedValue(0.0);
407 if (parser.parseFloat(fpType.getFloatSemantics(), parsedValue))
410 value.emplace(parsedValue);
418MemoryEffectsAttr MemoryEffectsAttr::none(MLIRContext *ctx) {
419 return get(ctx, ModRefInfo::NoModRef);
422MemoryEffectsAttr MemoryEffectsAttr::readOnly(MLIRContext *ctx) {
423 return get(ctx, ModRefInfo::Ref);
426MemoryEffectsAttr MemoryEffectsAttr::writeOnly(MLIRContext *ctx) {
427 return get(ctx, ModRefInfo::Mod);
430MemoryEffectsAttr MemoryEffectsAttr::argMemOnly(MLIRContext *ctx,
432 return get(ctx, ModRefInfo::NoModRef, mr,
433 ModRefInfo::NoModRef,
434 ModRefInfo::NoModRef,
435 ModRefInfo::NoModRef,
436 ModRefInfo::NoModRef);
439MemoryEffectsAttr MemoryEffectsAttr::inaccessibleMemOnly(MLIRContext *ctx,
441 return get(ctx, ModRefInfo::NoModRef,
442 ModRefInfo::NoModRef, mr,
443 ModRefInfo::NoModRef,
444 ModRefInfo::NoModRef,
445 ModRefInfo::NoModRef);
448MemoryEffectsAttr MemoryEffectsAttr::errnoMemOnly(MLIRContext *ctx,
450 return get(ctx, ModRefInfo::NoModRef,
451 ModRefInfo::NoModRef,
452 ModRefInfo::NoModRef, mr,
453 ModRefInfo::NoModRef,
454 ModRefInfo::NoModRef);
457MemoryEffectsAttr MemoryEffectsAttr::otherMemOnly(MLIRContext *ctx,
459 return get(ctx, mr, ModRefInfo::NoModRef,
460 ModRefInfo::NoModRef,
461 ModRefInfo::NoModRef,
462 ModRefInfo::NoModRef,
463 ModRefInfo::NoModRef);
466MemoryEffectsAttr MemoryEffectsAttr::inaccessibleOrArgMemOnly(MLIRContext *ctx,
468 return get(ctx, ModRefInfo::NoModRef, mr,
469 mr, ModRefInfo::NoModRef,
470 ModRefInfo::NoModRef,
471 ModRefInfo::NoModRef);
474MemoryEffectsAttr MemoryEffectsAttr::inaccessibleOrErrnoMemOnly(
475 MLIRContext *ctx, ModRefInfo inaccessibleMr, ModRefInfo errnoMr) {
476 return get(ctx, ModRefInfo::NoModRef,
477 ModRefInfo::NoModRef,
478 inaccessibleMr, errnoMr,
479 ModRefInfo::NoModRef,
480 ModRefInfo::NoModRef);
483MemoryEffectsAttr MemoryEffectsAttr::inaccessibleOrArgOrErrnoMemOnly(
484 MLIRContext *ctx, ModRefInfo inaccessibleOrArgMr, ModRefInfo errnoMr) {
485 return get(ctx, ModRefInfo::NoModRef,
487 inaccessibleOrArgMr, errnoMr,
488 ModRefInfo::NoModRef,
489 ModRefInfo::NoModRef);
493MemoryEffectsAttr::argumentOrErrnoMemOnly(MLIRContext *ctx, ModRefInfo argMr,
494 ModRefInfo errnoMr) {
495 return get(ctx, ModRefInfo::NoModRef, argMr,
496 ModRefInfo::NoModRef, errnoMr,
497 ModRefInfo::NoModRef,
498 ModRefInfo::NoModRef);
501FPAttr FPAttr::getZero(Type type) {
504 mlir::cast<cir::FPTypeInterface>(type).getFloatSemantics()));
507LogicalResult FPAttr::verify(function_ref<InFlightDiagnostic()> emitError,
508 cir::FPTypeInterface fpType, APFloat value) {
509 if (APFloat::SemanticsToEnum(fpType.getFloatSemantics()) !=
510 APFloat::SemanticsToEnum(value.getSemantics()))
511 return emitError() <<
"floating-point semantics mismatch";
520std::string CmpThreeWayInfoAttr::getAlias()
const {
521 std::string alias =
"cmpinfo";
523 switch (getOrdering()) {
524 case CmpOrdering::Strong:
525 alias.append(
"_strong_");
527 case CmpOrdering::Weak:
528 alias.append(
"_weak_");
530 case CmpOrdering::Partial:
531 alias.append(
"_partial_");
535 auto appendInt = [&](int64_t value) {
537 alias.push_back(
'n');
540 alias.append(std::to_string(value));
550 if (std::optional<int> unordered = getUnordered()) {
552 appendInt(unordered.value());
559CmpThreeWayInfoAttr::verify(function_ref<InFlightDiagnostic()> emitError,
560 CmpOrdering ordering, int64_t lt, int64_t eq,
561 int64_t gt, std::optional<int64_t> unordered) {
563 if ((ordering == CmpOrdering::Strong || ordering == CmpOrdering::Weak) &&
565 emitError() <<
"strong and weak ordering do not include unordered";
568 if (ordering == CmpOrdering::Partial && !unordered) {
569 emitError() <<
"partial ordering requires unordered value";
581ConstComplexAttr::verify(function_ref<InFlightDiagnostic()> emitError,
582 cir::ComplexType type, mlir::TypedAttr real,
583 mlir::TypedAttr imag) {
584 mlir::Type elemType = type.getElementType();
585 if (real.getType() != elemType)
587 <<
"type of the real part does not match the complex type";
589 if (imag.getType() != elemType)
591 <<
"type of the imaginary part does not match the complex type";
600void CUDAVarRegistrationInfoAttr::print(AsmPrinter &p)
const {
601 p <<
"<" << getDeviceSideName();
602 p <<
", " << stringifyEnum(
getKind());
612Attribute CUDAVarRegistrationInfoAttr::parse(AsmParser &parser, Type odsType) {
613 if (parser.parseLess())
616 std::string deviceSideName;
617 if (parser.parseKeywordOrString(&deviceSideName)) {
618 parser.emitError(parser.getCurrentLocation(),
619 "expected device variable name");
623 if (parser.parseComma())
628 if (parser.parseKeyword(&kindStr))
631 std::optional<CUDADeviceVarKind>
kind = symbolizeCUDADeviceVarKind(kindStr);
633 parser.emitError(parser.getCurrentLocation(),
634 "unknown device variable kind: ")
640 bool isExtern =
false;
641 bool isConstant =
false;
642 bool isManaged =
false;
644 while (parser.parseOptionalGreater().failed()) {
645 if (parser.parseComma())
649 if (parser.parseKeyword(&flag))
652 if (flag ==
"extern")
654 else if (flag ==
"constant")
656 else if (flag ==
"managed")
659 parser.emitError(parser.getCurrentLocation(),
"unknown flag: ") << flag;
664 return get(parser.getContext(), deviceSideName, *
kind, isExtern, isConstant,
673DataMemberAttr::verify(function_ref<InFlightDiagnostic()> emitError,
674 cir::DataMemberType ty,
675 mlir::DenseI32ArrayAttr memberPath) {
679 if (memberPath.empty())
680 return emitError() <<
"#cir.data_member path must not be empty";
682 mlir::Type currentTy = ty.getClassTy();
683 for (
auto [
step, idx] : llvm::enumerate(memberPath.asArrayRef())) {
684 auto recTy = mlir::dyn_cast<cir::RecordType>(currentTy);
686 return emitError() <<
"#cir.data_member path step " <<
step
687 <<
" reaches a non-record type";
689 if (recTy.isIncomplete())
692 if (idx < 0 ||
static_cast<unsigned>(idx) >= recTy.getNumElements())
693 return emitError() <<
"#cir.data_member path index " << idx <<
" at step "
694 <<
step <<
" is out of range";
696 currentTy = recTy.getMembers()[idx];
699 if (currentTy != ty.getMemberTy())
701 <<
"member type of a #cir.data_member attribute must match "
702 "the attribute type";
711LogicalResult MethodAttr::verify(function_ref<InFlightDiagnostic()> emitError,
712 cir::MethodType type,
713 std::optional<FlatSymbolRefAttr> symbol,
714 std::optional<uint64_t> vtable_offset) {
715 if (symbol.has_value() && vtable_offset.has_value())
717 <<
"at most one of symbol and vtable_offset can be present "
723Attribute MethodAttr::parse(AsmParser &parser, Type odsType) {
724 auto ty = mlir::cast<cir::MethodType>(odsType);
726 if (parser.parseLess().failed())
730 if (parser.parseOptionalKeyword(
"null").succeeded()) {
731 if (parser.parseGreater().failed())
738 FlatSymbolRefAttr symbol;
739 mlir::OptionalParseResult parseSymbolRefResult =
740 parser.parseOptionalAttribute(symbol);
741 if (parseSymbolRefResult.has_value()) {
742 if (parseSymbolRefResult.value().failed())
744 if (parser.parseGreater().failed())
746 return get(ty, symbol);
750 std::uint64_t vtableOffset = 0;
751 if (parser.parseKeyword(
"vtable_offset"))
753 if (parser.parseEqual())
755 if (parser.parseInteger(vtableOffset))
758 if (parser.parseGreater())
761 return get(ty, vtableOffset);
764void MethodAttr::print(AsmPrinter &printer)
const {
765 auto symbol = getSymbol();
766 auto vtableOffset = getVtableOffset();
769 if (symbol.has_value()) {
771 }
else if (vtableOffset.has_value()) {
772 printer <<
"vtable_offset = " << *vtableOffset;
784ConstArrayAttr::verify(function_ref<InFlightDiagnostic()> emitError, Type type,
785 Attribute elts,
int trailingZerosNum) {
787 if (!(mlir::isa<ArrayAttr, StringAttr>(elts)))
788 return emitError() <<
"constant array expects ArrayAttr or StringAttr";
790 if (
auto strAttr = mlir::dyn_cast<StringAttr>(elts)) {
791 const auto arrayTy = mlir::cast<ArrayType>(type);
792 const auto intTy = mlir::dyn_cast<IntType>(arrayTy.getElementType());
795 if (!intTy || intTy.getWidth() != 8)
797 <<
"constant array element for string literals expects "
798 "!cir.int<u, 8> element type";
802 assert(mlir::isa<ArrayAttr>(elts));
803 const auto arrayAttr = mlir::cast<mlir::ArrayAttr>(elts);
804 const auto arrayTy = mlir::cast<ArrayType>(type);
807 if (arrayAttr.size() > arrayTy.getSize())
808 return emitError() <<
"constant array has " << arrayAttr.size()
809 <<
" values but array type has size "
810 << arrayTy.getSize();
811 if (arrayTy.getSize() != arrayAttr.size() + trailingZerosNum)
812 return emitError() <<
"constant array size should match type size";
816Attribute ConstArrayAttr::parse(AsmParser &parser, Type type) {
817 mlir::FailureOr<Type> resultTy;
818 mlir::FailureOr<Attribute> resultVal;
821 if (parser.parseLess())
825 resultVal = FieldParser<Attribute>::parse(parser);
826 if (failed(resultVal)) {
828 parser.getCurrentLocation(),
829 "failed to parse ConstArrayAttr parameter 'value' which is "
830 "to be a `Attribute`");
835 if (mlir::isa<ArrayAttr>(*resultVal)) {
837 if (parser.parseOptionalColon().failed()) {
840 resultTy = FieldParser<Type>::parse(parser);
841 if (failed(resultTy)) {
843 parser.getCurrentLocation(),
844 "failed to parse ConstArrayAttr parameter 'type' which is "
845 "to be a `::mlir::Type`");
850 auto ta = mlir::cast<TypedAttr>(*resultVal);
851 resultTy = ta.getType();
852 if (mlir::isa<mlir::NoneType>(*resultTy)) {
853 parser.emitError(parser.getCurrentLocation(),
854 "expected type declaration for string literal");
860 if (parser.parseOptionalComma().succeeded()) {
861 if (parser.parseOptionalKeyword(
"trailing_zeros").succeeded()) {
862 unsigned totalSize = mlir::cast<cir::ArrayType>(type).getSize();
863 mlir::Attribute elts = resultVal.value();
864 if (
auto str = mlir::dyn_cast<mlir::StringAttr>(elts))
865 zeros = totalSize - str.size();
867 zeros = totalSize - mlir::cast<mlir::ArrayAttr>(elts).size();
874 if (parser.parseGreater())
877 return parser.getChecked<ConstArrayAttr>(parser.getCurrentLocation(),
878 parser.getContext(), type,
879 resultVal.value(), zeros);
882void ConstArrayAttr::print(AsmPrinter &printer)
const {
884 printer.printStrippedAttrOrType(getElts());
885 if (getTrailingZerosNum())
886 printer <<
", trailing_zeros";
895cir::ConstVectorAttr::verify(function_ref<InFlightDiagnostic()> emitError,
896 Type type, ArrayAttr elts) {
898 if (!mlir::isa<cir::VectorType>(type))
899 return emitError() <<
"type of cir::ConstVectorAttr is not a "
903 const auto vecType = mlir::cast<cir::VectorType>(type);
905 if (vecType.getSize() != elts.size())
907 <<
"number of constant elements should match vector size";
910 LogicalResult elementTypeCheck =
success();
911 elts.walkImmediateSubElements(
912 [&](Attribute element) {
913 if (elementTypeCheck.failed()) {
917 auto typedElement = mlir::dyn_cast<TypedAttr>(element);
919 typedElement.getType() != vecType.getElementType()) {
920 elementTypeCheck = failure();
921 emitError() <<
"constant type should match vector element type";
926 return elementTypeCheck;
933LogicalResult cir::VTableAttr::verify(
934 llvm::function_ref<mlir::InFlightDiagnostic()> emitError, mlir::Type type,
935 mlir::ArrayAttr data) {
936 auto sTy = mlir::dyn_cast_if_present<cir::RecordType>(type);
938 return emitError() <<
"expected !cir.struct or !cir.union type result";
939 if (sTy.getMembers().empty() || data.empty())
940 return emitError() <<
"expected record type with one or more subtype";
942 if (cir::ConstRecordAttr::verify(emitError, type, data).failed())
945 for (
const auto &element : data.getAsRange<mlir::Attribute>()) {
946 const auto &constArrayAttr = mlir::dyn_cast<cir::ConstArrayAttr>(element);
948 return emitError() <<
"expected constant array subtype";
950 LogicalResult eltTypeCheck =
success();
951 auto arrayElts = mlir::cast<ArrayAttr>(constArrayAttr.getElts());
952 arrayElts.walkImmediateSubElements(
953 [&](mlir::Attribute attr) {
954 if (mlir::isa<ConstPtrAttr, GlobalViewAttr>(attr))
957 eltTypeCheck = emitError()
958 <<
"expected GlobalViewAttr or ConstPtrAttr";
960 [&](mlir::Type type) {});
961 if (eltTypeCheck.failed())
971std::string DynamicCastInfoAttr::getAlias()
const {
974 std::string alias =
"dyn_cast_info_";
976 alias.append(getSrcRtti().getSymbol().getValue());
977 alias.push_back(
'_');
978 alias.append(getDestRtti().getSymbol().getValue());
986 auto ptrTy = mlir::dyn_cast<cir::PointerType>(ty);
990 auto pointeeIntTy = mlir::dyn_cast<cir::IntType>(ptrTy.getPointee());
994 return pointeeIntTy.isUnsigned() && pointeeIntTy.getWidth() == 8;
997LogicalResult DynamicCastInfoAttr::verify(
998 function_ref<InFlightDiagnostic()> emitError, cir::GlobalViewAttr srcRtti,
999 cir::GlobalViewAttr destRtti, mlir::FlatSymbolRefAttr runtimeFunc,
1000 mlir::FlatSymbolRefAttr badCastFunc, cir::IntAttr offsetHint) {
1002 return emitError() <<
"srcRtti must be an RTTI pointer";
1005 return emitError() <<
"destRtti must be an RTTI pointer";
1014LogicalResult EhFilterAttr::verify(function_ref<InFlightDiagnostic()> emitError,
1015 mlir::ArrayAttr permittedTypes) {
1016 for (mlir::Attribute typeAttr : permittedTypes) {
1017 auto rtti = mlir::dyn_cast<cir::GlobalViewAttr>(typeAttr);
1018 if (!rtti || !
isRttiPtr(rtti.getType()))
1019 return emitError() <<
"permitted type list must contain only type info "
1031 mlir::StringAttr name) {
1034 auto dict = mod->getAttrOfType<mlir::DictionaryAttr>(
1035 CIRDialect::getRecordLayoutsAttrName());
1038 return dict.getAs<RecordLayoutAttr>(name);
1042 mlir::StringAttr name) {
1044 assert(attr &&
"record layout entry missing for named record");
1052void CIRDialect::registerAttributes() {
1054#define GET_ATTRDEF_LIST
1055#include "clang/CIR/Dialect/IR/CIROpsAttributes.cpp.inc"
static mlir::ParseResult parseFloatLiteral(mlir::AsmParser &parser, mlir::FailureOr< llvm::APFloat > &value, cir::FPTypeInterface fpType)
static void printConstPtr(mlir::AsmPrinter &p, mlir::IntegerAttr value)
static void printRecordMembers(mlir::AsmPrinter &p, mlir::ArrayAttr members)
static mlir::ParseResult parseIntLiteral(mlir::AsmParser &parser, llvm::APInt &value, cir::IntTypeInterface ty)
static void printIntLiteral(mlir::AsmPrinter &p, llvm::APInt value, cir::IntTypeInterface ty)
static mlir::ParseResult parseConstPtr(mlir::AsmParser &parser, mlir::IntegerAttr &value)
static void printFloatLiteral(mlir::AsmPrinter &p, llvm::APFloat value, mlir::Type ty)
static mlir::ParseResult parseDataMemberPath(mlir::AsmParser &parser, mlir::DenseI32ArrayAttr &memberPath)
static bool isRttiPtr(mlir::Type ty)
static void printDataMemberPath(mlir::AsmPrinter &p, mlir::DenseI32ArrayAttr memberPath)
static mlir::ParseResult parseRecordMembers(mlir::AsmParser &parser, mlir::ArrayAttr &members)
static Decl::Kind getKind(const Decl *D)
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
RecordLayoutAttr tryGetRecordLayout(mlir::ModuleOp mod, mlir::StringAttr name)
Same lookup as getRecordLayout, but returns a null attribute instead of asserting when the record has...
RecordLayoutAttr getRecordLayout(mlir::ModuleOp mod, mlir::StringAttr name)
Look up the RecordLayoutAttr for a named record in the module's cir.record_layouts dictionary.
mlir::Type memberStorageType(mlir::Type memberTy)
The storage a member is stored as: the access unit for a bit-field member, and the member type itself...
bool memberOwnsBytes(mlir::Type memberTy)
Whether a record member occupies bytes of its record.
float __ovld __cnfn step(float, float)
Returns 0.0 if x < edge, otherwise it returns 1.0.
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t