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
21#include "llvm/ADT/FoldingSet.h"
22#include "llvm/Support/TrailingObjects.h"
23
24namespace clang::CIRGen {
25
26/// Return the number of parameters with the pass_object_size attribute.
27inline unsigned
29 if (!proto->hasExtParameterInfos())
30 return 0;
31 return llvm::count_if(
32 proto->getExtParameterInfos(),
34 return info.hasPassObjectSize();
35 });
36}
37
38/// A class for recording the number of arguments that a function signature
39/// requires.
41 /// The number of required arguments, or ~0 if the signature does not permit
42 /// optional arguments.
43 unsigned numRequired;
44
45public:
46 enum All_t { All };
47
48 RequiredArgs(All_t _) : numRequired(~0U) {}
49 explicit RequiredArgs(unsigned n) : numRequired(n) { assert(n != ~0U); }
50
51 unsigned getOpaqueData() const { return numRequired; }
52
53 bool allowsOptionalArgs() const { return numRequired != ~0U; }
54
55 /// Compute the arguments required by the given formal prototype, given that
56 /// there may be some additional, non-formal arguments in play.
57 ///
58 /// If FD is not null, this will consider pass_object_size params in FD.
59 static RequiredArgs
61 unsigned additional) {
62 if (!prototype->isVariadic())
63 return All;
64
65 additional += getNumPassObjectSizeParams(prototype);
66
67 return RequiredArgs(prototype->getNumParams() + additional);
68 }
69
70 static RequiredArgs
72 unsigned additional) {
73 return getFromProtoWithExtraSlots(prototype.getTypePtr(), additional);
74 }
75
76 unsigned getNumRequiredArgs() const {
77 assert(allowsOptionalArgs());
78 return numRequired;
79 }
80};
81
82// The TrailingObjects for this class contain the function return type in the
83// first CanQualType slot, followed by the argument types.
84class CIRGenFunctionInfo final
85 : public llvm::FoldingSetNode,
86 private llvm::TrailingObjects<CIRGenFunctionInfo, CanQualType> {
87 // Whether this function has noreturn.
88 LLVM_PREFERRED_TYPE(bool)
89 unsigned noReturn : 1;
90
91 // Whether this is an instance method/non-static member function with implicit
92 // 'this' argument.
93 LLVM_PREFERRED_TYPE(bool)
94 unsigned instanceMethod : 1;
95
96 RequiredArgs required;
97
98 unsigned numArgs;
99
100 CanQualType *getArgTypes() { return getTrailingObjects(); }
101 const CanQualType *getArgTypes() const { return getTrailingObjects(); }
102
103 CIRGenFunctionInfo() : required(RequiredArgs::All) {}
104
105 FunctionType::ExtInfo getExtInfo() const {
106 // TODO(cir): as we add this information to this type, we need to add calls
107 // here instead of explicit false/0.
109 isNoReturn(), /*getHasRegParm=*/false, /*getRegParm=*/false,
110 /*getASTCallingConvention=*/CallingConv(0), /*isReturnsRetained=*/false,
111 /*isNoCallerSavedRegs=*/false, /*isNoCfCheck=*/false,
112 /*isCmseNSCall=*/false);
113 }
114
115public:
116 static CIRGenFunctionInfo *create(FunctionType::ExtInfo info,
117 bool instanceMethod, CanQualType resultType,
119 RequiredArgs required);
120
121 void operator delete(void *p) { ::operator delete(p); }
122
123 // Friending class TrailingObjects is apparantly not good enough for MSVC, so
124 // these have to be public.
125 friend class TrailingObjects;
126
129
130 // This function has to be CamelCase because llvm::FoldingSet requires so.
131 // NOLINTNEXTLINE(readability-identifier-naming)
132 static void Profile(llvm::FoldingSetNodeID &id, bool instanceMethod,
133 FunctionType::ExtInfo info, RequiredArgs required,
134 CanQualType resultType,
136 id.AddBoolean(instanceMethod);
137 id.AddBoolean(info.getNoReturn());
138 id.AddInteger(required.getOpaqueData());
139 resultType.Profile(id);
140 for (const CanQualType &arg : argTypes)
141 arg.Profile(id);
142 }
143
144 // NOLINTNEXTLINE(readability-identifier-naming)
145 void Profile(llvm::FoldingSetNodeID &id) {
146 // If the Profile functions get out of sync, we can end up with incorrect
147 // function signatures, so we call the static Profile function here rather
148 // than duplicating the logic.
149 Profile(id, isInstanceMethod(), getExtInfo(), required, getReturnType(),
150 arguments());
151 }
152
156
160
161 CanQualType getReturnType() const { return getArgTypes()[0]; }
162
165 // TODO(cir): we currently just 'fake' this, but should calculate
166 // this/figure out what it means when we get our ABI info set correctly.
167 // For now, we leave this as a direct return.
168
170 }
171
172 const_arg_iterator argTypesBegin() const { return getArgTypes() + 1; }
173 const_arg_iterator argTypesEnd() const { return getArgTypes() + 1 + numArgs; }
174 arg_iterator argTypesBegin() { return getArgTypes() + 1; }
175 arg_iterator argTypesEnd() { return getArgTypes() + 1 + numArgs; }
176
177 unsigned argTypeSize() const { return numArgs; }
178
185
186 bool isVariadic() const { return required.allowsOptionalArgs(); }
187 RequiredArgs getRequiredArgs() const { return required; }
188 unsigned getNumRequiredArgs() const {
190 : argTypeSize();
191 }
192
193 bool isNoReturn() const { return noReturn; }
194 bool isInstanceMethod() const { return instanceMethod; }
195};
196
197} // namespace clang::CIRGen
198
199#endif
static ABIArgInfo getDirect(mlir::Type ty=nullptr)
Definition ABIArgInfo.h:56
const_arg_iterator argTypesEnd() const
cir::ABIArgInfo getReturnInfo() const
llvm::ArrayRef< CanQualType > argTypes() const
static CIRGenFunctionInfo * create(FunctionType::ExtInfo info, bool instanceMethod, CanQualType resultType, llvm::ArrayRef< CanQualType > argTypes, RequiredArgs required)
void Profile(llvm::FoldingSetNodeID &id)
llvm::MutableArrayRef< CanQualType > argTypes()
llvm::ArrayRef< CanQualType > requiredArguments() const
static void Profile(llvm::FoldingSetNodeID &id, bool instanceMethod, FunctionType::ExtInfo info, RequiredArgs required, CanQualType resultType, llvm::ArrayRef< CanQualType > argTypes)
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:5362
unsigned getNumParams() const
Definition TypeBase.h:5640
bool isVariadic() const
Whether this function prototype is variadic.
Definition TypeBase.h:5766
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
Definition TypeBase.h:5835
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type?
Definition TypeBase.h:5831
A class which abstracts out some details necessary for making a call.
Definition TypeBase.h:4669
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition TypeBase.h:4584
unsigned getNumPassObjectSizeParams(const clang::FunctionProtoType *proto)
Return the number of parameters with the pass_object_size attribute.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition Specifiers.h:279