@@ -44,14 +44,11 @@ CIRGenFunctionInfo::create(CanQualType resultType,
4444
4545cir::FuncType CIRGenTypes::getFunctionType (const CIRGenFunctionInfo &fi) {
4646 mlir::Type resultType = convertType (fi.getReturnType ());
47+ SmallVector<mlir::Type, 8 > argTypes;
48+ argTypes.reserve (fi.getNumRequiredArgs ());
4749
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 ));
5552
5653 return cir::FuncType::get (argTypes,
5754 (resultType ? resultType : builder.getVoidTy ()),
@@ -63,6 +60,35 @@ CIRGenCallee CIRGenCallee::prepareConcreteCallee(CIRGenFunction &cgf) const {
6360 return *this ;
6461}
6562
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+
6692static const CIRGenFunctionInfo &
6793arrangeFreeFunctionLikeCall (CIRGenTypes &cgt, CIRGenModule &cgm,
6894 const CallArgList &args,
@@ -95,6 +121,34 @@ CIRGenTypes::arrangeFreeFunctionCall(const CallArgList &args,
95121 return arrangeFreeFunctionLikeCall (*this , cgm, args, fnType);
96122}
97123
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+
98152static cir::CIRCallOpInterface
99153emitCallLikeOp (CIRGenFunction &cgf, mlir::Location callLoc,
100154 cir::FuncOp directFuncOp,
@@ -112,13 +166,8 @@ emitCallLikeOp(CIRGenFunction &cgf, mlir::Location callLoc,
112166
113167const CIRGenFunctionInfo &
114168CIRGenTypes::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);
122171}
123172
124173const CIRGenFunctionInfo &
0 commit comments