15#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
16#include "mlir/IR/BuiltinAttributes.h"
17#include "mlir/IR/DialectImplementation.h"
18#include "mlir/IR/MLIRContext.h"
19#include "mlir/Support/LLVM.h"
26#include "llvm/ADT/APInt.h"
27#include "llvm/ADT/APSInt.h"
28#include "llvm/ADT/TypeSwitch.h"
34 if (
auto sizedTy = mlir::dyn_cast<cir::SizedTypeInterface>(ty))
35 return sizedTy.isSized();
44static mlir::ParseResult
48 mlir::ArrayRef<mlir::Type> params,
54static mlir::ParseResult
59 mlir::ArrayRef<mlir::Type> params,
68 mlir::ptr::MemorySpaceAttrInterface &attr);
71 mlir::ptr::MemorySpaceAttrInterface attr);
75 cir::TargetAddressSpaceAttr &attr);
78 cir::TargetAddressSpaceAttr attr);
86#include "clang/CIR/Dialect/IR/CIRTypeConstraints.cpp.inc"
90#define GET_TYPEDEF_CLASSES
91#include "clang/CIR/Dialect/IR/CIROpsTypes.cpp.inc"
100Type CIRDialect::parseType(DialectAsmParser &parser)
const {
101 llvm::SMLoc typeLoc = parser.getCurrentLocation();
102 llvm::StringRef mnemonic;
106 OptionalParseResult parseResult =
107 generatedTypeParser(parser, &mnemonic, genType);
108 if (parseResult.has_value())
112 return StringSwitch<function_ref<Type()>>(mnemonic)
113 .Case(
"record", [&] {
return RecordType::parse(parser); })
115 parser.emitError(typeLoc) <<
"unknown CIR type: " << mnemonic;
120void CIRDialect::printType(Type type, DialectAsmPrinter &os)
const {
122 if (generatedTypePrinter(type, os).succeeded())
126 llvm::report_fatal_error(
"printer is missing a handler for this type");
133Type RecordType::parse(mlir::AsmParser &parser) {
134 FailureOr<AsmParser::CyclicParseReset> cyclicParseGuard;
135 const llvm::SMLoc loc = parser.getCurrentLocation();
136 const mlir::Location eLoc = parser.getEncodedSourceLoc(loc);
140 mlir::MLIRContext *context = parser.getContext();
142 if (parser.parseLess())
147 if (parser.parseOptionalKeyword(
"struct").succeeded())
148 kind = RecordKind::Struct;
149 else if (parser.parseOptionalKeyword(
"union").succeeded())
150 kind = RecordKind::Union;
151 else if (parser.parseOptionalKeyword(
"class").succeeded())
152 kind = RecordKind::Class;
154 parser.emitError(loc,
"unknown record type");
158 mlir::StringAttr
name;
159 parser.parseOptionalAttribute(name);
162 if (name && parser.parseOptionalGreater().succeeded()) {
163 RecordType
type = getChecked(eLoc, context, name,
kind);
164 if (succeeded(parser.tryStartCyclicParse(type))) {
165 parser.emitError(loc,
"invalid self-reference within record");
173 RecordType
type = getChecked(eLoc, context, name,
kind);
174 cyclicParseGuard = parser.tryStartCyclicParse(type);
175 if (failed(cyclicParseGuard)) {
176 parser.emitError(loc,
"record already defined");
181 if (parser.parseOptionalKeyword(
"packed").succeeded())
184 if (parser.parseOptionalKeyword(
"padded").succeeded())
188 bool incomplete =
true;
189 llvm::SmallVector<mlir::Type> members;
190 if (parser.parseOptionalKeyword(
"incomplete").failed()) {
192 const auto delimiter = AsmParser::Delimiter::Braces;
193 const auto parseElementFn = [&parser, &members]() {
194 return parser.parseType(members.emplace_back());
196 if (parser.parseCommaSeparatedList(delimiter, parseElementFn).failed())
200 if (parser.parseGreater())
204 ArrayRef<mlir::Type> membersRef(members);
205 mlir::Type
type = {};
206 if (name && incomplete) {
207 type = getChecked(eLoc, context, name,
kind);
208 }
else if (!name && !incomplete) {
209 type = getChecked(eLoc, context, membersRef, packed, padded,
kind);
210 }
else if (!incomplete) {
211 type = getChecked(eLoc, context, membersRef, name, packed, padded,
kind);
214 if (mlir::cast<RecordType>(type).isIncomplete())
215 mlir::cast<RecordType>(type).complete(membersRef, packed, padded);
218 parser.emitError(loc,
"anonymous records must be complete");
225void RecordType::print(mlir::AsmPrinter &printer)
const {
226 FailureOr<AsmPrinter::CyclicPrintReset> cyclicPrintGuard;
230 case RecordKind::Struct:
231 printer <<
"struct ";
233 case RecordKind::Union:
236 case RecordKind::Class:
245 cyclicPrintGuard = printer.tryStartCyclicPrint(*
this);
246 if (failed(cyclicPrintGuard)) {
255 printer <<
"packed ";
258 printer <<
"padded ";
260 if (isIncomplete()) {
261 printer <<
"incomplete";
264 llvm::interleaveComma(getMembers(), printer);
272RecordType::verify(function_ref<mlir::InFlightDiagnostic()> emitError,
273 llvm::ArrayRef<mlir::Type> members, mlir::StringAttr name,
274 bool incomplete,
bool packed,
bool padded,
275 RecordType::RecordKind
kind) {
276 if (name &&
name.getValue().empty())
277 return emitError() <<
"identified records cannot have an empty name";
278 return mlir::success();
281::llvm::ArrayRef<mlir::Type> RecordType::getMembers()
const {
285bool RecordType::isIncomplete()
const {
return getImpl()->incomplete; }
287mlir::StringAttr RecordType::getName()
const {
return getImpl()->name; }
289bool RecordType::getIncomplete()
const {
return getImpl()->incomplete; }
291bool RecordType::getPacked()
const {
return getImpl()->packed; }
293bool RecordType::getPadded()
const {
return getImpl()->padded; }
295cir::RecordType::RecordKind RecordType::getKind()
const {
299void RecordType::complete(ArrayRef<Type> members,
bool packed,
bool padded) {
301 if (mutate(members, packed, padded).failed())
302 llvm_unreachable(
"failed to complete record");
308Type RecordType::getLargestMember(const ::mlir::DataLayout &dataLayout)
const {
309 assert(isUnion() &&
"Only call getLargestMember on unions");
310 llvm::ArrayRef<Type> members = getMembers();
316 auto endIt = getPadded() ? std::prev(members.end()) : members.end();
317 if (endIt == members.begin())
319 return *std::max_element(
320 members.begin(), endIt, [&](Type lhs, Type rhs) {
321 return dataLayout.getTypeABIAlignment(lhs) <
322 dataLayout.getTypeABIAlignment(rhs) ||
323 (dataLayout.getTypeABIAlignment(lhs) ==
324 dataLayout.getTypeABIAlignment(rhs) &&
325 dataLayout.getTypeSize(lhs) < dataLayout.getTypeSize(rhs));
329bool RecordType::isLayoutIdentical(
const RecordType &other) {
330 if (
getImpl() == other.getImpl())
333 if (getPacked() != other.getPacked())
336 return getMembers() == other.getMembers();
344PointerType::getTypeSizeInBits(const ::mlir::DataLayout &dataLayout,
345 ::mlir::DataLayoutEntryListRef params)
const {
348 return llvm::TypeSize::getFixed(64);
352PointerType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
353 ::mlir::DataLayoutEntryListRef params)
const {
360RecordType::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
361 mlir::DataLayoutEntryListRef params)
const {
363 return dataLayout.getTypeSize(getLargestMember(dataLayout));
365 auto recordSize =
static_cast<uint64_t>(computeStructSize(dataLayout));
366 return llvm::TypeSize::getFixed(recordSize * 8);
370RecordType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
371 ::mlir::DataLayoutEntryListRef params)
const {
373 return dataLayout.getTypeABIAlignment(getLargestMember(dataLayout));
378 return computeStructAlignment(dataLayout);
382RecordType::computeStructSize(
const mlir::DataLayout &dataLayout)
const {
383 assert(isComplete() &&
"Cannot get layout of incomplete records");
386 unsigned recordSize = 0;
389 for (mlir::Type ty : getMembers()) {
393 (getPacked() ? 1 : dataLayout.getTypeABIAlignment(ty));
397 recordSize = llvm::alignTo(recordSize, tyAlign);
398 recordSize += dataLayout.getTypeSize(ty);
402 recordAlignment = std::max(tyAlign, recordAlignment);
407 recordSize = llvm::alignTo(recordSize, recordAlignment);
416RecordType::computeStructAlignment(
const mlir::DataLayout &dataLayout)
const {
417 assert(isComplete() &&
"Cannot get layout of incomplete records");
421 for (mlir::Type ty : getMembers())
423 std::max(dataLayout.getTypeABIAlignment(ty), recordAlignment);
425 return recordAlignment;
428uint64_t RecordType::getElementOffset(const ::mlir::DataLayout &dataLayout,
429 unsigned idx)
const {
430 assert(idx < getMembers().size() &&
"access not valid");
433 if (isUnion() || idx == 0)
436 assert(isComplete() &&
"Cannot get layout of incomplete records");
437 assert(idx < getNumElements());
438 llvm::ArrayRef<mlir::Type> members = getMembers();
443 llvm::make_range(members.begin(), std::next(members.begin(), idx))) {
445 const llvm::Align tyAlign =
446 llvm::Align(getPacked() ? 1 : dataLayout.getTypeABIAlignment(ty));
449 offset = llvm::alignTo(offset, tyAlign);
452 offset += dataLayout.getTypeSize(ty);
457 const llvm::Align tyAlign = llvm::Align(
458 getPacked() ? 1 : dataLayout.getTypeABIAlignment(members[idx]));
459 offset = llvm::alignTo(offset, tyAlign);
468Type IntType::parse(mlir::AsmParser &parser) {
469 mlir::MLIRContext *context = parser.getBuilder().getContext();
470 llvm::SMLoc loc = parser.getCurrentLocation();
474 if (parser.parseLess())
478 llvm::StringRef
sign;
479 if (parser.parseKeyword(&
sign))
483 else if (
sign ==
"u")
486 parser.emitError(loc,
"expected 's' or 'u'");
490 if (parser.parseComma())
494 if (parser.parseInteger(width))
496 if (width < IntType::minBitwidth() || width > IntType::maxBitwidth()) {
497 parser.emitError(loc,
"expected integer width to be from ")
498 << IntType::minBitwidth() <<
" up to " << IntType::maxBitwidth();
502 if (parser.parseGreater())
505 return IntType::get(context, width, isSigned);
508void IntType::print(mlir::AsmPrinter &printer)
const {
509 char sign = isSigned() ?
's' :
'u';
510 printer <<
'<' <<
sign <<
", " << getWidth() <<
'>';
514IntType::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
515 mlir::DataLayoutEntryListRef params)
const {
516 return llvm::TypeSize::getFixed(getWidth());
519uint64_t IntType::getABIAlignment(
const mlir::DataLayout &dataLayout,
520 mlir::DataLayoutEntryListRef params)
const {
521 return (uint64_t)(getWidth() / 8);
525IntType::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
526 unsigned width,
bool isSigned) {
527 if (width < IntType::minBitwidth() || width > IntType::maxBitwidth())
528 return emitError() <<
"IntType only supports widths from "
529 << IntType::minBitwidth() <<
" up to "
530 << IntType::maxBitwidth();
531 return mlir::success();
535 return width == 8 || width == 16 || width == 32 || width == 64;
542const llvm::fltSemantics &SingleType::getFloatSemantics()
const {
543 return llvm::APFloat::IEEEsingle();
547SingleType::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
548 mlir::DataLayoutEntryListRef params)
const {
549 return llvm::TypeSize::getFixed(getWidth());
553SingleType::getABIAlignment(
const mlir::DataLayout &dataLayout,
554 mlir::DataLayoutEntryListRef params)
const {
555 return (uint64_t)(getWidth() / 8);
558const llvm::fltSemantics &DoubleType::getFloatSemantics()
const {
559 return llvm::APFloat::IEEEdouble();
563DoubleType::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
564 mlir::DataLayoutEntryListRef params)
const {
565 return llvm::TypeSize::getFixed(getWidth());
569DoubleType::getABIAlignment(
const mlir::DataLayout &dataLayout,
570 mlir::DataLayoutEntryListRef params)
const {
571 return (uint64_t)(getWidth() / 8);
574const llvm::fltSemantics &FP16Type::getFloatSemantics()
const {
575 return llvm::APFloat::IEEEhalf();
579FP16Type::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
580 mlir::DataLayoutEntryListRef params)
const {
581 return llvm::TypeSize::getFixed(getWidth());
584uint64_t FP16Type::getABIAlignment(
const mlir::DataLayout &dataLayout,
585 mlir::DataLayoutEntryListRef params)
const {
586 return (uint64_t)(getWidth() / 8);
589const llvm::fltSemantics &BF16Type::getFloatSemantics()
const {
590 return llvm::APFloat::BFloat();
594BF16Type::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
595 mlir::DataLayoutEntryListRef params)
const {
596 return llvm::TypeSize::getFixed(getWidth());
599uint64_t BF16Type::getABIAlignment(
const mlir::DataLayout &dataLayout,
600 mlir::DataLayoutEntryListRef params)
const {
601 return (uint64_t)(getWidth() / 8);
604const llvm::fltSemantics &FP80Type::getFloatSemantics()
const {
605 return llvm::APFloat::x87DoubleExtended();
609FP80Type::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
610 mlir::DataLayoutEntryListRef params)
const {
612 return llvm::TypeSize::getFixed(128);
615uint64_t FP80Type::getABIAlignment(
const mlir::DataLayout &dataLayout,
616 mlir::DataLayoutEntryListRef params)
const {
620const llvm::fltSemantics &FP128Type::getFloatSemantics()
const {
621 return llvm::APFloat::IEEEquad();
625FP128Type::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
626 mlir::DataLayoutEntryListRef params)
const {
627 return llvm::TypeSize::getFixed(getWidth());
630uint64_t FP128Type::getABIAlignment(
const mlir::DataLayout &dataLayout,
631 mlir::DataLayoutEntryListRef params)
const {
635const llvm::fltSemantics &LongDoubleType::getFloatSemantics()
const {
636 return mlir::cast<cir::FPTypeInterface>(getUnderlying()).getFloatSemantics();
640LongDoubleType::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
641 mlir::DataLayoutEntryListRef params)
const {
642 return mlir::cast<mlir::DataLayoutTypeInterface>(getUnderlying())
643 .getTypeSizeInBits(dataLayout, params);
647LongDoubleType::getABIAlignment(
const mlir::DataLayout &dataLayout,
648 mlir::DataLayoutEntryListRef params)
const {
649 return mlir::cast<mlir::DataLayoutTypeInterface>(getUnderlying())
650 .getABIAlignment(dataLayout, params);
658cir::ComplexType::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
659 mlir::DataLayoutEntryListRef params)
const {
665 return dataLayout.getTypeSizeInBits(getElementType()) * 2;
669cir::ComplexType::getABIAlignment(
const mlir::DataLayout &dataLayout,
670 mlir::DataLayoutEntryListRef params)
const {
676 return dataLayout.getTypeABIAlignment(getElementType());
679FuncType FuncType::clone(TypeRange inputs, TypeRange results)
const {
680 assert(results.size() == 1 &&
"expected exactly one result type");
681 return get(llvm::to_vector(inputs), results[0], isVarArg());
685static mlir::ParseResult
689 return p.parseCommaSeparatedList(
690 AsmParser::Delimiter::Paren, [&]() -> mlir::ParseResult {
692 return p.emitError(p.getCurrentLocation(),
693 "variadic `...` must be the last parameter");
694 if (succeeded(p.parseOptionalEllipsis())) {
699 if (failed(p.parseType(type)))
701 params.push_back(type);
707 mlir::ArrayRef<mlir::Type> params,
710 llvm::interleaveComma(params, p,
711 [&p](mlir::Type type) { p.printType(type); });
722mlir::Type FuncType::getReturnType()
const {
724 return cir::VoidType::get(getContext());
725 return getOptionalReturnType();
731llvm::ArrayRef<mlir::Type> FuncType::getReturnTypes()
const {
737 return getImpl()->optionalReturnType;
741bool FuncType::hasVoidReturn()
const {
return !getOptionalReturnType(); }
744FuncType::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
745 llvm::ArrayRef<mlir::Type> argTypes, mlir::Type returnType,
747 if (mlir::isa_and_nonnull<cir::VoidType>(returnType))
749 <<
"!cir.func cannot have an explicit 'void' return type";
750 return mlir::success();
762 auto voidPtrTy = cir::PointerType::get(cir::VoidType::get(ctx));
763 mlir::Type fields[2]{voidPtrTy, voidPtrTy};
764 return cir::RecordType::get(ctx, fields,
false,
765 false, cir::RecordType::Struct);
769MethodType::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
770 mlir::DataLayoutEntryListRef params)
const {
775MethodType::getABIAlignment(
const mlir::DataLayout &dataLayout,
776 mlir::DataLayoutEntryListRef params)
const {
785BoolType::getTypeSizeInBits(const ::mlir::DataLayout &dataLayout,
786 ::mlir::DataLayoutEntryListRef params)
const {
787 return llvm::TypeSize::getFixed(8);
791BoolType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
792 ::mlir::DataLayoutEntryListRef params)
const {
801DataMemberType::getTypeSizeInBits(const ::mlir::DataLayout &dataLayout,
802 ::mlir::DataLayoutEntryListRef params)
const {
805 return llvm::TypeSize::getFixed(64);
809DataMemberType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
810 ::mlir::DataLayoutEntryListRef params)
const {
821VPtrType::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
822 mlir::DataLayoutEntryListRef params)
const {
824 return llvm::TypeSize::getFixed(64);
827uint64_t VPtrType::getABIAlignment(
const mlir::DataLayout &dataLayout,
828 mlir::DataLayoutEntryListRef params)
const {
838ArrayType::getTypeSizeInBits(const ::mlir::DataLayout &dataLayout,
839 ::mlir::DataLayoutEntryListRef params)
const {
840 return getSize() * dataLayout.getTypeSizeInBits(getElementType());
844ArrayType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
845 ::mlir::DataLayoutEntryListRef params)
const {
846 return dataLayout.getTypeABIAlignment(getElementType());
853llvm::TypeSize cir::VectorType::getTypeSizeInBits(
854 const ::mlir::DataLayout &dataLayout,
855 ::mlir::DataLayoutEntryListRef params)
const {
856 return llvm::TypeSize::getFixed(
857 getSize() * dataLayout.getTypeSizeInBits(getElementType()));
861cir::VectorType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
862 ::mlir::DataLayoutEntryListRef params)
const {
863 return llvm::NextPowerOf2(dataLayout.getTypeSizeInBits(*
this));
866mlir::LogicalResult cir::VectorType::verify(
867 llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
868 mlir::Type elementType, uint64_t size,
bool scalable) {
870 return emitError() <<
"the number of vector elements must be non-zero";
874mlir::Type cir::VectorType::parse(::mlir::AsmParser &odsParser) {
876 llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
877 mlir::Builder odsBuilder(odsParser.getContext());
878 mlir::FailureOr<::mlir::Type> elementType;
879 mlir::FailureOr<uint64_t> size;
880 bool isScalabe =
false;
883 if (odsParser.parseLess())
887 if (odsParser.parseOptionalLSquare().succeeded())
891 size = mlir::FieldParser<uint64_t>::parse(odsParser);
892 if (mlir::failed(size)) {
893 odsParser.emitError(odsParser.getCurrentLocation(),
894 "failed to parse CIR_VectorType parameter 'size' which "
895 "is to be a `uint64_t`");
901 if (isScalabe && odsParser.parseRSquare().failed()) {
902 odsParser.emitError(odsParser.getCurrentLocation(),
903 "missing closing `]` for scalable dim size");
908 if (odsParser.parseKeyword(
"x"))
912 elementType = mlir::FieldParser<::mlir::Type>::parse(odsParser);
913 if (mlir::failed(elementType)) {
914 odsParser.emitError(odsParser.getCurrentLocation(),
915 "failed to parse CIR_VectorType parameter "
916 "'elementType' which is to be a `mlir::Type`");
921 if (odsParser.parseGreater())
923 return odsParser.getChecked<VectorType>(odsLoc, odsParser.getContext(),
924 mlir::Type((*elementType)),
928void cir::VectorType::print(mlir::AsmPrinter &odsPrinter)
const {
929 mlir::Builder odsBuilder(getContext());
931 if (this->getIsScalable())
934 odsPrinter.printStrippedAttrOrType(getSize());
935 if (this->getIsScalable())
937 odsPrinter <<
' ' <<
"x";
939 odsPrinter.printStrippedAttrOrType(getElementType());
948 mlir::ptr::MemorySpaceAttrInterface memorySpace) {
949 return mlir::isa<cir::LangAddressSpaceAttr, cir::TargetAddressSpaceAttr>(
956 case LangAS::Default:
957 return LangAddressSpace::Default;
958 case LangAS::opencl_global:
959 return LangAddressSpace::OffloadGlobal;
960 case LangAS::opencl_local:
961 case LangAS::cuda_shared:
964 return LangAddressSpace::OffloadLocal;
965 case LangAS::cuda_device:
966 return LangAddressSpace::OffloadGlobal;
967 case LangAS::opencl_constant:
968 case LangAS::cuda_constant:
969 return LangAddressSpace::OffloadConstant;
970 case LangAS::opencl_private:
971 return LangAddressSpace::OffloadPrivate;
972 case LangAS::opencl_generic:
973 return LangAddressSpace::OffloadGeneric;
974 case LangAS::opencl_global_device:
975 case LangAS::opencl_global_host:
976 case LangAS::sycl_global:
977 case LangAS::sycl_global_device:
978 case LangAS::sycl_global_host:
979 case LangAS::sycl_local:
980 case LangAS::sycl_private:
981 case LangAS::ptr32_sptr:
982 case LangAS::ptr32_uptr:
984 case LangAS::hlsl_groupshared:
985 case LangAS::wasm_funcref:
986 llvm_unreachable(
"NYI");
988 llvm_unreachable(
"unknown/unsupported clang language address space");
994 mlir::ptr::MemorySpaceAttrInterface &attr) {
996 llvm::SMLoc loc = p.getCurrentLocation();
1000 if (p.parseOptionalKeyword(
"target_address_space").succeeded()) {
1002 if (p.parseLParen())
1003 return p.emitError(loc,
"expected '(' after 'target_address_space'");
1005 if (p.parseInteger(val))
1006 return p.emitError(loc,
"expected target address space value");
1008 if (p.parseRParen())
1009 return p.emitError(loc,
"expected ')'");
1011 attr = cir::TargetAddressSpaceAttr::get(p.getContext(), val);
1012 return mlir::success();
1016 if (p.parseOptionalKeyword(
"lang_address_space").succeeded()) {
1017 if (p.parseLParen())
1018 return p.emitError(loc,
"expected '(' after 'lang_address_space'");
1020 mlir::FailureOr<cir::LangAddressSpace> result =
1021 mlir::FieldParser<cir::LangAddressSpace>::parse(p);
1022 if (mlir::failed(result))
1023 return mlir::failure();
1025 if (p.parseRParen())
1026 return p.emitError(loc,
"expected ')'");
1028 attr = cir::LangAddressSpaceAttr::get(p.getContext(), result.value());
1029 return mlir::success();
1032 llvm::StringRef keyword;
1033 if (p.parseOptionalKeyword(&keyword).succeeded())
1034 return p.emitError(loc,
"unknown address space specifier '")
1035 << keyword <<
"'; expected 'target_address_space' or "
1036 <<
"'lang_address_space'";
1038 return mlir::success();
1042 mlir::ptr::MemorySpaceAttrInterface attr) {
1046 if (
auto language = dyn_cast<cir::LangAddressSpaceAttr>(attr)) {
1047 p <<
"lang_address_space("
1048 << cir::stringifyLangAddressSpace(language.getValue()) <<
')';
1052 if (
auto target = dyn_cast<cir::TargetAddressSpaceAttr>(attr)) {
1053 p <<
"target_address_space(" << target.getValue() <<
')';
1057 llvm_unreachable(
"unexpected address-space attribute kind");
1061 mlir::ptr::MemorySpaceAttrInterface addrSpace) {
1063 mlir::dyn_cast_if_present<cir::LangAddressSpaceAttr>(addrSpace))
1064 if (langAS.getValue() == cir::LangAddressSpace::Default)
1069mlir::ptr::MemorySpaceAttrInterface
1073 if (langAS == LangAS::Default)
1074 return cir::LangAddressSpaceAttr::get(&ctx, cir::LangAddressSpace::Default);
1078 return cir::TargetAddressSpaceAttr::get(&ctx, targetAS);
1091 return expected == cirAS;
1098mlir::LogicalResult cir::PointerType::verify(
1099 llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
1100 mlir::Type pointee, mlir::ptr::MemorySpaceAttrInterface addrSpace) {
1103 return emitError() <<
"unsupported address space attribute; expected "
1104 "'target_address_space' or 'lang_address_space'";
1115void CIRDialect::registerTypes() {
1118#define GET_TYPEDEF_LIST
1119#include "clang/CIR/Dialect/IR/CIROpsTypes.cpp.inc"
Provides definitions for the various language-specific address spaces.
void printAddressSpaceValue(mlir::AsmPrinter &p, cir::LangAddressSpace addrSpace)
mlir::ParseResult parseAddressSpaceValue(mlir::AsmParser &p, cir::LangAddressSpace &addrSpace)
void printAddressSpaceValue(mlir::AsmPrinter &printer, mlir::ptr::MemorySpaceAttrInterface attr)
mlir::ParseResult parseTargetAddressSpace(mlir::AsmParser &p, cir::TargetAddressSpaceAttr &attr)
mlir::ParseResult parseAddressSpaceValue(mlir::AsmParser &p, mlir::ptr::MemorySpaceAttrInterface &attr)
static mlir::ParseResult parseFuncTypeParams(mlir::AsmParser &p, llvm::SmallVector< mlir::Type > ¶ms, bool &isVarArg)
static mlir::Type getMethodLayoutType(mlir::MLIRContext *ctx)
static void printFuncTypeParams(mlir::AsmPrinter &p, mlir::ArrayRef< mlir::Type > params, bool isVarArg)
void printTargetAddressSpace(mlir::AsmPrinter &p, cir::TargetAddressSpaceAttr attr)
static Decl::Kind getKind(const Decl *D)
static LiveVariablesImpl & getImpl(void *x)
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
bool isMatchingAddressSpace(mlir::ptr::MemorySpaceAttrInterface cirAS, clang::LangAS as)
cir::LangAddressSpace toCIRLangAddressSpace(clang::LangAS langAS)
bool isValidFundamentalIntWidth(unsigned width)
mlir::ptr::MemorySpaceAttrInterface toCIRAddressSpaceAttr(mlir::MLIRContext &ctx, clang::LangAS langAS)
Convert an AST LangAS to the appropriate CIR address space attribute interface.
mlir::ptr::MemorySpaceAttrInterface normalizeDefaultAddressSpace(mlir::ptr::MemorySpaceAttrInterface addrSpace)
Normalize LangAddressSpace::Default to null (empty attribute).
bool isSized(mlir::Type ty)
Returns true if the type is a CIR sized type.
bool isSupportedCIRMemorySpaceAttr(mlir::ptr::MemorySpaceAttrInterface memorySpace)
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
StringRef getName(const HeaderType T)
bool isTargetAddressSpace(LangAS AS)
unsigned toTargetAddressSpace(LangAS AS)
LangAS
Defines the address space values used by the address space qualifier of QualType.
float __ovld __cnfn sign(float)
Returns 1.0 if x > 0, -0.0 if x = -0.0, +0.0 if x = +0.0, or -1.0 if x < 0.
static bool unsizedTypes()
static bool dataLayoutPtrHandlingBasedOnLangAS()
static bool astRecordDeclAttr()