@@ -25,57 +25,71 @@ CIRGenFunctionInfo::create(CanQualType resultType,
2525 RequiredArgs required) {
2626 void *buffer = operator new (totalSizeToAlloc<ArgInfo>(argTypes.size () + 1 ));
2727
28+ assert (!cir::MissingFeatures::paramInfo ());
29+ assert (!cir::MissingFeatures::funcTypeExtInfo ());
30+
2831 CIRGenFunctionInfo *fi = new (buffer) CIRGenFunctionInfo ();
2932
3033 fi->required = required;
3134 fi->numArgs = argTypes.size ();
32- fi->getArgsBuffer ()[0 ].type = resultType;
33- for (unsigned i = 0 ; i < argTypes.size (); ++i)
34- fi->getArgsBuffer ()[i + 1 ].type = argTypes[i];
35+
36+ // ArgsBuffer contains the return type at index 0, and the argument types
37+ // starting at index 1, so there are argTypes.size() + 1 elements in total.
38+ unsigned idx = 1 ;
39+ ArgInfo *argsBuffer = fi->getArgsBuffer ();
40+ argsBuffer[0 ].type = resultType;
41+ for (const auto &argType : argTypes)
42+ argsBuffer[idx++].type = argType;
3543
3644 return fi;
3745}
3846
3947cir::FuncType CIRGenTypes::getFunctionType (const CIRGenFunctionInfo &fi) {
4048 bool inserted = functionsBeingProcessed.insert (&fi).second ;
49+ (void )inserted;
4150 assert (inserted && " Recursively being processed?" );
4251
43- mlir::Type resultType = nullptr ;
44- const cir::ABIArgInfo &retAI = fi.getReturnInfo ();
52+ mlir::Type resultType;
53+ const cir::ABIArgInfo &retInfo = fi.getReturnInfo ();
4554
46- switch (retAI .getKind ()) {
55+ switch (retInfo .getKind ()) {
4756 case cir::ABIArgInfo::Ignore:
4857 // TODO(CIR): This should probably be the None type from the builtin
4958 // dialect.
5059 resultType = nullptr ;
5160 break ;
5261
5362 case cir::ABIArgInfo::Direct:
54- resultType = retAI .getCoerceToType ();
63+ resultType = retInfo .getCoerceToType ();
5564 break ;
5665
5766 default :
58- assert ( false && " NYI " );
67+ cgm. errorNYI ( " getFunctionType: unhandled return kind " );
5968 }
6069
61- SmallVector<mlir::Type, 8 > argTypes;
62- unsigned argNo = 0 ;
63- CIRGenFunctionInfo::const_arg_iterator it = fi.arg_begin (),
64- ie = it + fi.getNumRequiredArgs ();
65- for (; it != ie; ++it, ++argNo) {
66- const auto &argInfo = it->info ;
70+ // TODO(cir): ClangToCIRArgMapping
6771
68- switch (argInfo.getKind ()) {
69- default :
70- llvm_unreachable (" NYI" );
71- case cir::ABIArgInfo::Direct:
72- mlir::Type argType = argInfo.getCoerceToType ();
73- argTypes.push_back (argType);
72+ SmallVector<mlir::Type, 8 > argTypes (fi.getNumRequiredArgs ());
73+
74+ unsigned argNo = 0 ;
75+ llvm::ArrayRef<CIRGenFunctionInfoArgInfo> argInfos (fi.argInfoBegin (),
76+ fi.getNumRequiredArgs ());
77+ for (const auto &argInfo : argInfos) {
78+ const auto &abiArgInfo = argInfo.info ;
79+
80+ switch (abiArgInfo.getKind ()) {
81+ case cir::ABIArgInfo::Direct: {
82+ mlir::Type argType = abiArgInfo.getCoerceToType ();
83+ argTypes[argNo++] = argType;
7484 break ;
7585 }
86+ default :
87+ cgm.errorNYI (" getFunctionType: unhandled argument kind" );
88+ }
7689 }
7790
7891 bool erased = functionsBeingProcessed.erase (&fi);
92+ (void )erased;
7993 assert (erased && " Not in set?" );
8094
8195 return cir::FuncType::get (argTypes,
0 commit comments