clang 24.0.0git
PPC.cpp
Go to the documentation of this file.
1//===- PPC.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"
12
13using namespace clang;
14using namespace clang::CodeGen;
15
17 QualType Ty, CharUnits SlotSize,
18 CharUnits EltSize, const ComplexType *CTy) {
20 emitVoidPtrDirectVAArg(CGF, VAListAddr, CGF.Int8Ty, SlotSize * 2,
21 SlotSize, SlotSize, /*AllowHigher*/ true);
22
23 Address RealAddr = Addr;
24 Address ImagAddr = RealAddr;
25 if (CGF.CGM.getDataLayout().isBigEndian()) {
26 RealAddr =
27 CGF.Builder.CreateConstInBoundsByteGEP(RealAddr, SlotSize - EltSize);
28 ImagAddr = CGF.Builder.CreateConstInBoundsByteGEP(ImagAddr,
29 2 * SlotSize - EltSize);
30 } else {
31 ImagAddr = CGF.Builder.CreateConstInBoundsByteGEP(RealAddr, SlotSize);
32 }
33
34 llvm::Type *EltTy = CGF.ConvertTypeForMem(CTy->getElementType());
35 RealAddr = RealAddr.withElementType(EltTy);
36 ImagAddr = ImagAddr.withElementType(EltTy);
37 llvm::Value *Real = CGF.Builder.CreateLoad(RealAddr, ".vareal");
38 llvm::Value *Imag = CGF.Builder.CreateLoad(ImagAddr, ".vaimag");
39
40 return RValue::getComplex(Real, Imag);
41}
42
44 llvm::Value *Address, bool Is64Bit,
45 bool IsAIX) {
46 // This is calculated from the LLVM and GCC tables and verified
47 // against gcc output. AFAIK all PPC ABIs use the same encoding.
48
49 CodeGen::CGBuilderTy &Builder = CGF.Builder;
50
51 llvm::IntegerType *i8 = CGF.Int8Ty;
52 llvm::Value *Four8 = llvm::ConstantInt::get(i8, 4);
53 llvm::Value *Eight8 = llvm::ConstantInt::get(i8, 8);
54 llvm::Value *Sixteen8 = llvm::ConstantInt::get(i8, 16);
55
56 // 0-31: r0-31, the 4-byte or 8-byte general-purpose registers
57 AssignToArrayRange(Builder, Address, Is64Bit ? Eight8 : Four8, 0, 31);
58
59 // 32-63: fp0-31, the 8-byte floating-point registers
60 AssignToArrayRange(Builder, Address, Eight8, 32, 63);
61
62 // 64-67 are various 4-byte or 8-byte special-purpose registers:
63 // 64: mq
64 // 65: lr
65 // 66: ctr
66 // 67: ap
67 AssignToArrayRange(Builder, Address, Is64Bit ? Eight8 : Four8, 64, 67);
68
69 // 68-76 are various 4-byte special-purpose registers:
70 // 68-75 cr0-7
71 // 76: xer
72 AssignToArrayRange(Builder, Address, Four8, 68, 76);
73
74 // 77-108: v0-31, the 16-byte vector registers
75 AssignToArrayRange(Builder, Address, Sixteen8, 77, 108);
76
77 // 109: vrsave
78 // 110: vscr
79 AssignToArrayRange(Builder, Address, Is64Bit ? Eight8 : Four8, 109, 110);
80
81 // AIX does not utilize the rest of the registers.
82 if (IsAIX)
83 return false;
84
85 // 111: spe_acc
86 // 112: spefscr
87 // 113: sfp
88 AssignToArrayRange(Builder, Address, Is64Bit ? Eight8 : Four8, 111, 113);
89
90 if (!Is64Bit)
91 return false;
92
93 // TODO: Need to verify if these registers are used on 64 bit AIX with Power8
94 // or above CPU.
95 // 64-bit only registers:
96 // 114: tfhar
97 // 115: tfiar
98 // 116: texasr
99 AssignToArrayRange(Builder, Address, Eight8, 114, 116);
100
101 return false;
102}
103
104// AIX
105namespace {
106/// AIXABIInfo - The AIX XCOFF ABI information.
107class AIXABIInfo : public ABIInfo {
108 const bool Is64Bit;
109 const unsigned PtrByteSize;
110 CharUnits getParamTypeAlignment(QualType Ty) const;
111
112public:
113 AIXABIInfo(CodeGen::CodeGenTypes &CGT, bool Is64Bit)
114 : ABIInfo(CGT), Is64Bit(Is64Bit), PtrByteSize(Is64Bit ? 8 : 4) {}
115
116 bool isPromotableTypeForABI(QualType Ty) const;
117
118 ABIArgInfo classifyReturnType(QualType RetTy) const;
119 ABIArgInfo classifyArgumentType(QualType Ty) const;
120
121 void computeInfo(CGFunctionInfo &FI) const override {
122 if (!getCXXABI().classifyReturnType(FI))
124
125 for (auto &I : FI.arguments())
126 I.info = classifyArgumentType(I.type);
127 }
128
129 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
130 AggValueSlot Slot) const override;
131
133 void appendAttributeMangling(TargetClonesAttr *Attr, unsigned Index,
134 raw_ostream &Out) const override;
135 void appendAttributeMangling(StringRef AttrStr,
136 raw_ostream &Out) const override;
137};
138
139void AIXABIInfo::appendAttributeMangling(TargetClonesAttr *Attr, unsigned Index,
140 raw_ostream &Out) const {
141 appendAttributeMangling(Attr->getFeatureStr(Index), Out);
142}
143
144void AIXABIInfo::appendAttributeMangling(StringRef AttrStr,
145 raw_ostream &Out) const {
146 if (AttrStr == "default") {
147 Out << ".default";
148 return;
149 }
150
151 const TargetInfo &TI = CGT.getTarget();
152 ParsedTargetAttr Info = TI.parseTargetAttr(AttrStr);
153
154 if (!Info.CPU.empty()) {
155 assert(Info.Features.empty() && "cannot have both a CPU and a feature");
156 Out << ".cpu_" << Info.CPU;
157 return;
158 }
159
160 // Handle feature strings
161 if (Info.Features.size() == 1) {
162 StringRef Feature = Info.Features[0];
163 assert(Feature.starts_with("+") || Feature.starts_with("-"));
164
165 // replace hyphens with underscores
166 std::string MangledName(Feature.drop_front(1));
167 std::replace(MangledName.begin(), MangledName.end(), '-', '_');
168
169 Out << "." << (Feature.starts_with("-") ? "no_" : "") << MangledName;
170 return;
171 }
172
173 llvm_unreachable("Invalid target_clones parameter");
174}
175
176class AIXTargetCodeGenInfo : public TargetCodeGenInfo {
177 const bool Is64Bit;
178
179public:
180 AIXTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT, bool Is64Bit)
181 : TargetCodeGenInfo(std::make_unique<AIXABIInfo>(CGT, Is64Bit)),
182 Is64Bit(Is64Bit) {}
183 int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
184 return 1; // r1 is the dedicated stack pointer
185 }
186
187 bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
188 llvm::Value *Address) const override;
189
190 void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
191 CodeGen::CodeGenModule &M) const override;
192};
193} // namespace
194
195// Return true if the ABI requires Ty to be passed sign- or zero-
196// extended to 32/64 bits.
197bool AIXABIInfo::isPromotableTypeForABI(QualType Ty) const {
198 // Treat an enum type as its underlying type.
199 if (const auto *ED = Ty->getAsEnumDecl())
200 Ty = ED->getIntegerType();
201
202 // Promotable integer types are required to be promoted by the ABI.
203 if (getContext().isPromotableIntegerType(Ty))
204 return true;
205
206 if (!Is64Bit)
207 return false;
208
209 // For 64 bit mode, in addition to the usual promotable integer types, we also
210 // need to extend all 32-bit types, since the ABI requires promotion to 64
211 // bits.
212 if (const BuiltinType *BT = Ty->getAs<BuiltinType>())
213 switch (BT->getKind()) {
214 case BuiltinType::Int:
215 case BuiltinType::UInt:
216 return true;
217 default:
218 break;
219 }
220
221 return false;
222}
223
224ABIArgInfo AIXABIInfo::classifyReturnType(QualType RetTy) const {
225 if (RetTy->isAnyComplexType())
226 return ABIArgInfo::getDirect();
227
228 if (RetTy->isVectorType())
229 return ABIArgInfo::getDirect();
230
231 if (RetTy->isVoidType())
232 return ABIArgInfo::getIgnore();
233
234 if (isAggregateTypeForABI(RetTy))
235 return getNaturalAlignIndirect(RetTy, getDataLayout().getAllocaAddrSpace());
236
237 return (isPromotableTypeForABI(RetTy) ? ABIArgInfo::getExtend(RetTy)
239}
240
241ABIArgInfo AIXABIInfo::classifyArgumentType(QualType Ty) const {
243
244 if (Ty->isAnyComplexType())
245 return ABIArgInfo::getDirect();
246
247 if (Ty->isVectorType())
248 return ABIArgInfo::getDirect();
249
250 if (isAggregateTypeForABI(Ty)) {
251 // Records with non-trivial destructors/copy-constructors should not be
252 // passed by value.
253 if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI()))
254 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
256
257 CharUnits CCAlign = getParamTypeAlignment(Ty);
258 CharUnits TyAlign = getContext().getTypeAlignInChars(Ty);
259
261 CCAlign, /*AddrSpace=*/getDataLayout().getAllocaAddrSpace(),
262 /*ByVal=*/true,
263 /*Realign=*/TyAlign > CCAlign);
264 }
265
266 return (isPromotableTypeForABI(Ty)
267 ? ABIArgInfo::getExtend(Ty, CGT.ConvertType(Ty))
269}
270
271CharUnits AIXABIInfo::getParamTypeAlignment(QualType Ty) const {
272 // Complex types are passed just like their elements.
273 if (const ComplexType *CTy = Ty->getAs<ComplexType>())
274 Ty = CTy->getElementType();
275
276 if (Ty->isVectorType())
277 return CharUnits::fromQuantity(16);
278
279 // If the structure contains a vector type, the alignment is 16.
280 if (isRecordWithSIMDVectorType(getContext(), Ty))
281 return CharUnits::fromQuantity(16);
282
283 return CharUnits::fromQuantity(PtrByteSize);
284}
285
286RValue AIXABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
287 QualType Ty, AggValueSlot Slot) const {
288
289 auto TypeInfo = getContext().getTypeInfoInChars(Ty);
290 TypeInfo.Align = getParamTypeAlignment(Ty);
291
292 CharUnits SlotSize = CharUnits::fromQuantity(PtrByteSize);
293
294 // If we have a complex type and the base type is smaller than the register
295 // size, the ABI calls for the real and imaginary parts to be right-adjusted
296 // in separate words in 32bit mode or doublewords in 64bit mode. However,
297 // Clang expects us to produce a pointer to a structure with the two parts
298 // packed tightly. So generate loads of the real and imaginary parts relative
299 // to the va_list pointer, and store them to a temporary structure. We do the
300 // same as the PPC64ABI here.
301 if (const ComplexType *CTy = Ty->getAs<ComplexType>()) {
302 CharUnits EltSize = TypeInfo.Width / 2;
303 if (EltSize < SlotSize)
304 return complexTempStructure(CGF, VAListAddr, Ty, SlotSize, EltSize, CTy);
305 }
306
307 return emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*Indirect*/ false, TypeInfo,
308 SlotSize, /*AllowHigher*/ true, Slot);
309}
310
311bool AIXTargetCodeGenInfo::initDwarfEHRegSizeTable(
312 CodeGen::CodeGenFunction &CGF, llvm::Value *Address) const {
313 return PPC_initDwarfEHRegSizeTable(CGF, Address, Is64Bit, /*IsAIX*/ true);
314}
315
316void AIXTargetCodeGenInfo::setTargetAttributes(
317 const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
319 return;
320
321 auto *GVar = cast<llvm::GlobalVariable>(GV);
322 auto GVId = GV->getName();
323
324 // Is this a global variable specified by the user as toc-data?
325 bool UserSpecifiedTOC =
326 llvm::binary_search(M.getCodeGenOpts().TocDataVarsUserSpecified, GVId);
327 // Assumes the same variable cannot be in both TocVarsUserSpecified and
328 // NoTocVars.
329 if (UserSpecifiedTOC ||
330 ((M.getCodeGenOpts().AllTocData) &&
331 !llvm::binary_search(M.getCodeGenOpts().NoTocDataVars, GVId))) {
332 const unsigned long PointerSize =
333 GV->getParent()->getDataLayout().getPointerSizeInBits() / 8;
334 auto *VarD = dyn_cast<VarDecl>(D);
335 assert(VarD && "Invalid declaration of global variable.");
336
337 ASTContext &Context = D->getASTContext();
338 unsigned Alignment = Context.toBits(Context.getDeclAlign(D)) / 8;
339 const auto *Ty = VarD->getType().getTypePtr();
340 const RecordDecl *RDecl = Ty->getAsRecordDecl();
341
342 bool EmitDiagnostic = UserSpecifiedTOC && GV->hasExternalLinkage();
343 auto reportUnsupportedWarning = [&](bool ShouldEmitWarning, StringRef Msg) {
344 if (ShouldEmitWarning)
345 M.getDiags().Report(D->getLocation(), diag::warn_toc_unsupported_type)
346 << GVId << Msg;
347 };
348 if (!Ty || Ty->isIncompleteType())
349 reportUnsupportedWarning(EmitDiagnostic, "of incomplete type");
350 else if (RDecl && RDecl->hasFlexibleArrayMember())
351 reportUnsupportedWarning(EmitDiagnostic,
352 "it contains a flexible array member");
353 else if (VarD->getTLSKind() != VarDecl::TLS_None)
354 reportUnsupportedWarning(EmitDiagnostic, "of thread local storage");
355 else if (PointerSize < Context.getTypeInfo(VarD->getType()).Width / 8)
356 reportUnsupportedWarning(EmitDiagnostic,
357 "variable is larger than a pointer");
358 else if (PointerSize < Alignment)
359 reportUnsupportedWarning(EmitDiagnostic,
360 "variable is aligned wider than a pointer");
361 else if (D->hasAttr<SectionAttr>())
362 reportUnsupportedWarning(EmitDiagnostic,
363 "variable has a section attribute");
364 else if (GV->hasExternalLinkage() ||
365 (M.getCodeGenOpts().AllTocData && !GV->hasLocalLinkage()))
366 GVar->addAttribute("toc-data");
367 }
368}
369
370// PowerPC-32
371namespace {
372/// PPC32_SVR4_ABIInfo - The 32-bit PowerPC ELF (SVR4) ABI information.
373class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
374 bool IsSoftFloatABI;
375 bool IsRetSmallStructInRegABI;
376
377 CharUnits getParamTypeAlignment(QualType Ty) const;
378
379public:
380 PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, bool SoftFloatABI,
381 bool RetSmallStructInRegABI)
382 : DefaultABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
383 IsRetSmallStructInRegABI(RetSmallStructInRegABI) {}
384
385 ABIArgInfo classifyReturnType(QualType RetTy) const;
386
387 void computeInfo(CGFunctionInfo &FI) const override {
388 if (!getCXXABI().classifyReturnType(FI))
390 for (auto &I : FI.arguments())
391 I.info = classifyArgumentType(I.type);
392 }
393
394 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
395 AggValueSlot Slot) const override;
396};
397
398class PPC32TargetCodeGenInfo : public TargetCodeGenInfo {
399public:
400 PPC32TargetCodeGenInfo(CodeGenTypes &CGT, bool SoftFloatABI,
401 bool RetSmallStructInRegABI)
402 : TargetCodeGenInfo(std::make_unique<PPC32_SVR4_ABIInfo>(
403 CGT, SoftFloatABI, RetSmallStructInRegABI)) {}
404
405 static bool isStructReturnInRegABI(const llvm::Triple &Triple,
406 const CodeGenOptions &Opts);
407
408 int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
409 // This is recovered from gcc output.
410 return 1; // r1 is the dedicated stack pointer
411 }
412
413 bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
414 llvm::Value *Address) const override;
415};
416}
417
418CharUnits PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
419 // Complex types are passed just like their elements.
420 if (const ComplexType *CTy = Ty->getAs<ComplexType>())
421 Ty = CTy->getElementType();
422
423 if (Ty->isVectorType())
424 return CharUnits::fromQuantity(getContext().getTypeSize(Ty) == 128 ? 16
425 : 4);
426
427 // For single-element float/vector structs, we consider the whole type
428 // to have the same alignment requirements as its single element.
429 const Type *AlignTy = nullptr;
430 if (const Type *EltType = isSingleElementRecord(Ty, getContext())) {
431 const BuiltinType *BT = EltType->getAs<BuiltinType>();
432 if ((EltType->isVectorType() && getContext().getTypeSize(EltType) == 128) ||
433 (BT && BT->isFloatingPoint()))
434 AlignTy = EltType;
435 }
436
437 if (AlignTy)
438 return CharUnits::fromQuantity(AlignTy->isVectorType() ? 16 : 4);
439 return CharUnits::fromQuantity(4);
440}
441
442ABIArgInfo PPC32_SVR4_ABIInfo::classifyReturnType(QualType RetTy) const {
444
445 // -msvr4-struct-return puts small aggregates in GPR3 and GPR4.
446 if (isAggregateTypeForABI(RetTy) && IsRetSmallStructInRegABI &&
447 (Size = getContext().getTypeSize(RetTy)) <= 64) {
448 // System V ABI (1995), page 3-22, specified:
449 // > A structure or union whose size is less than or equal to 8 bytes
450 // > shall be returned in r3 and r4, as if it were first stored in the
451 // > 8-byte aligned memory area and then the low addressed word were
452 // > loaded into r3 and the high-addressed word into r4. Bits beyond
453 // > the last member of the structure or union are not defined.
454 //
455 // GCC for big-endian PPC32 inserts the pad before the first member,
456 // not "beyond the last member" of the struct. To stay compatible
457 // with GCC, we coerce the struct to an integer of the same size.
458 // LLVM will extend it and return i32 in r3, or i64 in r3:r4.
459 if (Size == 0)
460 return ABIArgInfo::getIgnore();
461 else {
462 llvm::Type *CoerceTy = llvm::Type::getIntNTy(getVMContext(), Size);
463 return ABIArgInfo::getDirect(CoerceTy);
464 }
465 }
466
468}
469
470// TODO: this implementation is now likely redundant with
471// DefaultABIInfo::EmitVAArg.
472RValue PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAList,
473 QualType Ty, AggValueSlot Slot) const {
474 if (getTarget().getTriple().isOSDarwin()) {
475 auto TI = getContext().getTypeInfoInChars(Ty);
476 TI.Align = getParamTypeAlignment(Ty);
477
478 CharUnits SlotSize = CharUnits::fromQuantity(4);
479 return emitVoidPtrVAArg(CGF, VAList, Ty,
480 classifyArgumentType(Ty).isIndirect(), TI, SlotSize,
481 /*AllowHigherAlign=*/true, Slot);
482 }
483
484 const unsigned OverflowLimit = 8;
485 if (const ComplexType *CTy = Ty->getAs<ComplexType>()) {
486 // TODO: Implement this. For now ignore.
487 (void)CTy;
488 return RValue::getAggregate(Address::invalid()); // FIXME?
489 }
490
491 // struct __va_list_tag {
492 // unsigned char gpr;
493 // unsigned char fpr;
494 // unsigned short reserved;
495 // void *overflow_arg_area;
496 // void *reg_save_area;
497 // };
498
499 bool isI64 = Ty->isIntegerType() && getContext().getTypeSize(Ty) == 64;
500 bool isInt = !Ty->isFloatingType();
501 bool isF64 = Ty->isFloatingType() && getContext().getTypeSize(Ty) == 64;
502
503 // All aggregates are passed indirectly? That doesn't seem consistent
504 // with the argument-lowering code.
505 bool isIndirect = isAggregateTypeForABI(Ty);
506
507 CGBuilderTy &Builder = CGF.Builder;
508
509 // The calling convention either uses 1-2 GPRs or 1 FPR.
510 Address NumRegsAddr = Address::invalid();
511 if (isInt || IsSoftFloatABI) {
512 NumRegsAddr = Builder.CreateStructGEP(VAList, 0, "gpr");
513 } else {
514 NumRegsAddr = Builder.CreateStructGEP(VAList, 1, "fpr");
515 }
516
517 llvm::Value *NumRegs = Builder.CreateLoad(NumRegsAddr, "numUsedRegs");
518
519 // "Align" the register count when TY is i64.
520 if (isI64 || (isF64 && IsSoftFloatABI)) {
521 NumRegs = Builder.CreateAdd(NumRegs, Builder.getInt8(1));
522 NumRegs = Builder.CreateAnd(NumRegs, Builder.getInt8((uint8_t) ~1U));
523 }
524
525 llvm::Value *CC =
526 Builder.CreateICmpULT(NumRegs, Builder.getInt8(OverflowLimit), "cond");
527
528 llvm::BasicBlock *UsingRegs = CGF.createBasicBlock("using_regs");
529 llvm::BasicBlock *UsingOverflow = CGF.createBasicBlock("using_overflow");
530 llvm::BasicBlock *Cont = CGF.createBasicBlock("cont");
531
532 Builder.CreateCondBr(CC, UsingRegs, UsingOverflow);
533
534 llvm::Type *DirectTy = CGF.ConvertType(Ty), *ElementTy = DirectTy;
535 if (isIndirect)
536 DirectTy = CGF.DefaultPtrTy;
537
538 // Case 1: consume registers.
539 Address RegAddr = Address::invalid();
540 {
541 CGF.EmitBlock(UsingRegs);
542
543 Address RegSaveAreaPtr = Builder.CreateStructGEP(VAList, 4);
544 RegAddr = Address(Builder.CreateLoad(RegSaveAreaPtr), CGF.Int8Ty,
546 assert(RegAddr.getElementType() == CGF.Int8Ty);
547
548 // Floating-point registers start after the general-purpose registers.
549 if (!(isInt || IsSoftFloatABI)) {
550 RegAddr = Builder.CreateConstInBoundsByteGEP(RegAddr,
552 }
553
554 // Get the address of the saved value by scaling the number of
555 // registers we've used by the number of
556 CharUnits RegSize = CharUnits::fromQuantity((isInt || IsSoftFloatABI) ? 4 : 8);
557 llvm::Value *RegOffset =
558 Builder.CreateMul(NumRegs, Builder.getInt8(RegSize.getQuantity()));
559 RegAddr = Address(Builder.CreateInBoundsGEP(
560 CGF.Int8Ty, RegAddr.emitRawPointer(CGF), RegOffset),
561 DirectTy,
562 RegAddr.getAlignment().alignmentOfArrayElement(RegSize));
563
564 // Increase the used-register count.
565 NumRegs =
566 Builder.CreateAdd(NumRegs,
567 Builder.getInt8((isI64 || (isF64 && IsSoftFloatABI)) ? 2 : 1));
568 Builder.CreateStore(NumRegs, NumRegsAddr);
569
570 CGF.EmitBranch(Cont);
571 }
572
573 // Case 2: consume space in the overflow area.
574 Address MemAddr = Address::invalid();
575 {
576 CGF.EmitBlock(UsingOverflow);
577
578 Builder.CreateStore(Builder.getInt8(OverflowLimit), NumRegsAddr);
579
580 // Everything in the overflow area is rounded up to a size of at least 4.
581 CharUnits OverflowAreaAlign = CharUnits::fromQuantity(4);
582
583 CharUnits Size;
584 if (!isIndirect) {
585 auto TypeInfo = CGF.getContext().getTypeInfoInChars(Ty);
586 Size = TypeInfo.Width.alignTo(OverflowAreaAlign);
587 } else {
588 Size = CGF.getPointerSize();
589 }
590
591 Address OverflowAreaAddr = Builder.CreateStructGEP(VAList, 3);
592 Address OverflowArea =
593 Address(Builder.CreateLoad(OverflowAreaAddr, "argp.cur"), CGF.Int8Ty,
594 OverflowAreaAlign);
595 // Round up address of argument to alignment
596 CharUnits Align = CGF.getContext().getTypeAlignInChars(Ty);
597 if (Align > OverflowAreaAlign) {
598 llvm::Value *Ptr = OverflowArea.emitRawPointer(CGF);
599 OverflowArea = Address(emitRoundPointerUpToAlignment(CGF, Ptr, Align),
600 OverflowArea.getElementType(), Align);
601 }
602
603 MemAddr = OverflowArea.withElementType(DirectTy);
604
605 // Increase the overflow area.
606 OverflowArea = Builder.CreateConstInBoundsByteGEP(OverflowArea, Size);
607 Builder.CreateStore(OverflowArea.emitRawPointer(CGF), OverflowAreaAddr);
608 CGF.EmitBranch(Cont);
609 }
610
611 CGF.EmitBlock(Cont);
612
613 // Merge the cases with a phi.
614 Address Result = emitMergePHI(CGF, RegAddr, UsingRegs, MemAddr, UsingOverflow,
615 "vaarg.addr");
616
617 // Load the pointer if the argument was passed indirectly.
618 if (isIndirect) {
619 Result = Address(Builder.CreateLoad(Result, "aggr"), ElementTy,
620 getContext().getTypeAlignInChars(Ty));
621 }
622
623 return CGF.EmitLoadOfAnyValue(CGF.MakeAddrLValue(Result, Ty), Slot);
624}
625
626bool PPC32TargetCodeGenInfo::isStructReturnInRegABI(
627 const llvm::Triple &Triple, const CodeGenOptions &Opts) {
628 assert(Triple.isPPC32());
629
630 switch (Opts.getStructReturnConvention()) {
632 break;
633 case CodeGenOptions::SRCK_OnStack: // -maix-struct-return
634 return false;
635 case CodeGenOptions::SRCK_InRegs: // -msvr4-struct-return
636 return true;
637 }
638
639 if (Triple.isOSBinFormatELF() && !Triple.isOSLinux())
640 return true;
641
642 return false;
643}
644
645bool
646PPC32TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
647 llvm::Value *Address) const {
648 return PPC_initDwarfEHRegSizeTable(CGF, Address, /*Is64Bit*/ false,
649 /*IsAIX*/ false);
650}
651
652// PowerPC-64
653
654namespace {
655
656/// PPC64_SVR4_ABIInfo - The 64-bit PowerPC ELF (SVR4) ABI information.
657class PPC64_SVR4_ABIInfo : public ABIInfo {
658 static const unsigned GPRBits = 64;
660 bool IsSoftFloatABI;
661
662public:
663 PPC64_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, PPC64_SVR4_ABIKind Kind,
664 bool SoftFloatABI)
665 : ABIInfo(CGT), Kind(Kind), IsSoftFloatABI(SoftFloatABI) {}
666
667 bool isPromotableTypeForABI(QualType Ty) const;
668 CharUnits getParamTypeAlignment(QualType Ty) const;
669 const Type *getSingleElementFPOrVectorType(QualType Ty) const;
670
671 ABIArgInfo classifyReturnType(QualType RetTy) const;
672 ABIArgInfo classifyArgumentType(QualType Ty) const;
673
674 bool isHomogeneousAggregateBaseType(QualType Ty) const override;
675 bool isHomogeneousAggregateSmallEnough(const Type *Ty,
676 uint64_t Members) const override;
677
678 // TODO: We can add more logic to computeInfo to improve performance.
679 // Example: For aggregate arguments that fit in a register, we could
680 // use getDirectInReg (as is done below for structs containing a single
681 // floating-point value) to avoid pushing them to memory on function
682 // entry. This would require changing the logic in PPCISelLowering
683 // when lowering the parameters in the caller and args in the callee.
684 void computeInfo(CGFunctionInfo &FI) const override {
685 if (!getCXXABI().classifyReturnType(FI))
687 for (auto &I : FI.arguments()) {
688 // We rely on the default argument classification for the most part.
689 // One exception: An aggregate containing a single floating-point
690 // or vector item must be passed in a register if one is available.
691 if (const Type *T = getSingleElementFPOrVectorType(I.type)) {
692 I.info = ABIArgInfo::getDirectInReg(CGT.ConvertType(QualType(T, 0)));
693 continue;
694 }
695 I.info = classifyArgumentType(I.type);
696 }
697 }
698
699 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
700 AggValueSlot Slot) const override;
701};
702
703class PPC64_SVR4_TargetCodeGenInfo : public TargetCodeGenInfo {
704
705public:
706 PPC64_SVR4_TargetCodeGenInfo(CodeGenTypes &CGT, PPC64_SVR4_ABIKind Kind,
707 bool SoftFloatABI)
708 : TargetCodeGenInfo(
709 std::make_unique<PPC64_SVR4_ABIInfo>(CGT, Kind, SoftFloatABI)) {
710 SwiftInfo =
711 std::make_unique<SwiftABIInfo>(CGT, /*SwiftErrorInRegister=*/false);
712 }
713
714 int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
715 // This is recovered from gcc output.
716 return 1; // r1 is the dedicated stack pointer
717 }
718
719 bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
720 llvm::Value *Address) const override;
721};
722
723class PPC64TargetCodeGenInfo : public TargetCodeGenInfo {
724public:
725 PPC64TargetCodeGenInfo(CodeGenTypes &CGT)
726 : TargetCodeGenInfo(std::make_unique<DefaultABIInfo>(CGT)) {}
727
728 int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
729 // This is recovered from gcc output.
730 return 1; // r1 is the dedicated stack pointer
731 }
732
733 bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
734 llvm::Value *Address) const override;
735};
736}
737
738// Return true if the ABI requires Ty to be passed sign- or zero-
739// extended to 64 bits.
740bool
741PPC64_SVR4_ABIInfo::isPromotableTypeForABI(QualType Ty) const {
742 // Treat an enum type as its underlying type.
743 if (const auto *ED = Ty->getAsEnumDecl())
744 Ty = ED->getIntegerType();
745
746 // Promotable integer types are required to be promoted by the ABI.
747 if (isPromotableIntegerTypeForABI(Ty))
748 return true;
749
750 // In addition to the usual promotable integer types, we also need to
751 // extend all 32-bit types, since the ABI requires promotion to 64 bits.
752 if (const BuiltinType *BT = Ty->getAs<BuiltinType>())
753 switch (BT->getKind()) {
754 case BuiltinType::Int:
755 case BuiltinType::UInt:
756 return true;
757 default:
758 break;
759 }
760
761 if (const auto *EIT = Ty->getAs<BitIntType>())
762 if (EIT->getNumBits() < 64)
763 return true;
764
765 return false;
766}
767
768/// isAlignedParamType - Determine whether a type requires 16-byte or
769/// higher alignment in the parameter area. Always returns at least 8.
770CharUnits PPC64_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
771 // Complex types are passed just like their elements.
772 if (const ComplexType *CTy = Ty->getAs<ComplexType>())
773 Ty = CTy->getElementType();
774
775 auto FloatUsesVector = [this](QualType Ty){
776 return Ty->isRealFloatingType() && &getContext().getFloatTypeSemantics(
777 Ty) == &llvm::APFloat::IEEEquad();
778 };
779
780 // Only vector types of size 16 bytes need alignment (larger types are
781 // passed via reference, smaller types are not aligned).
782 if (Ty->isVectorType()) {
783 return CharUnits::fromQuantity(getContext().getTypeSize(Ty) == 128 ? 16 : 8);
784 } else if (FloatUsesVector(Ty)) {
785 // According to ABI document section 'Optional Save Areas': If extended
786 // precision floating-point values in IEEE BINARY 128 QUADRUPLE PRECISION
787 // format are supported, map them to a single quadword, quadword aligned.
788 return CharUnits::fromQuantity(16);
789 }
790
791 // For single-element float/vector structs, we consider the whole type
792 // to have the same alignment requirements as its single element.
793 const Type *AlignAsType = getSingleElementFPOrVectorType(Ty);
794
795 // Likewise for ELFv2 homogeneous aggregates.
796 const Type *Base = nullptr;
797 uint64_t Members = 0;
798 if (!AlignAsType && Kind == PPC64_SVR4_ABIKind::ELFv2 &&
799 isAggregateTypeForABI(Ty) && isHomogeneousAggregate(Ty, Base, Members))
800 AlignAsType = Base;
801
802 // With special case aggregates, only vector base types need alignment.
803 if (AlignAsType) {
804 bool UsesVector = AlignAsType->isVectorType() ||
805 FloatUsesVector(QualType(AlignAsType, 0));
806 return CharUnits::fromQuantity(UsesVector ? 16 : 8);
807 }
808
809 // Otherwise, we only need alignment for any aggregate type that
810 // has an alignment requirement of >= 16 bytes.
811 if (isAggregateTypeForABI(Ty) && getContext().getTypeAlign(Ty) >= 128) {
812 return CharUnits::fromQuantity(16);
813 }
814
815 return CharUnits::fromQuantity(8);
816}
817
818/// If Ty is a one-member aggregate wrapping a floating-point or 128-bit vector
819/// type, return that type. ELFv1 only unwraps structs and arrays; GCC passes
820/// unions in GPRs.
821const Type *
822PPC64_SVR4_ABIInfo::getSingleElementFPOrVectorType(QualType Ty) const {
823 bool AllowUnions =
824 Kind != PPC64_SVR4_ABIKind::ELFv1 ||
825 getContext().getLangOpts().isCompatibleWith(LangOptions::ClangABI::Ver23);
826 const Type *EltType = AllowUnions ? isSingleElementRecord(Ty, getContext())
827 : isSingleElementStruct(Ty, getContext());
828 if (!EltType)
829 return nullptr;
830 const BuiltinType *BT = EltType->getAs<BuiltinType>();
831 if ((EltType->isVectorType() && getContext().getTypeSize(EltType) == 128) ||
832 (BT && BT->isFloatingPoint()))
833 return EltType;
834 return nullptr;
835}
836
837bool PPC64_SVR4_ABIInfo::isHomogeneousAggregateBaseType(QualType Ty) const {
838 // Homogeneous aggregates for ELFv2 must have base types of float,
839 // double, long double, or 128-bit vectors.
840 if (const BuiltinType *BT = Ty->getAs<BuiltinType>()) {
841 if (BT->getKind() == BuiltinType::Float ||
842 BT->getKind() == BuiltinType::Double ||
843 BT->getKind() == BuiltinType::LongDouble ||
844 BT->getKind() == BuiltinType::Ibm128 ||
845 (getContext().getTargetInfo().hasFloat128Type() &&
846 (BT->getKind() == BuiltinType::Float128))) {
847 if (IsSoftFloatABI)
848 return false;
849 return true;
850 }
851 }
852 if (const VectorType *VT = Ty->getAs<VectorType>()) {
853 if (getContext().getTypeSize(VT) == 128)
854 return true;
855 }
856 return false;
857}
858
859bool PPC64_SVR4_ABIInfo::isHomogeneousAggregateSmallEnough(
860 const Type *Base, uint64_t Members) const {
861 // Vector and fp128 types require one register, other floating point types
862 // require one or two registers depending on their size.
863 uint32_t NumRegs =
864 ((getContext().getTargetInfo().hasFloat128Type() &&
865 Base->isFloat128Type()) ||
866 Base->isVectorType()) ? 1
867 : (getContext().getTypeSize(Base) + 63) / 64;
868
869 // Homogeneous Aggregates may occupy at most 8 registers.
870 return Members * NumRegs <= 8;
871}
872
873ABIArgInfo
874PPC64_SVR4_ABIInfo::classifyArgumentType(QualType Ty) const {
876
877 if (Ty->isAnyComplexType())
878 return ABIArgInfo::getDirect();
879
880 // Non-Altivec vector types are passed in GPRs (smaller than 16 bytes)
881 // or via reference (larger than 16 bytes).
882 if (Ty->isVectorType()) {
883 uint64_t Size = getContext().getTypeSize(Ty);
884 if (Size > 128)
885 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
886 /*ByVal=*/false);
887 else if (Size < 128) {
888 llvm::Type *CoerceTy = llvm::IntegerType::get(getVMContext(), Size);
889 return ABIArgInfo::getDirect(CoerceTy);
890 }
891 }
892
893 if (const auto *EIT = Ty->getAs<BitIntType>())
894 if (EIT->getNumBits() > 128)
895 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
896 /*ByVal=*/true);
897
898 if (isAggregateTypeForABI(Ty)) {
899 if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI()))
900 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
902
903 uint64_t ABIAlign = getParamTypeAlignment(Ty).getQuantity();
904 uint64_t TyAlign = getContext().getTypeAlignInChars(Ty).getQuantity();
905
906 // ELFv2 homogeneous aggregates are passed as array types.
907 const Type *Base = nullptr;
908 uint64_t Members = 0;
909 if (Kind == PPC64_SVR4_ABIKind::ELFv2 &&
910 isHomogeneousAggregate(Ty, Base, Members)) {
911 llvm::Type *BaseTy = CGT.ConvertType(QualType(Base, 0));
912 llvm::Type *CoerceTy = llvm::ArrayType::get(BaseTy, Members);
913 return ABIArgInfo::getDirect(CoerceTy);
914 }
915
916 // If an aggregate may end up fully in registers, we do not
917 // use the ByVal method, but pass the aggregate as array.
918 // This is usually beneficial since we avoid forcing the
919 // back-end to store the argument to memory.
920 uint64_t Bits = getContext().getTypeSize(Ty);
921 if (Bits > 0 && Bits <= 8 * GPRBits) {
922 llvm::Type *CoerceTy;
923
924 // Types up to 8 bytes are passed as integer type (which will be
925 // properly aligned in the argument save area doubleword).
926 if (Bits <= GPRBits)
927 CoerceTy =
928 llvm::IntegerType::get(getVMContext(), llvm::alignTo(Bits, 8));
929 // Larger types are passed as arrays, with the base type selected
930 // according to the required alignment in the save area.
931 else {
932 uint64_t RegBits = ABIAlign * 8;
933 uint64_t NumRegs = llvm::alignTo(Bits, RegBits) / RegBits;
934 llvm::Type *RegTy = llvm::IntegerType::get(getVMContext(), RegBits);
935 CoerceTy = llvm::ArrayType::get(RegTy, NumRegs);
936 }
937
938 return ABIArgInfo::getDirect(CoerceTy);
939 }
940
941 // All other aggregates are passed ByVal.
943 CharUnits::fromQuantity(ABIAlign),
944 /*AddrSpace=*/getDataLayout().getAllocaAddrSpace(),
945 /*ByVal=*/true, /*Realign=*/TyAlign > ABIAlign);
946 }
947
948 return (isPromotableTypeForABI(Ty)
949 ? ABIArgInfo::getExtend(Ty, CGT.ConvertType(Ty))
951}
952
953ABIArgInfo
954PPC64_SVR4_ABIInfo::classifyReturnType(QualType RetTy) const {
955 if (RetTy->isVoidType())
956 return ABIArgInfo::getIgnore();
957
958 if (RetTy->isAnyComplexType())
959 return ABIArgInfo::getDirect();
960
961 // Non-Altivec vector types are returned in GPRs (smaller than 16 bytes)
962 // or via reference (larger than 16 bytes).
963 if (RetTy->isVectorType()) {
964 uint64_t Size = getContext().getTypeSize(RetTy);
965 if (Size > 128)
966 return getNaturalAlignIndirect(RetTy,
967 getDataLayout().getAllocaAddrSpace());
968 else if (Size < 128) {
969 llvm::Type *CoerceTy = llvm::IntegerType::get(getVMContext(), Size);
970 return ABIArgInfo::getDirect(CoerceTy);
971 }
972 }
973
974 if (const auto *EIT = RetTy->getAs<BitIntType>())
975 if (EIT->getNumBits() > 128)
976 return getNaturalAlignIndirect(
977 RetTy, getDataLayout().getAllocaAddrSpace(), /*ByVal=*/false);
978
979 if (isAggregateTypeForABI(RetTy)) {
980 // ELFv2 homogeneous aggregates are returned as array types.
981 const Type *Base = nullptr;
982 uint64_t Members = 0;
983 if (Kind == PPC64_SVR4_ABIKind::ELFv2 &&
984 isHomogeneousAggregate(RetTy, Base, Members)) {
985 llvm::Type *BaseTy = CGT.ConvertType(QualType(Base, 0));
986 llvm::Type *CoerceTy = llvm::ArrayType::get(BaseTy, Members);
987 return ABIArgInfo::getDirect(CoerceTy);
988 }
989
990 // ELFv2 small aggregates are returned in up to two registers.
991 uint64_t Bits = getContext().getTypeSize(RetTy);
992 if (Kind == PPC64_SVR4_ABIKind::ELFv2 && Bits <= 2 * GPRBits) {
993 if (Bits == 0)
994 return ABIArgInfo::getIgnore();
995
996 llvm::Type *CoerceTy;
997 if (Bits > GPRBits) {
998 CoerceTy = llvm::IntegerType::get(getVMContext(), GPRBits);
999 CoerceTy = llvm::StructType::get(CoerceTy, CoerceTy);
1000 } else
1001 CoerceTy =
1002 llvm::IntegerType::get(getVMContext(), llvm::alignTo(Bits, 8));
1003 return ABIArgInfo::getDirect(CoerceTy);
1004 }
1005
1006 // All other aggregates are returned indirectly.
1007 return getNaturalAlignIndirect(RetTy, getDataLayout().getAllocaAddrSpace());
1008 }
1009
1010 return (isPromotableTypeForABI(RetTy) ? ABIArgInfo::getExtend(RetTy)
1012}
1013
1014// Based on ARMABIInfo::EmitVAArg, adjusted for 64-bit machine.
1015RValue PPC64_SVR4_ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
1016 QualType Ty, AggValueSlot Slot) const {
1017 auto TypeInfo = getContext().getTypeInfoInChars(Ty);
1018 TypeInfo.Align = getParamTypeAlignment(Ty);
1019
1020 CharUnits SlotSize = CharUnits::fromQuantity(8);
1021
1022 // If we have a complex type and the base type is smaller than 8 bytes,
1023 // the ABI calls for the real and imaginary parts to be right-adjusted
1024 // in separate doublewords. However, Clang expects us to produce a
1025 // pointer to a structure with the two parts packed tightly. So generate
1026 // loads of the real and imaginary parts relative to the va_list pointer,
1027 // and store them to a temporary structure.
1028 if (const ComplexType *CTy = Ty->getAs<ComplexType>()) {
1029 CharUnits EltSize = TypeInfo.Width / 2;
1030 if (EltSize < SlotSize)
1031 return complexTempStructure(CGF, VAListAddr, Ty, SlotSize, EltSize, CTy);
1032 }
1033
1034 // Otherwise, just use the general rule.
1035 //
1036 // The PPC64 ABI passes some arguments in integer registers, even to variadic
1037 // functions. To allow va_list to use the simple "void*" representation,
1038 // variadic calls allocate space in the argument area for the integer argument
1039 // registers, and variadic functions spill their integer argument registers to
1040 // this area in their prologues. When aggregates smaller than a register are
1041 // passed this way, they are passed in the least significant bits of the
1042 // register, which means that after spilling on big-endian targets they will
1043 // be right-aligned in their argument slot. This is uncommon; for a variety of
1044 // reasons, other big-endian targets don't end up right-aligning aggregate
1045 // types this way, and so right-alignment only applies to fundamental types.
1046 // So on PPC64, we must force the use of right-alignment even for aggregates.
1047 return emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*Indirect*/ false, TypeInfo,
1048 SlotSize, /*AllowHigher*/ true, Slot,
1049 /*ForceRightAdjust*/ true);
1050}
1051
1052bool
1053PPC64_SVR4_TargetCodeGenInfo::initDwarfEHRegSizeTable(
1054 CodeGen::CodeGenFunction &CGF,
1055 llvm::Value *Address) const {
1056 return PPC_initDwarfEHRegSizeTable(CGF, Address, /*Is64Bit*/ true,
1057 /*IsAIX*/ false);
1058}
1059
1060bool
1061PPC64TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
1062 llvm::Value *Address) const {
1063 return PPC_initDwarfEHRegSizeTable(CGF, Address, /*Is64Bit*/ true,
1064 /*IsAIX*/ false);
1065}
1066
1067std::unique_ptr<TargetCodeGenInfo>
1069 return std::make_unique<AIXTargetCodeGenInfo>(CGM.getTypes(), Is64Bit);
1070}
1071
1072std::unique_ptr<TargetCodeGenInfo>
1074 bool RetSmallStructInRegABI = PPC32TargetCodeGenInfo::isStructReturnInRegABI(
1075 CGM.getTriple(), CGM.getCodeGenOpts());
1076 return std::make_unique<PPC32TargetCodeGenInfo>(CGM.getTypes(), SoftFloatABI,
1077 RetSmallStructInRegABI);
1078}
1079
1080std::unique_ptr<TargetCodeGenInfo>
1082 return std::make_unique<PPC64TargetCodeGenInfo>(CGM.getTypes());
1083}
1084
1085std::unique_ptr<TargetCodeGenInfo> CodeGen::createPPC64_SVR4_TargetCodeGenInfo(
1086 CodeGenModule &CGM, PPC64_SVR4_ABIKind Kind, bool SoftFloatABI) {
1087 return std::make_unique<PPC64_SVR4_TargetCodeGenInfo>(CGM.getTypes(), Kind,
1088 SoftFloatABI);
1089}
static RValue complexTempStructure(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, CharUnits SlotSize, CharUnits EltSize, const ComplexType *CTy)
Definition PPC.cpp:16
static bool PPC_initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF, llvm::Value *Address, bool Is64Bit, bool IsAIX)
Definition PPC.cpp:43
Result
Implement __builtin_bit_cast and related operations.
static StringRef getTriple(const Command &Job)
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
TypeInfo getTypeInfo(const Type *T) const
Get the size and alignment of the specified complete type in bits.
TypeInfoChars getTypeInfoInChars(const Type *T) const
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
int64_t toBits(CharUnits CharSize) const
Convert a size in characters to a size in bits.
Attr - This represents one attribute.
Definition Attr.h:47
bool isFloatingPoint() const
Definition TypeBase.h:3325
Kind getKind() const
Definition TypeBase.h:3300
This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
Definition CharUnits.h:155
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
Definition CharUnits.h:184
static constexpr CharUnits fromQuantity(QuantityType Quantity)
Construct a CharUnits quantity from a raw integer type.
Definition CharUnits.h:58
std::vector< std::string > TocDataVarsUserSpecified
List of global variables explicitly specified by the user as toc-data.
std::vector< std::string > NoTocDataVars
List of global variables that over-ride the toc-data default.
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 getIndirect(CharUnits Alignment, unsigned AddrSpace, bool ByVal=true, bool Realign=false, llvm::Type *Padding=nullptr)
static ABIArgInfo getDirectInReg(llvm::Type *T=nullptr)
ABIInfo - Target specific hooks for defining how a type should be passed or returned from functions.
Definition ABIInfo.h:49
virtual void appendAttributeMangling(TargetAttr *Attr, raw_ostream &Out) const
Definition ABIInfo.cpp:201
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
Definition Address.h:128
static Address invalid()
Definition Address.h:176
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
Definition Address.h:253
CharUnits getAlignment() const
Definition Address.h:194
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
Address CreateConstInBoundsByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
Given a pointer to i8, adjust it by a given constant offset.
Definition CGBuilder.h:325
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
Definition CGBuilder.h:128
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()
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
llvm::Type * ConvertType(QualType T)
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
RValue EmitLoadOfAnyValue(LValue V, AggValueSlot Slot=AggValueSlot::ignored(), SourceLocation Loc={})
Like EmitLoadOfLValue but also handles complex and aggregate types.
Definition CGExpr.cpp:2523
llvm::Type * ConvertTypeForMem(QualType T)
void EmitBranch(llvm::BasicBlock *Block)
EmitBranch - Emit a branch to the specified basic block from the current insert block,...
Definition CGStmt.cpp:679
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
Definition CGStmt.cpp:659
This class organizes the cross-function state that is used while generating LLVM code.
DiagnosticsEngine & getDiags() const
const llvm::DataLayout & getDataLayout() const
const llvm::Triple & getTriple() const
const CodeGenOptions & getCodeGenOpts() const
ABIArgInfo classifyReturnType(QualType RetTy) const
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
Definition CGValue.h:42
static RValue getAggregate(Address addr, bool isVolatile=false)
Convert an Address to an RValue.
Definition CGValue.h:126
static RValue getComplex(llvm::Value *V1, llvm::Value *V2)
Definition CGValue.h:109
Complex values, per C99 6.2.5p11.
Definition TypeBase.h:3363
QualType getElementType() const
Definition TypeBase.h:3373
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:550
SourceLocation getLocation() const
Definition DeclBase.h:449
bool hasAttr() const
Definition DeclBase.h:587
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
A (possibly-)qualified type.
Definition TypeBase.h:938
bool hasFlexibleArrayMember() const
Definition Decl.h:4545
virtual ParsedTargetAttr parseTargetAttr(StringRef Str) const
bool isVoidType() const
Definition TypeBase.h:9306
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
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition Type.cpp:2678
bool isVectorType() const
Definition TypeBase.h:9056
bool isRealFloatingType() const
Floating point categories.
Definition Type.cpp:2551
bool isFloatingType() const
Definition Type.cpp:2535
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9537
@ TLS_None
Not a TLS variable.
Definition Decl.h:954
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)
std::unique_ptr< TargetCodeGenInfo > createPPC64_SVR4_TargetCodeGenInfo(CodeGenModule &CGM, PPC64_SVR4_ABIKind Kind, bool SoftFloatABI)
Definition PPC.cpp:1085
Address emitVoidPtrDirectVAArg(CodeGenFunction &CGF, Address VAListAddr, llvm::Type *DirectTy, CharUnits DirectSize, CharUnits DirectAlign, CharUnits SlotSize, bool AllowHigherAlign, bool ForceRightAdjust=false)
Emit va_arg for a platform using the common void* representation, where arguments are simply emitted ...
std::unique_ptr< TargetCodeGenInfo > createAIXTargetCodeGenInfo(CodeGenModule &CGM, bool Is64Bit)
Definition PPC.cpp:1068
bool isRecordWithSIMDVectorType(ASTContext &Context, QualType Ty)
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 ...
Address emitMergePHI(CodeGenFunction &CGF, Address Addr1, llvm::BasicBlock *Block1, Address Addr2, llvm::BasicBlock *Block2, const llvm::Twine &Name="")
const Type * isSingleElementRecord(QualType T, ASTContext &Context)
isSingleElementRecord - Determine if a record is a "singleelement record", i.e.
llvm::Value * emitRoundPointerUpToAlignment(CodeGenFunction &CGF, llvm::Value *Ptr, CharUnits Align)
bool isAggregateTypeForABI(QualType T)
const Type * isSingleElementStruct(QualType T, ASTContext &Context)
isSingleElementStruct - Like isSingleElementRecord, but neither T nor any record nested in it may be ...
void AssignToArrayRange(CodeGen::CGBuilderTy &Builder, llvm::Value *Array, llvm::Value *Value, unsigned FirstIndex, unsigned LastIndex)
QualType useFirstFieldIfTransparentUnion(QualType Ty)
Pass transparent unions as if they were the type of the first element.
std::unique_ptr< TargetCodeGenInfo > createPPC32TargetCodeGenInfo(CodeGenModule &CGM, bool SoftFloatABI)
Definition PPC.cpp:1073
std::unique_ptr< TargetCodeGenInfo > createPPC64TargetCodeGenInfo(CodeGenModule &CGM)
Definition PPC.cpp:1081
@ Address
A pointer to a ValueDecl.
Definition Primitives.h:28
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
Definition Address.h:330
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
int32_t uint32_t uint32_t __builtin_riscv_mhracc_i32 __builtin_riscv_mhraccu_u32 __builtin_riscv_mhraccsu_i32 __builtin_riscv_mhacc_h1_i32 __builtin_riscv_mhaccsu_h1_i32 __builtin_riscv_mulqr_i32 __builtin_riscv_mqrwacc_i64 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 uint8_t
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
std::vector< std::string > Features
Definition TargetInfo.h:60