@@ -44,14 +44,11 @@ CIRGenFunctionInfo::create(CanQualType resultType,
44
44
45
45
cir::FuncType CIRGenTypes::getFunctionType (const CIRGenFunctionInfo &fi) {
46
46
mlir::Type resultType = convertType (fi.getReturnType ());
47
+ SmallVector<mlir::Type, 8 > argTypes;
48
+ argTypes.reserve (fi.getNumRequiredArgs ());
47
49
48
- SmallVector<mlir::Type, 8 > argTypes (fi.getNumRequiredArgs ());
49
-
50
- unsigned argNo = 0 ;
51
- llvm::ArrayRef<CIRGenFunctionInfoArgInfo> argInfos (fi.argInfoBegin (),
52
- fi.getNumRequiredArgs ());
53
- for (const auto &argInfo : argInfos)
54
- argTypes[argNo++] = convertType (argInfo.type );
50
+ for (const CIRGenFunctionInfoArgInfo &argInfo : fi.requiredArguments ())
51
+ argTypes.push_back (convertType (argInfo.type ));
55
52
56
53
return cir::FuncType::get (argTypes,
57
54
(resultType ? resultType : builder.getVoidTy ()),
@@ -63,6 +60,35 @@ CIRGenCallee CIRGenCallee::prepareConcreteCallee(CIRGenFunction &cgf) const {
63
60
return *this ;
64
61
}
65
62
63
+ // / Adds the formal parameters in FPT to the given prefix. If any parameter in
64
+ // / FPT has pass_object_size_attrs, then we'll add parameters for those, too.
65
+ // / TODO(cir): this should be shared with LLVM codegen
66
+ static void appendParameterTypes (const CIRGenTypes &cgt,
67
+ SmallVectorImpl<CanQualType> &prefix,
68
+ CanQual<FunctionProtoType> fpt) {
69
+ assert (!cir::MissingFeatures::opCallExtParameterInfo ());
70
+ // Fast path: don't touch param info if we don't need to.
71
+ if (!fpt->hasExtParameterInfos ()) {
72
+ prefix.append (fpt->param_type_begin (), fpt->param_type_end ());
73
+ return ;
74
+ }
75
+
76
+ cgt.getCGModule ().errorNYI (" appendParameterTypes: hasExtParameterInfos" );
77
+ }
78
+
79
+ // / Arrange the CIR function layout for a value of the given function type, on
80
+ // / top of any implicit parameters already stored.
81
+ static const CIRGenFunctionInfo &
82
+ arrangeCIRFunctionInfo (CIRGenTypes &cgt, SmallVectorImpl<CanQualType> &prefix,
83
+ CanQual<FunctionProtoType> ftp) {
84
+ RequiredArgs required =
85
+ RequiredArgs::getFromProtoWithExtraSlots (ftp, prefix.size ());
86
+ assert (!cir::MissingFeatures::opCallExtParameterInfo ());
87
+ appendParameterTypes (cgt, prefix, ftp);
88
+ CanQualType resultType = ftp->getReturnType ().getUnqualifiedType ();
89
+ return cgt.arrangeCIRFunctionInfo (resultType, prefix, required);
90
+ }
91
+
66
92
static const CIRGenFunctionInfo &
67
93
arrangeFreeFunctionLikeCall (CIRGenTypes &cgt, CIRGenModule &cgm,
68
94
const CallArgList &args,
@@ -95,6 +121,34 @@ CIRGenTypes::arrangeFreeFunctionCall(const CallArgList &args,
95
121
return arrangeFreeFunctionLikeCall (*this , cgm, args, fnType);
96
122
}
97
123
124
+ // / Arrange the argument and result information for the declaration or
125
+ // / definition of the given function.
126
+ const CIRGenFunctionInfo &
127
+ CIRGenTypes::arrangeFunctionDeclaration (const FunctionDecl *fd) {
128
+ if (const auto *md = dyn_cast<CXXMethodDecl>(fd)) {
129
+ if (md->isInstance ()) {
130
+ cgm.errorNYI (" arrangeFunctionDeclaration: instance method" );
131
+ }
132
+ }
133
+
134
+ CanQualType funcTy = fd->getType ()->getCanonicalTypeUnqualified ();
135
+
136
+ assert (isa<FunctionType>(funcTy));
137
+ // TODO: setCUDAKernelCallingConvention
138
+ assert (!cir::MissingFeatures::cudaSupport ());
139
+
140
+ // When declaring a function without a prototype, always use a non-variadic
141
+ // type.
142
+ if (CanQual<FunctionNoProtoType> noProto =
143
+ funcTy.getAs <FunctionNoProtoType>()) {
144
+ assert (!cir::MissingFeatures::opCallCIRGenFuncInfoExtParamInfo ());
145
+ return arrangeCIRFunctionInfo (noProto->getReturnType (), std::nullopt,
146
+ RequiredArgs::All);
147
+ }
148
+
149
+ return arrangeFreeFunctionType (funcTy.castAs <FunctionProtoType>());
150
+ }
151
+
98
152
static cir::CIRCallOpInterface
99
153
emitCallLikeOp (CIRGenFunction &cgf, mlir::Location callLoc,
100
154
cir::FuncOp directFuncOp,
@@ -112,13 +166,8 @@ emitCallLikeOp(CIRGenFunction &cgf, mlir::Location callLoc,
112
166
113
167
const CIRGenFunctionInfo &
114
168
CIRGenTypes::arrangeFreeFunctionType (CanQual<FunctionProtoType> fpt) {
115
- SmallVector<CanQualType, 8 > argTypes;
116
- for (unsigned i = 0 , e = fpt->getNumParams (); i != e; ++i)
117
- argTypes.push_back (fpt->getParamType (i));
118
- RequiredArgs required = RequiredArgs::forPrototypePlus (fpt);
119
-
120
- CanQualType resultType = fpt->getReturnType ().getUnqualifiedType ();
121
- return arrangeCIRFunctionInfo (resultType, argTypes, required);
169
+ SmallVector<CanQualType, 16 > argTypes;
170
+ return ::arrangeCIRFunctionInfo (*this , argTypes, fpt);
122
171
}
123
172
124
173
const CIRGenFunctionInfo &
0 commit comments