18#include "mlir/ABI/Targets/Test/TestTarget.h"
21#include "llvm/ABI/Types.h"
22#include "llvm/ADT/TypeSwitch.h"
23#include "llvm/Support/MathExtras.h"
26using namespace mlir::abi;
49 return layout.getArgPassingKind() == cir::ArgPassingKind::CanPassInRegs;
54 return layout && layout.getTransparentUnion();
61 return layout && layout.getFlexibleArrayMember();
68 if (isa<cir::VectorType>(ty))
69 return llvm::PowerOf2Ceil(dl.getTypeSizeInBits(ty).getFixedValue()) >= 128;
70 if (
auto fpTy = dyn_cast<cir::FPTypeInterface>(ty))
71 return &fpTy.getFloatSemantics() == &llvm::APFloat::IEEEquad();
72 if (
auto arrTy = dyn_cast<cir::ArrayType>(ty))
74 if (
auto recTy = dyn_cast<cir::RecordType>(ty))
75 return recTy.isComplete() &&
76 llvm::any_of(recTy.getMembers(),
77 [&](mlir::Type m) { return mayReachSseUp(m, dl); });
80 assert((isa<cir::IntType, cir::BoolType, cir::PointerType, cir::VPtrType,
81 cir::VoidType, cir::ComplexType, cir::BitFieldType>(ty)) &&
82 "unhandled type in the SSEUP walk");
91 const DataLayout &dl) {
92 if (recordBits == 128 || recordBits == 256 || recordBits == 512)
94 if (recordBits < 128 || recordBits > 512)
96 return llvm::any_of(members,
103 while (
auto arrTy = dyn_cast<cir::ArrayType>(ty))
104 ty = arrTy.getElementType();
105 auto recTy = dyn_cast<cir::RecordType>(ty);
106 return recTy && recTy.isEmptyForABI();
118 return llvm::Align(layout.getUnadjustedAlign());
132 if (
auto ptrTy = dyn_cast<cir::PointerType>(ty))
133 return !ptrTy.getAddrSpace() ||
134 mlir::isa<cir::TargetAddressSpaceAttr>(ptrTy.getAddrSpace());
138 if (isa<cir::VPtrType>(ty)) {
142 if (isa<cir::VoidType, cir::BoolType>(ty))
146 if (isa<cir::FPTypeInterface>(ty))
148 if (
auto intTy = dyn_cast<cir::IntType>(ty)) {
156 if (intTy.getIsBitInt())
158 return intTy.getWidth() <= 64 || intTy.getWidth() == 128;
160 if (
auto complexTy = dyn_cast<cir::ComplexType>(ty))
162 if (
auto vecTy = dyn_cast<cir::VectorType>(ty)) {
165 if (vecTy.isScalable())
170 mlir::Type elemTy = vecTy.getElementType();
171 if (
auto elemInt = dyn_cast<cir::IntType>(elemTy)) {
172 if (elemInt.getWidth() % 8)
174 }
else if (!isa<cir::FPTypeInterface, cir::BoolType>(elemTy)) {
179 if (
auto arrTy = dyn_cast<cir::ArrayType>(ty))
184 if (
auto bfTy = dyn_cast<cir::BitFieldType>(ty)) {
185 if (mlir::Type storageTy = bfTy.getStorageType())
188 return llvm::all_of(bfTy.getFields(), [&](cir::BitFieldDeclAttr decl) {
189 return isSupportedType(decl.getDeclaredType(), dl);
192 if (
auto recTy = dyn_cast<cir::RecordType>(ty)) {
194 if (!recTy.isComplete())
198 if (!llvm::all_of(recTy.getMembers(),
199 [&](mlir::Type m) { return isSupportedType(m, dl); }))
201 if (recTy.isUnion()) {
203 uint64_t recordBits = dl.getTypeSizeInBits(recTy).getFixedValue();
211 if (members.empty() && recordBits > 128)
216 if (llvm::any_of(members, [&](mlir::Type m) {
217 auto bfTy = dyn_cast<cir::BitFieldType>(m);
218 if (!bfTy || dl.getTypeSizeInBits(bfTy).getFixedValue() <= 64)
220 return llvm::any_of(bfTy.getFields(), [](cir::BitFieldDeclAttr d) {
221 return cir::isBitIntType(d.getDeclaredType());
234 for (
auto [idx, memberTy,
kind] :
235 llvm::enumerate(recTy.getMembers(), recTy.getMemberKinds())) {
236 if (
kind != cir::RecordMemberKind::Empty)
238 if (dl.getTypeSizeInBits(memberTy).getFixedValue()) {
241 }
else if (recTy.getElementOffset(dl, idx) %
242 dl.getTypeABIAlignment(memberTy)) {
253static mlir::Type
abiTypeToCIR(
const llvm::abi::Type *ty, MLIRContext *ctx) {
256 return llvm::TypeSwitch<const llvm::abi::Type *, mlir::Type>(ty)
258 [&](
const llvm::abi::VoidType *) {
return cir::VoidType::get(ctx); })
259 .Case([&](
const llvm::abi::IntegerType *intTy) -> mlir::Type {
262 return cir::BoolType::get(ctx);
263 return cir::IntType::get(ctx, intTy->getSizeInBits().getFixedValue(),
264 intTy->isSigned(), intTy->isBitInt());
266 .Case([&](
const llvm::abi::FloatType *fltTy) {
269 .Case([&](
const llvm::abi::PointerType *ptrTy) {
270 auto voidTy = cir::VoidType::get(ctx);
271 if (
unsigned as = ptrTy->getAddrSpace())
272 return cir::PointerType::get(
273 voidTy, cir::TargetAddressSpaceAttr::get(ctx, as));
274 return cir::PointerType::get(voidTy);
276 .Case([&](
const llvm::abi::VectorType *vecTy) -> mlir::Type {
277 mlir::Type elemCIR =
abiTypeToCIR(vecTy->getElementType(), ctx);
280 return cir::VectorType::getFixed(
281 elemCIR, vecTy->getNumElements().getFixedValue());
283 .Case([&](
const llvm::abi::ArrayType *arrTy) -> mlir::Type {
284 mlir::Type elemCIR =
abiTypeToCIR(arrTy->getElementType(), ctx);
287 return cir::ArrayType::get(elemCIR, arrTy->getNumElements());
289 .Case([&](
const llvm::abi::RecordType *recTy) -> mlir::Type {
291 fieldTypes.reserve(recTy->getFields().size());
292 for (
const auto &field : recTy->getFields()) {
293 mlir::Type fieldCIR =
abiTypeToCIR(field.FieldType, ctx);
296 fieldTypes.push_back(fieldCIR);
299 return cir::StructType::get(
300 ctx, fieldTypes,
false,
303 .Default([](
const llvm::abi::Type *) -> mlir::Type {
return nullptr; });
310 if (
auto vecTy = dyn_cast<cir::VectorType>(ty)) {
311 if (
auto longDoubleTy =
312 dyn_cast<cir::LongDoubleType>(vecTy.getElementType()))
313 return cir::VectorType::get(longDoubleTy.getUnderlying(),
323 mlir::abi::ABITypeMapper &typeMapper,
324 const DataLayout &dl,
327 llvm::abi::TypeBuilder &tb = typeMapper.getTypeBuilder();
328 return llvm::TypeSwitch<mlir::Type, const llvm::abi::Type *>(type)
329 .Case([&](cir::IntType intTy) {
330 return tb.getIntegerType(
332 intTy.isSigned(), intTy.getIsBitInt());
334 .Case([&](cir::PointerType ptrTy) {
335 unsigned addrSpace = 0;
336 if (
auto targetAsAttr =
337 dyn_cast_if_present<cir::TargetAddressSpaceAttr>(
338 ptrTy.getAddrSpace()))
339 addrSpace = targetAsAttr.getValue();
341 bool hasAddressSpaceQualifier = ptrTy.getAddrSpace() !=
nullptr;
342 return tb.getPointerType(
343 dl.getTypeSizeInBits(type),
345 hasAddressSpaceQualifier);
347 .Case([&](cir::VPtrType) {
351 return tb.getPointerType(
352 dl.getTypeSizeInBits(type),
355 .Case([&](cir::BoolType) {
358 return tb.getIntegerType(
362 .Case([&](cir::VoidType) {
return tb.getVoidType(); })
363 .Case([&](cir::FPTypeInterface fpTy) {
366 return tb.getFloatType(
367 fpTy.getFloatSemantics(),
370 .Case([&](cir::ComplexType complexTy) {
371 return tb.getComplexType(
372 mapCIRType(complexTy.getElementType(), typeMapper, dl, cirDL,
376 .Case([&](cir::VectorType vecTy) {
379 return tb.getVectorType(
380 mapCIRType(vecTy.getElementType(), typeMapper, dl, cirDL, modOp),
383 .Case([&](cir::ArrayType arrTy) {
384 const llvm::abi::Type *elemAbi =
385 mapCIRType(arrTy.getElementType(), typeMapper, dl, cirDL, modOp);
386 return tb.getArrayType(elemAbi, arrTy.getSize(),
387 dl.getTypeSizeInBits(type).getFixedValue());
390 llvm::abi::RecordFlags flags = llvm::abi::RecordFlags::None;
392 flags = flags | llvm::abi::RecordFlags::CanPassInRegisters;
394 flags = flags | llvm::abi::RecordFlags::IsTransparent;
396 flags = flags | llvm::abi::RecordFlags::HasFlexibleArrayMember;
397 llvm::TypeSize sizeBits = llvm::TypeSize::getFixed(
398 dl.getTypeSizeInBits(type).getFixedValue());
400 llvm::Align unadjustedAlign =
407 return tb.getRecordType(
408 {}, sizeBits, align, unadjustedAlign,
409 llvm::abi::StructPacking::Default,
434 auto addAccessUnit = [&](cir::BitFieldType bfTy,
436 mlir::Type unitTy = bfTy.getStorageType();
438 unitTy ? dl.getTypeSizeInBits(unitTy).getFixedValue() : 0;
439 for (
auto [idx, decl] : llvm::enumerate(bfTy.getFields())) {
441 unitOffsetBits + bfTy.getFieldBitOffset(idx);
442 const bool holdsUnit = idx == 0 && unitTy;
444 fields.push_back(llvm::abi::FieldInfo(
445 mapCIRType(unitTy, typeMapper, dl, cirDL, modOp), offsetBits,
446 true, decl.getWidth(),
447 decl.getIsUnnamed()));
448 mlir::Type declaredTy = decl.getDeclaredType();
450 dl.getTypeSizeInBits(declaredTy).getFixedValue() > unitBits)
451 fields.push_back(llvm::abi::FieldInfo(
452 mapCIRType(declaredTy, typeMapper, dl, cirDL, modOp),
454 true, holdsUnit ? 0 : decl.getWidth(),
455 holdsUnit || decl.getIsUnnamed()));
470 cir::RecordMemberKind::Pad) &&
471 "a union member cannot be marked pad");
472 for (mlir::Type variantTy : recTy.
getMembers()) {
473 if (
auto bfTy = dyn_cast<cir::BitFieldType>(variantTy)) {
477 addAccessUnit(bfTy, 0);
480 if (dl.getTypeSizeInBits(variantTy).getFixedValue() == 0 ||
483 fields.push_back(llvm::abi::FieldInfo(
484 mapCIRType(variantTy, typeMapper, dl, cirDL, modOp)));
486 return tb.getUnionType(fields, sizeBits, align, unadjustedAlign,
487 llvm::abi::StructPacking::Default, flags);
496 for (
auto [idx, fieldTy,
kind] :
498 if (
kind == cir::RecordMemberKind::Pad)
500 if (
auto bfTy = dyn_cast<cir::BitFieldType>(fieldTy)) {
506 bool isUnnamed =
kind == cir::RecordMemberKind::Empty;
507 uint64_t widthBits = dl.getTypeSizeInBits(fieldTy).getFixedValue();
508 if (isUnnamed && widthBits == 0)
511 "an empty-for-ABI member must not reach the classifier as an "
512 "unnamed bit-field");
513 fields.push_back(llvm::abi::FieldInfo(
514 mapCIRType(fieldTy, typeMapper, dl, cirDL, modOp),
516 isUnnamed, isUnnamed ? widthBits : 0,
520 return tb.getRecordType(fields, sizeBits, align, unadjustedAlign,
521 llvm::abi::StructPacking::Default,
525 .Default([](mlir::Type) ->
const llvm::abi::Type * {
527 "mapCIRType: type not pre-filtered by classifySignature");
536 const llvm::abi::Type *coercedAbiTy) {
537 if (
auto intTy = dyn_cast<cir::IntType>(origTy)) {
538 const auto *abiInt = dyn_cast<llvm::abi::IntegerType>(coercedAbiTy);
540 abiInt->getSizeInBits().getFixedValue() == intTy.getWidth();
542 if (isa<cir::BoolType>(origTy))
543 return isa<llvm::abi::IntegerType>(coercedAbiTy);
544 if (
auto fpTy = dyn_cast<cir::FPTypeInterface>(origTy)) {
545 const auto *abiFloat = dyn_cast<llvm::abi::FloatType>(coercedAbiTy);
546 return abiFloat && abiFloat->getSemantics() == &fpTy.getFloatSemantics();
548 if (isa<cir::PointerType, cir::VPtrType>(origTy))
549 return isa<llvm::abi::PointerType>(coercedAbiTy);
560static mlir::FailureOr<ArgClassification>
563 assert(origTy &&
"a Direct value must have a type");
564 unsigned offset = info.getDirectOffset();
565 llvm::MaybeAlign align = info.getDirectAlign();
566 auto passUnchanged = [&] {
567 return ArgClassification::getDirect(
nullptr, 0,
570 auto passCoerced = [&](mlir::Type coerced,
unsigned coercedOffset) {
571 ArgClassification classified =
572 ArgClassification::getDirect(coerced, coercedOffset, align);
573 classified.canFlatten = info.getCanBeFlattened();
577 const llvm::abi::Type *coercedAbiTy = info.getCoerceToType();
582 auto recTy = dyn_cast<cir::RecordType>(origTy);
583 if (recTy && (recTy.isStruct() || recTy.isUnion()) &&
584 info.getCanBeFlattened())
585 return passCoerced(recTy, 0);
587 if (
auto complexTy = dyn_cast<cir::ComplexType>(origTy);
588 complexTy && info.getCanBeFlattened()) {
591 cir::StructType::get(ctx, parts,
false,
596 return passUnchanged();
603 bool coercedIsStruct = isa<llvm::abi::RecordType>(coercedAbiTy);
604 if (offset && coercedIsStruct)
605 return mlir::failure();
614 !isa<cir::VectorType, cir::RecordType, cir::ArrayType, cir::ComplexType>(
616 if (isScalar && !offset && !coercedIsStruct) {
617 auto origPtr = dyn_cast<cir::PointerType>(origTy);
618 const auto *coercedAbiPtr = dyn_cast<llvm::abi::PointerType>(coercedAbiTy);
619 if (origPtr && coercedAbiPtr) {
622 auto origAS = dyn_cast_if_present<cir::TargetAddressSpaceAttr>(
623 origPtr.getAddrSpace());
624 if (coercedAbiPtr->getAddrSpace() == (origAS ? origAS.getValue() : 0))
625 return passUnchanged();
626 auto coercedPtr = cast<cir::PointerType>(
abiTypeToCIR(coercedAbiTy, ctx));
627 return passCoerced(cir::PointerType::get(origPtr.getPointee(),
628 coercedPtr.getAddrSpace()),
631 auto origInt = dyn_cast<cir::IntType>(origTy);
632 const auto *coercedAbiInt = dyn_cast<llvm::abi::IntegerType>(coercedAbiTy);
634 origInt && coercedAbiInt &&
635 coercedAbiInt->getSizeInBits().getFixedValue() > origInt.getWidth();
642 "the classifier changed a scalar's kind or width");
643 return passUnchanged();
649 return mlir::failure();
655 return mlir::failure();
657 if (isa<cir::VectorType>(origTy))
658 return passUnchanged();
662 return passCoerced(coerced, offset);
668static mlir::FailureOr<ArgClassification>
675 if (info.isExtend()) {
676 assert(origTy &&
"an extended value must have a type");
677 if (isa<cir::BoolType>(origTy))
678 return ArgClassification::getExtend(
nullptr, info.isSignExt(),
679 info.isConservative());
680 assert((isa<cir::IntType, cir::RecordType>(origTy)) &&
681 "Extend is only expected for integers, bool, and transparent "
683 mlir::Type extendedTy =
abiTypeToCIR(info.getCoerceToType(), ctx);
684 return ArgClassification::getExtend(extendedTy, info.isSignExt(),
685 info.isConservative());
687 if (info.isIndirect())
688 return ArgClassification::getIndirect(info.getIndirectAlign(),
689 info.getIndirectByVal(),
690 info.getIndirectAddrSpace());
691 if (info.isIndirectAliased())
692 return ArgClassification::getIndirectAliased(info.getIndirectAlign(),
693 info.getIndirectAddrSpace());
696 assert(!info.isCoerceAndExpand() &&
"CoerceAndExpand is not handled yet");
697 assert(info.isIgnore() &&
"Unexpected classification");
698 return ArgClassification::getIgnore();
703 if (!fnTy.isVarArg())
704 return llvm::abi::RequiredArgs::All;
705 return llvm::abi::RequiredArgs(fnTy.getNumInputs());
717mlir::FailureOr<FunctionClassification>
718CIRABIClassifierCommon::classifySignature(
719 mlir::Type retCIR, mlir::TypeRange inputs, llvm::abi::RequiredArgs required,
720 const llvm::abi::TargetInfo &targetInfo, llvm::CallingConv::ID callConv,
721 llvm::function_ref<mlir::InFlightDiagnostic()> emitError) {
722 assert(retCIR &&
"signature return type must be non-null");
723 assert((!required.allowsOptionalArgs() ||
724 required.getNumRequiredArgs() <= inputs.size()) &&
725 "declared parameters cannot outnumber the classified arguments");
726 MLIRContext *ctx =
modOp->getContext();
727 bool voidRet = isa<cir::VoidType>(retCIR);
729 auto reject = [&](mlir::Type t) ->
bool {
732 emitError() <<
"calling-convention lowering not yet implemented for type "
736 if (!voidRet && reject(retCIR))
737 return mlir::failure();
738 for (mlir::Type a : inputs)
740 return mlir::failure();
742 const llvm::abi::Type *retAbi =
743 voidRet ?
typeMapper.getTypeBuilder().getVoidType()
745 SmallVector<const llvm::abi::Type *> argAbi;
746 for (mlir::Type a : inputs)
749 std::unique_ptr<llvm::abi::FunctionInfo> fi =
750 llvm::abi::FunctionInfo::create(callConv, retAbi, argAbi, required);
751 targetInfo.computeInfo(*fi);
755 auto nyiCoercion = [&](mlir::Type t) {
756 emitError() <<
"calling-convention lowering not yet "
757 "implemented for the ABI coercion of type "
761 FunctionClassification fc;
762 fc.returnsVoid = voidRet;
763 mlir::Type origRet = voidRet ? mlir::Type() : retCIR;
764 mlir::FailureOr<ArgClassification> retAc =
768 return mlir::failure();
770 fc.returnInfo = *retAc;
771 for (
unsigned i = 0, e = fi->arg_size(); i < e; ++i) {
772 mlir::Type origArg = inputs[i];
773 const llvm::abi::ArgInfo &argInfo = fi->getArgInfo(i).Info;
774 mlir::FailureOr<ArgClassification> ac =
777 nyiCoercion(origArg);
778 return mlir::failure();
783 auto recTy = dyn_cast<cir::RecordType>(origArg);
784 if (ac->kind == ArgKind::Direct && recTy &&
785 (!ac->coercedType || ac->coercedType == recTy) &&
787 ac->coercedType = recTy.getMembers().front();
788 ac->neededIntRegs = argInfo.getNeededIntRegs();
789 ac->neededSseRegs = argInfo.getNeededSseRegs();
790 fc.argInfos.push_back(*ac);
797 if (cc == cir::CallingConv::AMDGPUKernel)
798 return llvm::CallingConv::AMDGPU_KERNEL;
799 if (cc == cir::CallingConv::SpirKernel)
800 return llvm::CallingConv::SPIR_KERNEL;
801 return llvm::CallingConv::C;
807mlir::FailureOr<FunctionClassification>
809 cir::FuncType fnTy = func.getFunctionType();
810 return classifySignature(fnTy.getReturnType(), fnTy.getInputs(),
813 [&]() { return func.emitOpError(); });
820 mlir::Type ty,
const llvm::abi::TargetInfo &targetInfo,
821 llvm::function_ref<mlir::InFlightDiagnostic()> emitError) {
822 MLIRContext *ctx =
modOp->getContext();
823 mlir::FailureOr<FunctionClassification> fc = classifySignature(
824 cir::VoidType::get(ctx), mlir::TypeRange(ty), llvm::abi::RequiredArgs(0),
825 targetInfo, llvm::CallingConv::C, emitError);
827 return mlir::failure();
828 return fc->argInfos[0];
838mlir::FailureOr<FunctionClassification>
840 cir::CIRCallOpInterface call, cir::FuncType calleeTy,
841 const llvm::abi::TargetInfo &targetInfo, llvm::CallingConv::ID callConv) {
842 assert(calleeTy.isVarArg() &&
843 "only a variadic callee can take more operands than it declares");
844 Operation *op = call.getOperation();
845 return classifySignature(calleeTy.getReturnType(),
846 call.getArgOperands().getTypes(),
848 [&]() {
return op->emitOpError(); });
851mlir::FailureOr<FunctionClassification>
853 cir::FuncOp callee) {
859mlir::FailureOr<FunctionClassification>
862 const llvm::abi::TargetInfo &targetInfo =
866 if (call.getNumArgOperands() > funcTy.getNumInputs())
868 return classifySignature(
869 funcTy.getReturnType(), funcTy.getInputs(),
requiredArgs(funcTy),
870 targetInfo, llvm::CallingConv::C, [&]() {
return call->emitOpError(); });
879static mlir::FailureOr<FunctionClassification>
881 mlir::Type returnType) {
883 fc->returnsVoid = mlir::isa<cir::VoidType>(returnType);
891static mlir::FailureOr<FunctionClassification>
895 Type returnType = func.getFunctionType().getReturnType();
897 if (!classificationAttrName.empty()) {
898 auto attr = func->getAttrOfType<DictionaryAttr>(classificationAttrName);
901 <<
"missing classification attribute '" << classificationAttrName
902 <<
"' (CallConvLowering driver mode 'classification-attr')";
903 return mlir::failure();
906 attr, [&]() {
return func.emitOpError(); }),
913 "classifyFunction only handles the test target");
925 explicit TestTargetClassifier(
const mlir::DataLayout &dl) : dl(dl) {}
927 mlir::FailureOr<FunctionClassification>
934 mlir::FailureOr<FunctionClassification>
935 classifyVariadicCall(cir::CIRCallOpInterface call, cir::FuncOp)
final {
937 <<
"variadic arguments not yet implemented in CallConvLowering";
938 return mlir::failure();
941 mlir::FailureOr<FunctionClassification>
942 classifyIndirectCall(cir::CIRCallOpInterface call)
final {
944 if (call.getNumArgOperands() > funcTy.getNumInputs()) {
946 <<
"variadic arguments not yet implemented in CallConvLowering";
947 return mlir::failure();
950 funcTy.getReturnType(),
952 funcTy.getReturnType());
955 mlir::FailureOr<ArgClassification> classifyVAArg(cir::VAArgOp vaArg)
final {
957 <<
"not yet implemented in CallConvLowering for the test target";
958 return mlir::failure();
962 const mlir::DataLayout &dl;
970 InjectedClassifier(
const mlir::DataLayout &dl, llvm::StringRef attrName)
971 : dl(dl), attrName(attrName) {}
973 mlir::FailureOr<FunctionClassification>
980 mlir::FailureOr<FunctionClassification>
981 classifyVariadicCall(cir::CIRCallOpInterface call, cir::FuncOp)
final {
983 <<
"variadic arguments not yet implemented in CallConvLowering";
984 return mlir::failure();
989 mlir::FailureOr<FunctionClassification>
990 classifyIndirectCall(cir::CIRCallOpInterface call)
final {
991 call->emitOpError() <<
"indirect call cannot be classified in the "
992 "'classification-attr' driver mode";
993 return mlir::failure();
996 mlir::FailureOr<ArgClassification> classifyVAArg(cir::VAArgOp vaArg)
final {
997 vaArg->emitOpError() <<
"cannot be classified in the "
998 "'classification-attr' driver mode";
999 return mlir::failure();
1003 const mlir::DataLayout &dl;
1004 std::string attrName;
1009std::unique_ptr<CIRABIClassifier>
1011 return std::make_unique<TestTargetClassifier>(dl);
1014std::unique_ptr<CIRABIClassifier>
1016 llvm::StringRef attrName) {
1017 return std::make_unique<InjectedClassifier>(dl, attrName);
static bool recordHasFlexibleArrayMember(ModuleOp modOp, cir::RecordType recTy)
Read from the layout, which also covers a last field that has one.
static llvm::Align recordUnadjustedAlign(ModuleOp modOp, cir::RecordType recTy, const cir::CIRDataLayout &cirDL)
A record's unadjusted alignment, the alignment its members give it before an alignment attribute on t...
static bool recordIsTransparentUnion(ModuleOp modOp, cir::RecordType recTy)
static bool memberIsEmptyRecord(mlir::Type ty)
Whether a member is an empty record, looking through arrays, since an array of empty records supplies...
static bool recordCanPassInRegs(ModuleOp modOp, cir::RecordType recTy)
Whether a struct's declared argument-passing kind (from the module's record-layout metadata) allows i...
static mlir::FailureOr< ArgClassification > convertABIArgInfo(const llvm::abi::ArgInfo &info, MLIRContext *ctx, mlir::Type origTy)
Convert an llvm::abi::ArgInfo into the ArgClassification consumed by CIRABIRewriteContext.
static mlir::FailureOr< FunctionClassification > withReturnVoidness(mlir::FailureOr< FunctionClassification > fc, mlir::Type returnType)
Record on fc whether returnType is CIR's void.
static mlir::Type unwrapLongDoubleVectorElement(mlir::Type ty)
Returns ty with a LongDoubleType vector element replaced by its underlying format,...
static bool mayReachSseUp(mlir::Type ty, const DataLayout &dl)
Whether the classifier could give this type the SSEUP class, looking through arrays and records at th...
static llvm::abi::RequiredArgs requiredArgs(cir::FuncType fnTy)
Where fnTy's declared parameters end and its ellipsis arguments begin.
static bool coerceKeepsScalarValue(mlir::Type origTy, const llvm::abi::Type *coercedAbiTy)
Whether coercedAbiTy holds the same value as the scalar origTy: an integer of the same width,...
static mlir::FailureOr< FunctionClassification > classifyFunction(cir::FuncOp func, const DataLayout &dl, cir::CallConvTarget target, StringRef classificationAttrName)
Classify func using whichever driver mode is configured.
static mlir::FailureOr< ArgClassification > convertDirectArgInfo(const llvm::abi::ArgInfo &info, MLIRContext *ctx, mlir::Type origTy)
Convert a Direct llvm::abi::ArgInfo.
static bool sseUpCoerceSizeUnsupported(uint64_t recordBits, llvm::ArrayRef< mlir::Type > members, const DataLayout &dl)
Whether the record's size has no SSEUP coerce.
static bool isSupportedType(mlir::Type ty, const DataLayout &dl)
The CIR types the bridge handles.
static const llvm::abi::Type * mapCIRType(mlir::Type type, mlir::abi::ABITypeMapper &typeMapper, const DataLayout &dl, const cir::CIRDataLayout &cirDL, ModuleOp modOp)
Map a CIR type to an llvm::abi::Type.
static mlir::Type abiTypeToCIR(const llvm::abi::Type *ty, MLIRContext *ctx)
Convert an llvm::abi::Type coercion type back to a CIR type.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
cir::CIRDataLayout cirDataLayout
mlir::FailureOr< mlir::abi::FunctionClassification > classifyIndirectCall(cir::CIRCallOpInterface call) override
A callee resolved at run time carries no features of its own, so the call is classified at the featur...
mlir::FailureOr< mlir::abi::FunctionClassification > classifyFunction(cir::FuncOp func) override
Classify a cir.func using the LLVM ABI library.
const mlir::DataLayout & dl
mlir::FailureOr< mlir::abi::ArgClassification > classifyVarArgType(mlir::Type ty, const llvm::abi::TargetInfo &targetInfo, llvm::function_ref< mlir::InFlightDiagnostic()> emitError)
Classify ty, the type fetched by a cir.va_arg, as an unnamed argument with every argument register fr...
mlir::FailureOr< mlir::abi::FunctionClassification > classifyVariadicCall(cir::CIRCallOpInterface call, cir::FuncOp callee) override
The call is classified at the callee's features, not the caller's, because the pass rewrites the defi...
virtual const llvm::abi::TargetInfo & getTargetInfo(cir::FuncOp featureSource)=0
The library classifier for a function whose recorded target features may refine the ABI rules.
mlir::abi::ABITypeMapper typeMapper
Produces the classification CallConvLowering rewrites a signature from.
uint64_t getTypeLanguageAlignment(mlir::Type ty) const
Returns the alignment, in bytes, that the source language requires for an object of type ty.
C++ view class that accepts both !cir.struct and !cir.union types.
bool isEmptyForABI() const
Whether no member holds data.
llvm::ArrayRef< mlir::Type > getMembers() const
static llvm::SmallVector< RecordMemberKind > getAllDataKinds(llvm::ArrayRef< mlir::Type > members)
One Data kind per member.
mlir::StringAttr getName() const
llvm::ArrayRef< RecordMemberKind > getMemberKinds() const
uint64_t getElementOffset(const mlir::DataLayout &dataLayout, unsigned idx) const
RecordLayoutAttr tryGetRecordLayout(mlir::ModuleOp mod, mlir::StringAttr name)
Same lookup as getRecordLayout, but returns a null attribute instead of asserting when the record has...
llvm::CallingConv::ID convertCallingConv(cir::CallingConv cc)
Map a CIR calling convention to the llvm::CallingConv the ABI classifier uses.
cir::FPTypeInterface getFloatingPointType(const llvm::fltSemantics &sem, mlir::MLIRContext *ctx)
Returns the CIR floating-point type for the given semantics, or a null type if CIR has no type for it...
cir::FuncType getIndirectCalleeType(cir::CIRCallOpInterface call)
The signature the indirect call call reaches its callee through.
std::unique_ptr< CIRABIClassifier > createInjectedABIClassifier(const mlir::DataLayout &dl, llvm::StringRef attrName)
A classifier that reads each function's classification from the DictionaryAttr named attrName.
std::unique_ptr< CIRABIClassifier > createTestTargetABIClassifier(const mlir::DataLayout &dl)
The MLIR test ABI target's classifier, whose predictable rules approximate x86_64 SysV.
CallConvTarget
The ABI target whose calling-convention rules drive CallConvLowering.
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
static bool addressSpace()