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 // Handle feature strings
162 if (Info.Features.size() == 1) {
163 StringRef Feature = Info.Features[0];
164 assert(Feature.starts_with("+") || Feature.starts_with("-"));
165
166 // replace hyphens with underscores
167 std::string MangledName(Feature.drop_front(1));
168 std::replace(MangledName.begin(), MangledName.end(), '-', '_');
169
170 Out << "." << (Feature.starts_with("-") ? "no_" : "") << MangledName;
171 return;
172 }
173
174 llvm_unreachable("Invalid target_clones parameter");
175}
176
177class AIXTargetCodeGenInfo : public TargetCodeGenInfo {
178 const bool Is64Bit;
179
180public:
181 AIXTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT, bool Is64Bit)
182 : TargetCodeGenInfo(std::make_unique<AIXABIInfo>(CGT, Is64Bit)),
183 Is64Bit(Is64Bit) {}
184 int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
185 return 1; // r1 is the dedicated stack pointer
186 }
187
188 bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
189 llvm::Value *Address) const override;
190
191 void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
192 CodeGen::CodeGenModule &M) const override;
193};
194} // namespace
195
196// Return true if the ABI requires Ty to be passed sign- or zero-
197// extended to 32/64 bits.
198bool AIXABIInfo::isPromotableTypeForABI(QualType Ty) const {
199 // Treat an enum type as its underlying type.
200 if (const auto *ED = Ty->getAsEnumDecl())
201 Ty = ED->getIntegerType();
202
203 // Promotable integer types are required to be promoted by the ABI.
204 if (getContext().isPromotableIntegerType(Ty))
205 return true;
206
207 if (!Is64Bit)
208 return false;
209
210 // For 64 bit mode, in addition to the usual promotable integer types, we also
211 // need to extend all 32-bit types, since the ABI requires promotion to 64
212 // bits.
213 if (const BuiltinType *BT = Ty->getAs<BuiltinType>())
214 switch (BT->getKind()) {
215 case BuiltinType::Int:
216 case BuiltinType::UInt:
217 return true;
218 default:
219 break;
220 }
221
222 return false;
223}
224
225ABIArgInfo AIXABIInfo::classifyReturnType(QualType RetTy) const {
226 if (RetTy->isAnyComplexType())
227 return ABIArgInfo::getDirect();
228
229 if (RetTy->isVectorType())
230 return ABIArgInfo::getDirect();
231
232 if (RetTy->isVoidType())
233 return ABIArgInfo::getIgnore();
234
235 if (isAggregateTypeForABI(RetTy))
236 return getNaturalAlignIndirect(RetTy, getDataLayout().getAllocaAddrSpace());
237
238 return (isPromotableTypeForABI(RetTy) ? ABIArgInfo::getExtend(RetTy)
240}
241
242ABIArgInfo AIXABIInfo::classifyArgumentType(QualType Ty) const {
244
245 if (Ty->isAnyComplexType())
246 return ABIArgInfo::getDirect();
247
248 if (Ty->isVectorType())
249 return ABIArgInfo::getDirect();
250
251 if (isAggregateTypeForABI(Ty)) {
252 // Records with non-trivial destructors/copy-constructors should not be
253 // passed by value.
254 if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI()))
255 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
257
258 CharUnits CCAlign = getParamTypeAlignment(Ty);
259 CharUnits TyAlign = getContext().getTypeAlignInChars(Ty);
260
262 CCAlign, /*AddrSpace=*/getDataLayout().getAllocaAddrSpace(),
263 /*ByVal=*/true,
264 /*Realign=*/TyAlign > CCAlign);
265 }
266
267 return (isPromotableTypeForABI(Ty)
268 ? ABIArgInfo::getExtend(Ty, CGT.ConvertType(Ty))
270}
271
272CharUnits AIXABIInfo::getParamTypeAlignment(QualType Ty) const {
273 // Complex types are passed just like their elements.
274 if (const ComplexType *CTy = Ty->getAs<ComplexType>())
275 Ty = CTy->getElementType();
276
277 if (Ty->isVectorType())
278 return CharUnits::fromQuantity(16);
279
280 // If the structure contains a vector type, the alignment is 16.
281 if (isRecordWithSIMDVectorType(getContext(), Ty))
282 return CharUnits::fromQuantity(16);
283
284 return CharUnits::fromQuantity(PtrByteSize);
285}
286
287RValue AIXABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
288 QualType Ty, AggValueSlot Slot) const {
289
290 auto TypeInfo = getContext().getTypeInfoInChars(Ty);
291 TypeInfo.Align = getParamTypeAlignment(Ty);
292
293 CharUnits SlotSize = CharUnits::fromQuantity(PtrByteSize);
294
295 // If we have a complex type and the base type is smaller than the register
296 // size, the ABI calls for the real and imaginary parts to be right-adjusted
297 // in separate words in 32bit mode or doublewords in 64bit mode. However,
298 // Clang expects us to produce a pointer to a structure with the two parts
299 // packed tightly. So generate loads of the real and imaginary parts relative
300 // to the va_list pointer, and store them to a temporary structure. We do the
301 // same as the PPC64ABI here.
302 if (const ComplexType *CTy = Ty->getAs<ComplexType>()) {
303 CharUnits EltSize = TypeInfo.Width / 2;
304 if (EltSize < SlotSize)
305 return complexTempStructure(CGF, VAListAddr, Ty, SlotSize, EltSize, CTy);
306 }
307
308 return emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*Indirect*/ false, TypeInfo,
309 SlotSize, /*AllowHigher*/ true, Slot);
310}
311
312bool AIXTargetCodeGenInfo::initDwarfEHRegSizeTable(
313 CodeGen::CodeGenFunction &CGF, llvm::Value *Address) const {
314 return PPC_initDwarfEHRegSizeTable(CGF, Address, Is64Bit, /*IsAIX*/ true);
315}
316
317void AIXTargetCodeGenInfo::setTargetAttributes(
318 const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
320 return;
321
322 auto *GVar = cast<llvm::GlobalVariable>(GV);
323 auto GVId = GV->getName();
324
325 // Is this a global variable specified by the user as toc-data?
326 bool UserSpecifiedTOC =
327 llvm::binary_search(M.getCodeGenOpts().TocDataVarsUserSpecified, GVId);
328 // Assumes the same variable cannot be in both TocVarsUserSpecified and
329 // NoTocVars.
330 if (UserSpecifiedTOC ||
331 ((M.getCodeGenOpts().AllTocData) &&
332 !llvm::binary_search(M.getCodeGenOpts().NoTocDataVars, GVId))) {
333 const unsigned long PointerSize =
334 GV->getParent()->getDataLayout().getPointerSizeInBits() / 8;
335 auto *VarD = dyn_cast<VarDecl>(D);
336 assert(VarD && "Invalid declaration of global variable.");
337
338 ASTContext &Context = D->getASTContext();
339 unsigned Alignment = Context.toBits(Context.getDeclAlign(D)) / 8;
340 const auto *Ty = VarD->getType().getTypePtr();
341 const RecordDecl *RDecl = Ty->getAsRecordDecl();
342
343 bool EmitDiagnostic = UserSpecifiedTOC && GV->hasExternalLinkage();
344 auto reportUnsupportedWarning = [&](bool ShouldEmitWarning, StringRef Msg) {
345 if (ShouldEmitWarning)
346 M.getDiags().Report(D->getLocation(), diag::warn_toc_unsupported_type)
347 << GVId << Msg;
348 };
349 if (!Ty || Ty->isIncompleteType())
350 reportUnsupportedWarning(EmitDiagnostic, "of incomplete type");
351 else if (RDecl && RDecl->hasFlexibleArrayMember())
352 reportUnsupportedWarning(EmitDiagnostic,
353 "it contains a flexible array member");
354 else if (VarD->getTLSKind() != VarDecl::TLS_None)
355 reportUnsupportedWarning(EmitDiagnostic, "of thread local storage");
356 else if (PointerSize < Context.getTypeInfo(VarD->getType()).Width / 8)
357 reportUnsupportedWarning(EmitDiagnostic,
358 "variable is larger than a pointer");
359 else if (PointerSize < Alignment)
360 reportUnsupportedWarning(EmitDiagnostic,
361 "variable is aligned wider than a pointer");
362 else if (D->hasAttr<SectionAttr>())
363 reportUnsupportedWarning(EmitDiagnostic,
364 "variable has a section attribute");
365 else if (GV->hasExternalLinkage() ||
366 (M.getCodeGenOpts().AllTocData && !GV->hasLocalLinkage()))
367 GVar->addAttribute("toc-data");
368 }
369}
370
371// PowerPC-32
372namespace {
373/// PPC32_SVR4_ABIInfo - The 32-bit PowerPC ELF (SVR4) ABI information.
374class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
375 bool IsSoftFloatABI;
376 bool IsRetSmallStructInRegABI;
377
378 CharUnits getParamTypeAlignment(QualType Ty) const;
379
380public:
381 PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, bool SoftFloatABI,
382 bool RetSmallStructInRegABI)
383 : DefaultABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
384 IsRetSmallStructInRegABI(RetSmallStructInRegABI) {}
385
386 ABIArgInfo classifyReturnType(QualType RetTy) const;
387
388 void computeInfo(CGFunctionInfo &FI) const override {
389 if (!getCXXABI().classifyReturnType(FI))
391 for (auto &I : FI.arguments())
392 I.info = classifyArgumentType(I.type);
393 }
394
395 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
396 AggValueSlot Slot) const override;
397};
398
399class PPC32TargetCodeGenInfo : public TargetCodeGenInfo {
400public:
401 PPC32TargetCodeGenInfo(CodeGenTypes &CGT, bool SoftFloatABI,
402 bool RetSmallStructInRegABI)
403 : TargetCodeGenInfo(std::make_unique<PPC32_SVR4_ABIInfo>(
404 CGT, SoftFloatABI, RetSmallStructInRegABI)) {}
405
406 static bool isStructReturnInRegABI(const llvm::Triple &Triple,
407 const CodeGenOptions &Opts);
408
409 int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
410 // This is recovered from gcc output.
411 return 1; // r1 is the dedicated stack pointer
412 }
413
414 bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
415 llvm::Value *Address) const override;
416};
417}
418
419CharUnits PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
420 // Complex types are passed just like their elements.
421 if (const ComplexType *CTy = Ty->getAs<ComplexType>())
422 Ty = CTy->getElementType();
423
424 if (Ty->isVectorType())
425 return CharUnits::fromQuantity(getContext().getTypeSize(Ty) == 128 ? 16
426 : 4);
427
428 // For single-element float/vector structs, we consider the whole type
429 // to have the same alignment requirements as its single element.
430 const Type *AlignTy = nullptr;
431 if (const Type *EltType = isSingleElementStruct(Ty, getContext())) {
432 const BuiltinType *BT = EltType->getAs<BuiltinType>();
433 if ((EltType->isVectorType() && getContext().getTypeSize(EltType) == 128) ||
434 (BT && BT->isFloatingPoint()))
435 AlignTy = EltType;
436 }
437
438 if (AlignTy)
439 return CharUnits::fromQuantity(AlignTy->isVectorType() ? 16 : 4);
440 return CharUnits::fromQuantity(4);
441}
442
443ABIArgInfo PPC32_SVR4_ABIInfo::classifyReturnType(QualType RetTy) const {
445
446 // -msvr4-struct-return puts small aggregates in GPR3 and GPR4.
447 if (isAggregateTypeForABI(RetTy) && IsRetSmallStructInRegABI &&
448 (Size = getContext().getTypeSize(RetTy)) <= 64) {
449 // System V ABI (1995), page 3-22, specified:
450 // > A structure or union whose size is less than or equal to 8 bytes
451 // > shall be returned in r3 and r4, as if it were first stored in the
452 // > 8-byte aligned memory area and then the low addressed word were
453 // > loaded into r3 and the high-addressed word into r4. Bits beyond
454 // > the last member of the structure or union are not defined.
455 //
456 // GCC for big-endian PPC32 inserts the pad before the first member,
457 // not "beyond the last member" of the struct. To stay compatible
458 // with GCC, we coerce the struct to an integer of the same size.
459 // LLVM will extend it and return i32 in r3, or i64 in r3:r4.
460 if (Size == 0)
461 return ABIArgInfo::getIgnore();
462 else {
463 llvm::Type *CoerceTy = llvm::Type::getIntNTy(getVMContext(), Size);
464 return ABIArgInfo::getDirect(CoerceTy);
465 }
466 }
467
469}
470
471// TODO: this implementation is now likely redundant with
472// DefaultABIInfo::EmitVAArg.
473RValue PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAList,
474 QualType Ty, AggValueSlot Slot) const {
475 if (getTarget().getTriple().isOSDarwin()) {
476 auto TI = getContext().getTypeInfoInChars(Ty);
477 TI.Align = getParamTypeAlignment(Ty);
478
479 CharUnits SlotSize = CharUnits::fromQuantity(4);
480 return emitVoidPtrVAArg(CGF, VAList, Ty,
481 classifyArgumentType(Ty).isIndirect(), TI, SlotSize,
482 /*AllowHigherAlign=*/true, Slot);
483 }
484
485 const unsigned OverflowLimit = 8;
486 if (const ComplexType *CTy = Ty->getAs<ComplexType>()) {
487 // TODO: Implement this. For now ignore.
488 (void)CTy;
489 return RValue::getAggregate(Address::invalid()); // FIXME?
490 }
491
492 // struct __va_list_tag {
493 // unsigned char gpr;
494 // unsigned char fpr;
495 // unsigned short reserved;
496 // void *overflow_arg_area;
497 // void *reg_save_area;
498 // };
499
500 bool isI64 = Ty->isIntegerType() && getContext().getTypeSize(Ty) == 64;
501 bool isInt = !Ty->isFloatingType();
502 bool isF64 = Ty->isFloatingType() && getContext().getTypeSize(Ty) == 64;
503
504 // All aggregates are passed indirectly? That doesn't seem consistent
505 // with the argument-lowering code.
506 bool isIndirect = isAggregateTypeForABI(Ty);
507
508 CGBuilderTy &Builder = CGF.Builder;
509
510 // The calling convention either uses 1-2 GPRs or 1 FPR.
511 Address NumRegsAddr = Address::invalid();
512 if (isInt || IsSoftFloatABI) {
513 NumRegsAddr = Builder.CreateStructGEP(VAList, 0, "gpr");
514 } else {
515 NumRegsAddr = Builder.CreateStructGEP(VAList, 1, "fpr");
516 }
517
518 llvm::Value *NumRegs = Builder.CreateLoad(NumRegsAddr, "numUsedRegs");
519
520 // "Align" the register count when TY is i64.
521 if (isI64 || (isF64 && IsSoftFloatABI)) {
522 NumRegs = Builder.CreateAdd(NumRegs, Builder.getInt8(1));
523 NumRegs = Builder.CreateAnd(NumRegs, Builder.getInt8((uint8_t) ~1U));
524 }
525
526 llvm::Value *CC =
527 Builder.CreateICmpULT(NumRegs, Builder.getInt8(OverflowLimit), "cond");
528
529 llvm::BasicBlock *UsingRegs = CGF.createBasicBlock("using_regs");
530 llvm::BasicBlock *UsingOverflow = CGF.createBasicBlock("using_overflow");
531 llvm::BasicBlock *Cont = CGF.createBasicBlock("cont");
532
533 Builder.CreateCondBr(CC, UsingRegs, UsingOverflow);
534
535 llvm::Type *DirectTy = CGF.ConvertType(Ty), *ElementTy = DirectTy;
536 if (isIndirect)
537 DirectTy = CGF.DefaultPtrTy;
538
539 // Case 1: consume registers.
540 Address RegAddr = Address::invalid();
541 {
542 CGF.EmitBlock(UsingRegs);
543
544 Address RegSaveAreaPtr = Builder.CreateStructGEP(VAList, 4);
545 RegAddr = Address(Builder.CreateLoad(RegSaveAreaPtr), CGF.Int8Ty,
547 assert(RegAddr.getElementType() == CGF.Int8Ty);
548
549 // Floating-point registers start after the general-purpose registers.
550 if (!(isInt || IsSoftFloatABI)) {
551 RegAddr = Builder.CreateConstInBoundsByteGEP(RegAddr,
553 }
554
555 // Get the address of the saved value by scaling the number of
556 // registers we've used by the number of
557 CharUnits RegSize = CharUnits::fromQuantity((isInt || IsSoftFloatABI) ? 4 : 8);
558 llvm::Value *RegOffset =
559 Builder.CreateMul(NumRegs, Builder.getInt8(RegSize.getQuantity()));
560 RegAddr = Address(Builder.CreateInBoundsGEP(
561 CGF.Int8Ty, RegAddr.emitRawPointer(CGF), RegOffset),
562 DirectTy,
563 RegAddr.getAlignment().alignmentOfArrayElement(RegSize));
564
565 // Increase the used-register count.
566 NumRegs =
567 Builder.CreateAdd(NumRegs,
568 Builder.getInt8((isI64 || (isF64 && IsSoftFloatABI)) ? 2 : 1));
569 Builder.CreateStore(NumRegs, NumRegsAddr);
570
571 CGF.EmitBranch(Cont);
572 }
573
574 // Case 2: consume space in the overflow area.
575 Address MemAddr = Address::invalid();
576 {
577 CGF.EmitBlock(UsingOverflow);
578
579 Builder.CreateStore(Builder.getInt8(OverflowLimit), NumRegsAddr);
580
581 // Everything in the overflow area is rounded up to a size of at least 4.
582 CharUnits OverflowAreaAlign = CharUnits::fromQuantity(4);
583
584 CharUnits Size;
585 if (!isIndirect) {
586 auto TypeInfo = CGF.getContext().getTypeInfoInChars(Ty);
587 Size = TypeInfo.Width.alignTo(OverflowAreaAlign);
588 } else {
589 Size = CGF.getPointerSize();
590 }
591
592 Address OverflowAreaAddr = Builder.CreateStructGEP(VAList, 3);
593 Address OverflowArea =
594 Address(Builder.CreateLoad(OverflowAreaAddr, "argp.cur"), CGF.Int8Ty,
595 OverflowAreaAlign);
596 // Round up address of argument to alignment
597 CharUnits Align = CGF.getContext().getTypeAlignInChars(Ty);
598 if (Align > OverflowAreaAlign) {
599 llvm::Value *Ptr = OverflowArea.emitRawPointer(CGF);
600 OverflowArea = Address(emitRoundPointerUpToAlignment(CGF, Ptr, Align),
601 OverflowArea.getElementType(), Align);
602 }
603
604 MemAddr = OverflowArea.withElementType(DirectTy);
605
606 // Increase the overflow area.
607 OverflowArea = Builder.CreateConstInBoundsByteGEP(OverflowArea, Size);
608 Builder.CreateStore(OverflowArea.emitRawPointer(CGF), OverflowAreaAddr);
609 CGF.EmitBranch(Cont);
610 }
611
612 CGF.EmitBlock(Cont);
613
614 // Merge the cases with a phi.
615 Address Result = emitMergePHI(CGF, RegAddr, UsingRegs, MemAddr, UsingOverflow,
616 "vaarg.addr");
617
618 // Load the pointer if the argument was passed indirectly.
619 if (isIndirect) {
620 Result = Address(Builder.CreateLoad(Result, "aggr"), ElementTy,
621 getContext().getTypeAlignInChars(Ty));
622 }
623
624 return CGF.EmitLoadOfAnyValue(CGF.MakeAddrLValue(Result, Ty), Slot);
625}
626
627bool PPC32TargetCodeGenInfo::isStructReturnInRegABI(
628 const llvm::Triple &Triple, const CodeGenOptions &Opts) {
629 assert(Triple.isPPC32());
630
631 switch (Opts.getStructReturnConvention()) {
633 break;
634 case CodeGenOptions::SRCK_OnStack: // -maix-struct-return
635 return false;
636 case CodeGenOptions::SRCK_InRegs: // -msvr4-struct-return
637 return true;
638 }
639
640 if (Triple.isOSBinFormatELF() && !Triple.isOSLinux())
641 return true;
642
643 return false;
644}
645
646bool
647PPC32TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
648 llvm::Value *Address) const {
649 return PPC_initDwarfEHRegSizeTable(CGF, Address, /*Is64Bit*/ false,
650 /*IsAIX*/ false);
651}
652
653// PowerPC-64
654
655namespace {
656
657/// PPC64_SVR4_ABIInfo - The 64-bit PowerPC ELF (SVR4) ABI information.
658class PPC64_SVR4_ABIInfo : public ABIInfo {
659 static const unsigned GPRBits = 64;
661 bool IsSoftFloatABI;
662
663public:
664 PPC64_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, PPC64_SVR4_ABIKind Kind,
665 bool SoftFloatABI)
666 : ABIInfo(CGT), Kind(Kind), IsSoftFloatABI(SoftFloatABI) {}
667
668 bool isPromotableTypeForABI(QualType Ty) const;
669 CharUnits getParamTypeAlignment(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 const Type *T = isSingleElementStruct(I.type, getContext());
692 if (T) {
693 const BuiltinType *BT = T->getAs<BuiltinType>();
694 if ((T->isVectorType() && getContext().getTypeSize(T) == 128) ||
695 (BT && BT->isFloatingPoint())) {
696 QualType QT(T, 0);
697 I.info = ABIArgInfo::getDirectInReg(CGT.ConvertType(QT));
698 continue;
699 }
700 }
701 I.info = classifyArgumentType(I.type);
702 }
703 }
704
705 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
706 AggValueSlot Slot) const override;
707};
708
709class PPC64_SVR4_TargetCodeGenInfo : public TargetCodeGenInfo {
710
711public:
712 PPC64_SVR4_TargetCodeGenInfo(CodeGenTypes &CGT, PPC64_SVR4_ABIKind Kind,
713 bool SoftFloatABI)
714 : TargetCodeGenInfo(
715 std::make_unique<PPC64_SVR4_ABIInfo>(CGT, Kind, SoftFloatABI)) {
716 SwiftInfo =
717 std::make_unique<SwiftABIInfo>(CGT, /*SwiftErrorInRegister=*/false);
718 }
719
720 int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
721 // This is recovered from gcc output.
722 return 1; // r1 is the dedicated stack pointer
723 }
724
725 bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
726 llvm::Value *Address) const override;
727};
728
729class PPC64TargetCodeGenInfo : public TargetCodeGenInfo {
730public:
731 PPC64TargetCodeGenInfo(CodeGenTypes &CGT)
732 : TargetCodeGenInfo(std::make_unique<DefaultABIInfo>(CGT)) {}
733
734 int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
735 // This is recovered from gcc output.
736 return 1; // r1 is the dedicated stack pointer
737 }
738
739 bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
740 llvm::Value *Address) const override;
741};
742}
743
744// Return true if the ABI requires Ty to be passed sign- or zero-
745// extended to 64 bits.
746bool
747PPC64_SVR4_ABIInfo::isPromotableTypeForABI(QualType Ty) const {
748 // Treat an enum type as its underlying type.
749 if (const auto *ED = Ty->getAsEnumDecl())
750 Ty = ED->getIntegerType();
751
752 // Promotable integer types are required to be promoted by the ABI.
753 if (isPromotableIntegerTypeForABI(Ty))
754 return true;
755
756 // In addition to the usual promotable integer types, we also need to
757 // extend all 32-bit types, since the ABI requires promotion to 64 bits.
758 if (const BuiltinType *BT = Ty->getAs<BuiltinType>())
759 switch (BT->getKind()) {
760 case BuiltinType::Int:
761 case BuiltinType::UInt:
762 return true;
763 default:
764 break;
765 }
766
767 if (const auto *EIT = Ty->getAs<BitIntType>())
768 if (EIT->getNumBits() < 64)
769 return true;
770
771 return false;
772}
773
774/// isAlignedParamType - Determine whether a type requires 16-byte or
775/// higher alignment in the parameter area. Always returns at least 8.
776CharUnits PPC64_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
777 // Complex types are passed just like their elements.
778 if (const ComplexType *CTy = Ty->getAs<ComplexType>())
779 Ty = CTy->getElementType();
780
781 auto FloatUsesVector = [this](QualType Ty){
782 return Ty->isRealFloatingType() && &getContext().getFloatTypeSemantics(
783 Ty) == &llvm::APFloat::IEEEquad();
784 };
785
786 // Only vector types of size 16 bytes need alignment (larger types are
787 // passed via reference, smaller types are not aligned).
788 if (Ty->isVectorType()) {
789 return CharUnits::fromQuantity(getContext().getTypeSize(Ty) == 128 ? 16 : 8);
790 } else if (FloatUsesVector(Ty)) {
791 // According to ABI document section 'Optional Save Areas': If extended
792 // precision floating-point values in IEEE BINARY 128 QUADRUPLE PRECISION
793 // format are supported, map them to a single quadword, quadword aligned.
794 return CharUnits::fromQuantity(16);
795 }
796
797 // For single-element float/vector structs, we consider the whole type
798 // to have the same alignment requirements as its single element.
799 const Type *AlignAsType = nullptr;
800 const Type *EltType = isSingleElementStruct(Ty, getContext());
801 if (EltType) {
802 const BuiltinType *BT = EltType->getAs<BuiltinType>();
803 if ((EltType->isVectorType() && getContext().getTypeSize(EltType) == 128) ||
804 (BT && BT->isFloatingPoint()))
805 AlignAsType = EltType;
806 }
807
808 // Likewise for ELFv2 homogeneous aggregates.
809 const Type *Base = nullptr;
810 uint64_t Members = 0;
811 if (!AlignAsType && Kind == PPC64_SVR4_ABIKind::ELFv2 &&
812 isAggregateTypeForABI(Ty) && isHomogeneousAggregate(Ty, Base, Members))
813 AlignAsType = Base;
814
815 // With special case aggregates, only vector base types need alignment.
816 if (AlignAsType) {
817 bool UsesVector = AlignAsType->isVectorType() ||
818 FloatUsesVector(QualType(AlignAsType, 0));
819 return CharUnits::fromQuantity(UsesVector ? 16 : 8);
820 }
821
822 // Otherwise, we only need alignment for any aggregate type that
823 // has an alignment requirement of >= 16 bytes.
824 if (isAggregateTypeForABI(Ty) && getContext().getTypeAlign(Ty) >= 128) {
825 return CharUnits::fromQuantity(16);
826 }
827
828 return CharUnits::fromQuantity(8);
829}
830
831bool PPC64_SVR4_ABIInfo::isHomogeneousAggregateBaseType(QualType Ty) const {
832 // Homogeneous aggregates for ELFv2 must have base types of float,
833 // double, long double, or 128-bit vectors.
834 if (const BuiltinType *BT = Ty->getAs<BuiltinType>()) {
835 if (BT->getKind() == BuiltinType::Float ||
836 BT->getKind() == BuiltinType::Double ||
837 BT->getKind() == BuiltinType::LongDouble ||
838 BT->getKind() == BuiltinType::Ibm128 ||
839 (getContext().getTargetInfo().hasFloat128Type() &&
840 (BT->getKind() == BuiltinType::Float128))) {
841 if (IsSoftFloatABI)
842 return false;
843 return true;
844 }
845 }
846 if (const VectorType *VT = Ty->getAs<VectorType>()) {
847 if (getContext().getTypeSize(VT) == 128)
848 return true;
849 }
850 return false;
851}
852
853bool PPC64_SVR4_ABIInfo::isHomogeneousAggregateSmallEnough(
854 const Type *Base, uint64_t Members) const {
855 // Vector and fp128 types require one register, other floating point types
856 // require one or two registers depending on their size.
857 uint32_t NumRegs =
858 ((getContext().getTargetInfo().hasFloat128Type() &&
859 Base->isFloat128Type()) ||
860 Base->isVectorType()) ? 1
861 : (getContext().getTypeSize(Base) + 63) / 64;
862
863 // Homogeneous Aggregates may occupy at most 8 registers.
864 return Members * NumRegs <= 8;
865}
866
867ABIArgInfo
868PPC64_SVR4_ABIInfo::classifyArgumentType(QualType Ty) const {
870
871 if (Ty->isAnyComplexType())
872 return ABIArgInfo::getDirect();
873
874 // Non-Altivec vector types are passed in GPRs (smaller than 16 bytes)
875 // or via reference (larger than 16 bytes).
876 if (Ty->isVectorType()) {
877 uint64_t Size = getContext().getTypeSize(Ty);
878 if (Size > 128)
879 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
880 /*ByVal=*/false);
881 else if (Size < 128) {
882 llvm::Type *CoerceTy = llvm::IntegerType::get(getVMContext(), Size);
883 return ABIArgInfo::getDirect(CoerceTy);
884 }
885 }
886
887 if (const auto *EIT = Ty->getAs<BitIntType>())
888 if (EIT->getNumBits() > 128)
889 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
890 /*ByVal=*/true);
891
892 if (isAggregateTypeForABI(Ty)) {
893 if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI()))
894 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
896
897 uint64_t ABIAlign = getParamTypeAlignment(Ty).getQuantity();
898 uint64_t TyAlign = getContext().getTypeAlignInChars(Ty).getQuantity();
899
900 // ELFv2 homogeneous aggregates are passed as array types.
901 const Type *Base = nullptr;
902 uint64_t Members = 0;
903 if (Kind == PPC64_SVR4_ABIKind::ELFv2 &&
904 isHomogeneousAggregate(Ty, Base, Members)) {
905 llvm::Type *BaseTy = CGT.ConvertType(QualType(Base, 0));
906 llvm::Type *CoerceTy = llvm::ArrayType::get(BaseTy, Members);
907 return ABIArgInfo::getDirect(CoerceTy);
908 }
909
910 // If an aggregate may end up fully in registers, we do not
911 // use the ByVal method, but pass the aggregate as array.
912 // This is usually beneficial since we avoid forcing the
913 // back-end to store the argument to memory.
914 uint64_t Bits = getContext().getTypeSize(Ty);
915 if (Bits > 0 && Bits <= 8 * GPRBits) {
916 llvm::Type *CoerceTy;
917
918 // Types up to 8 bytes are passed as integer type (which will be
919 // properly aligned in the argument save area doubleword).
920 if (Bits <= GPRBits)
921 CoerceTy =
922 llvm::IntegerType::get(getVMContext(), llvm::alignTo(Bits, 8));
923 // Larger types are passed as arrays, with the base type selected
924 // according to the required alignment in the save area.
925 else {
926 uint64_t RegBits = ABIAlign * 8;
927 uint64_t NumRegs = llvm::alignTo(Bits, RegBits) / RegBits;
928 llvm::Type *RegTy = llvm::IntegerType::get(getVMContext(), RegBits);
929 CoerceTy = llvm::ArrayType::get(RegTy, NumRegs);
930 }
931
932 return ABIArgInfo::getDirect(CoerceTy);
933 }
934
935 // All other aggregates are passed ByVal.
937 CharUnits::fromQuantity(ABIAlign),
938 /*AddrSpace=*/getDataLayout().getAllocaAddrSpace(),
939 /*ByVal=*/true, /*Realign=*/TyAlign > ABIAlign);
940 }
941
942 return (isPromotableTypeForABI(Ty)
943 ? ABIArgInfo::getExtend(Ty, CGT.ConvertType(Ty))
945}
946
947ABIArgInfo
948PPC64_SVR4_ABIInfo::classifyReturnType(QualType RetTy) const {
949 if (RetTy->isVoidType())
950 return ABIArgInfo::getIgnore();
951
952 if (RetTy->isAnyComplexType())
953 return ABIArgInfo::getDirect();
954
955 // Non-Altivec vector types are returned in GPRs (smaller than 16 bytes)
956 // or via reference (larger than 16 bytes).
957 if (RetTy->isVectorType()) {
958 uint64_t Size = getContext().getTypeSize(RetTy);
959 if (Size > 128)
960 return getNaturalAlignIndirect(RetTy,
961 getDataLayout().getAllocaAddrSpace());
962 else if (Size < 128) {
963 llvm::Type *CoerceTy = llvm::IntegerType::get(getVMContext(), Size);
964 return ABIArgInfo::getDirect(CoerceTy);
965 }
966 }
967
968 if (const auto *EIT = RetTy->getAs<BitIntType>())
969 if (EIT->getNumBits() > 128)
970 return getNaturalAlignIndirect(
971 RetTy, getDataLayout().getAllocaAddrSpace(), /*ByVal=*/false);
972
973 if (isAggregateTypeForABI(RetTy)) {
974 // ELFv2 homogeneous aggregates are returned as array types.
975 const Type *Base = nullptr;
976 uint64_t Members = 0;
977 if (Kind == PPC64_SVR4_ABIKind::ELFv2 &&
978 isHomogeneousAggregate(RetTy, Base, Members)) {
979 llvm::Type *BaseTy = CGT.ConvertType(QualType(Base, 0));
980 llvm::Type *CoerceTy = llvm::ArrayType::get(BaseTy, Members);
981 return ABIArgInfo::getDirect(CoerceTy);
982 }
983
984 // ELFv2 small aggregates are returned in up to two registers.
985 uint64_t Bits = getContext().getTypeSize(RetTy);
986 if (Kind == PPC64_SVR4_ABIKind::ELFv2 && Bits <= 2 * GPRBits) {
987 if (Bits == 0)
988 return ABIArgInfo::getIgnore();
989
990 llvm::Type *CoerceTy;
991 if (Bits > GPRBits) {
992 CoerceTy = llvm::IntegerType::get(getVMContext(), GPRBits);
993 CoerceTy = llvm::StructType::get(CoerceTy, CoerceTy);
994 } else
995 CoerceTy =
996 llvm::IntegerType::get(getVMContext(), llvm::alignTo(Bits, 8));
997 return ABIArgInfo::getDirect(CoerceTy);
998 }
999
1000 // All other aggregates are returned indirectly.
1001 return getNaturalAlignIndirect(RetTy, getDataLayout().getAllocaAddrSpace());
1002 }
1003
1004 return (isPromotableTypeForABI(RetTy) ? ABIArgInfo::getExtend(RetTy)
1006}
1007
1008// Based on ARMABIInfo::EmitVAArg, adjusted for 64-bit machine.
1009RValue PPC64_SVR4_ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
1010 QualType Ty, AggValueSlot Slot) const {
1011 auto TypeInfo = getContext().getTypeInfoInChars(Ty);
1012 TypeInfo.Align = getParamTypeAlignment(Ty);
1013
1014 CharUnits SlotSize = CharUnits::fromQuantity(8);
1015
1016 // If we have a complex type and the base type is smaller than 8 bytes,
1017 // the ABI calls for the real and imaginary parts to be right-adjusted
1018 // in separate doublewords. However, Clang expects us to produce a
1019 // pointer to a structure with the two parts packed tightly. So generate
1020 // loads of the real and imaginary parts relative to the va_list pointer,
1021 // and store them to a temporary structure.
1022 if (const ComplexType *CTy = Ty->getAs<ComplexType>()) {
1023 CharUnits EltSize = TypeInfo.Width / 2;
1024 if (EltSize < SlotSize)
1025 return complexTempStructure(CGF, VAListAddr, Ty, SlotSize, EltSize, CTy);
1026 }
1027
1028 // Otherwise, just use the general rule.
1029 //
1030 // The PPC64 ABI passes some arguments in integer registers, even to variadic
1031 // functions. To allow va_list to use the simple "void*" representation,
1032 // variadic calls allocate space in the argument area for the integer argument
1033 // registers, and variadic functions spill their integer argument registers to
1034 // this area in their prologues. When aggregates smaller than a register are
1035 // passed this way, they are passed in the least significant bits of the
1036 // register, which means that after spilling on big-endian targets they will
1037 // be right-aligned in their argument slot. This is uncommon; for a variety of
1038 // reasons, other big-endian targets don't end up right-aligning aggregate
1039 // types this way, and so right-alignment only applies to fundamental types.
1040 // So on PPC64, we must force the use of right-alignment even for aggregates.
1041 return emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*Indirect*/ false, TypeInfo,
1042 SlotSize, /*AllowHigher*/ true, Slot,
1043 /*ForceRightAdjust*/ true);
1044}
1045
1046bool
1047PPC64_SVR4_TargetCodeGenInfo::initDwarfEHRegSizeTable(
1048 CodeGen::CodeGenFunction &CGF,
1049 llvm::Value *Address) const {
1050 return PPC_initDwarfEHRegSizeTable(CGF, Address, /*Is64Bit*/ true,
1051 /*IsAIX*/ false);
1052}
1053
1054bool
1055PPC64TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
1056 llvm::Value *Address) const {
1057 return PPC_initDwarfEHRegSizeTable(CGF, Address, /*Is64Bit*/ true,
1058 /*IsAIX*/ false);
1059}
1060
1061std::unique_ptr<TargetCodeGenInfo>
1063 return std::make_unique<AIXTargetCodeGenInfo>(CGM.getTypes(), Is64Bit);
1064}
1065
1066std::unique_ptr<TargetCodeGenInfo>
1068 bool RetSmallStructInRegABI = PPC32TargetCodeGenInfo::isStructReturnInRegABI(
1069 CGM.getTriple(), CGM.getCodeGenOpts());
1070 return std::make_unique<PPC32TargetCodeGenInfo>(CGM.getTypes(), SoftFloatABI,
1071 RetSmallStructInRegABI);
1072}
1073
1074std::unique_ptr<TargetCodeGenInfo>
1076 return std::make_unique<PPC64TargetCodeGenInfo>(CGM.getTypes());
1077}
1078
1079std::unique_ptr<TargetCodeGenInfo> CodeGen::createPPC64_SVR4_TargetCodeGenInfo(
1080 CodeGenModule &CGM, PPC64_SVR4_ABIKind Kind, bool SoftFloatABI) {
1081 return std::make_unique<PPC64_SVR4_TargetCodeGenInfo>(CGM.getTypes(), Kind,
1082 SoftFloatABI);
1083}
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:3324
Kind getKind() const
Definition TypeBase.h:3299
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 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:317
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
Definition CGBuilder.h:120
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:2541
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:675
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:655
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:3362
QualType getElementType() const
Definition TypeBase.h:3372
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:4493
virtual ParsedTargetAttr parseTargetAttr(StringRef Str) const
bool isVoidType() const
Definition TypeBase.h:9068
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:9116
bool isAnyComplexType() const
Definition TypeBase.h:8818
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:2655
bool isVectorType() const
Definition TypeBase.h:8822
bool isRealFloatingType() const
Floating point categories.
Definition Type.cpp:2533
bool isFloatingType() const
Definition Type.cpp:2517
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9299
@ TLS_None
Not a TLS variable.
Definition Decl.h:953
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:1079
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:1062
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:1067
std::unique_ptr< TargetCodeGenInfo > createPPC64TargetCodeGenInfo(CodeGenModule &CGM)
Definition PPC.cpp:1075
@ 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
const FunctionProtoType * T
U cast(CodeGen::Address addr)
Definition Address.h:327
unsigned long uint64_t
int32_t uint32_t
int32_t uint32_t uint32_t __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