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