15#ifndef LLVM_CLANG_CODEGEN_CGFUNCTIONINFO_H
16#define LLVM_CLANG_CODEGEN_CGFUNCTIONINFO_H
22#include "llvm/IR/DerivedTypes.h"
23#include "llvm/ADT/FoldingSet.h"
24#include "llvm/Support/TrailingObjects.h"
96 struct DirectAttrInfo {
100 struct IndirectAttrInfo {
110 bool PaddingInReg : 1;
111 bool InAllocaSRet : 1;
112 bool InAllocaIndirect : 1;
113 bool IndirectByVal : 1;
114 bool IndirectRealign : 1;
115 bool SRetAfterThis : 1;
117 bool CanBeFlattened: 1;
120 bool canHavePaddingType()
const {
124 void setPaddingType(llvm::Type *
T) {
125 assert(canHavePaddingType());
129 void setUnpaddedCoerceToType(llvm::Type *
T) {
143 llvm::Type *Padding =
nullptr,
144 bool CanBeFlattened =
true,
unsigned Align = 0) {
146 AI.setCoerceToType(
T);
147 AI.setPaddingType(Padding);
148 AI.setDirectOffset(Offset);
149 AI.setDirectAlign(Align);
150 AI.setCanBeFlattened(CanBeFlattened);
162 AI.setCoerceToType(
T);
163 AI.setPaddingType(
nullptr);
164 AI.setDirectOffset(0);
165 AI.setDirectAlign(0);
173 AI.setCoerceToType(
T);
174 AI.setPaddingType(
nullptr);
175 AI.setDirectOffset(0);
176 AI.setDirectAlign(0);
177 AI.setSignExt(
false);
199 bool Realign =
false,
200 llvm::Type *Padding =
nullptr) {
202 AI.setIndirectAlign(Alignment);
203 AI.setIndirectByVal(ByVal);
204 AI.setIndirectRealign(Realign);
205 AI.setSRetAfterThis(
false);
206 AI.setPaddingType(Padding);
212 bool Realign =
false,
213 llvm::Type *Padding =
nullptr) {
215 AI.setIndirectAlign(Alignment);
216 AI.setIndirectRealign(Realign);
217 AI.setPaddingType(Padding);
218 AI.setIndirectAddrSpace(AddrSpace);
223 bool Realign =
false) {
230 AI.setInAllocaFieldIndex(FieldIndex);
236 AI.setPaddingType(
nullptr);
240 llvm::Type *Padding) {
242 AI.setPaddingInReg(PaddingInReg);
243 AI.setPaddingType(Padding);
251 llvm::Type *unpaddedCoerceToType) {
256 auto unpaddedStruct = dyn_cast<llvm::StructType>(unpaddedCoerceToType);
257 assert(!unpaddedStruct || unpaddedStruct->getNumElements() != 1);
261 unsigned unpaddedIndex = 0;
262 for (
auto eltType : coerceToType->elements()) {
264 if (unpaddedStruct) {
265 assert(unpaddedStruct->getElementType(unpaddedIndex) == eltType);
267 assert(unpaddedIndex == 0 && unpaddedCoerceToType == eltType);
273 if (unpaddedStruct) {
274 assert(unpaddedStruct->getNumElements() == unpaddedIndex);
276 assert(unpaddedIndex == 1);
281 AI.setCoerceToType(coerceToType);
282 AI.setUnpaddedCoerceToType(unpaddedCoerceToType);
287 if (eltType->isArrayTy()) {
288 assert(eltType->getArrayElementType()->isIntegerTy(8));
329 assert(
isExtend() &&
"Invalid kind!");
333 assert(
isExtend() &&
"Invalid kind!");
338 return (canHavePaddingType() ?
PaddingType :
nullptr);
360 return cast<llvm::StructType>(TypeData);
372 return structTy->elements();
400 return IndirectByVal;
419 return IndirectRealign;
423 IndirectRealign = IR;
428 return SRetAfterThis;
432 SRetAfterThis = AfterThis;
446 return InAllocaIndirect;
466 assert(
isDirect() &&
"Invalid kind!");
467 return CanBeFlattened;
471 assert(
isDirect() &&
"Invalid kind!");
472 CanBeFlattened = Flatten;
483 unsigned NumRequired;
498 unsigned additional) {
502 additional += llvm::count_if(
505 return ExtInfo.hasPassObjectSize();
512 unsigned additional) {
532 return argIdx == ~0
U || argIdx < NumRequired;
537 if (value == ~0
U)
return All;
552 :
public llvm::FoldingSetNode,
553 private llvm::TrailingObjects<CGFunctionInfo, CGFunctionInfoArgInfo,
554 FunctionProtoType::ExtParameterInfo> {
560 unsigned CallingConvention : 8;
564 unsigned EffectiveCallingConvention : 8;
568 unsigned ASTCallingConvention : 6;
571 LLVM_PREFERRED_TYPE(
bool)
572 unsigned InstanceMethod : 1;
575 LLVM_PREFERRED_TYPE(
bool)
576 unsigned ChainCall : 1;
580 LLVM_PREFERRED_TYPE(
bool)
581 unsigned DelegateCall : 1;
584 LLVM_PREFERRED_TYPE(
bool)
585 unsigned CmseNSCall : 1;
588 LLVM_PREFERRED_TYPE(
bool)
589 unsigned NoReturn : 1;
592 LLVM_PREFERRED_TYPE(
bool)
593 unsigned ReturnsRetained : 1;
596 LLVM_PREFERRED_TYPE(
bool)
597 unsigned NoCallerSavedRegs : 1;
600 LLVM_PREFERRED_TYPE(
bool)
601 unsigned HasRegParm : 1;
602 unsigned RegParm : 3;
605 LLVM_PREFERRED_TYPE(
bool)
606 unsigned NoCfCheck : 1;
609 unsigned MaxVectorWidth : 4;
615 llvm::StructType *ArgStruct;
616 unsigned ArgStructAlign : 31;
617 LLVM_PREFERRED_TYPE(
bool)
618 unsigned HasExtParameterInfos : 1;
623 return getTrailingObjects<ArgInfo>();
625 const ArgInfo *getArgsBuffer()
const {
626 return getTrailingObjects<ArgInfo>();
630 return getTrailingObjects<ExtParameterInfo>();
633 return getTrailingObjects<ExtParameterInfo>();
640 create(
unsigned llvmCC,
bool instanceMethod,
bool chainCall,
644 void operator delete(
void *p) { ::operator
delete(p); }
653 return (HasExtParameterInfos ? NumArgs : 0);
712 return EffectiveCallingConvention;
715 EffectiveCallingConvention =
Value;
734 if (!HasExtParameterInfos)
return {};
738 assert(argIndex <= NumArgs);
758 return MaxVectorWidth ? 1U << (MaxVectorWidth - 1) : 0;
763 assert(llvm::isPowerOf2_32(Width) &&
"Expected power of 2 vector");
764 MaxVectorWidth = llvm::countr_zero(Width) + 1;
769 ID.AddBoolean(InstanceMethod);
770 ID.AddBoolean(ChainCall);
771 ID.AddBoolean(DelegateCall);
772 ID.AddBoolean(NoReturn);
773 ID.AddBoolean(ReturnsRetained);
774 ID.AddBoolean(NoCallerSavedRegs);
775 ID.AddBoolean(HasRegParm);
776 ID.AddInteger(RegParm);
777 ID.AddBoolean(NoCfCheck);
778 ID.AddBoolean(CmseNSCall);
780 ID.AddBoolean(HasExtParameterInfos);
781 if (HasExtParameterInfos) {
783 ID.AddInteger(paramInfo.getOpaqueValue());
789 static void Profile(llvm::FoldingSetNodeID &
ID,
bool InstanceMethod,
796 ID.AddBoolean(InstanceMethod);
797 ID.AddBoolean(ChainCall);
807 ID.AddBoolean(!paramInfos.empty());
808 if (!paramInfos.empty()) {
809 for (
auto paramInfo : paramInfos)
810 ID.AddInteger(paramInfo.getOpaqueValue());
814 i = argTypes.begin(), e = argTypes.end(); i != e; ++i) {
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.
CharUnits - This is an opaque type for sizes expressed in character units.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
unsigned getInAllocaFieldIndex() const
void setIndirectAddrSpace(unsigned AddrSpace)
bool getIndirectByVal() const
llvm::StructType * getCoerceAndExpandType() const
bool getIndirectRealign() const
static ABIArgInfo getInAlloca(unsigned FieldIndex, bool Indirect=false)
static ABIArgInfo getIgnore()
static ABIArgInfo getExpand()
void setCoerceToType(llvm::Type *T)
llvm::Type * getUnpaddedCoerceAndExpandType() const
bool getCanBeFlattened() const
unsigned getDirectOffset() const
static bool isPaddingForCoerceAndExpand(llvm::Type *eltType)
void setDirectOffset(unsigned Offset)
void setPaddingInReg(bool PIR)
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
void setIndirectByVal(bool IBV)
static ABIArgInfo getExtendInReg(QualType Ty, llvm::Type *T=nullptr)
bool getPaddingInReg() const
static ABIArgInfo getExpandWithPadding(bool PaddingInReg, llvm::Type *Padding)
unsigned getDirectAlign() const
unsigned getIndirectAddrSpace() const
ABIArgInfo(Kind K=Direct)
static ABIArgInfo getIndirectInReg(CharUnits Alignment, bool ByVal=true, bool Realign=false)
static ABIArgInfo getIndirect(CharUnits Alignment, bool ByVal=true, bool Realign=false, llvm::Type *Padding=nullptr)
void setIndirectRealign(bool IR)
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.
@ 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...
ArrayRef< llvm::Type * > getCoerceAndExpandTypeSequence() const
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)
bool isCoerceAndExpand() const
static ABIArgInfo getZeroExtend(QualType Ty, llvm::Type *T=nullptr)
static ABIArgInfo getExtend(QualType Ty, llvm::Type *T=nullptr)
DirectAttrInfo DirectAttr
static ABIArgInfo getCoerceAndExpand(llvm::StructType *coerceToType, llvm::Type *unpaddedCoerceToType)
unsigned AllocaFieldIndex
unsigned getInAllocaIndirect() const
llvm::Type * getCoerceToType() const
bool isIndirectAliased() const
void setInAllocaFieldIndex(unsigned FieldIndex)
bool isSRetAfterThis() const
IndirectAttrInfo IndirectAttr
bool canHaveCoerceToType() const
llvm::Type * UnpaddedCoerceAndExpandType
void setSignExt(bool SExt)
void setCanBeFlattened(bool Flatten)
void setDirectAlign(unsigned Align)
static ABIArgInfo getSignExtend(QualType Ty, llvm::Type *T=nullptr)
CharUnits getIndirectAlign() const
static ABIArgInfo getDirectInReg(llvm::Type *T=nullptr)
CGFunctionInfo - Class to encapsulate the information about a function definition.
bool usesInAlloca() const
Return true if this function uses inalloca arguments.
FunctionType::ExtInfo getExtInfo() const
bool isInstanceMethod() const
ABIArgInfo & getReturnInfo()
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.
unsigned getRegParm() const
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
CanQualType getReturnType() const
bool isNoCfCheck() const
Whether this function has nocf_check attribute.
CallingConv getASTCallingConvention() const
getASTCallingConvention() - Return the AST-specified calling convention.
const ABIArgInfo & getReturnInfo() const
bool getHasRegParm() const
ArrayRef< ArgInfo > arguments() const
const ArgInfo * const_arg_iterator
static CGFunctionInfo * create(unsigned llvmCC, bool instanceMethod, bool chainCall, bool delegateCall, const FunctionType::ExtInfo &extInfo, ArrayRef< ExtParameterInfo > paramInfos, CanQualType resultType, ArrayRef< CanQualType > argTypes, RequiredArgs required)
static void Profile(llvm::FoldingSetNodeID &ID, bool InstanceMethod, bool ChainCall, bool IsDelegateCall, const FunctionType::ExtInfo &info, ArrayRef< ExtParameterInfo > paramInfos, RequiredArgs required, CanQualType resultType, ArrayRef< CanQualType > argTypes)
friend class TrailingObjects
bool isCmseNSCall() const
bool isDelegateCall() 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
unsigned arg_size() const
RequiredArgs getRequiredArgs() const
void setEffectiveCallingConvention(unsigned Value)
unsigned getNumRequiredArgs() const
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)
bool allowsOptionalArgs() const
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)
unsigned getOpaqueData() const
Represents a prototype with parameter type info, e.g.
unsigned getNumParams() const
bool isVariadic() const
Whether this function prototype is variadic.
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type?
A class which abstracts out some details necessary for making a call.
CallingConv getCC() const
bool getCmseNSCall() const
bool getNoCfCheck() const
unsigned getRegParm() const
bool getNoCallerSavedRegs() const
bool getHasRegParm() const
bool getProducesResult() const
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
A (possibly-)qualified type.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g....
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
CallingConv
CallingConv - Specifies the calling convention that a function uses.