10#include "TargetInfo.h"
25 SparcV8ABIInfo(CodeGenTypes &CGT)
26 : DefaultABIInfo(CGT),
27 IsComplexGnuABI(!CGT.getContext().getLangOpts().isCompatibleWith(
28 LangOptions::ClangABI::Ver23)) {}
34 ABIArgInfo classifyComplexType(
const ComplexType *Ty,
bool IsRet)
const;
37 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
38 AggValueSlot Slot)
const override;
39 void computeInfo(CGFunctionInfo &FI)
const override;
49 uint64_t ElementTypeSize = getContext().getTypeSize(ElementTy);
50 if (ElementTypeSize <= 32) {
53 llvm::IntegerType::get(getVMContext(), 2 * ElementTypeSize));
59 return getNaturalAlignIndirect(QualType(CT, 0),
60 getDataLayout().getAllocaAddrSpace());
63 const auto *BT = ElementTy->
getAs<BuiltinType>();
64 if (BT && BT->getKind() == BuiltinType::LongDouble)
70ABIArgInfo SparcV8ABIInfo::classifyReturnType(QualType Ty)
const {
71 if (
const auto *CT = Ty->
getAs<ComplexType>())
72 return classifyComplexType(CT,
true);
74 if (
const auto *VT = Ty->
getAs<VectorType>()) {
77 if (VT->getElementType()->isRealFloatingType() || Size > 64)
78 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace());
81 llvm::Type *FloatTy = llvm::Type::getFloatTy(getVMContext());
82 llvm::Type *DoubleTy = llvm::Type::getDoubleTy(getVMContext());
83 llvm::Type *CoerceTy =
Size <= 32 ? FloatTy : DoubleTy;
87 if (
const auto *BT = Ty->
getAs<BuiltinType>();
88 BT && BT->getKind() == BuiltinType::LongDouble &&
89 getContext().getTypeSize(Ty) > 64)
90 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
96ABIArgInfo SparcV8ABIInfo::classifyArgumentType(QualType Ty)
const {
97 if (
const auto *CT = Ty->
getAs<ComplexType>())
98 return classifyComplexType(CT,
false);
101 if (
const auto *VT = Ty->
getAs<VectorType>()) {
102 uint64_t SizeInBits = getContext().getTypeSize(Ty);
103 if (VT->getElementType()->isRealFloatingType() || SizeInBits > 64)
104 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace());
107 const auto *BT = Ty->
getAs<BuiltinType>();
108 if (BT && BT->getKind() == BuiltinType::LongDouble &&
109 getContext().getTypeSize(Ty) > 64)
110 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace());
115void SparcV8ABIInfo::computeInfo(CGFunctionInfo &FI)
const {
121RValue SparcV8ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
122 QualType Ty, AggValueSlot Slot)
const {
124 auto TInfo = getContext().getTypeInfoInChars(Ty);
130 bool AllowHigherAlign =
false;
134 bool ForceRightAdjust =
true;
137 AllowHigherAlign, Slot, ForceRightAdjust);
141class SparcV8TargetCodeGenInfo :
public TargetCodeGenInfo {
143 SparcV8TargetCodeGenInfo(CodeGenTypes &CGT)
144 : TargetCodeGenInfo(std::make_unique<SparcV8ABIInfo>(CGT)) {}
146 llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF,
147 llvm::Value *Address)
const override {
154 llvm::ConstantInt::get(CGF.
Int32Ty, Offset));
157 llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
158 llvm::Value *Address)
const override {
165 llvm::ConstantInt::get(CGF.
Int32Ty, Offset));
197class SparcV9ABIInfo :
public ABIInfo {
199 SparcV9ABIInfo(CodeGenTypes &CGT)
201 IsComplexGnuABI(!CGT.getContext().getLangOpts().isCompatibleWith(
202 LangOptions::ClangABI::Ver23)),
203 IsPackedUnionGnuABI(!CGT.getContext().getLangOpts().isCompatibleWith(
204 LangOptions::ClangABI::Ver23)) {}
208 bool IsComplexGnuABI;
212 bool IsPackedUnionGnuABI;
214 ABIArgInfo
classifyType(QualType RetTy,
unsigned SizeLimit,
215 unsigned &RegOffset,
bool IsVarArg)
const;
216 void computeInfo(CGFunctionInfo &FI)
const override;
217 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
218 AggValueSlot Slot)
const override;
231 struct CoerceBuilder {
232 llvm::LLVMContext &Context;
233 const llvm::DataLayout &DL;
234 SmallVector<llvm::Type*, 8> Elems;
240 SmallVector<std::pair<uint64_t, uint64_t>, 4> IntRanges;
242 CoerceBuilder(llvm::LLVMContext &c,
const llvm::DataLayout &dl,
244 : Context(c), DL(dl),
Size(0), InReg(
false), IsVarArg(IsVarArg) {}
248 assert(ToSize >= Size &&
"Cannot remove elements");
253 uint64_t Aligned = llvm::alignTo(Size, 64);
254 if (Aligned > Size && Aligned <= ToSize) {
255 Elems.push_back(llvm::IntegerType::get(Context, Aligned - Size));
260 while (Size + 64 <= ToSize) {
261 Elems.push_back(llvm::Type::getInt64Ty(Context));
267 Elems.push_back(llvm::IntegerType::get(Context, ToSize - Size));
273 void addFloat(
uint64_t Offset, llvm::Type *Ty,
unsigned Bits) {
281 if (llvm::any_of(IntRanges, [Offset](
const auto &R) {
282 return R.first <= Offset && Offset <
R.second;
290 Size = Offset + Bits;
294 void addStruct(
uint64_t Offset, llvm::StructType *StrTy) {
295 const llvm::StructLayout *Layout = DL.getStructLayout(StrTy);
296 for (
unsigned i = 0, e = StrTy->getNumElements(); i != e; ++i) {
297 llvm::Type *ElemTy = StrTy->getElementType(i);
298 uint64_t ElemOffset = Offset + Layout->getElementOffsetInBits(i);
299 switch (ElemTy->getTypeID()) {
300 case llvm::Type::StructTyID:
303 case llvm::Type::FloatTyID:
304 addFloat(ElemOffset, ElemTy, 32);
306 case llvm::Type::DoubleTyID:
307 addFloat(ElemOffset, ElemTy, 64);
309 case llvm::Type::FP128TyID:
310 addFloat(ElemOffset, ElemTy, 128);
312 case llvm::Type::PointerTyID:
313 if (ElemOffset % 64 == 0) {
315 Elems.push_back(ElemTy);
326 bool isUsableType(llvm::StructType *Ty)
const {
327 return llvm::ArrayRef(Elems) == Ty->elements();
332 if (Elems.size() == 1)
333 return Elems.front();
335 return llvm::StructType::get(Context, Elems);
354 const auto *FieldClass =
356 return !FieldClass || FieldClass->
isPOD() ||
357 FieldClass->hasAttr<PackedAttr>();
373 Ranges.emplace_back(Offset, Offset + Ctx.
toBits(Layout.
getSize()));
379 return isPackedField(Ctx, FD);
385 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
387 if (
Base.isVirtual())
389 const auto *BaseRD =
Base.getType()->castAsCXXRecordDecl();
398 if (
const auto *FieldRD =
406 Ranges.emplace_back(FieldOffset,
411ABIArgInfo SparcV9ABIInfo::classifyType(QualType Ty,
unsigned SizeLimit,
413 bool IsVarArg)
const {
417 auto &Context = getContext();
418 auto &VMContext = getVMContext();
432 if (Size > SizeLimit) {
434 return getNaturalAlignIndirect(
435 Ty, getDataLayout().getAllocaAddrSpace(),
444 llvm::Type *Padding = (Alignment > 64 && RegOffset % 2 != 0)
445 ? llvm::Type::getInt64Ty(VMContext)
447 unsigned PaddingSlots = Padding ? 1 : 0;
448 unsigned SizeSlots = llvm::divideCeil(Size, 64);
452 Ty = ED->getIntegerType();
456 RegOffset += PaddingSlots + SizeSlots;
460 if (
const auto *EIT = Ty->
getAs<BitIntType>())
461 if (EIT->getNumBits() < 64) {
462 RegOffset += PaddingSlots + SizeSlots;
470 if (IsComplexGnuABI) {
471 const auto *CT = Ty->
getAs<ComplexType>();
474 if (ElementTypeSize <= 32) {
477 llvm::IntegerType::get(VMContext, 2 * ElementTypeSize),
485 RegOffset += PaddingSlots + SizeSlots;
493 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
499 llvm::StructType *StrTy = dyn_cast<llvm::StructType>(CGT.ConvertType(Ty));
501 RegOffset += PaddingSlots + SizeSlots;
505 CoerceBuilder CB(VMContext, getDataLayout(), IsVarArg);
506 if (IsPackedUnionGnuABI)
509 false, CB.IntRanges);
510 CB.addStruct(0, StrTy);
513 CB.pad(llvm::alignTo(
514 std::max(CB.DL.getTypeSizeInBits(StrTy).getKnownMinValue(),
uint64_t(1)),
516 RegOffset += PaddingSlots + CB.Size / 64;
519 llvm::Type *CoerceTy = CB.isUsableType(StrTy) ? StrTy : CB.getType();
526RValue SparcV9ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
527 QualType Ty, AggValueSlot Slot)
const {
529 auto TInfo = getContext().getTypeInfoInChars(Ty);
539 TInfo.Width > 2 * SlotSize, TInfo,
541 true, Slot, ForceRightAdjust);
544void SparcV9ABIInfo::computeInfo(CGFunctionInfo &FI)
const {
545 unsigned RetOffset = 0;
551 unsigned ArgOffset = RetType.
isIndirect() ? RetOffset : 0;
552 for (
auto [ArgNo, I] : llvm::enumerate(FI.
arguments())) {
554 I.info =
classifyType(I.type, 16 * 8, ArgOffset, IsVarArg);
559class SparcV9TargetCodeGenInfo :
public TargetCodeGenInfo {
561 SparcV9TargetCodeGenInfo(CodeGenTypes &CGT)
562 : TargetCodeGenInfo(std::make_unique<SparcV9ABIInfo>(CGT)) {}
564 int getDwarfEHStackPointer(CodeGen::CodeGenModule &M)
const override {
568 bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
569 llvm::Value *Address)
const override;
571 llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF,
572 llvm::Value *Address)
const override {
574 llvm::ConstantInt::get(CGF.
Int32Ty, 8));
577 llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
578 llvm::Value *Address)
const override {
580 llvm::ConstantInt::get(CGF.
Int32Ty, -8));
586SparcV9TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
587 llvm::Value *Address)
const {
591 CodeGen::CGBuilderTy &Builder = CGF.
Builder;
593 llvm::IntegerType *i8 = CGF.
Int8Ty;
594 llvm::Value *Four8 = llvm::ConstantInt::get(i8, 4);
595 llvm::Value *Eight8 = llvm::ConstantInt::get(i8, 8);
619std::unique_ptr<TargetCodeGenInfo>
621 return std::make_unique<SparcV8TargetCodeGenInfo>(CGM.
getTypes());
624std::unique_ptr<TargetCodeGenInfo>
626 return std::make_unique<SparcV9TargetCodeGenInfo>(CGM.
getTypes());
static void collectIntRanges(const ASTContext &Ctx, const RecordDecl *RD, uint64_t Offset, bool Packed, SmallVectorImpl< std::pair< uint64_t, uint64_t > > &Ranges)
Collect the bit ranges of the fields of RD, placed at bit Offset, that GCC never passes or returns in...
static bool isPackedField(const ASTContext &Ctx, const FieldDecl *FD)
Return true if GCC treats FD as a packed field (DECL_PACKED).
static ABIArgInfo classifyType(CodeGenModule &CGM, CanQualType type, bool forReturn)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
int64_t toBits(CharUnits CharSize) const
Convert a size in characters to a size in bits.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
unsigned getTypeAlign(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in bits.
uint64_t getCharWidth() const
Return the size of the character type, in bits.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
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.
Represents a base class of a C++ class.
bool isPOD() const
Whether this class is a POD-type (C++ [class]p4)
static constexpr CharUnits fromQuantity(QuantityType Quantity)
Construct a CharUnits quantity from a raw integer type.
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
static ABIArgInfo getIgnore()
static ABIArgInfo getDirect(llvm::Type *T=nullptr, unsigned Offset=0, llvm::Type *Padding=nullptr, bool CanBeFlattened=true, unsigned Align=0)
static ABIArgInfo getExtend(QualType Ty, llvm::Type *T=nullptr, llvm::Type *Padding=nullptr)
static ABIArgInfo getDirectInReg(llvm::Type *T=nullptr)
Address CreateGEP(CodeGenFunction &CGF, Address Addr, llvm::Value *Index, const llvm::Twine &Name="")
RecordArgABI
Specify how one should pass an argument of a record type.
@ RAA_DirectInMemory
Pass it on the stack using its defined layout.
ABIArgInfo & getReturnInfo()
CanQualType getReturnType() const
MutableArrayRef< ArgInfo > arguments()
unsigned getNumRequiredArgs() const
const CGFunctionInfo * CurFnInfo
This class organizes the cross-function state that is used while generating LLVM code.
CodeGenTypes & getTypes()
DefaultABIInfo - The default implementation for ABI specific details.
ABIArgInfo classifyArgumentType(QualType RetTy) const
ABIArgInfo classifyReturnType(QualType RetTy) const
Complex values, per C99 6.2.5p11.
QualType getElementType() const
Represents a member of a struct/union/class.
bool isBitField() const
Determines whether this field is a bitfield.
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
QualType getAtomicUnqualifiedType() const
Remove all qualifiers including _Atomic.
Represents a struct/union/class.
field_range fields() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
bool isAnyComplexType() const
EnumDecl * getAsEnumDecl() const
Retrieves the EnumDecl this type refers to.
const T * getAs() const
Member-template getAs<specific type>'.
ABIArgInfo classifyArgumentType(CodeGenModule &CGM, CanQualType type)
Classify the rules for how to pass a particular type.
CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT, CGCXXABI &CXXABI)
bool classifyReturnType(const CGCXXABI &CXXABI, CGFunctionInfo &FI, const ABIInfo &Info)
RValue emitVoidPtrVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType ValueTy, bool IsIndirect, TypeInfoChars ValueInfo, CharUnits SlotSizeAndAlign, bool AllowHigherAlign, AggValueSlot Slot, bool ForceRightAdjust=false)
Emit va_arg for a platform using the common void* representation, where arguments are simply emitted ...
bool isAggregateTypeForABI(QualType T)
void AssignToArrayRange(CodeGen::CGBuilderTy &Builder, llvm::Value *Array, llvm::Value *Value, unsigned FirstIndex, unsigned LastIndex)
std::unique_ptr< TargetCodeGenInfo > createSparcV8TargetCodeGenInfo(CodeGenModule &CGM)
std::unique_ptr< TargetCodeGenInfo > createSparcV9TargetCodeGenInfo(CodeGenModule &CGM)
constexpr bool isIntegerType(PrimType T)
Top level wrappers for InstallAPI frontend operations.
U cast(CodeGen::Address addr)
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
llvm::IntegerType * Int32Ty