clang 24.0.0git
CIRABIClassifier.cpp File Reference
#include "CIRABIClassifier.h"
#include "TargetLowering/CIRABIRewriteContext.h"
#include "mlir/ABI/Targets/Test/TestTarget.h"
#include "clang/CIR/Dialect/IR/CIRDialect.h"
#include "clang/CIR/MissingFeatures.h"
#include "llvm/ABI/Types.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/MathExtras.h"

Go to the source code of this file.

Functions

static bool recordCanPassInRegs (ModuleOp modOp, cir::RecordType recTy)
 Whether a struct's declared argument-passing kind (from the module's record-layout metadata) allows it to be passed in registers.
static bool recordIsTransparentUnion (ModuleOp modOp, cir::RecordType recTy)
static bool recordHasFlexibleArrayMember (ModuleOp modOp, cir::RecordType recTy)
 Read from the layout, which also covers a last field that has one.
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 the types they hold.
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 memberIsEmptyRecord (mlir::Type ty)
 Whether a member is an empty record, looking through arrays, since an array of empty records supplies no bytes either.
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 the record raises it.
static bool isSupportedType (mlir::Type ty, const DataLayout &dl)
 The CIR types the bridge handles.
static mlir::Type abiTypeToCIR (const llvm::abi::Type *ty, MLIRContext *ctx)
 Convert an llvm::abi::Type coercion type back to a CIR type.
static mlir::Type unwrapLongDoubleVectorElement (mlir::Type ty)
 Returns ty with a LongDoubleType vector element replaced by its underlying format, which is the element abiTypeToCIR builds for the same float.
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 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, a float with the same semantics, or a pointer.
static mlir::FailureOr< ArgClassification > convertDirectArgInfo (const llvm::abi::ArgInfo &info, MLIRContext *ctx, mlir::Type origTy)
 Convert a Direct llvm::abi::ArgInfo.
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 llvm::abi::RequiredArgs requiredArgs (cir::FuncType fnTy)
 Where fnTy's declared parameters end and its ellipsis arguments begin.
static mlir::FailureOr< FunctionClassification > withReturnVoidness (mlir::FailureOr< FunctionClassification > fc, mlir::Type returnType)
 Record on fc whether returnType is CIR's void.
static mlir::FailureOr< FunctionClassification > classifyFunction (cir::FuncOp func, const DataLayout &dl, cir::CallConvTarget target, StringRef classificationAttrName)
 Classify func using whichever driver mode is configured.

Function Documentation

◆ abiTypeToCIR()

mlir::Type abiTypeToCIR ( const llvm::abi::Type * ty,
MLIRContext * ctx )
static

Convert an llvm::abi::Type coercion type back to a CIR type.

Definition at line 253 of file CIRABIClassifier.cpp.

References abiTypeToCIR(), cir::RecordType::getAllDataKinds(), and cir::getFloatingPointType().

Referenced by abiTypeToCIR(), convertABIArgInfo(), and convertDirectArgInfo().

◆ classifyFunction()

mlir::FailureOr< FunctionClassification > classifyFunction ( cir::FuncOp func,
const DataLayout & dl,
cir::CallConvTarget target,
StringRef classificationAttrName )
static

Classify func using whichever driver mode is configured.

Returns failure and emits an error on the function if classification fails (e.g. injection-driver mode but the function is missing the attribute, or the attribute is malformed).

Definition at line 892 of file CIRABIClassifier.cpp.

References cir::Test, and withReturnVoidness().

◆ coerceKeepsScalarValue()

bool coerceKeepsScalarValue ( mlir::Type origTy,
const llvm::abi::Type * coercedAbiTy )
static

Whether coercedAbiTy holds the same value as the scalar origTy: an integer of the same width, a float with the same semantics, or a pointer.

Used only in an assert in convertDirectArgInfo.

Definition at line 535 of file CIRABIClassifier.cpp.

Referenced by convertDirectArgInfo().

◆ convertABIArgInfo()

mlir::FailureOr< ArgClassification > convertABIArgInfo ( const llvm::abi::ArgInfo & info,
MLIRContext * ctx,
mlir::Type origTy )
static

Convert an llvm::abi::ArgInfo into the ArgClassification consumed by CIRABIRewriteContext.

Returns failure when the classifier picks a coercion this bridge cannot represent, which the caller reports as NYI.

Definition at line 669 of file CIRABIClassifier.cpp.

References abiTypeToCIR(), and convertDirectArgInfo().

Referenced by clang::CodeGen::CodeGenModule::computeABIInfoUsingLib().

◆ convertDirectArgInfo()

mlir::FailureOr< ArgClassification > convertDirectArgInfo ( const llvm::abi::ArgInfo & info,
MLIRContext * ctx,
mlir::Type origTy )
static

Convert a Direct llvm::abi::ArgInfo.

A null coercedType in the result means the value is passed unchanged in its own type. Otherwise the rewriter converts the value to coercedType, and when that is a struct and canFlatten is set, passes each field of the struct as a separate argument. When the classifier names no coerce type, a struct or _Complex that can be flattened is coerced to a struct of its own fields.

Definition at line 561 of file CIRABIClassifier.cpp.

References abiTypeToCIR(), coerceKeepsScalarValue(), cir::RecordType::getAllDataKinds(), and unwrapLongDoubleVectorElement().

Referenced by convertABIArgInfo().

◆ isSupportedType()

