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" 89 bool PaddingInReg : 1;
90 bool InAllocaSRet : 1;
91 bool IndirectByVal : 1;
92 bool IndirectRealign : 1;
93 bool SRetAfterThis : 1;
95 bool CanBeFlattened: 1;
98 bool canHavePaddingType()
const {
102 assert(canHavePaddingType());
114 TheKind(K), PaddingInReg(
false), InAllocaSRet(
false),
120 bool CanBeFlattened =
true) {
122 AI.setCoerceToType(T);
123 AI.setPaddingType(Padding);
124 AI.setDirectOffset(
Offset);
125 AI.setCanBeFlattened(CanBeFlattened);
137 AI.setCoerceToType(T);
138 AI.setPaddingType(
nullptr);
139 AI.setDirectOffset(0);
147 AI.setCoerceToType(T);
148 AI.setPaddingType(
nullptr);
149 AI.setDirectOffset(0);
150 AI.setSignExt(
false);
172 bool Realign =
false,
175 AI.setIndirectAlign(Alignment);
176 AI.setIndirectByVal(ByVal);
177 AI.setIndirectRealign(Realign);
178 AI.setSRetAfterThis(
false);
179 AI.setPaddingType(Padding);
183 bool Realign =
false) {
190 AI.setInAllocaFieldIndex(FieldIndex);
195 AI.setPaddingType(
nullptr);
201 AI.setPaddingInReg(PaddingInReg);
202 AI.setPaddingType(Padding);
215 auto unpaddedStruct = dyn_cast<llvm::StructType>(unpaddedCoerceToType);
216 assert(!unpaddedStruct || unpaddedStruct->getNumElements() != 1);
220 unsigned unpaddedIndex = 0;
221 for (
auto eltType : coerceToType->elements()) {
223 if (unpaddedStruct) {
224 assert(unpaddedStruct->getElementType(unpaddedIndex) == eltType);
226 assert(unpaddedIndex == 0 && unpaddedCoerceToType == eltType);
232 if (unpaddedStruct) {
233 assert(unpaddedStruct->getNumElements() == unpaddedIndex);
235 assert(unpaddedIndex == 1);
240 AI.setCoerceToType(coerceToType);
241 AI.setUnpaddedCoerceToType(unpaddedCoerceToType);
246 if (eltType->isArrayTy()) {
247 assert(eltType->getArrayElementType()->isIntegerTy(8));
278 assert(
isExtend() &&
"Invalid kind!");
282 assert(
isExtend() &&
"Invalid kind!");
287 return (canHavePaddingType() ?
PaddingType :
nullptr);
309 return cast<llvm::StructType>(TypeData);
321 return structTy->elements();
349 return IndirectByVal;
358 return IndirectRealign;
362 IndirectRealign = IR;
367 return SRetAfterThis;
371 SRetAfterThis = AfterThis;
396 assert(
isDirect() &&
"Invalid kind!");
397 return CanBeFlattened;
401 assert(
isDirect() &&
"Invalid kind!");
402 CanBeFlattened = Flatten;
413 unsigned NumRequired;
428 unsigned additional) {
432 additional += llvm::count_if(
435 return ExtInfo.hasPassObjectSize();
442 unsigned additional) {
443 return forPrototypePlus(prototype.
getTypePtr(), additional);
447 return forPrototypePlus(prototype, 0);
451 return forPrototypePlus(prototype.
getTypePtr(), 0);
456 assert(allowsOptionalArgs());
462 if (value == ~0U)
return All;
477 :
public llvm::FoldingSetNode,
479 FunctionProtoType::ExtParameterInfo> {
485 unsigned CallingConvention : 8;
489 unsigned EffectiveCallingConvention : 8;
492 unsigned ASTCallingConvention : 6;
495 unsigned InstanceMethod : 1;
498 unsigned ChainCall : 1;
501 unsigned NoReturn : 1;
504 unsigned ReturnsRetained : 1;
507 unsigned NoCallerSavedRegs : 1;
510 unsigned HasRegParm : 1;
511 unsigned RegParm : 3;
514 unsigned NoCfCheck : 1;
520 llvm::StructType *ArgStruct;
521 unsigned ArgStructAlign : 31;
522 unsigned HasExtParameterInfos : 1;
526 ArgInfo *getArgsBuffer() {
527 return getTrailingObjects<ArgInfo>();
529 const ArgInfo *getArgsBuffer()
const {
530 return getTrailingObjects<ArgInfo>();
533 ExtParameterInfo *getExtParameterInfosBuffer() {
534 return getTrailingObjects<ExtParameterInfo>();
536 const ExtParameterInfo *getExtParameterInfosBuffer()
const{
537 return getTrailingObjects<ExtParameterInfo>();
543 static CGFunctionInfo *
create(
unsigned llvmCC,
551 void operator delete(
void *p) { ::operator
delete(p); }
560 return (HasExtParameterInfos ? NumArgs : 0);
573 const_arg_iterator
arg_begin()
const {
return getArgsBuffer() + 1; }
574 const_arg_iterator
arg_end()
const {
return getArgsBuffer() + 1 + NumArgs; }
575 arg_iterator
arg_begin() {
return getArgsBuffer() + 1; }
576 arg_iterator
arg_end() {
return getArgsBuffer() + 1 + NumArgs; }
583 return isVariadic() ? getRequiredArgs().getNumRequiredArgs() : arg_size();
615 return EffectiveCallingConvention;
618 EffectiveCallingConvention =
Value;
626 getASTCallingConvention(), isReturnsRetained(),
627 isNoCallerSavedRegs(), isNoCfCheck());
636 if (!HasExtParameterInfos)
return {};
637 return llvm::makeArrayRef(getExtParameterInfosBuffer(), NumArgs);
640 assert(argIndex <= NumArgs);
641 if (!HasExtParameterInfos)
return ExtParameterInfo();
642 return getExtParameterInfos()[argIndex];
659 ID.AddInteger(getASTCallingConvention());
660 ID.AddBoolean(InstanceMethod);
661 ID.AddBoolean(ChainCall);
662 ID.AddBoolean(NoReturn);
663 ID.AddBoolean(ReturnsRetained);
664 ID.AddBoolean(NoCallerSavedRegs);
665 ID.AddBoolean(HasRegParm);
666 ID.AddInteger(RegParm);
667 ID.AddBoolean(NoCfCheck);
669 ID.AddBoolean(HasExtParameterInfos);
670 if (HasExtParameterInfos) {
671 for (
auto paramInfo : getExtParameterInfos())
672 ID.AddInteger(paramInfo.getOpaqueValue());
674 getReturnType().Profile(ID);
675 for (
const auto &I : arguments())
686 ID.AddInteger(info.
getCC());
687 ID.AddBoolean(InstanceMethod);
688 ID.AddBoolean(ChainCall);
696 ID.AddBoolean(!paramInfos.empty());
697 if (!paramInfos.empty()) {
698 for (
auto paramInfo : paramInfos)
699 ID.AddInteger(paramInfo.getOpaqueValue());
703 i = argTypes.begin(), e = argTypes.end(); i != e; ++i) {
Ignore - Ignore the argument (treat as void).
void setEffectiveCallingConvention(unsigned Value)
void setSRetAfterThis(bool AfterThis)
A (possibly-)qualified type.
llvm::Type * UnpaddedCoerceAndExpandType
bool getNoCfCheck() const
bool isReturnsRetained() const
In ARC, whether this function retains its return value.
static RequiredArgs getFromOpaqueData(unsigned value)
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type...
C Language Family Type Representation.
Extend - Valid only for integer argument types.
bool isNoCfCheck() const
Whether this function has nocf_check attribute.
bool isVariadic() const
Whether this function prototype is variadic.
Direct - Pass the argument directly using the normal converted LLVM type, or by coercing to another s...
void setIndirectAlign(CharUnits IA)
void Profile(llvm::FoldingSetNodeID &ID) const
MutableArrayRef< ArgInfo > arguments()
void setCanBeFlattened(bool Flatten)
bool isCoerceAndExpand() const
static void Profile(llvm::FoldingSetNodeID &ID, bool InstanceMethod, bool ChainCall, const FunctionType::ExtInfo &info, ArrayRef< ExtParameterInfo > paramInfos, RequiredArgs required, CanQualType resultType, ArrayRef< CanQualType > argTypes)
unsigned getNumParams() const
void setCoerceToType(llvm::Type *T)
static ABIArgInfo getIgnore()
unsigned AllocaFieldIndex
const ArgInfo * const_arg_iterator
unsigned arg_size() const
void setDirectOffset(unsigned Offset)
bool usesInAlloca() const
Return true if this function uses inalloca arguments.
unsigned getRegParm() const
void setSignExt(bool SExt)
Indirect - Pass the argument indirectly via a hidden pointer with the specified alignment (0 indicate...
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
RequiredArgs getRequiredArgs() const
CharUnits getArgStructAlignment() const
void setPaddingInReg(bool PIR)
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
static ABIArgInfo getIndirectInReg(CharUnits Alignment, bool ByVal=true, bool Realign=false)
bool getProducesResult() const
static ABIArgInfo getDirect(llvm::Type *T=nullptr, unsigned Offset=0, llvm::Type *Padding=nullptr, bool CanBeFlattened=true)
void setInAllocaFieldIndex(unsigned FieldIndex)
bool getHasRegParm() const
static ABIArgInfo getExpandWithPadding(bool PaddingInReg, llvm::Type *Padding)
CharUnits - This is an opaque type for sizes expressed in character units.
llvm::StructType * getCoerceAndExpandType() const
unsigned getInAllocaFieldIndex() const
const_arg_iterator arg_begin() const
static ABIArgInfo getExtendInReg(QualType Ty, llvm::Type *T=nullptr)
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
static ABIArgInfo getExpand()
FunctionType::ExtInfo getExtInfo() const
static RequiredArgs forPrototype(CanQual< FunctionProtoType > prototype)
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
bool getNoCallerSavedRegs() const
static ABIArgInfo getZeroExtend(QualType Ty, llvm::Type *T=nullptr)
ArrayRef< ArgInfo > arguments() const
static ABIArgInfo getSignExtend(QualType Ty, llvm::Type *T=nullptr)
CanQualType getReturnType() const
unsigned getNumRequiredArgs() const
Represents a prototype with parameter type info, e.g.
void setIndirectByVal(bool IBV)
bool allowsOptionalArgs() const
bool getPaddingInReg() const
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static ABIArgInfo getExtend(QualType Ty, llvm::Type *T=nullptr)
llvm::Type * getUnpaddedCoerceAndExpandType() const
bool getHasRegParm() const
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
static bool isPaddingForCoerceAndExpand(llvm::Type *eltType)
A class for recording the number of arguments that a function signature requires. ...
bool canHaveCoerceToType() const
bool getIndirectByVal() const
void Profile(llvm::FoldingSetNodeID &ID)
size_t numTrailingObjects(OverloadToken< ExtParameterInfo >) const
CallingConv
CallingConv - Specifies the calling convention that a function uses.
The l-value was considered opaque, so the alignment was determined from a type.
unsigned getEffectiveCallingConvention() const
getEffectiveCallingConvention - Return the actual calling convention to use, which may depend on the ...
ABIArgInfo(Kind K=Direct)
bool isSRetAfterThis() const
unsigned getRegParm() const
CallingConv getCC() const
void setArgStruct(llvm::StructType *Ty, CharUnits Align)
const_arg_iterator arg_end() const
llvm::StructType * getArgStruct() const
Get the struct type used to represent all the arguments in memory.
bool isInstanceMethod() const
CoerceAndExpand - Only valid for aggregate argument types.
InAlloca - Pass the argument directly using the LLVM inalloca attribute.
llvm::Type * getPaddingType() const
bool getInAllocaSRet() const
Return true if this field of an inalloca struct should be returned to implement a struct return calli...
CGFunctionInfo - Class to encapsulate the information about a function definition.
const ABIArgInfo & getReturnInfo() const
Dataflow Directional Tag Classes.
unsigned getOpaqueData() const
static ABIArgInfo getDirectInReg(llvm::Type *T=nullptr)
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
bool getCanBeFlattened() const
static RequiredArgs forPrototype(const FunctionProtoType *prototype)
bool isNoCallerSavedRegs() const
Whether this function no longer saves caller registers.
ArrayRef< llvm::Type * > getCoerceAndExpandTypeSequence() const
static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype, unsigned additional)
Compute the arguments required by the given formal prototype, given that there may be some additional...
CharUnits getIndirectAlign() const
Expand - Only valid for aggregate argument types.
ABIArgInfo & getReturnInfo()
static ABIArgInfo getInAlloca(unsigned FieldIndex)
static ABIArgInfo getCoerceAndExpand(llvm::StructType *coerceToType, llvm::Type *unpaddedCoerceToType)
unsigned getCallingConvention() const
getCallingConvention - Return the user specified calling convention, which has been translated into a...
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g., it is an signed integer type or a vector.
CallingConv getASTCallingConvention() const
getASTCallingConvention() - Return the AST-specified calling convention.
unsigned getNumRequiredArgs() const
unsigned getDirectOffset() const
static RequiredArgs forPrototypePlus(CanQual< FunctionProtoType > prototype, unsigned additional)
ExtParameterInfo getExtParameterInfo(unsigned argIndex) const
llvm::Type * getCoerceToType() const
void setInAllocaSRet(bool SRet)
size_t numTrailingObjects(OverloadToken< ArgInfo >) const
bool getIndirectRealign() const
static ABIArgInfo getIndirect(CharUnits Alignment, bool ByVal=true, bool Realign=false, llvm::Type *Padding=nullptr)
void setIndirectRealign(bool IR)
A class which abstracts out some details necessary for making a call.