2222
2323namespace clang ::CIRGen {
2424
25- struct CIRGenFunctionInfoArgInfo {
26- CanQualType type;
27- };
28-
2925// / A class for recording the number of arguments that a function signature
3026// / requires.
3127class RequiredArgs {
@@ -71,18 +67,19 @@ class RequiredArgs {
7167 }
7268};
7369
70+ // The TrailingObjects for this class contain the function return type in the
71+ // first CanQualType slot, followed by the argument types.
7472class CIRGenFunctionInfo final
7573 : public llvm::FoldingSetNode,
76- private llvm::TrailingObjects<CIRGenFunctionInfo,
77- CIRGenFunctionInfoArgInfo> {
78- using ArgInfo = CIRGenFunctionInfoArgInfo;
79-
74+ private llvm::TrailingObjects<CIRGenFunctionInfo, CanQualType> {
8075 RequiredArgs required;
8176
8277 unsigned numArgs;
8378
84- ArgInfo *getArgsBuffer () { return getTrailingObjects<ArgInfo>(); }
85- const ArgInfo *getArgsBuffer () const { return getTrailingObjects<ArgInfo>(); }
79+ CanQualType *getArgTypes () { return getTrailingObjects<CanQualType>(); }
80+ const CanQualType *getArgTypes () const {
81+ return getTrailingObjects<CanQualType>();
82+ }
8683
8784 CIRGenFunctionInfo () : required(RequiredArgs::All) {}
8885
@@ -97,8 +94,8 @@ class CIRGenFunctionInfo final
9794 // these have to be public.
9895 friend class TrailingObjects ;
9996
100- using const_arg_iterator = const ArgInfo *;
101- using arg_iterator = ArgInfo *;
97+ using const_arg_iterator = const CanQualType *;
98+ using arg_iterator = CanQualType *;
10299
103100 // This function has to be CamelCase because llvm::FoldingSet requires so.
104101 // NOLINTNEXTLINE(readability-identifier-naming)
@@ -113,49 +110,41 @@ class CIRGenFunctionInfo final
113110
114111 // NOLINTNEXTLINE(readability-identifier-naming)
115112 void Profile (llvm::FoldingSetNodeID &id) {
116- // It's unfortunate that we are looping over the arguments twice (here and
117- // in the static Profile function we call from here), but if the Profile
118- // functions get out of sync, we can end up with incorrect function
119- // signatures, and we don't have the argument types in the format that the
120- // static Profile function requires.
121- llvm::SmallVector<CanQualType, 16 > argTypes;
122- for (const ArgInfo &argInfo : arguments ())
123- argTypes.push_back (argInfo.type );
124-
125- Profile (id, required, getReturnType (), argTypes);
113+ // If the Profile functions get out of sync, we can end up with incorrect
114+ // function signatures, so we call the static Profile function here rather
115+ // than duplicating the logic.
116+ Profile (id, required, getReturnType (), arguments ());
126117 }
127118
128- llvm::ArrayRef<ArgInfo > arguments () const {
129- return llvm::ArrayRef<ArgInfo>( argInfoBegin (), numArgs);
119+ llvm::ArrayRef<CanQualType > arguments () const {
120+ return llvm::ArrayRef<CanQualType>( argTypesBegin (), numArgs);
130121 }
131122
132- llvm::ArrayRef<ArgInfo > requiredArguments () const {
133- return llvm::ArrayRef<ArgInfo>( argInfoBegin (), getNumRequiredArgs ());
123+ llvm::ArrayRef<CanQualType > requiredArguments () const {
124+ return llvm::ArrayRef<CanQualType>( argTypesBegin (), getNumRequiredArgs ());
134125 }
135126
136- CanQualType getReturnType () const { return getArgsBuffer ()[0 ]. type ; }
127+ CanQualType getReturnType () const { return getArgTypes ()[0 ]; }
137128
138- const_arg_iterator argInfoBegin () const { return getArgsBuffer () + 1 ; }
139- const_arg_iterator argInfoEnd () const {
140- return getArgsBuffer () + 1 + numArgs;
141- }
142- arg_iterator argInfoBegin () { return getArgsBuffer () + 1 ; }
143- arg_iterator argInfoEnd () { return getArgsBuffer () + 1 + numArgs; }
129+ const_arg_iterator argTypesBegin () const { return getArgTypes () + 1 ; }
130+ const_arg_iterator argTypesEnd () const { return getArgTypes () + 1 + numArgs; }
131+ arg_iterator argTypesBegin () { return getArgTypes () + 1 ; }
132+ arg_iterator argTypesEnd () { return getArgTypes () + 1 + numArgs; }
144133
145- unsigned argInfoSize () const { return numArgs; }
134+ unsigned argTypeSize () const { return numArgs; }
146135
147- llvm::MutableArrayRef<ArgInfo> argInfos () {
148- return llvm::MutableArrayRef<ArgInfo>( argInfoBegin (), numArgs);
136+ llvm::MutableArrayRef<CanQualType> argTypes () {
137+ return llvm::MutableArrayRef<CanQualType>( argTypesBegin (), numArgs);
149138 }
150- llvm::ArrayRef<ArgInfo> argInfos () const {
151- return llvm::ArrayRef<ArgInfo>( argInfoBegin (), numArgs);
139+ llvm::ArrayRef<CanQualType> argTypes () const {
140+ return llvm::ArrayRef<CanQualType>( argTypesBegin (), numArgs);
152141 }
153142
154143 bool isVariadic () const { return required.allowsOptionalArgs (); }
155144 RequiredArgs getRequiredArgs () const { return required; }
156145 unsigned getNumRequiredArgs () const {
157146 return isVariadic () ? getRequiredArgs ().getNumRequiredArgs ()
158- : argInfoSize ();
147+ : argTypeSize ();
159148 }
160149};
161150
0 commit comments