clang 23.0.0git
CIRGenFunctionInfo.h
Go to the documentation of this file.
1//==-- CIRGenFunctionInfo.h - Representation of fn 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 CIRGenFunctionInfo and associated types used in representing the
10// CIR source types and ABI-coerced types for function arguments and
11// return values.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_CIR_CIRGENFUNCTIONINFO_H
16#define LLVM_CLANG_CIR_CIRGENFUNCTIONINFO_H
17
20#include "llvm/ADT/FoldingSet.h"
21#include "llvm/Support/TrailingObjects.h"
22
23namespace clang::CIRGen {
24
25/// A class for recording the number of arguments that a function signature
26/// requires.
28 /// The number of required arguments, or ~0 if the signature does not permit
29 /// optional arguments.
30 unsigned numRequired;
31
32public:
33 enum All_t { All };
34
35 RequiredArgs(All_t _) : numRequired(~0U) {}
36 explicit RequiredArgs(unsigned n) : numRequired(n) { assert(n != ~0U); }
37
38 unsigned getOpaqueData() const { return numRequired; }
39
40 bool allowsOptionalArgs() const { return numRequired != ~0U; }
41
42 /// Compute the arguments required by the given formal prototype, given that
43 /// there may be some additional, non-formal arguments in play.
44 ///
45 /// If FD is not null, this will consider pass_object_size params in FD.
46 static RequiredArgs
48 unsigned additional) {
49 if (!prototype->isVariadic())
50 return All;
51
52 if (prototype->hasExtParameterInfos())
53 llvm_unreachable("NYI");
54
55 return RequiredArgs(prototype->getNumParams() + additional);
56 }
57
58 static RequiredArgs
60 unsigned additional) {
61 return getFromProtoWithExtraSlots(prototype.getTypePtr(), additional);
62 }
63
64 unsigned getNumRequiredArgs() const {
65 assert(allowsOptionalArgs());
66 return numRequired;
67 }
68};
69
70// The TrailingObjects for this class contain the function return type in the
71// first CanQualType slot, followed by the argument types.
72class CIRGenFunctionInfo final
73 : public llvm::FoldingSetNode,
74 private llvm::TrailingObjects<CIRGenFunctionInfo, CanQualType> {
75 // Whether this function has noreturn.
76 LLVM_PREFERRED_TYPE(bool)
77 unsigned noReturn : 1;
78
79 RequiredArgs required;
80
81 unsigned numArgs;
82
83 CanQualType *getArgTypes() { return getTrailingObjects(); }
84 const CanQualType *getArgTypes() const { return getTrailingObjects(); }
85
86 CIRGenFunctionInfo() : required(RequiredArgs::All) {}
87
88 FunctionType::ExtInfo getExtInfo() const {
89 // TODO(cir): as we add this information to this type, we need to add calls
90 // here instead of explicit false/0.
92 isNoReturn(), /*getHasRegParm=*/false, /*getRegParm=*/false,
93 /*getASTCallingConvention=*/CallingConv(0), /*isReturnsRetained=*/false,
94 /*isNoCallerSavedRegs=*/false, /*isNoCfCheck=*/false,
95 /*isCmseNSCall=*/false);
96 }
97
98public:
99 static CIRGenFunctionInfo *create(FunctionType::ExtInfo info,
100 CanQualType resultType,
102 RequiredArgs required);
103
104 void operator delete(void *p) { ::operator delete(p); }
105
106 // Friending class TrailingObjects is apparantly not good enough for MSVC, so
107 // these have to be public.
108 friend class TrailingObjects;
109
112
113 // This function has to be CamelCase because llvm::FoldingSet requires so.
114 // NOLINTNEXTLINE(readability-identifier-naming)
115 static void Profile(llvm::FoldingSetNodeID &id, FunctionType::ExtInfo info,
116 RequiredArgs required, CanQualType resultType,
118 id.AddBoolean(info.getNoReturn());
119 id.AddBoolean(required.getOpaqueData());
120 resultType.Profile(id);
121 for (const CanQualType &arg : argTypes)
122 arg.Profile(id);
123 }
124
125 // NOLINTNEXTLINE(readability-identifier-naming)
126 void Profile(llvm::FoldingSetNodeID &id) {
127 // If the Profile functions get out of sync, we can end up with incorrect
128 // function signatures, so we call the static Profile function here rather
129 // than duplicating the logic.
130 Profile(id, getExtInfo(), required, getReturnType(), arguments());
131 }
132
136
140
141 CanQualType getReturnType() const { return getArgTypes()[0]; }
142
143 const_arg_iterator argTypesBegin() const { return getArgTypes() + 1; }
144 const_arg_iterator argTypesEnd() const { return getArgTypes() + 1 + numArgs; }
145 arg_iterator argTypesBegin() { return getArgTypes() + 1; }
146 arg_iterator argTypesEnd() { return getArgTypes() + 1 + numArgs; }
147
148 unsigned argTypeSize() const { return numArgs; }
149
156
157 bool isVariadic() const { return required.allowsOptionalArgs(); }
158 RequiredArgs getRequiredArgs() const { return required; }
159 unsigned getNumRequiredArgs() const {
161 : argTypeSize();
162 }
163
164 bool isNoReturn() const { return noReturn; }
165};
166
167} // namespace clang::CIRGen
168
169#endif
static void Profile(llvm::FoldingSetNodeID &id, FunctionType::ExtInfo info, RequiredArgs required, CanQualType resultType, llvm::ArrayRef< CanQualType > argTypes)
const_arg_iterator argTypesEnd() const
llvm::ArrayRef< CanQualType > argTypes() const
void Profile(llvm::FoldingSetNodeID &id)
static CIRGenFunctionInfo * create(FunctionType::ExtInfo info, CanQualType resultType, llvm::ArrayRef< CanQualType > argTypes, RequiredArgs required)
llvm::MutableArrayRef< CanQualType > argTypes()
llvm::ArrayRef< CanQualType > requiredArguments() const
llvm::ArrayRef< CanQualType > arguments() const
const_arg_iterator argTypesBegin() const
A class for recording the number of arguments that a function signature requires.
static RequiredArgs getFromProtoWithExtraSlots(clang::CanQual< clang::FunctionProtoType > prototype, unsigned additional)
static RequiredArgs getFromProtoWithExtraSlots(const clang::FunctionProtoType *prototype, unsigned additional)
Compute the arguments required by the given formal prototype, given that there may be some additional...
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.
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5269
unsigned getNumParams() const
Definition TypeBase.h:5547
bool isVariadic() const
Whether this function prototype is variadic.
Definition TypeBase.h:5673
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type?
Definition TypeBase.h:5738
A class which abstracts out some details necessary for making a call.
Definition TypeBase.h:4576
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition Specifiers.h:278