[clang] [CIR] Cleanup support for C functions (PR #136854)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 23 10:49:28 PDT 2025
================
@@ -13,20 +13,76 @@
#include "CIRGenCall.h"
#include "CIRGenFunction.h"
+#include "CIRGenFunctionInfo.h"
#include "clang/CIR/MissingFeatures.h"
using namespace clang;
using namespace clang::CIRGen;
-CIRGenFunctionInfo *CIRGenFunctionInfo::create(CanQualType resultType) {
- void *buffer = operator new(totalSizeToAlloc<ArgInfo>(1));
+CIRGenFunctionInfo *
+CIRGenFunctionInfo::create(CanQualType resultType,
+ llvm::ArrayRef<CanQualType> argTypes,
+ RequiredArgs required) {
+ void *buffer = operator new(totalSizeToAlloc<ArgInfo>(argTypes.size() + 1));
CIRGenFunctionInfo *fi = new (buffer) CIRGenFunctionInfo();
+
+ fi->required = required;
+ fi->numArgs = argTypes.size();
fi->getArgsBuffer()[0].type = resultType;
+ for (unsigned i = 0; i < argTypes.size(); ++i)
+ fi->getArgsBuffer()[i + 1].type = argTypes[i];
return fi;
}
+cir::FuncType CIRGenTypes::getFunctionType(const CIRGenFunctionInfo &fi) {
+ bool inserted = functionsBeingProcessed.insert(&fi).second;
+ assert(inserted && "Recursively being processed?");
+
+ mlir::Type resultType = nullptr;
+ const cir::ABIArgInfo &retAI = fi.getReturnInfo();
+
+ switch (retAI.getKind()) {
+ case cir::ABIArgInfo::Ignore:
+ // TODO(CIR): This should probably be the None type from the builtin
+ // dialect.
+ resultType = nullptr;
+ break;
+
+ case cir::ABIArgInfo::Direct:
+ resultType = retAI.getCoerceToType();
+ break;
+
+ default:
+ assert(false && "NYI");
+ }
+
+ SmallVector<mlir::Type, 8> argTypes;
+ unsigned argNo = 0;
+ CIRGenFunctionInfo::const_arg_iterator it = fi.arg_begin(),
+ ie = it + fi.getNumRequiredArgs();
+ for (; it != ie; ++it, ++argNo) {
----------------
andykaylor wrote:
Can you make this a range-based loop?
https://github.com/llvm/llvm-project/pull/136854
More information about the cfe-commits
mailing list