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/// A class for recording the number of arguments that a function signature
27/// requires.
29 /// The number of required arguments, or ~0 if the signature does not permit
30 /// optional arguments.
31 unsigned numRequired;
32
33public:
34 enum All_t { All };
35
36 RequiredArgs(All_t _) : numRequired(~0U) {}
37 explicit RequiredArgs(unsigned n) : numRequired(n) { assert(n != ~0U); }
38
39 unsigned getOpaqueData() const { return numRequired; }
40
41 bool allowsOptionalArgs() const { return numRequired != ~0U; }
42
43 /// Compute the arguments required by the given formal prototype, given that
44 /// there may be some additional, non-formal arguments in play.
45 ///
46 /// If FD is not null, this will consider pass_object_size params in FD.
47 static RequiredArgs
49 unsigned additional) {
50 if (!prototype->isVariadic())
51 return All;
52
53 if (prototype->hasExtParameterInfos())
54 llvm_unreachable("NYI");
55
56 return RequiredArgs(prototype->getNumParams() + additional);
57 }
58
59 static RequiredArgs
61 unsigned additional) {
62 return getFromProtoWithExtraSlots(prototype.getTypePtr(), additional);
63 }
64
65 unsigned getNumRequiredArgs() const {
66 assert(allowsOptionalArgs());
67 return numRequired;
68 }
69};
70
71// The TrailingObjects for this class contain the function return type in the
72// first CanQualType slot, followed by the argument types.
73class CIRGenFunctionInfo final
74 : public llvm::FoldingSetNode,
75 private llvm::TrailingObjects<CIRGenFunctionInfo, CanQualType> {
76 // Whether this function has noreturn.
77 LLVM_PREFERRED_TYPE(bool)
78 unsigned noReturn : 1;
79
80 // Whether this is an instance method/non-static member function with implicit
81 // 'this' argument.
82 LLVM_PREFERRED_TYPE(bool)
83 unsigned instanceMethod : 1;
84
85 RequiredArgs required;
86
87 unsigned numArgs;
88
89 CanQualType *getArgTypes() { return getTrailingObjects(); }
90 const CanQualType *getArgTypes() const { return getTrailingObjects(); }
91
92 CIRGenFunctionInfo() : required(RequiredArgs::All) {}
93
94 FunctionType::ExtInfo getExtInfo() const {
95 // TODO(cir): as we add this information to this type, we need to add calls
96 // here instead of explicit false/0.
98 isNoReturn(), /*getHasRegParm=*/false, /*getRegParm=*/false,
99 /*getASTCallingConvention=*/CallingConv(0), /*isReturnsRetained=*/false,
100 /*isNoCallerSavedRegs=*/false, /*isNoCfCheck=*/false,
101 /*isCmseNSCall=*/false);
102 }
103
104public:
105 static CIRGenFunctionInfo *create(FunctionType::ExtInfo info,
106 bool instanceMethod, CanQualType resultType,
108 RequiredArgs required);
109
110 void operator delete(void *p) { ::operator delete(p); }
111
112 // Friending class TrailingObjects is apparantly not good enough for MSVC, so
113 // these have to be public.
114 friend class TrailingObjects;
115
118
119 // This function has to be CamelCase because llvm::FoldingSet requires so.
120 // NOLINTNEXTLINE(readability-identifier-naming)
121 static void Profile(llvm::FoldingSetNodeID &id, bool instanceMethod,
122 FunctionType::ExtInfo info, RequiredArgs required,
123 CanQualType resultType,
125 id.AddBoolean(instanceMethod);
126 id.AddBoolean(info.getNoReturn());
127 id.AddInteger(required.getOpaqueData());
128 resultType.Profile(id);
129 for (const CanQualType &arg : argTypes)
130 arg.Profile(id);
131 }
132
133 // NOLINTNEXTLINE(readability-identifier-naming)
134 void Profile(llvm::FoldingSetNodeID &id) {
135 // If the Profile functions get out of sync, we can end up with incorrect
136 // function signatures, so we call the static Profile function here rather
137 // than duplicating the logic.
138 Profile(id, isInstanceMethod(), getExtInfo(), required, getReturnType(),
139 arguments());
140 }
141
145
149
150 CanQualType getReturnType() const { return getArgTypes()[0]; }
151
154 // TODO(cir): we currently just 'fake' this, but should calculate
155 // this/figure out what it means when we get our ABI info set correctly.
156 // For now, we leave this as a direct return.
157
159 }
160
161 const_arg_iterator argTypesBegin() const { return getArgTypes() + 1; }
162 const_arg_iterator argTypesEnd() const { return getArgTypes() + 1 + numArgs; }
163 arg_iterator argTypesBegin() { return getArgTypes() + 1; }
164 arg_iterator argTypesEnd() { return getArgTypes() + 1 + numArgs; }
165
166 unsigned argTypeSize() const { return numArgs; }
167
174
175 bool isVariadic() const { return required.allowsOptionalArgs(); }
176 RequiredArgs getRequiredArgs() const { return required; }
177 unsigned getNumRequiredArgs() const {
179 : argTypeSize();
180 }
181
182 bool isNoReturn() const { return noReturn; }
183 bool isInstanceMethod() const { return instanceMethod; }
184};
185
186} // namespace clang::CIRGen
187
188#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:5315
unsigned getNumParams() const
Definition TypeBase.h:5593
bool isVariadic() const
Whether this function prototype is variadic.
Definition TypeBase.h:5719
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type?
Definition TypeBase.h:5784
A class which abstracts out some details necessary for making a call.
Definition TypeBase.h:4622
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition Specifiers.h:278