clang 24.0.0git
CGFunctionInfo.h
Go to the documentation of this file.
1//==-- CGFunctionInfo.h - Representation of function argument/return types -==//
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// Defines CGFunctionInfo and associated types used in representing the
10// LLVM source types and ABI-coerced types for function arguments and
11// return values.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_CODEGEN_CGFUNCTIONINFO_H
16#define LLVM_CLANG_CODEGEN_CGFUNCTIONINFO_H
17
19#include "clang/AST/CharUnits.h"
20#include "clang/AST/Type.h"
21#include "llvm/ADT/FoldingSet.h"
22#include "llvm/IR/DerivedTypes.h"
23#include "llvm/Support/TrailingObjects.h"
24#include <cassert>
25
26namespace clang {
27namespace CodeGen {
28
29/// ABIArgInfo - Helper class to encapsulate information about how a
30/// specific C type should be passed to or returned from a function.
32public:
33 enum Kind : uint8_t {
34 /// Direct - Pass the argument directly using the normal converted LLVM
35 /// type, or by coercing to another specified type stored in
36 /// 'CoerceToType'). If an offset is specified (in UIntData), then the
37 /// argument passed is offset by some number of bytes in the memory
38 /// representation. A dummy argument is emitted before the real argument
39 /// if the specified type stored in "PaddingType" is not zero.
41
42 /// Extend - Valid only for integer argument types. Same as 'direct'
43 /// but also emit a zero/sign extension attribute.
45
46 /// Indirect - Pass the argument indirectly via a hidden pointer with the
47 /// specified alignment (0 indicates default alignment) and address space.
49
50 /// IndirectAliased - Similar to Indirect, but the pointer may be to an
51 /// object that is otherwise referenced. The object is known to not be
52 /// modified through any other references for the duration of the call, and
53 /// the callee must not itself modify the object. Because C allows
54 /// parameter variables to be modified and guarantees that they have unique
55 /// addresses, the callee must defensively copy the object into a local
56 /// variable if it might be modified or its address might be compared.
57 /// Since those are uncommon, in principle this convention allows programs
58 /// to avoid copies in more situations. However, it may introduce *extra*
59 /// copies if the callee fails to prove that a copy is unnecessary and the
60 /// caller naturally produces an unaliased object for the argument.
62
63 /// Ignore - Ignore the argument (treat as void). Useful for void and
64 /// empty structs.
66
67 /// Expand - Only valid for aggregate argument types. The structure should
68 /// be expanded into consecutive arguments for its constituent fields.
69 /// Currently expand is only allowed on structures whose fields
70 /// are all scalar types or are themselves expandable types.
72
73 /// CoerceAndExpand - Only valid for aggregate argument types. The
74 /// structure should be expanded into consecutive arguments corresponding
75 /// to the non-array elements of the type stored in CoerceToType.
76 /// Array elements in the type are assumed to be padding and skipped.
78
79 /// TargetSpecific - Some argument types are passed as target specific types
80 /// such as RISC-V's tuple type, these need to be handled in the target
81 /// hook.
83
84 /// InAlloca - Pass the argument directly using the LLVM inalloca attribute.
85 /// This is similar to indirect with byval, except it only applies to
86 /// arguments stored in memory and forbids any implicit copies. When
87 /// applied to a return type, it means the value is returned indirectly via
88 /// an implicit sret parameter stored in the argument struct.
92 };
93
94private:
95 llvm::Type *TypeData; // canHaveCoerceToType()
96 union {
97 llvm::Type *PaddingType; // canHavePaddingType()
98 llvm::Type *UnpaddedCoerceAndExpandType; // isCoerceAndExpand()
99 };
100 struct DirectAttrInfo {
101 unsigned Offset;
102 unsigned Align;
103 };
104 struct IndirectAttrInfo {
105 unsigned Align;
106 unsigned AddrSpace;
107 };
108 union {
109 DirectAttrInfo DirectAttr; // isDirect() || isExtend()
110 IndirectAttrInfo IndirectAttr; // isIndirect()
111 unsigned AllocaFieldIndex; // isInAlloca()
112 };
113 Kind TheKind;
114 bool PaddingInReg : 1;
115 bool InAllocaSRet : 1; // isInAlloca()
116 bool InAllocaIndirect : 1;// isInAlloca()
117 bool IndirectByVal : 1; // isIndirect()
118 bool IndirectRealign : 1; // isIndirect()
119 bool SRetAfterThis : 1; // isIndirect()
120 bool InReg : 1; // isDirect() || isExtend() || isIndirect()
121 bool CanBeFlattened: 1; // isDirect()
122 bool SignExt : 1; // isExtend()
123 bool ZeroExt : 1; // isExtend()
124 bool Conservative : 1; // isExtend()
125
126 bool canHavePaddingType() const {
127 return isDirect() || isExtend() || isIndirect() || isIndirectAliased() ||
129 }
130 void setPaddingType(llvm::Type *T) {
131 assert(canHavePaddingType());
132 PaddingType = T;
133 }
134
135 void setUnpaddedCoerceToType(llvm::Type *T) {
136 assert(isCoerceAndExpand());
138 }
139
140public:
142 : TypeData(nullptr), PaddingType(nullptr), DirectAttr{0, 0}, TheKind(K),
143 PaddingInReg(false), InAllocaSRet(false), InAllocaIndirect(false),
144 IndirectByVal(false), IndirectRealign(false), SRetAfterThis(false),
145 InReg(false), CanBeFlattened(false), SignExt(false), ZeroExt(false),
146 Conservative(false) {}
147
148 static ABIArgInfo getDirect(llvm::Type *T = nullptr, unsigned Offset = 0,
149 llvm::Type *Padding = nullptr,
150 bool CanBeFlattened = true, unsigned Align = 0) {
151 auto AI = ABIArgInfo(Direct);
152 AI.setCoerceToType(T);
153 AI.setPaddingType(Padding);
154 AI.setDirectOffset(Offset);
155 AI.setDirectAlign(Align);
156 AI.setCanBeFlattened(CanBeFlattened);
157 return AI;
158 }
159 static ABIArgInfo getDirectInReg(llvm::Type *T = nullptr) {
160 auto AI = getDirect(T);
161 AI.setInReg(true);
162 return AI;
163 }
164
165 static ABIArgInfo getSignExtend(QualType Ty, llvm::Type *T = nullptr,
166 llvm::Type *Padding = nullptr) {
167 assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
168 auto AI = ABIArgInfo(Extend);
169 AI.setCoerceToType(T);
170 AI.setPaddingType(Padding);
171 AI.setDirectOffset(0);
172 AI.setDirectAlign(0);
173 AI.setSignExt(true);
174 return AI;
175 }
176
177 static ABIArgInfo getZeroExtend(QualType Ty, llvm::Type *T = nullptr,
178 llvm::Type *Padding = nullptr) {
179 assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
180 auto AI = ABIArgInfo(Extend);
181 AI.setCoerceToType(T);
182 AI.setPaddingType(Padding);
183 AI.setDirectOffset(0);
184 AI.setDirectAlign(0);
185 AI.setZeroExt(true);
186 return AI;
187 }
188
189 // ABIArgInfo will record the argument as being extended based on the sign
190 // of its type. Produces a sign or zero extension.
191 static ABIArgInfo getExtend(QualType Ty, llvm::Type *T = nullptr,
192 llvm::Type *Padding = nullptr) {
193 assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
195 return getSignExtend(Ty, T, Padding);
196 return getZeroExtend(Ty, T, Padding);
197 }
198
199 // Struct in register marked explicitly as not needing extension.
200 static ABIArgInfo getNoExtend(llvm::IntegerType *T) {
201 auto AI = ABIArgInfo(Extend);
202 AI.setCoerceToType(T);
203 AI.setPaddingType(nullptr);
204 AI.setDirectOffset(0);
205 AI.setDirectAlign(0);
206 return AI;
207 }
208
210 llvm::Type *T = nullptr) {
211 auto AI = getExtend(Ty, T);
212 AI.setConservative(true);
213 return AI;
214 }
215
217 llvm::Type *T = nullptr) {
218 auto AI = getConservativeExtend(Ty, T);
219 AI.setInReg(true);
220 return AI;
221 }
222
223 static ABIArgInfo getExtendInReg(QualType Ty, llvm::Type *T = nullptr) {
224 auto AI = getExtend(Ty, T);
225 AI.setInReg(true);
226 return AI;
227 }
229 return ABIArgInfo(Ignore);
230 }
231 static ABIArgInfo getIndirect(CharUnits Alignment, unsigned AddrSpace,
232 bool ByVal = true, bool Realign = false,
233 llvm::Type *Padding = nullptr) {
234 auto AI = ABIArgInfo(Indirect);
235 AI.setIndirectAlign(Alignment);
236 AI.setIndirectByVal(ByVal);
237 AI.setIndirectRealign(Realign);
238 AI.setSRetAfterThis(false);
239 AI.setPaddingType(Padding);
240 AI.setIndirectAddrSpace(AddrSpace);
241 return AI;
242 }
243
244 /// Pass this in memory using the IR byref attribute.
245 static ABIArgInfo getIndirectAliased(CharUnits Alignment, unsigned AddrSpace,
246 bool Realign = false,
247 llvm::Type *Padding = nullptr) {
248 auto AI = ABIArgInfo(IndirectAliased);
249 AI.setIndirectAlign(Alignment);
250 AI.setIndirectRealign(Realign);
251 AI.setPaddingType(Padding);
252 AI.setIndirectAddrSpace(AddrSpace);
253 return AI;
254 }
255
256 static ABIArgInfo getIndirectInReg(CharUnits Alignment, bool ByVal = true,
257 bool Realign = false) {
258 auto AI = getIndirect(Alignment, 0, ByVal, Realign);
259 AI.setInReg(true);
260 return AI;
261 }
262 static ABIArgInfo getInAlloca(unsigned FieldIndex, bool Indirect = false) {
263 auto AI = ABIArgInfo(InAlloca);
264 AI.setInAllocaFieldIndex(FieldIndex);
265 AI.setInAllocaIndirect(Indirect);
266 return AI;
267 }
269 auto AI = ABIArgInfo(Expand);
270 AI.setPaddingType(nullptr);
271 return AI;
272 }
273 static ABIArgInfo getExpandWithPadding(bool PaddingInReg,
274 llvm::Type *Padding) {
275 auto AI = getExpand();
276 AI.setPaddingInReg(PaddingInReg);
277 AI.setPaddingType(Padding);
278 return AI;
279 }
280
281 /// \param unpaddedCoerceToType The coerce-to type with padding elements
282 /// removed, canonicalized to a single element if it would otherwise
283 /// have exactly one element.
284 static ABIArgInfo getCoerceAndExpand(llvm::StructType *coerceToType,
285 llvm::Type *unpaddedCoerceToType) {
286#ifndef NDEBUG
287 // Check that unpaddedCoerceToType has roughly the right shape.
288
289 // Assert that we only have a struct type if there are multiple elements.
290 auto unpaddedStruct = dyn_cast<llvm::StructType>(unpaddedCoerceToType);
291 assert(!unpaddedStruct || unpaddedStruct->getNumElements() != 1);
292
293 // Assert that all the non-padding elements have a corresponding element
294 // in the unpadded type.
295 unsigned unpaddedIndex = 0;
296 for (auto eltType : coerceToType->elements()) {
297 if (isPaddingForCoerceAndExpand(eltType))
298 continue;
299 unpaddedIndex++;
300 }
301
302 // Assert that there aren't extra elements in the unpadded type.
303 if (unpaddedStruct) {
304 assert(unpaddedStruct->getNumElements() == unpaddedIndex);
305 } else {
306 assert(unpaddedIndex == 1);
307 }
308#endif
309
310 auto AI = ABIArgInfo(CoerceAndExpand);
311 AI.setCoerceToType(coerceToType);
312 AI.setUnpaddedCoerceToType(unpaddedCoerceToType);
313 return AI;
314 }
315
316 static ABIArgInfo getTargetSpecific(llvm::Type *T = nullptr,
317 unsigned Offset = 0,
318 llvm::Type *Padding = nullptr,
319 bool CanBeFlattened = true,
320 unsigned Align = 0) {
321 auto AI = ABIArgInfo(TargetSpecific);
322 AI.setCoerceToType(T);
323 AI.setPaddingType(Padding);
324 AI.setDirectOffset(Offset);
325 AI.setDirectAlign(Align);
326 AI.setCanBeFlattened(CanBeFlattened);
327 return AI;
328 }
329
330 static bool isPaddingForCoerceAndExpand(llvm::Type *eltType) {
331 return eltType->isArrayTy() &&
332 eltType->getArrayElementType()->isIntegerTy(8);
333 }
334
335 Kind getKind() const { return TheKind; }
336 bool isDirect() const { return TheKind == Direct; }
337 bool isInAlloca() const { return TheKind == InAlloca; }
338 bool isExtend() const { return TheKind == Extend; }
339 bool isIgnore() const { return TheKind == Ignore; }
340 bool isIndirect() const { return TheKind == Indirect; }
341 bool isIndirectAliased() const { return TheKind == IndirectAliased; }
342 bool isExpand() const { return TheKind == Expand; }
343 bool isCoerceAndExpand() const { return TheKind == CoerceAndExpand; }
344 bool isTargetSpecific() const { return TheKind == TargetSpecific; }
345
346 bool canHaveCoerceToType() const {
347 return isDirect() || isExtend() || isCoerceAndExpand() ||
349 }
350
351 // Direct/Extend accessors
352 unsigned getDirectOffset() const {
353 assert((isDirect() || isExtend() || isTargetSpecific()) &&
354 "Not a direct or extend or target specific kind");
355 return DirectAttr.Offset;
356 }
357 void setDirectOffset(unsigned Offset) {
358 assert((isDirect() || isExtend() || isTargetSpecific()) &&
359 "Not a direct or extend or target specific kind");
360 DirectAttr.Offset = Offset;
361 }
362
363 unsigned getDirectAlign() const {
364 assert((isDirect() || isExtend() || isTargetSpecific()) &&
365 "Not a direct or extend or target specific kind");
366 return DirectAttr.Align;
367 }
368 void setDirectAlign(unsigned Align) {
369 assert((isDirect() || isExtend() || isTargetSpecific()) &&
370 "Not a direct or extend or target specific kind");
371 DirectAttr.Align = Align;
372 }
373
374 bool isSignExt() const {
375 assert(isExtend() && (SignExt + ZeroExt <= 1) && "Invalid kind / flags!");
376 return SignExt;
377 }
378 void setSignExt(bool SExt) {
379 assert(isExtend() && "Invalid kind!");
380 SignExt = SExt;
381 }
382
383 bool isZeroExt() const {
384 assert(isExtend() && (SignExt + ZeroExt <= 1) && "Invalid kind / flags!");
385 return ZeroExt;
386 }
387 void setZeroExt(bool ZExt) {
388 assert(isExtend() && "Invalid kind!");
389 ZeroExt = ZExt;
390 }
391
392 bool isNoExt() const {
393 assert(isExtend() && (SignExt + ZeroExt <= 1) && "Invalid kind / flags!");
394 return !SignExt && !ZeroExt;
395 }
396
397 /// Whether the extension is conservative, i.e. the sender extends, but the
398 /// receiver does not assume the extension. Currently only supported for
399 /// arguments, i.e. caller extends, but callee does not assume extension.
400 bool isConservative() const {
401 assert(isExtend() && "Invalid kind");
402 return Conservative;
403 }
404 void setConservative(bool Val) {
405 assert(isExtend() && "Invalid kind");
406 Conservative = Val;
407 }
408
409 llvm::Type *getPaddingType() const {
410 return (canHavePaddingType() ? PaddingType : nullptr);
411 }
412
413 bool getPaddingInReg() const {
414 return PaddingInReg;
415 }
416 void setPaddingInReg(bool PIR) {
417 PaddingInReg = PIR;
418 }
419
420 llvm::Type *getCoerceToType() const {
421 assert(canHaveCoerceToType() && "Invalid kind!");
422 return TypeData;
423 }
424
425 void setCoerceToType(llvm::Type *T) {
426 assert(canHaveCoerceToType() && "Invalid kind!");
427 TypeData = T;
428 }
429
430 llvm::StructType *getCoerceAndExpandType() const {
431 assert(isCoerceAndExpand());
432 return cast<llvm::StructType>(TypeData);
433 }
434
435 llvm::Type *getUnpaddedCoerceAndExpandType() const {
436 assert(isCoerceAndExpand());
438 }
439
441 assert(isCoerceAndExpand());
442 if (auto structTy =
443 dyn_cast<llvm::StructType>(UnpaddedCoerceAndExpandType)) {
444 return structTy->elements();
445 } else {
447 }
448 }
449
450 bool getInReg() const {
451 assert((isDirect() || isExtend() || isIndirect() || isTargetSpecific()) &&
452 "Invalid kind!");
453 return InReg;
454 }
455
456 void setInReg(bool IR) {
457 assert((isDirect() || isExtend() || isIndirect() || isTargetSpecific()) &&
458 "Invalid kind!");
459 InReg = IR;
460 }
461
462 // Indirect accessors
464 assert((isIndirect() || isIndirectAliased()) && "Invalid kind!");
466 }
468 assert((isIndirect() || isIndirectAliased()) && "Invalid kind!");
469 IndirectAttr.Align = IA.getQuantity();
470 }
471
472 bool getIndirectByVal() const {
473 assert(isIndirect() && "Invalid kind!");
474 return IndirectByVal;
475 }
476 void setIndirectByVal(bool IBV) {
477 assert(isIndirect() && "Invalid kind!");
478 IndirectByVal = IBV;
479 }
480
481 unsigned getIndirectAddrSpace() const {
482 assert((isIndirect() || isIndirectAliased()) && "Invalid kind!");
483 return IndirectAttr.AddrSpace;
484 }
485
486 void setIndirectAddrSpace(unsigned AddrSpace) {
487 assert((isIndirect() || isIndirectAliased()) && "Invalid kind!");
488 IndirectAttr.AddrSpace = AddrSpace;
489 }
490
491 bool getIndirectRealign() const {
492 assert((isIndirect() || isIndirectAliased()) && "Invalid kind!");
493 return IndirectRealign;
494 }
495 void setIndirectRealign(bool IR) {
496 assert((isIndirect() || isIndirectAliased()) && "Invalid kind!");
497 IndirectRealign = IR;
498 }
499
500 bool isSRetAfterThis() const {
501 assert(isIndirect() && "Invalid kind!");
502 return SRetAfterThis;
503 }
504 void setSRetAfterThis(bool AfterThis) {
505 assert(isIndirect() && "Invalid kind!");
506 SRetAfterThis = AfterThis;
507 }
508
509 unsigned getInAllocaFieldIndex() const {
510 assert(isInAlloca() && "Invalid kind!");
511 return AllocaFieldIndex;
512 }
513 void setInAllocaFieldIndex(unsigned FieldIndex) {
514 assert(isInAlloca() && "Invalid kind!");
515 AllocaFieldIndex = FieldIndex;
516 }
517
518 unsigned getInAllocaIndirect() const {
519 assert(isInAlloca() && "Invalid kind!");
520 return InAllocaIndirect;
521 }
523 assert(isInAlloca() && "Invalid kind!");
524 InAllocaIndirect = Indirect;
525 }
526
527 /// Return true if this field of an inalloca struct should be returned
528 /// to implement a struct return calling convention.
529 bool getInAllocaSRet() const {
530 assert(isInAlloca() && "Invalid kind!");
531 return InAllocaSRet;
532 }
533
534 void setInAllocaSRet(bool SRet) {
535 assert(isInAlloca() && "Invalid kind!");
536 InAllocaSRet = SRet;
537 }
538
539 bool getCanBeFlattened() const {
540 assert((isDirect() || isTargetSpecific()) && "Invalid kind!");
541 return CanBeFlattened;
542 }
543
544 void setCanBeFlattened(bool Flatten) {
545 assert((isDirect() || isTargetSpecific()) && "Invalid kind!");
546 CanBeFlattened = Flatten;
547 }
548
549 void dump() const;
550};
551
552/// A class for recording the number of arguments that a function
553/// signature requires.
555 /// The number of required arguments, or ~0 if the signature does
556 /// not permit optional arguments.
557 unsigned NumRequired;
558public:
559 enum All_t { All };
560
561 RequiredArgs(All_t _) : NumRequired(~0U) {}
562 explicit RequiredArgs(unsigned n) : NumRequired(n) {
563 assert(n != ~0U);
564 }
565
566 /// Compute the arguments required by the given formal prototype,
567 /// given that there may be some additional, non-formal arguments
568 /// in play.
569 ///
570 /// If FD is not null, this will consider pass_object_size params in FD.
572 unsigned additional) {
573 if (!prototype->isVariadic()) return All;
574
575 if (prototype->hasExtParameterInfos())
576 additional += llvm::count_if(
577 prototype->getExtParameterInfos(),
578 [](const FunctionProtoType::ExtParameterInfo &ExtInfo) {
579 return ExtInfo.hasPassObjectSize();
580 });
581
582 return RequiredArgs(prototype->getNumParams() + additional);
583 }
584
586 unsigned additional) {
587 return forPrototypePlus(prototype.getTypePtr(), additional);
588 }
589
590 static RequiredArgs forPrototype(const FunctionProtoType *prototype) {
591 return forPrototypePlus(prototype, 0);
592 }
593
595 return forPrototypePlus(prototype.getTypePtr(), 0);
596 }
597
598 bool allowsOptionalArgs() const { return NumRequired != ~0U; }
599 unsigned getNumRequiredArgs() const {
600 assert(allowsOptionalArgs());
601 return NumRequired;
602 }
603
604 /// Return true if the argument at a given index is required.
605 bool isRequiredArg(unsigned argIdx) const {
606 return argIdx == ~0U || argIdx < NumRequired;
607 }
608
609 unsigned getOpaqueData() const { return NumRequired; }
610 static RequiredArgs getFromOpaqueData(unsigned value) {
611 if (value == ~0U) return All;
612 return RequiredArgs(value);
613 }
614};
615
616// Implementation detail of CGFunctionInfo, factored out so it can be named
617// in the TrailingObjects base class of CGFunctionInfo.
622
623/// CGFunctionInfo - Class to encapsulate the information about a
624/// function definition.
625class CGFunctionInfo final
626 : public llvm::FoldingSetNode,
627 private llvm::TrailingObjects<CGFunctionInfo, CGFunctionInfoArgInfo,
628 FunctionProtoType::ExtParameterInfo> {
629 typedef CGFunctionInfoArgInfo ArgInfo;
630 typedef FunctionProtoType::ExtParameterInfo ExtParameterInfo;
631
632 /// The LLVM::CallingConv to use for this function (as specified by the
633 /// user).
634 unsigned CallingConvention : 8;
635
636 /// The LLVM::CallingConv to actually use for this function, which may
637 /// depend on the ABI.
638 unsigned EffectiveCallingConvention : 8;
639
640 /// The clang::CallingConv that this was originally created with.
641 LLVM_PREFERRED_TYPE(CallingConv)
642 unsigned ASTCallingConvention : 6;
643
644 /// Whether this is an instance method.
645 LLVM_PREFERRED_TYPE(bool)
646 unsigned InstanceMethod : 1;
647
648 /// Whether this is a chain call.
649 LLVM_PREFERRED_TYPE(bool)
650 unsigned ChainCall : 1;
651
652 /// Whether this function is called by forwarding arguments.
653 /// This doesn't support inalloca or varargs.
654 LLVM_PREFERRED_TYPE(bool)
655 unsigned DelegateCall : 1;
656
657 /// Whether this function is a CMSE nonsecure call
658 LLVM_PREFERRED_TYPE(bool)
659 unsigned CmseNSCall : 1;
660
661 /// Whether this function is noreturn.
662 LLVM_PREFERRED_TYPE(bool)
663 unsigned NoReturn : 1;
664
665 /// Whether this function is returns-retained.
666 LLVM_PREFERRED_TYPE(bool)
667 unsigned ReturnsRetained : 1;
668
669 /// Whether this function saved caller registers.
670 LLVM_PREFERRED_TYPE(bool)
671 unsigned NoCallerSavedRegs : 1;
672
673 /// How many arguments to pass inreg.
674 LLVM_PREFERRED_TYPE(bool)
675 unsigned HasRegParm : 1;
676 unsigned RegParm : 3;
677
678 /// Whether this function has nocf_check attribute.
679 LLVM_PREFERRED_TYPE(bool)
680 unsigned NoCfCheck : 1;
681
682 /// Log 2 of the maximum vector width.
683 unsigned MaxVectorWidth : 4;
684
685 /// X86 AVX Level, can be different from global / module level AVX level
686 /// because of target attributes.
687 unsigned X86ABIAVXLevel = 0;
688
689 RequiredArgs Required;
690
691 /// The struct representing all arguments passed in memory. Only used when
692 /// passing non-trivial types with inalloca. Not part of the profile.
693 llvm::StructType *ArgStruct;
694 unsigned ArgStructAlign : 31;
695 LLVM_PREFERRED_TYPE(bool)
696 unsigned HasExtParameterInfos : 1;
697
698 unsigned NumArgs;
699
700 ArgInfo *getArgsBuffer() {
701 return getTrailingObjects<ArgInfo>();
702 }
703 const ArgInfo *getArgsBuffer() const {
704 return getTrailingObjects<ArgInfo>();
705 }
706
707 ExtParameterInfo *getExtParameterInfosBuffer() {
708 return getTrailingObjects<ExtParameterInfo>();
709 }
710 const ExtParameterInfo *getExtParameterInfosBuffer() const{
711 return getTrailingObjects<ExtParameterInfo>();
712 }
713
714 CGFunctionInfo() : Required(RequiredArgs::All) {}
715
716public:
717 static CGFunctionInfo *
718 create(unsigned llvmCC, bool instanceMethod, bool chainCall,
719 bool delegateCall, unsigned X86ABIAVXLevel,
720 const FunctionType::ExtInfo &extInfo,
721 ArrayRef<ExtParameterInfo> paramInfos, CanQualType resultType,
722 ArrayRef<CanQualType> argTypes, RequiredArgs required);
723 void operator delete(void *p) { ::operator delete(p); }
724
725 // Friending class TrailingObjects is apparently not good enough for MSVC,
726 // so these have to be public.
727 friend class TrailingObjects;
728 size_t numTrailingObjects(OverloadToken<ArgInfo>) const {
729 return NumArgs + 1;
730 }
731 size_t numTrailingObjects(OverloadToken<ExtParameterInfo>) const {
732 return (HasExtParameterInfos ? NumArgs : 0);
733 }
734
735 typedef const ArgInfo *const_arg_iterator;
736 typedef ArgInfo *arg_iterator;
737
742 return ArrayRef<ArgInfo>(arg_begin(), NumArgs);
743 }
744
745 const_arg_iterator arg_begin() const { return getArgsBuffer() + 1; }
746 const_arg_iterator arg_end() const { return getArgsBuffer() + 1 + NumArgs; }
747 arg_iterator arg_begin() { return getArgsBuffer() + 1; }
748 arg_iterator arg_end() { return getArgsBuffer() + 1 + NumArgs; }
749
750 unsigned arg_size() const { return NumArgs; }
751
752 bool isVariadic() const { return Required.allowsOptionalArgs(); }
753 RequiredArgs getRequiredArgs() const { return Required; }
754 unsigned getNumRequiredArgs() const {
756 }
757
758 bool isInstanceMethod() const { return InstanceMethod; }
759
760 bool isChainCall() const { return ChainCall; }
761
762 bool isDelegateCall() const { return DelegateCall; }
763
764 bool isCmseNSCall() const { return CmseNSCall; }
765
766 bool isNoReturn() const { return NoReturn; }
767
768 /// In ARC, whether this function retains its return value. This
769 /// is not always reliable for call sites.
770 bool isReturnsRetained() const { return ReturnsRetained; }
771
772 /// Whether this function no longer saves caller registers.
773 bool isNoCallerSavedRegs() const { return NoCallerSavedRegs; }
774
775 /// Whether this function has nocf_check attribute.
776 bool isNoCfCheck() const { return NoCfCheck; }
777
778 /// getASTCallingConvention() - Return the AST-specified calling
779 /// convention.
781 return CallingConv(ASTCallingConvention);
782 }
783
784 /// getCallingConvention - Return the user specified calling
785 /// convention, which has been translated into an LLVM CC.
786 unsigned getCallingConvention() const { return CallingConvention; }
787
788 /// getEffectiveCallingConvention - Return the actual calling convention to
789 /// use, which may depend on the ABI.
791 return EffectiveCallingConvention;
792 }
794 EffectiveCallingConvention = Value;
795 }
796
797 bool getHasRegParm() const { return HasRegParm; }
798 unsigned getRegParm() const { return RegParm; }
799
806
807 CanQualType getReturnType() const { return getArgsBuffer()[0].type; }
808
809 ABIArgInfo &getReturnInfo() { return getArgsBuffer()[0].info; }
810 const ABIArgInfo &getReturnInfo() const { return getArgsBuffer()[0].info; }
811
813 if (!HasExtParameterInfos) return {};
814 return llvm::ArrayRef(getExtParameterInfosBuffer(), NumArgs);
815 }
816 ExtParameterInfo getExtParameterInfo(unsigned argIndex) const {
817 assert(argIndex <= NumArgs);
818 if (!HasExtParameterInfos) return ExtParameterInfo();
819 return getExtParameterInfos()[argIndex];
820 }
821
822 /// Return true if this function uses inalloca arguments.
823 bool usesInAlloca() const { return ArgStruct; }
824
825 /// Get the struct type used to represent all the arguments in memory.
826 llvm::StructType *getArgStruct() const { return ArgStruct; }
828 return CharUnits::fromQuantity(ArgStructAlign);
829 }
830 void setArgStruct(llvm::StructType *Ty, CharUnits Align) {
831 ArgStruct = Ty;
832 ArgStructAlign = Align.getQuantity();
833 }
834
835 /// Return the maximum vector width in the arguments.
836 unsigned getMaxVectorWidth() const {
837 return MaxVectorWidth ? 1U << (MaxVectorWidth - 1) : 0;
838 }
839
840 /// Set the maximum vector width in the arguments.
841 void setMaxVectorWidth(unsigned Width) {
842 assert(llvm::isPowerOf2_32(Width) && "Expected power of 2 vector");
843 MaxVectorWidth = llvm::countr_zero(Width) + 1;
844 }
845
846 unsigned getX86ABIAVXLevel() const { return X86ABIAVXLevel; }
847
848 void Profile(llvm::FoldingSetNodeID &ID) {
849 ID.AddInteger(getASTCallingConvention());
850 ID.AddBoolean(InstanceMethod);
851 ID.AddBoolean(ChainCall);
852 ID.AddBoolean(DelegateCall);
853 ID.AddBoolean(NoReturn);
854 ID.AddBoolean(ReturnsRetained);
855 ID.AddBoolean(NoCallerSavedRegs);
856 ID.AddBoolean(HasRegParm);
857 ID.AddInteger(RegParm);
858 ID.AddBoolean(NoCfCheck);
859 ID.AddBoolean(CmseNSCall);
860 ID.AddInteger(X86ABIAVXLevel);
861 ID.AddInteger(Required.getOpaqueData());
862 ID.AddBoolean(HasExtParameterInfos);
863 if (HasExtParameterInfos) {
864 for (auto paramInfo : getExtParameterInfos())
865 ID.AddInteger(paramInfo.getOpaqueValue());
866 }
868 for (const auto &I : arguments())
869 I.type.Profile(ID);
870 }
871 static void Profile(llvm::FoldingSetNodeID &ID, bool InstanceMethod,
872 bool ChainCall, bool IsDelegateCall,
873 unsigned X86ABIAVXLevel,
874 const FunctionType::ExtInfo &info,
876 RequiredArgs required, CanQualType resultType,
877 ArrayRef<CanQualType> argTypes) {
878 ID.AddInteger(info.getCC());
879 ID.AddBoolean(InstanceMethod);
880 ID.AddBoolean(ChainCall);
881 ID.AddBoolean(IsDelegateCall);
882 ID.AddBoolean(info.getNoReturn());
883 ID.AddBoolean(info.getProducesResult());
884 ID.AddBoolean(info.getNoCallerSavedRegs());
885 ID.AddBoolean(info.getHasRegParm());
886 ID.AddInteger(info.getRegParm());
887 ID.AddBoolean(info.getNoCfCheck());
888 ID.AddBoolean(info.getCmseNSCall());
889 ID.AddInteger(X86ABIAVXLevel);
890 ID.AddInteger(required.getOpaqueData());
891 ID.AddBoolean(!paramInfos.empty());
892 if (!paramInfos.empty()) {
893 for (auto paramInfo : paramInfos)
894 ID.AddInteger(paramInfo.getOpaqueValue());
895 }
896 resultType.Profile(ID);
897 for (const CanQualType &argType : argTypes)
898 argType.Profile(ID);
899 }
900};
901
902} // end namespace CodeGen
903} // end namespace clang
904
905#endif
C Language Family Type Representation.
Represents a canonical, potentially-qualified type.
void Profile(llvm::FoldingSetNodeID &ID) const
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
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
static constexpr CharUnits fromQuantity(QuantityType Quantity)
Construct a CharUnits quantity from a raw integer type.
Definition CharUnits.h:58
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
static ABIArgInfo getZeroExtend(QualType Ty, llvm::Type *T=nullptr, llvm::Type *Padding=nullptr)
unsigned getInAllocaFieldIndex() const
static ABIArgInfo getSignExtend(QualType Ty, llvm::Type *T=nullptr, llvm::Type *Padding=nullptr)
void setIndirectAddrSpace(unsigned AddrSpace)
static ABIArgInfo getNoExtend(llvm::IntegerType *T)
bool isConservative() const
Whether the extension is conservative, i.e.
llvm::StructType * getCoerceAndExpandType() const
static ABIArgInfo getInAlloca(unsigned FieldIndex, bool Indirect=false)
static ABIArgInfo getIgnore()
static ABIArgInfo getExpand()
void setCoerceToType(llvm::Type *T)
llvm::Type * getUnpaddedCoerceAndExpandType() const
static ABIArgInfo getConservativeExtendInReg(QualType Ty, llvm::Type *T=nullptr)
unsigned getDirectOffset() const
static bool isPaddingForCoerceAndExpand(llvm::Type *eltType)
void setDirectOffset(unsigned Offset)
static ABIArgInfo getTargetSpecific(llvm::Type *T=nullptr, unsigned Offset=0, llvm::Type *Padding=nullptr, bool CanBeFlattened=true, unsigned Align=0)
bool getInAllocaSRet() const
Return true if this field of an inalloca struct should be returned to implement a struct return calli...
void setIndirectAlign(CharUnits IA)
llvm::Type * getPaddingType() const
static ABIArgInfo getExtendInReg(QualType Ty, llvm::Type *T=nullptr)
static ABIArgInfo getExpandWithPadding(bool PaddingInReg, llvm::Type *Padding)
unsigned getDirectAlign() const
unsigned getIndirectAddrSpace() const
static ABIArgInfo getIndirectInReg(CharUnits Alignment, bool ByVal=true, bool Realign=false)
static ABIArgInfo getDirect(llvm::Type *T=nullptr, unsigned Offset=0, llvm::Type *Padding=nullptr, bool CanBeFlattened=true, unsigned Align=0)
@ Extend
Extend - Valid only for integer argument types.
@ Ignore
Ignore - Ignore the argument (treat as void).
@ IndirectAliased
IndirectAliased - Similar to Indirect, but the pointer may be to an object that is otherwise referenc...
@ Expand
Expand - Only valid for aggregate argument types.
@ TargetSpecific
TargetSpecific - Some argument types are passed as target specific types such as RISC-V's tuple type,...
@ InAlloca
InAlloca - Pass the argument directly using the LLVM inalloca attribute.
@ Indirect
Indirect - Pass the argument indirectly via a hidden pointer with the specified alignment (0 indicate...
@ CoerceAndExpand
CoerceAndExpand - Only valid for aggregate argument types.
@ Direct
Direct - Pass the argument directly using the normal converted LLVM type, or by coercing to another s...
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)
ArrayRef< llvm::Type * > getCoerceAndExpandTypeSequence() const
static ABIArgInfo getConservativeExtend(QualType Ty, llvm::Type *T=nullptr)
static ABIArgInfo getIndirectAliased(CharUnits Alignment, unsigned AddrSpace, bool Realign=false, llvm::Type *Padding=nullptr)
Pass this in memory using the IR byref attribute.
void setSRetAfterThis(bool AfterThis)
void setInAllocaIndirect(bool Indirect)
void setInAllocaSRet(bool SRet)
static ABIArgInfo getCoerceAndExpand(llvm::StructType *coerceToType, llvm::Type *unpaddedCoerceToType)
unsigned getInAllocaIndirect() const
llvm::Type * getCoerceToType() const
void setInAllocaFieldIndex(unsigned FieldIndex)
IndirectAttrInfo IndirectAttr
llvm::Type * UnpaddedCoerceAndExpandType
void setCanBeFlattened(bool Flatten)
void setDirectAlign(unsigned Align)
CharUnits getIndirectAlign() const
static ABIArgInfo getDirectInReg(llvm::Type *T=nullptr)
bool usesInAlloca() const
Return true if this function uses inalloca arguments.
FunctionType::ExtInfo getExtInfo() const
bool isReturnsRetained() const
In ARC, whether this function retains its return value.
unsigned getCallingConvention() const
getCallingConvention - Return the user specified calling convention, which has been translated into a...
void Profile(llvm::FoldingSetNodeID &ID)
const_arg_iterator arg_begin() const
bool isNoCallerSavedRegs() const
Whether this function no longer saves caller registers.
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
static void Profile(llvm::FoldingSetNodeID &ID, bool InstanceMethod, bool ChainCall, bool IsDelegateCall, unsigned X86ABIAVXLevel, const FunctionType::ExtInfo &info, ArrayRef< ExtParameterInfo > paramInfos, RequiredArgs required, CanQualType resultType, ArrayRef< CanQualType > argTypes)
CanQualType getReturnType() const
static CGFunctionInfo * create(unsigned llvmCC, bool instanceMethod, bool chainCall, bool delegateCall, unsigned X86ABIAVXLevel, const FunctionType::ExtInfo &extInfo, ArrayRef< ExtParameterInfo > paramInfos, CanQualType resultType, ArrayRef< CanQualType > argTypes, RequiredArgs required)
Definition CGCall.cpp:1195
bool isNoCfCheck() const
Whether this function has nocf_check attribute.
CallingConv getASTCallingConvention() const
getASTCallingConvention() - Return the AST-specified calling convention.
const ABIArgInfo & getReturnInfo() const
ArrayRef< ArgInfo > arguments() const
MutableArrayRef< ArgInfo > arguments()
const_arg_iterator arg_end() const
unsigned getEffectiveCallingConvention() const
getEffectiveCallingConvention - Return the actual calling convention to use, which may depend on the ...
void setArgStruct(llvm::StructType *Ty, CharUnits Align)
size_t numTrailingObjects(OverloadToken< ArgInfo >) const
ExtParameterInfo getExtParameterInfo(unsigned argIndex) const
unsigned getMaxVectorWidth() const
Return the maximum vector width in the arguments.
CharUnits getArgStructAlignment() const
size_t numTrailingObjects(OverloadToken< ExtParameterInfo >) const
RequiredArgs getRequiredArgs() const
void setEffectiveCallingConvention(unsigned Value)
llvm::StructType * getArgStruct() const
Get the struct type used to represent all the arguments in memory.
void setMaxVectorWidth(unsigned Width)
Set the maximum vector width in the arguments.
A class for recording the number of arguments that a function signature requires.
static RequiredArgs forPrototypePlus(CanQual< FunctionProtoType > prototype, unsigned additional)
unsigned getNumRequiredArgs() const
static RequiredArgs forPrototype(CanQual< FunctionProtoType > prototype)
static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype, unsigned additional)
Compute the arguments required by the given formal prototype, given that there may be some additional...
static RequiredArgs getFromOpaqueData(unsigned value)
bool isRequiredArg(unsigned argIdx) const
Return true if the argument at a given index is required.
static RequiredArgs forPrototype(const FunctionProtoType *prototype)
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5548
unsigned getNumParams() const
Definition TypeBase.h:5826
bool isVariadic() const
Whether this function prototype is variadic.
Definition TypeBase.h:5952
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
Definition TypeBase.h:6021
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type?
Definition TypeBase.h:6017
A class which abstracts out some details necessary for making a call.
Definition TypeBase.h:4855
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition TypeBase.h:4770
A (possibly-)qualified type.
Definition TypeBase.h:938
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition TypeBase.h:9326
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g....
Definition Type.cpp:2438
Top level wrappers for InstallAPI frontend operations.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
const FunctionProtoType * T
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition Specifiers.h:282
U cast(CodeGen::Address addr)
Definition Address.h:327
int32_t uint32_t uint32_t __builtin_riscv_mhracc_i32 __builtin_riscv_mhraccu_u32 __builtin_riscv_mhraccsu_i32 __builtin_riscv_mhacc_h1_i32 __builtin_riscv_mhaccsu_h1_i32 __builtin_riscv_mulqr_i32 __builtin_riscv_mqrwacc_i64 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 uint8_t
#define false
Definition stdbool.h:26