clang 24.0.0git
Sparc.cpp
Go to the documentation of this file.
1//===- Sparc.cpp ----------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "ABIInfoImpl.h"
10#include "TargetInfo.h"
11#include <algorithm>
12
13using namespace clang;
14using namespace clang::CodeGen;
15
16//===----------------------------------------------------------------------===//
17// SPARC v8 ABI Implementation.
18// Based on the SPARC Compliance Definition version 2.4.1.
19//
20// Ensures that complex values are passed in registers.
21//
22namespace {
23class SparcV8ABIInfo : public DefaultABIInfo {
24public:
25 SparcV8ABIInfo(CodeGenTypes &CGT)
26 : DefaultABIInfo(CGT),
27 IsComplexGnuABI(!CGT.getContext().getLangOpts().isCompatibleWith(
28 LangOptions::ClangABI::Ver23)) {}
29
30private:
31 /// Whether how `_Complex` values are passed and returned is GCC-compatible.
32 bool IsComplexGnuABI;
33
34 ABIArgInfo classifyComplexType(const ComplexType *Ty, bool IsRet) const;
35 ABIArgInfo classifyReturnType(QualType RetTy) const;
36 ABIArgInfo classifyArgumentType(QualType Ty) const;
37 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
38 AggValueSlot Slot) const override;
39 void computeInfo(CGFunctionInfo &FI) const override;
40};
41} // end anonymous namespace
42
43ABIArgInfo SparcV8ABIInfo::classifyComplexType(const ComplexType *CT,
44 bool IsRet) const {
45 QualType ElementTy = CT->getElementType();
46
47 if (IsComplexGnuABI && ElementTy->isIntegerType()) {
48 // The default path already does the right thing for `long long _Complex`.
49 uint64_t ElementTypeSize = getContext().getTypeSize(ElementTy);
50 if (ElementTypeSize <= 32) {
51 // Coerce to an integer to get the correct scalar-like behavior.
53 llvm::IntegerType::get(getVMContext(), 2 * ElementTypeSize));
54 }
55 }
56
57 // Any other complex value is passed indirectly, but returned in registers.
58 if (!IsRet)
59 return getNaturalAlignIndirect(QualType(CT, 0),
60 getDataLayout().getAllocaAddrSpace());
61
62 // long double _Complex is special, it is marked as inreg.
63 const auto *BT = ElementTy->getAs<BuiltinType>();
64 if (BT && BT->getKind() == BuiltinType::LongDouble)
66
67 return ABIArgInfo::getDirect();
68}
69
70ABIArgInfo SparcV8ABIInfo::classifyReturnType(QualType Ty) const {
71 if (const auto *CT = Ty->getAs<ComplexType>())
72 return classifyComplexType(CT, /*IsRet=*/true);
73
74 if (const auto *VT = Ty->getAs<VectorType>()) {
75 uint64_t Size = getContext().getTypeSize(Ty);
76 // Return float vectors and larger integer vectors indirectly.
77 if (VT->getElementType()->isRealFloatingType() || Size > 64)
78 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace());
79
80 // Return smaller integer vectors via float registers.
81 llvm::Type *FloatTy = llvm::Type::getFloatTy(getVMContext());
82 llvm::Type *DoubleTy = llvm::Type::getDoubleTy(getVMContext());
83 llvm::Type *CoerceTy = Size <= 32 ? FloatTy : DoubleTy;
84 return ABIArgInfo::getDirect(CoerceTy);
85 }
86
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(),
91 /*ByVal=*/false);
92
94}
95
96ABIArgInfo SparcV8ABIInfo::classifyArgumentType(QualType Ty) const {
97 if (const auto *CT = Ty->getAs<ComplexType>())
98 return classifyComplexType(CT, /*IsRet=*/false);
99
100 // Pass floating-point vectors and vectors larger than 64 bits by reference.
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());
105 }
106
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());
111
113}
114
115void SparcV8ABIInfo::computeInfo(CGFunctionInfo &FI) const {
117 for (auto &Arg : FI.arguments())
118 Arg.info = classifyArgumentType(Arg.type);
119}
120
121RValue SparcV8ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
122 QualType Ty, AggValueSlot Slot) const {
123 CharUnits SlotSize = CharUnits::fromQuantity(4);
124 auto TInfo = getContext().getTypeInfoInChars(Ty);
125
126 // E.g. long double, larger _Complex and aggregate values are indirect.
127 bool IsIndirect = classifyArgumentType(Ty).isIndirect();
128
129 // An alignment higher than the slot size is not respected.
130 bool AllowHigherAlign = false;
131
132 // Force values smaller than a slot (e.g. _Complex char)
133 // into the right-most bytes.
134 bool ForceRightAdjust = true;
135
136 return emitVoidPtrVAArg(CGF, VAListAddr, Ty, IsIndirect, TInfo, SlotSize,
137 AllowHigherAlign, Slot, ForceRightAdjust);
138}
139
140namespace {
141class SparcV8TargetCodeGenInfo : public TargetCodeGenInfo {
142public:
143 SparcV8TargetCodeGenInfo(CodeGenTypes &CGT)
144 : TargetCodeGenInfo(std::make_unique<SparcV8ABIInfo>(CGT)) {}
145
146 llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF,
147 llvm::Value *Address) const override {
148 int Offset;
150 Offset = 12;
151 else
152 Offset = 8;
153 return CGF.Builder.CreateGEP(CGF.Int8Ty, Address,
154 llvm::ConstantInt::get(CGF.Int32Ty, Offset));
155 }
156
157 llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
158 llvm::Value *Address) const override {
159 int Offset;
161 Offset = -12;
162 else
163 Offset = -8;
164 return CGF.Builder.CreateGEP(CGF.Int8Ty, Address,
165 llvm::ConstantInt::get(CGF.Int32Ty, Offset));
166 }
167};
168} // end anonymous namespace
169
170//===----------------------------------------------------------------------===//
171// SPARC v9 ABI Implementation.
172// Based on the SPARC Compliance Definition version 2.4.1.
173//
174// Function arguments a mapped to a nominal "parameter array" and promoted to
175// registers depending on their type. Each argument occupies 8 or 16 bytes in
176// the array, structs larger than 16 bytes are passed indirectly.
177//
178// One case requires special care:
179//
180// struct mixed {
181// int i;
182// float f;
183// };
184//
185// When a struct mixed is passed by value, it only occupies 8 bytes in the
186// parameter array, but the int is passed in an integer register, and the float
187// is passed in a floating point register. This is represented as two arguments
188// with the LLVM IR inreg attribute:
189//
190// declare void f(i32 inreg %i, float inreg %f)
191//
192// The code generator will only allocate 4 bytes from the parameter array for
193// the inreg arguments. All other arguments are allocated a multiple of 8
194// bytes.
195//
196namespace {
197class SparcV9ABIInfo : public ABIInfo {
198public:
199 SparcV9ABIInfo(CodeGenTypes &CGT)
200 : ABIInfo(CGT),
201 IsComplexGnuABI(!CGT.getContext().getLangOpts().isCompatibleWith(
202 LangOptions::ClangABI::Ver23)),
203 IsPackedUnionGnuABI(!CGT.getContext().getLangOpts().isCompatibleWith(
204 LangOptions::ClangABI::Ver23)) {}
205
206private:
207 /// Whether how `_Complex` values are passed and returned is GCC-compatible.
208 bool IsComplexGnuABI;
209
210 /// Whether the floating-point fields of packed structs and of unions are
211 /// kept out of floating-point registers, as GCC does.
212 bool IsPackedUnionGnuABI;
213
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;
219
220 // Coercion type builder for structs passed in registers. The coercion type
221 // serves two purposes:
222 //
223 // 1. Pad structs to a multiple of 64 bits, so they are passed 'left-aligned'
224 // in registers.
225 // 2. Expose aligned floating point elements as first-level elements, so the
226 // code generator knows to pass them in floating point registers.
227 //
228 // We also compute the InReg flag which indicates that the struct contains
229 // aligned 32-bit floats.
230 //
231 struct CoerceBuilder {
232 llvm::LLVMContext &Context;
233 const llvm::DataLayout &DL;
234 SmallVector<llvm::Type*, 8> Elems;
236 bool InReg;
237 bool IsVarArg;
238 // Bit ranges [Begin, End) whose floating-point elements must be passed in
239 // integer registers.
240 SmallVector<std::pair<uint64_t, uint64_t>, 4> IntRanges;
241
242 CoerceBuilder(llvm::LLVMContext &c, const llvm::DataLayout &dl,
243 bool IsVarArg)
244 : Context(c), DL(dl), Size(0), InReg(false), IsVarArg(IsVarArg) {}
245
246 // Pad Elems with integers until Size is ToSize.
247 void pad(uint64_t ToSize) {
248 assert(ToSize >= Size && "Cannot remove elements");
249 if (ToSize == Size)
250 return;
251
252 // Finish the current 64-bit word.
253 uint64_t Aligned = llvm::alignTo(Size, 64);
254 if (Aligned > Size && Aligned <= ToSize) {
255 Elems.push_back(llvm::IntegerType::get(Context, Aligned - Size));
256 Size = Aligned;
257 }
258
259 // Add whole 64-bit words.
260 while (Size + 64 <= ToSize) {
261 Elems.push_back(llvm::Type::getInt64Ty(Context));
262 Size += 64;
263 }
264
265 // Final in-word padding.
266 if (Size < ToSize) {
267 Elems.push_back(llvm::IntegerType::get(Context, ToSize - Size));
268 Size = ToSize;
269 }
270 }
271
272 // Add a floating point element at Offset.
273 void addFloat(uint64_t Offset, llvm::Type *Ty, unsigned Bits) {
274 // Varargs are treated as integers.
275 if (IsVarArg)
276 return;
277 // Unaligned floats are treated as integers.
278 if (Offset % Bits)
279 return;
280 // Floats in packed structs and in unions are treated as integers.
281 if (llvm::any_of(IntRanges, [Offset](const auto &R) {
282 return R.first <= Offset && Offset < R.second;
283 }))
284 return;
285 // The InReg flag is only required if there are any floats < 64 bits.
286 if (Bits < 64)
287 InReg = true;
288 pad(Offset);
289 Elems.push_back(Ty);
290 Size = Offset + Bits;
291 }
292
293 // Add a struct type to the coercion type, starting at Offset (in 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:
301 addStruct(ElemOffset, cast<llvm::StructType>(ElemTy));
302 break;
303 case llvm::Type::FloatTyID:
304 addFloat(ElemOffset, ElemTy, 32);
305 break;
306 case llvm::Type::DoubleTyID:
307 addFloat(ElemOffset, ElemTy, 64);
308 break;
309 case llvm::Type::FP128TyID:
310 addFloat(ElemOffset, ElemTy, 128);
311 break;
312 case llvm::Type::PointerTyID:
313 if (ElemOffset % 64 == 0) {
314 pad(ElemOffset);
315 Elems.push_back(ElemTy);
316 Size += 64;
317 }
318 break;
319 default:
320 break;
321 }
322 }
323 }
324
325 // Check if Ty is a usable substitute for the coercion type.
326 bool isUsableType(llvm::StructType *Ty) const {
327 return llvm::ArrayRef(Elems) == Ty->elements();
328 }
329
330 // Get the coercion type as a literal struct type.
331 llvm::Type *getType() const {
332 if (Elems.size() == 1)
333 return Elems.front();
334 else
335 return llvm::StructType::get(Context, Elems);
336 }
337 };
338};
339} // end anonymous namespace
340
341/// Return true if GCC treats \p FD as a packed field (DECL_PACKED). That is the
342/// case when the field or its record has the packed attribute.
343static bool isPackedField(const ASTContext &Ctx, const FieldDecl *FD) {
344 // The packed attribute has no effect on a byte-aligned non-bit-field.
345 if (!FD->isBitField() &&
346 Ctx.getTypeAlign(FD->getType()) <= Ctx.getCharWidth())
347 return false;
348 if (FD->hasAttr<PackedAttr>())
349 return true;
350 if (!FD->getParent()->hasAttr<PackedAttr>())
351 return false;
352 // A packed class does not pack a field of a non-POD class type, unless that
353 // class is packed itself.
354 const auto *FieldClass =
356 return !FieldClass || FieldClass->isPOD() ||
357 FieldClass->hasAttr<PackedAttr>();
358}
359
360/// Collect the bit ranges of the fields of \p RD, placed at bit \p Offset, that
361/// GCC never passes or returns in floating-point registers.
362///
363/// This follows GCC's traverse_record_type(): a struct with a packed field is
364/// passed in integer registers, and so is everything nested in it, including
365/// its base classes. A union is always passed in integer registers.
366static void
367collectIntRanges(const ASTContext &Ctx, const RecordDecl *RD, uint64_t Offset,
368 bool Packed,
369 SmallVectorImpl<std::pair<uint64_t, uint64_t>> &Ranges) {
370 const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
371
372 if (RD->isUnion()) {
373 Ranges.emplace_back(Offset, Offset + Ctx.toBits(Layout.getSize()));
374 return;
375 }
376
377 if (!Packed)
378 Packed = llvm::any_of(RD->fields(), [&Ctx](const FieldDecl *FD) {
379 return isPackedField(Ctx, FD);
380 });
381
382 // GCC represents base classes as fields, so they are handled the same way.
383 // Virtual bases are not considered: such a class is never passed in
384 // registers.
385 if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
386 for (const CXXBaseSpecifier &Base : CXXRD->bases()) {
387 if (Base.isVirtual())
388 continue;
389 const auto *BaseRD = Base.getType()->castAsCXXRecordDecl();
390 collectIntRanges(Ctx, BaseRD,
391 Offset + Ctx.toBits(Layout.getBaseClassOffset(BaseRD)),
392 Packed, Ranges);
393 }
394 }
395
396 for (const FieldDecl *FD : RD->fields()) {
397 uint64_t FieldOffset = Offset + Layout.getFieldOffset(FD->getFieldIndex());
398 if (const auto *FieldRD =
400 collectIntRanges(Ctx, FieldRD->getDefinitionOrSelf(), FieldOffset, Packed,
401 Ranges);
402 continue;
403 }
404 // Bit-fields are never floating point.
405 if (Packed && !FD->isBitField())
406 Ranges.emplace_back(FieldOffset,
407 FieldOffset + Ctx.getTypeSize(FD->getType()));
408 }
409}
410
411ABIArgInfo SparcV9ABIInfo::classifyType(QualType Ty, unsigned SizeLimit,
412 unsigned &RegOffset,
413 bool IsVarArg) const {
414 if (Ty->isVoidType())
415 return ABIArgInfo::getIgnore();
416
417 auto &Context = getContext();
418 auto &VMContext = getVMContext();
419
420 // FIXME: the GCC-style `aligned` attribute on typedefs is not taken into
421 // account here, because the canonicalized type no longer has that
422 // information. Hence such over-aligned typedefs are not ABI-compatible with
423 // GCC.
424 //
425 // This is different from the `aligned` attribute on structs or fields, which
426 // is taken into account.
427 unsigned Alignment = Context.getTypeAlign(Ty);
428 uint64_t Size = Context.getTypeSize(Ty);
429
430 // Anything too big to fit in registers is passed with an explicit indirect
431 // pointer / sret pointer.
432 if (Size > SizeLimit) {
433 RegOffset += 1;
434 return getNaturalAlignIndirect(
435 Ty, /*AddrSpace=*/getDataLayout().getAllocaAddrSpace(),
436 /*ByVal=*/false);
437 }
438
439 // An argument that is passed in registers but has an alignment higher than 8
440 // bytes must be register-aligned. Insert a dummy i64 argument to fill the
441 // odd-numbered register.
442 //
443 // See SCD 2.4.1, pages 3P-11 and 3P-12.
444 llvm::Type *Padding = (Alignment > 64 && RegOffset % 2 != 0)
445 ? llvm::Type::getInt64Ty(VMContext)
446 : nullptr;
447 unsigned PaddingSlots = Padding ? 1 : 0;
448 unsigned SizeSlots = llvm::divideCeil(Size, 64);
449
450 // Treat an enum type as its underlying type.
451 if (const auto *ED = Ty->getAsEnumDecl())
452 Ty = ED->getIntegerType();
453
454 // Integer types smaller than a register are extended.
455 if (Size < 64 && Ty->isIntegerType()) {
456 RegOffset += PaddingSlots + SizeSlots;
457 return ABIArgInfo::getExtend(Ty, /*T=*/nullptr, Padding);
458 }
459
460 if (const auto *EIT = Ty->getAs<BitIntType>())
461 if (EIT->getNumBits() < 64) {
462 RegOffset += PaddingSlots + SizeSlots;
463 return ABIArgInfo::getExtend(Ty, /*T=*/nullptr, Padding);
464 }
465
466 // When being GCC-compatible, cast a complex char, short and int to an integer
467 // type of the right size to get the correct scalar-like behavior. Other
468 // complex types fall through and are treated like a struct containing the
469 // real and imaginary parts, e.g. `{ i64, i64 }` or `{ double, double }`.
470 if (IsComplexGnuABI) {
471 const auto *CT = Ty->getAs<ComplexType>();
472 if (CT && CT->getElementType()->isIntegerType()) {
473 uint64_t ElementTypeSize = Context.getTypeSize(CT->getElementType());
474 if (ElementTypeSize <= 32) {
475 RegOffset += 1;
477 llvm::IntegerType::get(VMContext, 2 * ElementTypeSize),
478 /*Offset=*/0, Padding);
479 }
480 }
481 }
482
483 // Other non-aggregates go in registers.
484 if (!isAggregateTypeForABI(Ty)) {
485 RegOffset += PaddingSlots + SizeSlots;
486 return ABIArgInfo::getDirect(/*T=*/nullptr, /*Offset=*/0, Padding);
487 }
488
489 // If a C++ object has either a non-trivial copy constructor or a non-trivial
490 // destructor, it is passed with an explicit indirect pointer / sret pointer.
491 if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI())) {
492 RegOffset += 1;
493 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
495 }
496
497 // This is a small aggregate type that should be passed in registers.
498 // Build a coercion type from the LLVM struct type.
499 llvm::StructType *StrTy = dyn_cast<llvm::StructType>(CGT.ConvertType(Ty));
500 if (!StrTy) {
501 RegOffset += PaddingSlots + SizeSlots;
502 return ABIArgInfo::getDirect(/*T=*/nullptr, /*Offset=*/0, Padding);
503 }
504
505 CoerceBuilder CB(VMContext, getDataLayout(), IsVarArg);
506 if (IsPackedUnionGnuABI)
507 if (const auto *RD = Ty.getAtomicUnqualifiedType()->getAsRecordDecl())
508 collectIntRanges(Context, RD->getDefinitionOrSelf(), /*Offset=*/0,
509 /*Packed=*/false, CB.IntRanges);
510 CB.addStruct(0, StrTy);
511 // All structs, even empty ones, should take up a register argument slot,
512 // so pin the minimum struct size to one bit.
513 CB.pad(llvm::alignTo(
514 std::max(CB.DL.getTypeSizeInBits(StrTy).getKnownMinValue(), uint64_t(1)),
515 64));
516 RegOffset += PaddingSlots + CB.Size / 64;
517
518 // Try to use the original type for coercion.
519 llvm::Type *CoerceTy = CB.isUsableType(StrTy) ? StrTy : CB.getType();
520
521 ABIArgInfo AAI = ABIArgInfo::getDirect(CoerceTy, 0, Padding);
522 AAI.setInReg(CB.InReg);
523 return AAI;
524}
525
526RValue SparcV9ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
527 QualType Ty, AggValueSlot Slot) const {
528 CharUnits SlotSize = CharUnits::fromQuantity(8);
529 auto TInfo = getContext().getTypeInfoInChars(Ty);
530
531 // Zero-sized types have a width of one byte for parameter passing purposes.
532 TInfo.Width = std::max(TInfo.Width, CharUnits::fromQuantity(1));
533
534 // Small _Complex types are right-adjusted, but small aggregates are not.
535 bool ForceRightAdjust = Ty->isAnyComplexType();
536
537 // Arguments bigger than 2*SlotSize bytes are passed indirectly.
538 return emitVoidPtrVAArg(CGF, VAListAddr, Ty,
539 /*IsIndirect=*/TInfo.Width > 2 * SlotSize, TInfo,
540 SlotSize,
541 /*AllowHigherAlign=*/true, Slot, ForceRightAdjust);
542}
543
544void SparcV9ABIInfo::computeInfo(CGFunctionInfo &FI) const {
545 unsigned RetOffset = 0;
546 ABIArgInfo RetType =
547 classifyType(FI.getReturnType(), 32 * 8, RetOffset, /*IsVarArg=*/false);
548 FI.getReturnInfo() = RetType;
549
550 // Indirect returns will have its pointer passed as an argument.
551 unsigned ArgOffset = RetType.isIndirect() ? RetOffset : 0;
552 for (auto [ArgNo, I] : llvm::enumerate(FI.arguments())) {
553 bool IsVarArg = ArgNo >= FI.getNumRequiredArgs();
554 I.info = classifyType(I.type, 16 * 8, ArgOffset, IsVarArg);
555 }
556}
557
558namespace {
559class SparcV9TargetCodeGenInfo : public TargetCodeGenInfo {
560public:
561 SparcV9TargetCodeGenInfo(CodeGenTypes &CGT)
562 : TargetCodeGenInfo(std::make_unique<SparcV9ABIInfo>(CGT)) {}
563
564 int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
565 return 14;
566 }
567
568 bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
569 llvm::Value *Address) const override;
570
571 llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF,
572 llvm::Value *Address) const override {
573 return CGF.Builder.CreateGEP(CGF.Int8Ty, Address,
574 llvm::ConstantInt::get(CGF.Int32Ty, 8));
575 }
576
577 llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
578 llvm::Value *Address) const override {
579 return CGF.Builder.CreateGEP(CGF.Int8Ty, Address,
580 llvm::ConstantInt::get(CGF.Int32Ty, -8));
581 }
582};
583} // end anonymous namespace
584
585bool
586SparcV9TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
587 llvm::Value *Address) const {
588 // This is calculated from the LLVM and GCC tables and verified
589 // against gcc output. AFAIK all ABIs use the same encoding.
590
591 CodeGen::CGBuilderTy &Builder = CGF.Builder;
592
593 llvm::IntegerType *i8 = CGF.Int8Ty;
594 llvm::Value *Four8 = llvm::ConstantInt::get(i8, 4);
595 llvm::Value *Eight8 = llvm::ConstantInt::get(i8, 8);
596
597 // 0-31: the 8-byte general-purpose registers
598 AssignToArrayRange(Builder, Address, Eight8, 0, 31);
599
600 // 32-63: f0-31, the 4-byte floating-point registers
601 AssignToArrayRange(Builder, Address, Four8, 32, 63);
602
603 // Y = 64
604 // PSR = 65
605 // WIM = 66
606 // TBR = 67
607 // PC = 68
608 // NPC = 69
609 // FSR = 70
610 // CSR = 71
611 AssignToArrayRange(Builder, Address, Eight8, 64, 71);
612
613 // 72-87: d0-15, the 8-byte floating-point registers
614 AssignToArrayRange(Builder, Address, Eight8, 72, 87);
615
616 return false;
617}
618
619std::unique_ptr<TargetCodeGenInfo>
621 return std::make_unique<SparcV8TargetCodeGenInfo>(CGM.getTypes());
622}
623
624std::unique_ptr<TargetCodeGenInfo>
626 return std::make_unique<SparcV9TargetCodeGenInfo>(CGM.getTypes());
627}
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...
Definition Sparc.cpp:367
static bool isPackedField(const ASTContext &Ctx, const FieldDecl *FD)
Return true if GCC treats FD as a packed field (DECL_PACKED).
Definition Sparc.cpp:343
TokenType getType() const
Returns the token's type, e.g.
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 ...
Definition ASTContext.h:245
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.
Definition DeclCXX.h:146
bool isPOD() const
Whether this class is a POD-type (C++ [class]p4)
Definition DeclCXX.h:1181
static constexpr CharUnits fromQuantity(QuantityType Quantity)
Construct a CharUnits quantity from a raw integer type.
Definition CharUnits.h:58
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="")
Definition CGBuilder.h:312
RecordArgABI
Specify how one should pass an argument of a record type.
Definition CGCXXABI.h:150
@ RAA_DirectInMemory
Pass it on the stack using its defined layout.
Definition CGCXXABI.h:158
CanQualType getReturnType() const
MutableArrayRef< ArgInfo > arguments()
const CGFunctionInfo * CurFnInfo
This class organizes the cross-function state that is used while generating LLVM code.
DefaultABIInfo - The default implementation for ABI specific details.
Definition ABIInfoImpl.h:21
ABIArgInfo classifyArgumentType(QualType RetTy) const
ABIArgInfo classifyReturnType(QualType RetTy) const
Complex values, per C99 6.2.5p11.
Definition TypeBase.h:3363
QualType getElementType() const
Definition TypeBase.h:3373
bool hasAttr() const
Definition DeclBase.h:586
Represents a member of a struct/union/class.
Definition Decl.h:3341
bool isBitField() const
Determines whether this field is a bitfield.
Definition Decl.h:3444
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition Decl.h:3426
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Definition Decl.h:3577
QualType getAtomicUnqualifiedType() const
Remove all qualifiers including _Atomic.
Definition Type.cpp:1853
Represents a struct/union/class.
Definition Decl.h:4506
field_range fields() const
Definition Decl.h:4709
bool isUnion() const
Definition Decl.h:4109
bool isVoidType() const
Definition TypeBase.h:9306
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition Type.h:26
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition Type.h:41
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition TypeBase.h:9354
bool isAnyComplexType() const
Definition TypeBase.h:9052
EnumDecl * getAsEnumDecl() const
Retrieves the EnumDecl this type refers to.
Definition Type.h:53
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9537
QualType getType() const
Definition Decl.h:725
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)
Definition Sparc.cpp:620
std::unique_ptr< TargetCodeGenInfo > createSparcV9TargetCodeGenInfo(CodeGenModule &CGM)
Definition Sparc.cpp:625
constexpr bool isIntegerType(PrimType T)
Definition PrimType.h:55
Top level wrappers for InstallAPI frontend operations.
U cast(CodeGen::Address addr)
Definition Address.h:327
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
#define false
Definition stdbool.h:26
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64