clang 23.0.0git
RISCV.cpp
Go to the documentation of this file.
1//===- RISCV.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 "llvm/IR/IntrinsicsRISCV.h"
12#include "llvm/TargetParser/RISCVTargetParser.h"
13
14using namespace clang;
15using namespace clang::CodeGen;
16
17//===----------------------------------------------------------------------===//
18// RISC-V ABI Implementation
19//===----------------------------------------------------------------------===//
20
21namespace {
22class RISCVABIInfo : public DefaultABIInfo {
23private:
24 // Size of the integer ('x') registers in bits.
25 unsigned XLen;
26 // Size of the floating point ('f') registers in bits. Note that the target
27 // ISA might have a wider FLen than the selected ABI (e.g. an RV32IF target
28 // with soft float ABI has FLen==0).
29 unsigned FLen;
30 const int NumArgGPRs;
31 const int NumArgFPRs;
32 const bool EABI;
33 bool detectFPCCEligibleStructHelper(QualType Ty, CharUnits CurOff,
34 llvm::Type *&Field1Ty,
35 CharUnits &Field1Off,
36 llvm::Type *&Field2Ty,
37 CharUnits &Field2Off) const;
38
39 llvm::Type *detectVLSCCEligibleStruct(QualType Ty, unsigned ABIVLen) const;
40
41public:
42 RISCVABIInfo(CodeGen::CodeGenTypes &CGT, unsigned XLen, unsigned FLen,
43 bool EABI)
44 : DefaultABIInfo(CGT), XLen(XLen), FLen(FLen), NumArgGPRs(EABI ? 6 : 8),
45 NumArgFPRs(FLen != 0 ? 8 : 0), EABI(EABI) {}
46
47 // DefaultABIInfo's classifyReturnType and classifyArgumentType are
48 // non-virtual, but computeInfo is virtual, so we overload it.
49 void computeInfo(CGFunctionInfo &FI) const override;
50
51 ABIArgInfo classifyArgumentType(QualType Ty, bool IsFixed, int &ArgGPRsLeft,
52 int &ArgFPRsLeft, unsigned ABIVLen) const;
53 ABIArgInfo classifyReturnType(QualType RetTy, unsigned ABIVLen) const;
54
55 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
56 AggValueSlot Slot) const override;
57
58 ABIArgInfo extendType(QualType Ty, llvm::Type *CoerceTy = nullptr) const;
59
60 bool detectFPCCEligibleStruct(QualType Ty, llvm::Type *&Field1Ty,
61 CharUnits &Field1Off, llvm::Type *&Field2Ty,
62 CharUnits &Field2Off, int &NeededArgGPRs,
63 int &NeededArgFPRs) const;
64 ABIArgInfo coerceAndExpandFPCCEligibleStruct(llvm::Type *Field1Ty,
65 CharUnits Field1Off,
66 llvm::Type *Field2Ty,
67 CharUnits Field2Off) const;
68
69 ABIArgInfo coerceVLSVector(QualType Ty, unsigned ABIVLen = 0) const;
70 // Some unsupported type e.g. bf16 without zvfbfmin or zvfbfa, should be
71 // passed as same size i8 type. This function check and return the appropriate
72 // fixed vector type.
73 llvm::FixedVectorType *
74 getVLSCCCompatibleType(llvm::FixedVectorType *FixedVecTy) const;
75
77 void appendAttributeMangling(TargetClonesAttr *Attr, unsigned Index,
78 raw_ostream &Out) const override;
79 void appendAttributeMangling(StringRef AttrStr,
80 raw_ostream &Out) const override;
81 llvm::Value *createCoercedLoad(Address SrcAddr, const ABIArgInfo &AI,
82 CodeGenFunction &CGF) const override;
83 void createCoercedStore(llvm::Value *Val, Address DstAddr,
84 const ABIArgInfo &AI, bool DestIsVolatile,
85 CodeGenFunction &CGF) const override;
86};
87} // end anonymous namespace
88
89void RISCVABIInfo::appendAttributeMangling(TargetClonesAttr *Attr,
90 unsigned Index,
91 raw_ostream &Out) const {
92 appendAttributeMangling(Attr->getFeatureStr(Index), Out);
93}
94
95void RISCVABIInfo::appendAttributeMangling(StringRef AttrStr,
96 raw_ostream &Out) const {
97 if (AttrStr == "default") {
98 Out << ".default";
99 return;
100 }
101
102 Out << '.';
103
104 SmallVector<StringRef, 8> Attrs;
105 AttrStr.split(Attrs, ';');
106
107 // Only consider the arch string.
108 StringRef ArchStr;
109 for (auto &Attr : Attrs) {
110 if (Attr.starts_with("arch="))
111 ArchStr = Attr;
112 }
113
114 // Extract features string.
115 SmallVector<StringRef, 8> Features;
116 ArchStr.consume_front("arch=");
117 ArchStr.split(Features, ',');
118
119 llvm::stable_sort(Features);
120
121 for (auto Feat : Features) {
122 Feat.consume_front("+");
123 Out << "_" << Feat;
124 }
125}
126
127void RISCVABIInfo::computeInfo(CGFunctionInfo &FI) const {
128 unsigned ABIVLen;
129 switch (FI.getExtInfo().getCC()) {
130 default:
131 ABIVLen = 0;
132 break;
133#define CC_VLS_CASE(ABI_VLEN) \
134 case CallingConv::CC_RISCVVLSCall_##ABI_VLEN: \
135 ABIVLen = ABI_VLEN; \
136 break;
137 CC_VLS_CASE(32)
138 CC_VLS_CASE(64)
139 CC_VLS_CASE(128)
140 CC_VLS_CASE(256)
141 CC_VLS_CASE(512)
142 CC_VLS_CASE(1024)
143 CC_VLS_CASE(2048)
144 CC_VLS_CASE(4096)
145 CC_VLS_CASE(8192)
146 CC_VLS_CASE(16384)
147 CC_VLS_CASE(32768)
148 CC_VLS_CASE(65536)
149#undef CC_VLS_CASE
150 }
151 QualType RetTy = FI.getReturnType();
152 if (!getCXXABI().classifyReturnType(FI))
153 FI.getReturnInfo() = classifyReturnType(RetTy, ABIVLen);
154
155 // IsRetIndirect is true if classifyArgumentType indicated the value should
156 // be passed indirect, or if the type size is a scalar greater than 2*XLen
157 // and not a complex type with elements <= FLen. e.g. fp128 is passed direct
158 // in LLVM IR, relying on the backend lowering code to rewrite the argument
159 // list and pass indirectly on RV32.
160 bool IsRetIndirect = FI.getReturnInfo().getKind() == ABIArgInfo::Indirect;
161 if (!IsRetIndirect && RetTy->isScalarType() &&
162 getContext().getTypeSize(RetTy) > (2 * XLen)) {
163 if (RetTy->isComplexType() && FLen) {
164 QualType EltTy = RetTy->castAs<ComplexType>()->getElementType();
165 IsRetIndirect = getContext().getTypeSize(EltTy) > FLen;
166 } else {
167 // This is a normal scalar > 2*XLen, such as fp128 on RV32.
168 IsRetIndirect = true;
169 }
170 }
171
172 int ArgGPRsLeft = IsRetIndirect ? NumArgGPRs - 1 : NumArgGPRs;
173 int ArgFPRsLeft = NumArgFPRs;
174 int NumFixedArgs = FI.getNumRequiredArgs();
175
176 int ArgNum = 0;
177 for (auto &ArgInfo : FI.arguments()) {
178 bool IsFixed = ArgNum < NumFixedArgs;
179 ArgInfo.info = classifyArgumentType(ArgInfo.type, IsFixed, ArgGPRsLeft,
180 ArgFPRsLeft, ABIVLen);
181 ArgNum++;
182 }
183}
184
185// Returns true if the struct is a potential candidate for the floating point
186// calling convention. If this function returns true, the caller is
187// responsible for checking that if there is only a single field then that
188// field is a float.
189bool RISCVABIInfo::detectFPCCEligibleStructHelper(QualType Ty, CharUnits CurOff,
190 llvm::Type *&Field1Ty,
191 CharUnits &Field1Off,
192 llvm::Type *&Field2Ty,
193 CharUnits &Field2Off) const {
194 bool IsInt = Ty->isIntegralOrEnumerationType();
195 bool IsFloat = Ty->isRealFloatingType();
196
197 if (IsInt || IsFloat) {
198 uint64_t Size = getContext().getTypeSize(Ty);
199 if (IsInt && Size > XLen)
200 return false;
201 // Can't be eligible if larger than the FP registers. Handling of half
202 // precision values has been specified in the ABI, so don't block those.
203 if (IsFloat && Size > FLen)
204 return false;
205 // Can't be eligible if an integer type was already found (int+int pairs
206 // are not eligible).
207 if (IsInt && Field1Ty && Field1Ty->isIntegerTy())
208 return false;
209 if (!Field1Ty) {
210 Field1Ty = CGT.ConvertType(Ty);
211 Field1Off = CurOff;
212 return true;
213 }
214 if (!Field2Ty) {
215 Field2Ty = CGT.ConvertType(Ty);
216 Field2Off = CurOff;
217 return true;
218 }
219 return false;
220 }
221
222 if (auto CTy = Ty->getAs<ComplexType>()) {
223 if (Field1Ty)
224 return false;
225 QualType EltTy = CTy->getElementType();
226 if (getContext().getTypeSize(EltTy) > FLen)
227 return false;
228 Field1Ty = CGT.ConvertType(EltTy);
229 Field1Off = CurOff;
230 Field2Ty = Field1Ty;
231 Field2Off = Field1Off + getContext().getTypeSizeInChars(EltTy);
232 return true;
233 }
234
235 if (const ConstantArrayType *ATy = getContext().getAsConstantArrayType(Ty)) {
236 uint64_t ArraySize = ATy->getZExtSize();
237 QualType EltTy = ATy->getElementType();
238 // Non-zero-length arrays of empty records make the struct ineligible for
239 // the FP calling convention in C++.
240 if (const auto *RTy = EltTy->getAsCanonical<RecordType>()) {
241 if (ArraySize != 0 && isa<CXXRecordDecl>(RTy->getDecl()) &&
242 isEmptyRecord(getContext(), EltTy, true, true))
243 return false;
244 }
245 CharUnits EltSize = getContext().getTypeSizeInChars(EltTy);
246 for (uint64_t i = 0; i < ArraySize; ++i) {
247 bool Ret = detectFPCCEligibleStructHelper(EltTy, CurOff, Field1Ty,
248 Field1Off, Field2Ty, Field2Off);
249 if (!Ret)
250 return false;
251 CurOff += EltSize;
252 }
253 return true;
254 }
255
256 if (const auto *RTy = Ty->getAsCanonical<RecordType>()) {
257 // Structures with either a non-trivial destructor or a non-trivial
258 // copy constructor are not eligible for the FP calling convention.
259 if (getRecordArgABI(Ty, CGT.getCXXABI()))
260 return false;
261 if (isEmptyRecord(getContext(), Ty, true, true))
262 return true;
263 const RecordDecl *RD = RTy->getDecl()->getDefinitionOrSelf();
264 // Unions aren't eligible unless they're empty (which is caught above).
265 if (RD->isUnion())
266 return false;
267 const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
268 // If this is a C++ record, check the bases first.
269 if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
270 for (const CXXBaseSpecifier &B : CXXRD->bases()) {
271 const auto *BDecl = B.getType()->castAsCXXRecordDecl();
272 CharUnits BaseOff = Layout.getBaseClassOffset(BDecl);
273 bool Ret = detectFPCCEligibleStructHelper(B.getType(), CurOff + BaseOff,
274 Field1Ty, Field1Off, Field2Ty,
275 Field2Off);
276 if (!Ret)
277 return false;
278 }
279 }
280 int ZeroWidthBitFieldCount = 0;
281 for (const FieldDecl *FD : RD->fields()) {
282 uint64_t FieldOffInBits = Layout.getFieldOffset(FD->getFieldIndex());
283 QualType QTy = FD->getType();
284 if (FD->isBitField()) {
285 unsigned BitWidth = FD->getBitWidthValue();
286 // Allow a bitfield with a type greater than XLen as long as the
287 // bitwidth is XLen or less.
288 if (getContext().getTypeSize(QTy) > XLen && BitWidth <= XLen)
289 QTy = getContext().getIntTypeForBitwidth(XLen, false);
290 // Trim type to bitwidth if possible
291 else if (getContext().getTypeSize(QTy) > BitWidth) {
292 bool IsSigned =
293 FD->getType().getTypePtr()->hasSignedIntegerRepresentation();
294 unsigned Bits = std::max(8U, (unsigned)llvm::PowerOf2Ceil(BitWidth));
295 QTy = getContext().getIntTypeForBitwidth(Bits, IsSigned);
296 }
297 if (BitWidth == 0) {
298 ZeroWidthBitFieldCount++;
299 continue;
300 }
301 }
302
303 bool Ret = detectFPCCEligibleStructHelper(
304 QTy, CurOff + getContext().toCharUnitsFromBits(FieldOffInBits),
305 Field1Ty, Field1Off, Field2Ty, Field2Off);
306 if (!Ret)
307 return false;
308
309 // As a quirk of the ABI, zero-width bitfields aren't ignored for fp+fp
310 // or int+fp structs, but are ignored for a struct with an fp field and
311 // any number of zero-width bitfields.
312 if (Field2Ty && ZeroWidthBitFieldCount > 0)
313 return false;
314 }
315 return Field1Ty != nullptr;
316 }
317
318 return false;
319}
320
321// Determine if a struct is eligible for passing according to the floating
322// point calling convention (i.e., when flattened it contains a single fp
323// value, fp+fp, or int+fp of appropriate size). If so, NeededArgFPRs and
324// NeededArgGPRs are incremented appropriately.
325bool RISCVABIInfo::detectFPCCEligibleStruct(QualType Ty, llvm::Type *&Field1Ty,
326 CharUnits &Field1Off,
327 llvm::Type *&Field2Ty,
328 CharUnits &Field2Off,
329 int &NeededArgGPRs,
330 int &NeededArgFPRs) const {
331 Field1Ty = nullptr;
332 Field2Ty = nullptr;
333 NeededArgGPRs = 0;
334 NeededArgFPRs = 0;
335 bool IsCandidate = detectFPCCEligibleStructHelper(
336 Ty, CharUnits::Zero(), Field1Ty, Field1Off, Field2Ty, Field2Off);
337 if (!Field1Ty)
338 return false;
339 // Not really a candidate if we have a single int but no float.
340 if (Field1Ty && !Field2Ty && !Field1Ty->isFloatingPointTy())
341 return false;
342 if (!IsCandidate)
343 return false;
344 if (Field1Ty && Field1Ty->isFloatingPointTy())
345 NeededArgFPRs++;
346 else if (Field1Ty)
347 NeededArgGPRs++;
348 if (Field2Ty && Field2Ty->isFloatingPointTy())
349 NeededArgFPRs++;
350 else if (Field2Ty)
351 NeededArgGPRs++;
352 return true;
353}
354
355// Call getCoerceAndExpand for the two-element flattened struct described by
356// Field1Ty, Field1Off, Field2Ty, Field2Off. This method will create an
357// appropriate coerceToType and unpaddedCoerceToType.
358ABIArgInfo RISCVABIInfo::coerceAndExpandFPCCEligibleStruct(
359 llvm::Type *Field1Ty, CharUnits Field1Off, llvm::Type *Field2Ty,
360 CharUnits Field2Off) const {
361 SmallVector<llvm::Type *, 3> CoerceElts;
362 SmallVector<llvm::Type *, 2> UnpaddedCoerceElts;
363 if (!Field1Off.isZero())
364 CoerceElts.push_back(llvm::ArrayType::get(
365 llvm::Type::getInt8Ty(getVMContext()), Field1Off.getQuantity()));
366
367 CoerceElts.push_back(Field1Ty);
368 UnpaddedCoerceElts.push_back(Field1Ty);
369
370 if (!Field2Ty) {
372 llvm::StructType::get(getVMContext(), CoerceElts, !Field1Off.isZero()),
373 UnpaddedCoerceElts[0]);
374 }
375
376 CharUnits Field2Align =
377 CharUnits::fromQuantity(getDataLayout().getABITypeAlign(Field2Ty));
378 CharUnits Field1End = Field1Off +
379 CharUnits::fromQuantity(getDataLayout().getTypeStoreSize(Field1Ty));
380 CharUnits Field2OffNoPadNoPack = Field1End.alignTo(Field2Align);
381
382 CharUnits Padding = CharUnits::Zero();
383 if (Field2Off > Field2OffNoPadNoPack)
384 Padding = Field2Off - Field2OffNoPadNoPack;
385 else if (Field2Off != Field2Align && Field2Off > Field1End)
386 Padding = Field2Off - Field1End;
387
388 bool IsPacked = !Field2Off.isMultipleOf(Field2Align);
389
390 if (!Padding.isZero())
391 CoerceElts.push_back(llvm::ArrayType::get(
392 llvm::Type::getInt8Ty(getVMContext()), Padding.getQuantity()));
393
394 CoerceElts.push_back(Field2Ty);
395 UnpaddedCoerceElts.push_back(Field2Ty);
396
397 auto CoerceToType =
398 llvm::StructType::get(getVMContext(), CoerceElts, IsPacked);
399 auto UnpaddedCoerceToType =
400 llvm::StructType::get(getVMContext(), UnpaddedCoerceElts, IsPacked);
401
402 return ABIArgInfo::getCoerceAndExpand(CoerceToType, UnpaddedCoerceToType);
403}
404
405llvm::Type *RISCVABIInfo::detectVLSCCEligibleStruct(QualType Ty,
406 unsigned ABIVLen) const {
407 // No riscv_vls_cc attribute.
408 if (ABIVLen == 0)
409 return nullptr;
410
411 // Legal struct for VLS calling convention should fulfill following rules:
412 // 1. Struct element should be either "homogeneous fixed-length vectors" or "a
413 // fixed-length vector array".
414 // 2. Number of struct elements or array elements should be greater or equal
415 // to 1 and less or equal to 8
416 // 3. Total number of vector registers needed should not exceed 8.
417 //
418 // Examples: Assume ABI_VLEN = 128.
419 // These are legal structs:
420 // a. Structs with 1~8 "same" fixed-length vectors, e.g.
421 // struct {
422 // __attribute__((vector_size(16))) int a;
423 // __attribute__((vector_size(16))) int b;
424 // }
425 //
426 // b. Structs with "single" fixed-length vector array with lengh 1~8, e.g.
427 // struct {
428 // __attribute__((vector_size(16))) int a[3];
429 // }
430 // These are illegal structs:
431 // a. Structs with 9 fixed-length vectors, e.g.
432 // struct {
433 // __attribute__((vector_size(16))) int a;
434 // __attribute__((vector_size(16))) int b;
435 // __attribute__((vector_size(16))) int c;
436 // __attribute__((vector_size(16))) int d;
437 // __attribute__((vector_size(16))) int e;
438 // __attribute__((vector_size(16))) int f;
439 // __attribute__((vector_size(16))) int g;
440 // __attribute__((vector_size(16))) int h;
441 // __attribute__((vector_size(16))) int i;
442 // }
443 //
444 // b. Structs with "multiple" fixed-length vector array, e.g.
445 // struct {
446 // __attribute__((vector_size(16))) int a[2];
447 // __attribute__((vector_size(16))) int b[2];
448 // }
449 //
450 // c. Vector registers needed exceeds 8, e.g.
451 // struct {
452 // // Registers needed for single fixed-length element:
453 // // 64 * 8 / ABI_VLEN = 4
454 // __attribute__((vector_size(64))) int a;
455 // __attribute__((vector_size(64))) int b;
456 // __attribute__((vector_size(64))) int c;
457 // __attribute__((vector_size(64))) int d;
458 // }
459 //
460 // 1. Struct of 1 fixed-length vector is passed as a scalable vector.
461 // 2. Struct of >1 fixed-length vectors are passed as vector tuple.
462 // 3. Struct of an array with 1 element of fixed-length vectors is passed as a
463 // scalable vector.
464 // 4. Struct of an array with >1 elements of fixed-length vectors is passed as
465 // vector tuple.
466 // 5. Otherwise, pass the struct indirectly.
467
468 llvm::StructType *STy = dyn_cast<llvm::StructType>(CGT.ConvertType(Ty));
469 if (!STy)
470 return nullptr;
471
472 unsigned NumElts = STy->getStructNumElements();
473 if (NumElts > 8)
474 return nullptr;
475
476 auto *FirstEltTy = STy->getElementType(0);
477 if (!STy->containsHomogeneousTypes())
478 return nullptr;
479
480 if (auto *ArrayTy = dyn_cast<llvm::ArrayType>(FirstEltTy)) {
481 // Only struct of single array is accepted
482 if (NumElts != 1)
483 return nullptr;
484 FirstEltTy = ArrayTy->getArrayElementType();
485 NumElts = ArrayTy->getNumElements();
486 }
487
488 auto *FixedVecTy = dyn_cast<llvm::FixedVectorType>(FirstEltTy);
489 if (!FixedVecTy)
490 return nullptr;
491
492 // Check registers needed <= 8.
493 if (NumElts * llvm::divideCeil(
494 FixedVecTy->getNumElements() *
495 FixedVecTy->getElementType()->getScalarSizeInBits(),
496 ABIVLen) >
497 8)
498 return nullptr;
499
500 // Turn them into scalable vector type or vector tuple type if legal.
501 if (NumElts == 1) {
502 // Handle single fixed-length vector.
503 llvm::FixedVectorType *VLSTy = getVLSCCCompatibleType(FixedVecTy);
504 return llvm::ScalableVectorType::get(
505 VLSTy->getElementType(),
506 llvm::divideCeil(VLSTy->getNumElements() * llvm::RISCV::RVVBitsPerBlock,
507 ABIVLen));
508 }
509
510 // LMUL
511 // = fixed-length vector size / ABIVLen
512 // = 8 * I8EltCount / RVVBitsPerBlock
513 // =>
514 // I8EltCount
515 // = (fixed-length vector size * RVVBitsPerBlock) / (ABIVLen * 8)
516 unsigned I8EltCount =
517 llvm::divideCeil(FixedVecTy->getNumElements() *
518 FixedVecTy->getElementType()->getScalarSizeInBits() *
519 llvm::RISCV::RVVBitsPerBlock,
520 ABIVLen * 8);
521 return llvm::TargetExtType::get(
522 getVMContext(), "riscv.vector.tuple",
523 llvm::ScalableVectorType::get(llvm::Type::getInt8Ty(getVMContext()),
524 I8EltCount),
525 NumElts);
526}
527
528llvm::FixedVectorType *
529RISCVABIInfo::getVLSCCCompatibleType(llvm::FixedVectorType *FixedVecTy) const {
530 llvm::Type *EltType = FixedVecTy->getElementType();
531 const TargetInfo &TI = getContext().getTargetInfo();
532 if ((EltType->isHalfTy() && !TI.hasFeature("zvfhmin")) ||
533 (EltType->isBFloatTy() &&
534 !(TI.hasFeature("zvfbfmin") || TI.hasFeature("experimental-zvfbfa"))) ||
535 (EltType->isFloatTy() && !TI.hasFeature("zve32f")) ||
536 (EltType->isDoubleTy() && !TI.hasFeature("zve64d")) ||
537 (EltType->isIntegerTy(64) && !TI.hasFeature("zve64x")) ||
538 EltType->isIntegerTy(128))
539 return llvm::FixedVectorType::get(llvm::Type::getInt8Ty(getVMContext()),
540 FixedVecTy->getNumElements() *
541 EltType->getScalarSizeInBits() / 8);
542 return FixedVecTy;
543}
544
545// Fixed-length RVV vectors are represented as scalable vectors in function
546// args/return and must be coerced from fixed vectors.
547ABIArgInfo RISCVABIInfo::coerceVLSVector(QualType Ty, unsigned ABIVLen) const {
548 assert(Ty->isVectorType() && "expected vector type!");
549
550 const auto *VT = Ty->castAs<VectorType>();
551 assert(VT->getElementType()->isBuiltinType() && "expected builtin type!");
552
553 auto VScale = getContext().getTargetInfo().getVScaleRange(
554 getContext().getLangOpts(), TargetInfo::ArmStreamingKind::NotStreaming);
555
556 unsigned NumElts = VT->getNumElements();
557 llvm::Type *EltType = llvm::Type::getInt1Ty(getVMContext());
558 switch (VT->getVectorKind()) {
559 case VectorKind::RVVFixedLengthMask_1:
560 break;
561 case VectorKind::RVVFixedLengthMask_2:
562 NumElts *= 2;
563 break;
564 case VectorKind::RVVFixedLengthMask_4:
565 NumElts *= 4;
566 break;
567 case VectorKind::RVVFixedLengthMask:
568 NumElts *= 8;
569 break;
570 default:
571 assert((VT->getVectorKind() == VectorKind::Generic ||
572 VT->getVectorKind() == VectorKind::RVVFixedLengthData) &&
573 "Unexpected vector kind");
574 EltType = CGT.ConvertType(VT->getElementType());
575 }
576
577 llvm::ScalableVectorType *ResType;
578
579 if (ABIVLen == 0) {
580 // The MinNumElts is simplified from equation:
581 // NumElts / VScale =
582 // (EltSize * NumElts / (VScale * RVVBitsPerBlock))
583 // * (RVVBitsPerBlock / EltSize)
584 ResType = llvm::ScalableVectorType::get(EltType, NumElts / VScale->first);
585 } else {
586 // Check registers needed <= 8.
587 if ((EltType->getScalarSizeInBits() * NumElts / ABIVLen) > 8)
588 return getNaturalAlignIndirect(
589 Ty, /*AddrSpace=*/getDataLayout().getAllocaAddrSpace(),
590 /*ByVal=*/false);
591
592 // Generic vector
593 // The number of elements needs to be at least 1.
594 llvm::FixedVectorType *VLSTy =
595 getVLSCCCompatibleType(llvm::FixedVectorType::get(EltType, NumElts));
596 ResType = llvm::ScalableVectorType::get(
597 VLSTy->getElementType(),
598 llvm::divideCeil(VLSTy->getNumElements() * llvm::RISCV::RVVBitsPerBlock,
599 ABIVLen));
600 }
601
602 return ABIArgInfo::getDirect(ResType);
603}
604
605ABIArgInfo RISCVABIInfo::classifyArgumentType(QualType Ty, bool IsFixed,
606 int &ArgGPRsLeft,
607 int &ArgFPRsLeft,
608 unsigned ABIVLen) const {
609 assert(ArgGPRsLeft <= NumArgGPRs && "Arg GPR tracking underflow");
611
612 // Structures with either a non-trivial destructor or a non-trivial
613 // copy constructor are always passed indirectly.
614 if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI())) {
615 if (ArgGPRsLeft)
616 ArgGPRsLeft -= 1;
617 return getNaturalAlignIndirect(
618 Ty, /*AddrSpace=*/getDataLayout().getAllocaAddrSpace(),
619 /*ByVal=*/RAA == CGCXXABI::RAA_DirectInMemory);
620 }
621
622 uint64_t Size = getContext().getTypeSize(Ty);
623
624 // Ignore empty structs/unions whose size is zero. According to the calling
625 // convention empty structs/unions are required to be sized types in C++.
626 if (isEmptyRecord(getContext(), Ty, true) && Size == 0)
627 return ABIArgInfo::getIgnore();
628
629 // Pass floating point values via FPRs if possible.
630 if (IsFixed && Ty->isFloatingType() && !Ty->isComplexType() &&
631 FLen >= Size && ArgFPRsLeft) {
632 ArgFPRsLeft--;
633 return ABIArgInfo::getDirect();
634 }
635
636 // Complex types for the hard float ABI must be passed direct rather than
637 // using CoerceAndExpand.
638 if (IsFixed && Ty->isComplexType() && FLen && ArgFPRsLeft >= 2) {
639 QualType EltTy = Ty->castAs<ComplexType>()->getElementType();
640 if (getContext().getTypeSize(EltTy) <= FLen) {
641 ArgFPRsLeft -= 2;
642 return ABIArgInfo::getDirect();
643 }
644 }
645
646 if (IsFixed && FLen && Ty->isStructureOrClassType()) {
647 llvm::Type *Field1Ty = nullptr;
648 llvm::Type *Field2Ty = nullptr;
649 CharUnits Field1Off = CharUnits::Zero();
650 CharUnits Field2Off = CharUnits::Zero();
651 int NeededArgGPRs = 0;
652 int NeededArgFPRs = 0;
653 bool IsCandidate =
654 detectFPCCEligibleStruct(Ty, Field1Ty, Field1Off, Field2Ty, Field2Off,
655 NeededArgGPRs, NeededArgFPRs);
656 if (IsCandidate && NeededArgGPRs <= ArgGPRsLeft &&
657 NeededArgFPRs <= ArgFPRsLeft) {
658 ArgGPRsLeft -= NeededArgGPRs;
659 ArgFPRsLeft -= NeededArgFPRs;
660 return coerceAndExpandFPCCEligibleStruct(Field1Ty, Field1Off, Field2Ty,
661 Field2Off);
662 }
663 }
664
665 if (IsFixed && Ty->isStructureOrClassType()) {
666 if (llvm::Type *VLSType = detectVLSCCEligibleStruct(Ty, ABIVLen))
667 return ABIArgInfo::getTargetSpecific(VLSType);
668 }
669
670 uint64_t NeededAlign = getContext().getTypeAlign(Ty);
671 // Determine the number of GPRs needed to pass the current argument
672 // according to the ABI. 2*XLen-aligned varargs are passed in "aligned"
673 // register pairs, so may consume 3 registers.
674 // TODO: To be compatible with GCC's behaviors, we don't align registers
675 // currently if we are using ILP32E calling convention. This behavior may be
676 // changed when RV32E/ILP32E is ratified.
677 int NeededArgGPRs = 1;
678 if (!IsFixed && NeededAlign == 2 * XLen)
679 NeededArgGPRs = 2 + (EABI && XLen == 32 ? 0 : (ArgGPRsLeft % 2));
680 else if (Size > XLen && Size <= 2 * XLen)
681 NeededArgGPRs = 2;
682
683 if (NeededArgGPRs > ArgGPRsLeft) {
684 NeededArgGPRs = ArgGPRsLeft;
685 }
686
687 ArgGPRsLeft -= NeededArgGPRs;
688
689 if (!isAggregateTypeForABI(Ty) && !Ty->isVectorType()) {
690 // Treat an enum type as its underlying type.
691 if (const auto *ED = Ty->getAsEnumDecl())
692 Ty = ED->getIntegerType();
693
694 if (const auto *EIT = Ty->getAs<BitIntType>()) {
695
696 if (XLen == 64 && EIT->getNumBits() == 32)
697 return extendType(Ty, CGT.ConvertType(Ty));
698
699 if (EIT->getNumBits() <= 2 * XLen)
700 return ABIArgInfo::getExtend(Ty, CGT.ConvertType(Ty));
701 return getNaturalAlignIndirect(
702 Ty, /*AddrSpace=*/getDataLayout().getAllocaAddrSpace(),
703 /*ByVal=*/false);
704 }
705
706 // All integral types are promoted to XLen width
707 if (Size < XLen && Ty->isIntegralOrEnumerationType())
708 return extendType(Ty, CGT.ConvertType(Ty));
709
710 return ABIArgInfo::getDirect();
711 }
712
713 // TODO: _BitInt is not handled yet in VLS calling convention since _BitInt
714 // ABI is also not merged yet in RISC-V:
715 // https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/419
716 if (const VectorType *VT = Ty->getAs<VectorType>();
717 VT && !VT->getElementType()->isBitIntType()) {
718 if (VT->getVectorKind() == VectorKind::RVVFixedLengthData ||
719 VT->getVectorKind() == VectorKind::RVVFixedLengthMask ||
720 VT->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
721 VT->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
722 VT->getVectorKind() == VectorKind::RVVFixedLengthMask_4)
723 return coerceVLSVector(Ty);
724 if (VT->getVectorKind() == VectorKind::Generic && ABIVLen != 0)
725 // Generic vector without riscv_vls_cc should fall through and pass by
726 // reference.
727 return coerceVLSVector(Ty, ABIVLen);
728 }
729
730 // Aggregates which are <= 2*XLen will be passed in registers if possible,
731 // so coerce to integers.
732 if (Size <= 2 * XLen) {
733 unsigned Alignment = getContext().getTypeAlign(Ty);
734
735 if (Size <= XLen) {
736 // Use the smallest integer type we can.
738 llvm::IntegerType::get(getVMContext(), Size));
739 }
740 // Use 2*XLen if 2*XLen alignment is required.
741 if (Alignment == 2 * XLen)
743 llvm::IntegerType::get(getVMContext(), 2 * XLen));
744 // Use 2-element XLen array if only XLen alignment is required.
746 llvm::ArrayType::get(llvm::IntegerType::get(getVMContext(), XLen), 2));
747 }
748 return getNaturalAlignIndirect(
749 Ty, /*AddrSpace=*/getDataLayout().getAllocaAddrSpace(),
750 /*ByVal=*/false);
751}
752
753ABIArgInfo RISCVABIInfo::classifyReturnType(QualType RetTy,
754 unsigned ABIVLen) const {
755 if (RetTy->isVoidType())
756 return ABIArgInfo::getIgnore();
757
758 int ArgGPRsLeft = 2;
759 int ArgFPRsLeft = FLen ? 2 : 0;
760
761 // The rules for return and argument types are the same, so defer to
762 // classifyArgumentType.
763 return classifyArgumentType(RetTy, /*IsFixed=*/true, ArgGPRsLeft, ArgFPRsLeft,
764 ABIVLen);
765}
766
767RValue RISCVABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
768 QualType Ty, AggValueSlot Slot) const {
769 CharUnits SlotSize = CharUnits::fromQuantity(XLen / 8);
770
771 // Empty records are ignored for parameter passing purposes.
772 if (isEmptyRecord(getContext(), Ty, true))
773 return Slot.asRValue();
774
775 auto TInfo = getContext().getTypeInfoInChars(Ty);
776
777 // TODO: To be compatible with GCC's behaviors, we force arguments with
778 // 2×XLEN-bit alignment and size at most 2×XLEN bits like `long long`,
779 // `unsigned long long` and `double` to have 4-byte alignment. This
780 // behavior may be changed when RV32E/ILP32E is ratified.
781 if (EABI && XLen == 32)
782 TInfo.Align = std::min(TInfo.Align, CharUnits::fromQuantity(4));
783
784 // Arguments bigger than 2*Xlen bytes are passed indirectly.
785 bool IsIndirect = TInfo.Width > 2 * SlotSize;
786
787 return emitVoidPtrVAArg(CGF, VAListAddr, Ty, IsIndirect, TInfo, SlotSize,
788 /*AllowHigherAlign=*/true, Slot);
789}
790
791ABIArgInfo RISCVABIInfo::extendType(QualType Ty, llvm::Type *CoerceTy) const {
792 int TySize = getContext().getTypeSize(Ty);
793 // RV64 ABI requires unsigned 32 bit integers to be sign extended.
794 if (XLen == 64 && Ty->isUnsignedIntegerOrEnumerationType() && TySize == 32)
795 return ABIArgInfo::getSignExtend(Ty, CoerceTy);
796 return ABIArgInfo::getExtend(Ty, CoerceTy);
797}
798
799llvm::Value *RISCVABIInfo::createCoercedLoad(Address Src, const ABIArgInfo &AI,
800 CodeGenFunction &CGF) const {
801 llvm::Type *Ty = AI.getCoerceToType();
802 llvm::Type *SrcTy = Src.getElementType();
803 llvm::StructType *SrcSTy = cast<llvm::StructType>(SrcTy);
804 assert((Ty->isScalableTy() || Ty->isTargetExtTy()) &&
805 "Only scalable vector type and vector tuple type are allowed for load "
806 "type.");
807 if (llvm::TargetExtType *TupTy = dyn_cast<llvm::TargetExtType>(Ty)) {
808 // In RISC-V VLS calling convention, struct of fixed vectors or struct of
809 // array of fixed vector of length >1 might be lowered using vector tuple
810 // type, we consider it as a valid load, e.g.
811 // struct i32x4x2 {
812 // __attribute__((vector_size(16))) int i;
813 // __attribute__((vector_size(16))) int i;
814 // };
815 // or
816 // struct i32x4 {
817 // __attribute__((vector_size(16))) int i[2];
818 // };
819 // is lowered to target("riscv.vector.tuple", <vscale x 8 x i8>, 2)
820 // when ABI_VLEN = 128 bits, please checkout
821 // clang/test/CodeGen/RISCV/riscv-vector-callingconv-llvm-ir.c
822 // for more information.
823 assert(TupTy->getName() == "riscv.vector.tuple");
824 llvm::Type *EltTy = TupTy->getTypeParameter(0);
825 unsigned NumElts = TupTy->getIntParameter(0);
826
827 if (auto *ArrayTy = dyn_cast<llvm::ArrayType>(SrcSTy->getElementType(0)))
828 Src = Src.withElementType(ArrayTy);
829
830 // Perform extract element and load
831 llvm::Value *TupleVal = llvm::PoisonValue::get(Ty);
832 auto *Load = CGF.Builder.CreateLoad(Src);
833 for (unsigned i = 0; i < NumElts; ++i) {
834 // Extract from struct
835 llvm::Value *ExtractFromLoad = CGF.Builder.CreateExtractValue(Load, i);
836 auto *FixedVecTy =
837 cast<llvm::FixedVectorType>(ExtractFromLoad->getType());
838 llvm::FixedVectorType *VLSTy = getVLSCCCompatibleType(FixedVecTy);
839 if (VLSTy != FixedVecTy)
840 ExtractFromLoad = CGF.Builder.CreateBitCast(ExtractFromLoad, VLSTy);
841 // Element in vector tuple type is always i8, so we need to cast back to
842 // it's original element type.
843 EltTy =
844 cast<llvm::ScalableVectorType>(llvm::VectorType::getWithSizeAndScalar(
845 cast<llvm::VectorType>(EltTy), VLSTy));
846 llvm::Value *VectorVal = llvm::PoisonValue::get(EltTy);
847 // Insert to scalable vector
848 VectorVal = CGF.Builder.CreateInsertVector(
849 EltTy, VectorVal, ExtractFromLoad, uint64_t(0), "cast.scalable");
850 // Insert scalable vector to vector tuple
851 llvm::Value *Idx = CGF.Builder.getInt32(i);
852 TupleVal =
853 CGF.Builder.CreateIntrinsic(llvm::Intrinsic::riscv_tuple_insert,
854 {Ty, EltTy}, {TupleVal, VectorVal, Idx});
855 }
856 return TupleVal;
857 }
858
859 // In RISC-V VLS calling convention, struct of fixed vector or struct of
860 // fixed vector array of length 1 might be lowered using scalable vector,
861 // we consider it as a valid load, e.g.
862 // struct i32x4 {
863 // __attribute__((vector_size(16))) int i;
864 // };
865 // or
866 // struct i32x4 {
867 // __attribute__((vector_size(16))) int i[1];
868 // };
869 // is lowered to <vscale x 2 x i32>
870 // when ABI_VLEN = 128 bits, please checkout
871 // clang/test/CodeGen/RISCV/riscv-vector-callingconv-llvm-ir.c
872 // for more information.
873 auto *ScalableDstTy = cast<llvm::ScalableVectorType>(Ty);
874 SrcTy = SrcSTy->getElementType(0);
875 if (auto *ArrayTy = dyn_cast<llvm::ArrayType>(SrcTy))
876 SrcTy = ArrayTy->getElementType();
877 Src = Src.withElementType(SrcTy);
878 auto *FixedSrcTy = cast<llvm::FixedVectorType>(SrcTy);
879 llvm::Value *Load = CGF.Builder.CreateLoad(Src);
880 llvm::FixedVectorType *VLSTy = getVLSCCCompatibleType(FixedSrcTy);
881 if (VLSTy != FixedSrcTy)
882 Load = CGF.Builder.CreateBitCast(Load, VLSTy);
883 auto *VectorVal = llvm::PoisonValue::get(ScalableDstTy);
884 llvm::Value *Result = CGF.Builder.CreateInsertVector(
885 ScalableDstTy, VectorVal, Load, uint64_t(0), "cast.scalable");
886 return Result;
887}
888
889void RISCVABIInfo::createCoercedStore(llvm::Value *Val, Address Dst,
890 const ABIArgInfo &AI, bool DestIsVolatile,
891 CodeGenFunction &CGF) const {
892 llvm::Type *SrcTy = Val->getType();
893 llvm::StructType *DstSTy = cast<llvm::StructType>(Dst.getElementType());
894 assert((SrcTy->isScalableTy() || SrcTy->isTargetExtTy()) &&
895 "Only scalable vector type and vector tuple type are allowed for "
896 "store value.");
897 if (llvm::TargetExtType *TupTy = dyn_cast<llvm::TargetExtType>(SrcTy)) {
898 // In RISC-V VLS calling convention, struct of fixed vectors or struct
899 // of array of fixed vector of length >1 might be lowered using vector
900 // tuple type, we consider it as a valid load, e.g.
901 // struct i32x4x2 {
902 // __attribute__((vector_size(16))) int i;
903 // __attribute__((vector_size(16))) int i;
904 // };
905 // or
906 // struct i32x4 {
907 // __attribute__((vector_size(16))) int i[2];
908 // };
909 // is lowered to target("riscv.vector.tuple", <vscale x 8 x i8>, 2)
910 // when ABI_VLEN = 128 bits, please checkout
911 // clang/test/CodeGen/RISCV/riscv-vector-callingconv-llvm-ir.c
912 // for more information.
913 assert(TupTy->getName() == "riscv.vector.tuple");
914 llvm::Type *EltTy = TupTy->getTypeParameter(0);
915 unsigned NumElts = TupTy->getIntParameter(0);
916
917 llvm::Type *FixedVecTy = DstSTy->getElementType(0);
918 if (auto *ArrayTy = dyn_cast<llvm::ArrayType>(DstSTy->getElementType(0))) {
919 Dst = Dst.withElementType(ArrayTy);
920 FixedVecTy = ArrayTy->getArrayElementType();
921 }
922
923 llvm::FixedVectorType *VLSTy =
924 getVLSCCCompatibleType(cast<llvm::FixedVectorType>(FixedVecTy));
925
926 // Perform extract element and store
927 for (unsigned i = 0; i < NumElts; ++i) {
928 // Element in vector tuple type is always i8, so we need to cast back
929 // to it's original element type.
930 EltTy =
931 cast<llvm::ScalableVectorType>(llvm::VectorType::getWithSizeAndScalar(
932 cast<llvm::VectorType>(EltTy), VLSTy));
933 // Extract scalable vector from tuple
934 llvm::Value *Idx = CGF.Builder.getInt32(i);
935 auto *TupleElement = CGF.Builder.CreateIntrinsic(
936 llvm::Intrinsic::riscv_tuple_extract, {EltTy, TupTy}, {Val, Idx});
937
938 // Extract fixed vector from scalable vector
939 llvm::Value *ExtractVec =
940 CGF.Builder.CreateExtractVector(VLSTy, TupleElement, uint64_t(0));
941 if (VLSTy != FixedVecTy)
942 ExtractVec = CGF.Builder.CreateBitCast(ExtractVec, FixedVecTy);
943 // Store fixed vector to corresponding address
944 Address EltPtr = Address::invalid();
945 if (Dst.getElementType()->isStructTy())
946 EltPtr = CGF.Builder.CreateStructGEP(Dst, i);
947 else
948 EltPtr = CGF.Builder.CreateConstArrayGEP(Dst, i);
949 auto *I = CGF.Builder.CreateStore(ExtractVec, EltPtr, DestIsVolatile);
950 CGF.addInstToCurrentSourceAtom(I, ExtractVec);
951 }
952 return;
953 }
954
955 // In RISC-V VLS calling convention, struct of fixed vector or struct of
956 // fixed vector array of length 1 might be lowered using scalable
957 // vector, we consider it as a valid load, e.g.
958 // struct i32x4 {
959 // __attribute__((vector_size(16))) int i;
960 // };
961 // or
962 // struct i32x4 {
963 // __attribute__((vector_size(16))) int i[1];
964 // };
965 // is lowered to <vscale x 2 x i32>
966 // when ABI_VLEN = 128 bits, please checkout
967 // clang/test/CodeGen/RISCV/riscv-vector-callingconv-llvm-ir.c
968 // for more information.
969 llvm::Type *EltTy = DstSTy->getElementType(0);
970 if (auto *ArrayTy = dyn_cast<llvm::ArrayType>(EltTy)) {
971 assert(ArrayTy->getNumElements() == 1);
972 EltTy = ArrayTy->getElementType();
973 }
974 auto *FixedVecTy = cast<llvm::FixedVectorType>(EltTy);
975 llvm::FixedVectorType *VLSTy = getVLSCCCompatibleType(FixedVecTy);
976 llvm::Value *Coerced =
977 CGF.Builder.CreateExtractVector(VLSTy, Val, uint64_t(0));
978 if (VLSTy != FixedVecTy)
979 Coerced = CGF.Builder.CreateBitCast(Coerced, FixedVecTy);
980 auto *I = CGF.Builder.CreateStore(Coerced, Dst, DestIsVolatile);
981 CGF.addInstToCurrentSourceAtom(I, Val);
982}
983
984namespace {
985class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
986public:
987 RISCVTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT, unsigned XLen,
988 unsigned FLen, bool EABI)
989 : TargetCodeGenInfo(
990 std::make_unique<RISCVABIInfo>(CGT, XLen, FLen, EABI)) {
991 SwiftInfo =
992 std::make_unique<SwiftABIInfo>(CGT, /*SwiftErrorInRegister=*/false);
993 }
994
995 void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
996 CodeGen::CodeGenModule &CGM) const override {
997 const auto *FD = dyn_cast_or_null<FunctionDecl>(D);
998 if (!FD) return;
999
1000 auto *Fn = cast<llvm::Function>(GV);
1001
1002 if (CGM.getCodeGenOpts().CFProtectionReturn)
1003 Fn->addFnAttr("hw-shadow-stack");
1004
1005 const auto *Attr = FD->getAttr<RISCVInterruptAttr>();
1006 if (!Attr)
1007 return;
1008
1009 StringRef Kind = "machine";
1010 bool HasSiFiveCLICPreemptible = false;
1011 bool HasSiFiveCLICStackSwap = false;
1012 for (RISCVInterruptAttr::InterruptType type : Attr->interrupt()) {
1013 switch (type) {
1014 case RISCVInterruptAttr::machine:
1015 // Do not update `Kind` because `Kind` is already "machine", or the
1016 // kinds also contains SiFive types which need to be applied.
1017 break;
1018 case RISCVInterruptAttr::supervisor:
1019 Kind = "supervisor";
1020 break;
1021 case RISCVInterruptAttr::rnmi:
1022 Kind = "rnmi";
1023 break;
1024 case RISCVInterruptAttr::qcinest:
1025 Kind = "qci-nest";
1026 break;
1027 case RISCVInterruptAttr::qcinonest:
1028 Kind = "qci-nonest";
1029 break;
1030 // There are three different LLVM IR attribute values for SiFive CLIC
1031 // interrupt kinds, one for each kind and one extra for their combination.
1032 case RISCVInterruptAttr::SiFiveCLICPreemptible: {
1033 HasSiFiveCLICPreemptible = true;
1034 Kind = HasSiFiveCLICStackSwap ? "SiFive-CLIC-preemptible-stack-swap"
1035 : "SiFive-CLIC-preemptible";
1036 break;
1037 }
1038 case RISCVInterruptAttr::SiFiveCLICStackSwap: {
1039 HasSiFiveCLICStackSwap = true;
1040 Kind = HasSiFiveCLICPreemptible ? "SiFive-CLIC-preemptible-stack-swap"
1041 : "SiFive-CLIC-stack-swap";
1042 break;
1043 }
1044 }
1045 }
1046
1047 Fn->addFnAttr("interrupt", Kind);
1048 }
1049};
1050} // namespace
1051
1052std::unique_ptr<TargetCodeGenInfo>
1054 unsigned FLen, bool EABI) {
1055 return std::make_unique<RISCVTargetCodeGenInfo>(CGM.getTypes(), XLen, FLen,
1056 EABI);
1057}
Result
Implement __builtin_bit_cast and related operations.
#define CC_VLS_CASE(ABI_VLEN)
static CharUnits getTypeStoreSize(CodeGenModule &CGM, llvm::Type *type)
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.
Attr - This represents one attribute.
Definition Attr.h:46
bool isZero() const
isZero - Test whether the quantity equals zero.
Definition CharUnits.h:122
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition CharUnits.h:185
bool isMultipleOf(CharUnits N) const
Test whether this is a multiple of the other value.
Definition CharUnits.h:143
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Definition CharUnits.h:63
CharUnits alignTo(const CharUnits &Align) const
alignTo - Returns the next integer (mod 2**64) that is greater than or equal to this quantity and is ...
Definition CharUnits.h:201
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Definition CharUnits.h:53
static ABIArgInfo getIgnore()
static ABIArgInfo getTargetSpecific(llvm::Type *T=nullptr, unsigned Offset=0, llvm::Type *Padding=nullptr, bool CanBeFlattened=true, unsigned Align=0)
static ABIArgInfo getDirect(llvm::Type *T=nullptr, unsigned Offset=0, llvm::Type *Padding=nullptr, bool CanBeFlattened=true, unsigned Align=0)
@ Indirect
Indirect - Pass the argument indirectly via a hidden pointer with the specified alignment (0 indicate...
static ABIArgInfo getExtend(QualType Ty, llvm::Type *T=nullptr)
static ABIArgInfo getCoerceAndExpand(llvm::StructType *coerceToType, llvm::Type *unpaddedCoerceToType)
llvm::Type * getCoerceToType() const
static ABIArgInfo getSignExtend(QualType Ty, llvm::Type *T=nullptr)
virtual void appendAttributeMangling(TargetAttr *Attr, raw_ostream &Out) const
Definition ABIInfo.cpp:186
static Address invalid()
Definition Address.h:176
llvm::Type * getElementType() const
Return the type of the values stored in this address.
Definition Address.h:209
Address withElementType(llvm::Type *ElemTy) const
Return address with different element type, but same pointer and alignment.
Definition Address.h:276
RValue asRValue() const
Definition CGValue.h:713
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Definition CGBuilder.h:146
Address CreateConstArrayGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = [n x T]* ... produce name = getelementptr inbounds addr, i64 0, i64 index where i64 is a...
Definition CGBuilder.h:251
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
Definition CGBuilder.h:229
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
Definition CGBuilder.h:118
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
FunctionType::ExtInfo getExtInfo() const
CanQualType getReturnType() const
MutableArrayRef< ArgInfo > arguments()
void addInstToCurrentSourceAtom(llvm::Instruction *KeyInstruction, llvm::Value *Backup)
See CGDebugInfo::addInstToCurrentSourceAtom.
This class organizes the cross-function state that is used while generating LLVM code.
const CodeGenOptions & getCodeGenOpts() const
DefaultABIInfo - The default implementation for ABI specific details.
Definition ABIInfoImpl.h:21
CallingConv getCC() const
Definition TypeBase.h:4737
field_range fields() const
Definition Decl.h:4559
bool isUnion() const
Definition Decl.h:3959
virtual bool hasFeature(StringRef Feature) const
Determine whether the given target has the given feature.
bool isVoidType() const
Definition TypeBase.h:9050
bool isComplexType() const
isComplexType() does not include complex integers (a GCC extension).
Definition Type.cpp:761
bool isUnsignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is unsigned or an enumeration types whose underlying ...
Definition Type.cpp:2355
const T * castAs() const
Member-template castAs<specific type>.
Definition TypeBase.h:9344
bool isScalarType() const
Definition TypeBase.h:9156
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition TypeBase.h:9172
EnumDecl * getAsEnumDecl() const
Retrieves the EnumDecl this type refers to.
Definition Type.h:53
bool isStructureOrClassType() const
Definition Type.cpp:743
bool isVectorType() const
Definition TypeBase.h:8823
bool isRealFloatingType() const
Floating point categories.
Definition Type.cpp:2405
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
Definition TypeBase.h:2985
bool isFloatingType() const
Definition Type.cpp:2389
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9277
ABIArgInfo classifyArgumentType(CodeGenModule &CGM, CanQualType type)
Classify the rules for how to pass a particular type.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
Definition CGValue.h:146
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)
QualType useFirstFieldIfTransparentUnion(QualType Ty)
Pass transparent unions as if they were the type of the first element.
std::unique_ptr< TargetCodeGenInfo > createRISCVTargetCodeGenInfo(CodeGenModule &CGM, unsigned XLen, unsigned FLen, bool EABI)
Definition RISCV.cpp:1053
bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays, bool AsIfNoUniqueAddr=false)
isEmptyRecord - Return true iff a structure contains only empty fields.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
@ Address
A pointer to a ValueDecl.
Definition Primitives.h:28
bool Load(InterpState &S, CodePtr OpPC)
Definition Interp.h:2212
PRESERVE_NONE bool Ret(InterpState &S, CodePtr &PC)
Definition Interp.h:261
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition Address.h:330
U cast(CodeGen::Address addr)
Definition Address.h:327
unsigned long uint64_t