16 #ifndef LLVM_CLANG_CODEGEN_CGFUNCTIONINFO_H 17 #define LLVM_CLANG_CODEGEN_CGFUNCTIONINFO_H 24 #include "llvm/IR/DerivedTypes.h" 25 #include "llvm/ADT/FoldingSet.h" 26 #include "llvm/Support/TrailingObjects.h" 91 bool PaddingInReg : 1;
92 bool InAllocaSRet : 1;
93 bool IndirectByVal : 1;
94 bool IndirectRealign : 1;
95 bool SRetAfterThis : 1;
97 bool CanBeFlattened: 1;
99 bool SuppressSRet : 1;
101 bool canHavePaddingType()
const {
105 assert(canHavePaddingType());
115 : TheKind(K), PaddingInReg(
false), InReg(
false), SuppressSRet(
false) {
122 SuppressSRet(
false) {}
126 bool CanBeFlattened =
true) {
128 AI.setCoerceToType(T);
129 AI.setPaddingType(Padding);
130 AI.setDirectOffset(
Offset);
131 AI.setCanBeFlattened(CanBeFlattened);
143 AI.setCoerceToType(T);
144 AI.setPaddingType(
nullptr);
145 AI.setDirectOffset(0);
153 AI.setCoerceToType(T);
154 AI.setPaddingType(
nullptr);
155 AI.setDirectOffset(0);
156 AI.setSignExt(
false);
178 bool Realign =
false,
181 AI.setIndirectAlign(Alignment);
182 AI.setIndirectByVal(ByVal);
183 AI.setIndirectRealign(Realign);
184 AI.setSRetAfterThis(
false);
185 AI.setPaddingType(Padding);
189 bool Realign =
false) {
196 AI.setInAllocaFieldIndex(FieldIndex);
201 AI.setPaddingType(
nullptr);
207 AI.setPaddingInReg(PaddingInReg);
208 AI.setPaddingType(Padding);
221 auto unpaddedStruct = dyn_cast<llvm::StructType>(unpaddedCoerceToType);
222 assert(!unpaddedStruct || unpaddedStruct->getNumElements() != 1);
226 unsigned unpaddedIndex = 0;
227 for (
auto eltType : coerceToType->elements()) {
229 if (unpaddedStruct) {
230 assert(unpaddedStruct->getElementType(unpaddedIndex) == eltType);
232 assert(unpaddedIndex == 0 && unpaddedCoerceToType == eltType);
238 if (unpaddedStruct) {
239 assert(unpaddedStruct->getNumElements() == unpaddedIndex);
241 assert(unpaddedIndex == 1);
246 AI.setCoerceToType(coerceToType);
247 AI.setUnpaddedCoerceToType(unpaddedCoerceToType);
252 if (eltType->isArrayTy()) {
253 assert(eltType->getArrayElementType()->isIntegerTy(8));
284 assert(
isExtend() &&
"Invalid kind!");
288 assert(
isExtend() &&
"Invalid kind!");
293 return (canHavePaddingType() ?
PaddingType :
nullptr);
315 return cast<llvm::StructType>(TypeData);
327 return structTy->elements();
355 return IndirectByVal;
364 return IndirectRealign;
368 IndirectRealign = IR;
373 return SRetAfterThis;
377 SRetAfterThis = AfterThis;
402 assert(
isDirect() &&
"Invalid kind!");
403 return CanBeFlattened;
407 assert(
isDirect() &&
"Invalid kind!");
408 CanBeFlattened = Flatten;
418 SuppressSRet = Suppress;
429 unsigned NumRequired;
450 return PVD->hasAttr<PassObjectSizeAttr>();
457 return forPrototypePlus(prototype, 0, FD);
462 return forPrototype(prototype.
getTypePtr(), FD);
468 return forPrototypePlus(prototype.
getTypePtr(), additional, FD);
473 assert(allowsOptionalArgs());
479 if (value == ~0U)
return All;
494 :
public llvm::FoldingSetNode,
496 FunctionProtoType::ExtParameterInfo> {
502 unsigned CallingConvention : 8;
506 unsigned EffectiveCallingConvention : 8;
509 unsigned ASTCallingConvention : 6;
512 unsigned InstanceMethod : 1;
515 unsigned ChainCall : 1;
518 unsigned NoReturn : 1;
521 unsigned ReturnsRetained : 1;
524 unsigned NoCallerSavedRegs : 1;
527 unsigned HasRegParm : 1;
528 unsigned RegParm : 3;
531 unsigned NoCfCheck : 1;
537 llvm::StructType *ArgStruct;
538 unsigned ArgStructAlign : 31;
539 unsigned HasExtParameterInfos : 1;
543 ArgInfo *getArgsBuffer() {
544 return getTrailingObjects<ArgInfo>();
546 const ArgInfo *getArgsBuffer()
const {
547 return getTrailingObjects<ArgInfo>();
550 ExtParameterInfo *getExtParameterInfosBuffer() {
551 return getTrailingObjects<ExtParameterInfo>();
553 const ExtParameterInfo *getExtParameterInfosBuffer()
const{
554 return getTrailingObjects<ExtParameterInfo>();
560 static CGFunctionInfo *
create(
unsigned llvmCC,
568 void operator delete(
void *p) { ::operator
delete(p); }
577 return (HasExtParameterInfos ? NumArgs : 0);
586 arg_range
arguments() {
return arg_range(arg_begin(), arg_end()); }
588 return const_arg_range(arg_begin(), arg_end());
591 const_arg_iterator
arg_begin()
const {
return getArgsBuffer() + 1; }
592 const_arg_iterator
arg_end()
const {
return getArgsBuffer() + 1 + NumArgs; }
593 arg_iterator
arg_begin() {
return getArgsBuffer() + 1; }
594 arg_iterator
arg_end() {
return getArgsBuffer() + 1 + NumArgs; }
601 return isVariadic() ? getRequiredArgs().getNumRequiredArgs() : arg_size();
633 return EffectiveCallingConvention;
636 EffectiveCallingConvention =
Value;
644 getASTCallingConvention(), isReturnsRetained(),
645 isNoCallerSavedRegs(), isNoCfCheck());
654 if (!HasExtParameterInfos)
return {};
655 return llvm::makeArrayRef(getExtParameterInfosBuffer(), NumArgs);
658 assert(argIndex <= NumArgs);
659 if (!HasExtParameterInfos)
return ExtParameterInfo();
660 return getExtParameterInfos()[argIndex];
677 ID.AddInteger(getASTCallingConvention());
678 ID.AddBoolean(InstanceMethod);
679 ID.AddBoolean(ChainCall);
680 ID.AddBoolean(NoReturn);
681 ID.AddBoolean(ReturnsRetained);
682 ID.AddBoolean(NoCallerSavedRegs);
683 ID.AddBoolean(HasRegParm);
684 ID.AddInteger(RegParm);
685 ID.AddBoolean(NoCfCheck);
687 ID.AddBoolean(HasExtParameterInfos);
688 if (HasExtParameterInfos) {
689 for (
auto paramInfo : getExtParameterInfos())
690 ID.AddInteger(paramInfo.getOpaqueValue());
692 getReturnType().Profile(ID);
693 for (
const auto &I : arguments())
704 ID.AddInteger(info.
getCC());
705 ID.AddBoolean(InstanceMethod);
706 ID.AddBoolean(ChainCall);
714 ID.AddBoolean(!paramInfos.empty());
715 if (!paramInfos.empty()) {
716 for (
auto paramInfo : paramInfos)
717 ID.AddInteger(paramInfo.getOpaqueValue());
721 i = argTypes.begin(), e = argTypes.end(); i != e; ++i) {
Ignore - Ignore the argument (treat as void).
Represents a function declaration or definition.
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 forPrototype(const FunctionProtoType *prototype, const FunctionDecl *FD)
static RequiredArgs getFromOpaqueData(unsigned value)
C Language Family Type Representation.
Extend - Valid only for integer argument types.
bool isNoCfCheck() const
Whether this function has nocf_check attribute.
const_arg_range arguments() const
bool isVariadic() const
Whether this function prototype is variadic.
llvm::iterator_range< const_arg_iterator > const_arg_range
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
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()
Represents a parameter to a function.
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...
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)
ArrayRef< ParmVarDecl * > parameters() const
bool getSuppressSRet() const
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
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)
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 RequiredArgs forPrototypePlus(CanQual< FunctionProtoType > prototype, unsigned additional, const FunctionDecl *FD)
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.
void setSuppressSRet(bool Suppress)
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 ...
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.
llvm::iterator_range< arg_iterator > arg_range
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
bool isNoCallerSavedRegs() const
Whether this function no longer saves caller registers.
ArrayRef< llvm::Type * > getCoerceAndExpandTypeSequence() const
static RequiredArgs forPrototype(CanQual< FunctionProtoType > prototype, const FunctionDecl *FD)
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.
static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype, unsigned additional, const FunctionDecl *FD)
Compute the arguments required by the given formal prototype, given that there may be some additional...
unsigned getNumRequiredArgs() const
unsigned getDirectOffset() const
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.