1313
1414#include " CIRGenCall.h"
1515#include " CIRGenFunction.h"
16+ #include " CIRGenFunctionInfo.h"
1617#include " clang/CIR/MissingFeatures.h"
1718
1819using namespace clang ;
1920using namespace clang ::CIRGen;
2021
21- CIRGenFunctionInfo *CIRGenFunctionInfo::create (CanQualType resultType) {
22- void *buffer = operator new (totalSizeToAlloc<ArgInfo>(1 ));
22+ CIRGenFunctionInfo *
23+ CIRGenFunctionInfo::create (CanQualType resultType,
24+ llvm::ArrayRef<CanQualType> argTypes,
25+ RequiredArgs required) {
26+ void *buffer = operator new (totalSizeToAlloc<ArgInfo>(argTypes.size () + 1 ));
2327
2428 CIRGenFunctionInfo *fi = new (buffer) CIRGenFunctionInfo ();
29+
30+ fi->required = required;
31+ fi->numArgs = argTypes.size ();
2532 fi->getArgsBuffer ()[0 ].type = resultType;
33+ for (unsigned i = 0 ; i < argTypes.size (); ++i)
34+ fi->getArgsBuffer ()[i + 1 ].type = argTypes[i];
2635
2736 return fi;
2837}
2938
39+ cir::FuncType CIRGenTypes::getFunctionType (const CIRGenFunctionInfo &fi) {
40+ bool inserted = functionsBeingProcessed.insert (&fi).second ;
41+ assert (inserted && " Recursively being processed?" );
42+
43+ mlir::Type resultType = nullptr ;
44+ const cir::ABIArgInfo &retAI = fi.getReturnInfo ();
45+
46+ switch (retAI.getKind ()) {
47+ case cir::ABIArgInfo::Ignore:
48+ // TODO(CIR): This should probably be the None type from the builtin
49+ // dialect.
50+ resultType = nullptr ;
51+ break ;
52+
53+ case cir::ABIArgInfo::Direct:
54+ resultType = retAI.getCoerceToType ();
55+ break ;
56+
57+ default :
58+ assert (false && " NYI" );
59+ }
60+
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 ;
67+
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);
74+ break ;
75+ }
76+ }
77+
78+ bool erased = functionsBeingProcessed.erase (&fi);
79+ assert (erased && " Not in set?" );
80+
81+ return cir::FuncType::get (argTypes,
82+ (resultType ? resultType : builder.getVoidTy ()),
83+ fi.isVariadic ());
84+ }
85+
3086CIRGenCallee CIRGenCallee::prepareConcreteCallee (CIRGenFunction &cgf) const {
3187 assert (!cir::MissingFeatures::opCallVirtual ());
3288 return *this ;
@@ -35,6 +91,9 @@ CIRGenCallee CIRGenCallee::prepareConcreteCallee(CIRGenFunction &cgf) const {
3591static const CIRGenFunctionInfo &
3692arrangeFreeFunctionLikeCall (CIRGenTypes &cgt, CIRGenModule &cgm,
3793 const FunctionType *fnType) {
94+
95+ RequiredArgs required = RequiredArgs::All;
96+
3897 if (const auto *proto = dyn_cast<FunctionProtoType>(fnType)) {
3998 if (proto->isVariadic ())
4099 cgm.errorNYI (" call to variadic function" );
@@ -49,7 +108,7 @@ arrangeFreeFunctionLikeCall(CIRGenTypes &cgt, CIRGenModule &cgm,
49108 CanQualType retType = fnType->getReturnType ()
50109 ->getCanonicalTypeUnqualified ()
51110 .getUnqualifiedType ();
52- return cgt.arrangeCIRFunctionInfo (retType);
111+ return cgt.arrangeCIRFunctionInfo (retType, {}, required );
53112}
54113
55114const CIRGenFunctionInfo &
@@ -71,6 +130,23 @@ static cir::CIRCallOpInterface emitCallLikeOp(CIRGenFunction &cgf,
71130 return builder.createCallOp (callLoc, directFuncOp);
72131}
73132
133+ const CIRGenFunctionInfo &
134+ CIRGenTypes::arrangeFreeFunctionType (CanQual<FunctionProtoType> fpt) {
135+ SmallVector<CanQualType, 16 > argTypes;
136+ for (unsigned i = 0 , e = fpt->getNumParams (); i != e; ++i)
137+ argTypes.push_back (fpt->getParamType (i));
138+ RequiredArgs required = RequiredArgs::forPrototypePlus (fpt);
139+
140+ CanQualType resultType = fpt->getReturnType ().getUnqualifiedType ();
141+ return arrangeCIRFunctionInfo (resultType, argTypes, required);
142+ }
143+
144+ const CIRGenFunctionInfo &
145+ CIRGenTypes::arrangeFreeFunctionType (CanQual<FunctionNoProtoType> fnpt) {
146+ CanQualType resultType = fnpt->getReturnType ().getUnqualifiedType ();
147+ return arrangeCIRFunctionInfo (resultType, {}, RequiredArgs (0 ));
148+ }
149+
74150RValue CIRGenFunction::emitCall (const CIRGenFunctionInfo &funcInfo,
75151 const CIRGenCallee &callee,
76152 ReturnValueSlot returnValue,
0 commit comments