bool isSupportedType ( mlir::Type ty,
const DataLayout & dl )
static

The CIR types the bridge handles.

Scalars: an integer up to 128 bits (including __int128), a _BitInt of any width, pointer, vtable pointer, bool, void, or any floating-point type. Aggregates: a complete struct or union whose members are all themselves supported, or an array of a supported element type. Also a _Complex, or a fixed-width vector, of a supported element type. Everything else is reported NYI at the reject() choke point in classifySignature.

Definition at line 128 of file CIRABIClassifier.cpp.

References cir::MissingFeatures::addressSpace(), isSupportedType(), kind, memberIsEmptyRecord(), sseUpCoerceSizeUnsupported(), and uint64_t.

Referenced by isSupportedType().

◆ mapCIRType()

const llvm::abi::Type * mapCIRType ( mlir::Type type,
mlir::abi::ABITypeMapper & typeMapper,
const DataLayout & dl,
const cir::CIRDataLayout & cirDL,
ModuleOp modOp )
static

◆ mayReachSseUp()

bool mayReachSseUp ( mlir::Type ty,
const DataLayout & dl )
static

Whether the classifier could give this type the SSEUP class, looking through arrays and records at the types they hold.

Definition at line 66 of file CIRABIClassifier.cpp.

References mayReachSseUp().

Referenced by mayReachSseUp(), and sseUpCoerceSizeUnsupported().

◆ memberIsEmptyRecord()

bool memberIsEmptyRecord ( mlir::Type ty)
static

Whether a member is an empty record, looking through arrays, since an array of empty records supplies no bytes either.

Definition at line 102 of file CIRABIClassifier.cpp.

Referenced by isSupportedType(), and mapCIRType().

◆ recordCanPassInRegs()

bool recordCanPassInRegs ( ModuleOp modOp,
cir::RecordType recTy )
static

Whether a struct's declared argument-passing kind (from the module's record-layout metadata) allows it to be passed in registers.

A record with no layout entry (e.g. an anonymous struct) has no C++ non-trivial reason to be forced to memory, so it defaults to can-pass-in-registers.

Definition at line 45 of file CIRABIClassifier.cpp.

References cir::RecordType::getName(), and cir::tryGetRecordLayout().

Referenced by mapCIRType().

◆ recordHasFlexibleArrayMember()

bool recordHasFlexibleArrayMember ( ModuleOp modOp,
cir::RecordType recTy )
static

Read from the layout, which also covers a last field that has one.

Definition at line 58 of file CIRABIClassifier.cpp.

References cir::RecordType::getName(), and cir::tryGetRecordLayout().

Referenced by mapCIRType().

◆ recordIsTransparentUnion()

bool recordIsTransparentUnion ( ModuleOp modOp,
cir::RecordType recTy )
static

Definition at line 52 of file CIRABIClassifier.cpp.

References cir::RecordType::getName(), and cir::tryGetRecordLayout().

Referenced by mapCIRType().

◆ recordUnadjustedAlign()

llvm::Align recordUnadjustedAlign ( ModuleOp modOp,
cir::RecordType recTy,
const cir::CIRDataLayout & cirDL )
static

A record's unadjusted alignment, the alignment its members give it before an alignment attribute on the record raises it.

It comes from the module's record-layout metadata, and the computed fallback only serves hand-written CIR.

Definition at line 113 of file CIRABIClassifier.cpp.

References cir::RecordType::getName(), cir::CIRDataLayout::getTypeLanguageAlignment(), and cir::tryGetRecordLayout().

Referenced by mapCIRType().

◆ requiredArgs()

llvm::abi::RequiredArgs requiredArgs ( cir::FuncType fnTy)
static

Where fnTy's declared parameters end and its ellipsis arguments begin.

Definition at line 702 of file CIRABIClassifier.cpp.

Referenced by cir::CIRABIClassifierCommon::classifyFunction(), and cir::CIRABIClassifierCommon::classifyIndirectCall().

◆ sseUpCoerceSizeUnsupported()

bool sseUpCoerceSizeUnsupported ( uint64_t recordBits,
llvm::ArrayRef< mlir::Type > members,
const DataLayout & dl )
static

Whether the record's size has no SSEUP coerce.

That coerce is a vector as wide as the record, so only 128, 256 and 512 bits have one. A record past 512 bits classifies memory before any coerce is asked for.

Definition at line 89 of file CIRABIClassifier.cpp.

References mayReachSseUp(), and uint64_t.

Referenced by isSupportedType().

◆ unwrapLongDoubleVectorElement()

mlir::Type unwrapLongDoubleVectorElement ( mlir::Type ty)
static

Returns ty with a LongDoubleType vector element replaced by its underlying format, which is the element abiTypeToCIR builds for the same float.

Definition at line 309 of file CIRABIClassifier.cpp.

Referenced by convertDirectArgInfo().

◆ withReturnVoidness()

mlir::FailureOr< FunctionClassification > withReturnVoidness ( mlir::FailureOr< FunctionClassification > fc,
mlir::Type returnType )
static

Record on fc whether returnType is CIR's void.

classifySignature answers this itself, but the other two drivers cannot: the test target is dialect-neutral and has no notion of CIR's void, and the classification-attr schema carries no return type at all. Both route through here so a classification always reaches needsRewrite paired with the return type it was built from.

Definition at line 880 of file CIRABIClassifier.cpp.

Referenced by classifyFunction().