================ @@ -18,22 +18,118 @@ 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) { + void *buffer = operator new(totalSizeToAlloc<ArgInfo>(argTypes.size() + 1)); CIRGenFunctionInfo *fi = new (buffer) CIRGenFunctionInfo(); + 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; } +namespace { + +/// Encapsulates information about the way function arguments from +/// CIRGenFunctionInfo should be passed to actual CIR function. +class ClangToCIRArgMapping { + static constexpr unsigned invalidIndex = ~0U; + unsigned totalNumCIRArgs; + + /// Arguments of CIR function corresponding to single Clang argument. + struct CIRArgs { + // Argument is expanded to CIR arguments at positions + // [FirstArgIndex, FirstArgIndex + NumberOfArgs). + unsigned firstArgIndex = 0; + unsigned numberOfArgs = 0; + + CIRArgs() : firstArgIndex(invalidIndex), numberOfArgs(0) {} + }; + + SmallVector<CIRArgs, 8> argInfo; + +public: + ClangToCIRArgMapping(const ASTContext &astContext, + const CIRGenFunctionInfo &funcInfo) + : totalNumCIRArgs(0), argInfo(funcInfo.arg_size()) { + construct(astContext, funcInfo); + } + + unsigned totalCIRArgs() const { return totalNumCIRArgs; } + + /// Returns index of first CIR argument corresponding to argNo, and their + /// quantity. + std::pair<unsigned, unsigned> getCIRArgs(unsigned argNo) const { + assert(argNo < argInfo.size()); + return std::make_pair(argInfo[argNo].firstArgIndex, + argInfo[argNo].numberOfArgs); + } + +private: + void construct(const ASTContext &astContext, + const CIRGenFunctionInfo &funcInfo); +}; + +void ClangToCIRArgMapping::construct(const ASTContext &astContext, + const CIRGenFunctionInfo &funcInfo) { + unsigned cirArgNo = 0; + + assert(!cir::MissingFeatures::opCallABIIndirectArg()); + + unsigned argNo = 0; + unsigned numArgs = funcInfo.arg_size(); + for (const auto *i = funcInfo.arg_begin(); argNo < numArgs; ++i, ++argNo) { + assert(i != funcInfo.arg_end()); + const cir::ABIArgInfo &ai = i->info; + // Collect data about CIR arguments corresponding to Clang argument ArgNo. + auto &cirArgs = argInfo[argNo]; + + assert(!cir::MissingFeatures::opCallPaddingArgs()); + + switch (ai.getKind()) { + default: + assert(!cir::MissingFeatures::abiArgInfo()); + // For now we just fall through. More argument kinds will be added later + // as the upstreaming proceeds. + [[fallthrough]]; + case cir::ABIArgInfo::Direct: + // Postpone splitting structs into elements since this makes it way + // more complicated for analysis to obtain information on the original + // arguments. + // + // TODO(cir): a LLVM lowering prepare pass should break this down into + // the appropriated pieces. + assert(!cir::MissingFeatures::opCallABIExtendArg()); + cirArgs.numberOfArgs = 1; + break; + } + + if (cirArgs.numberOfArgs > 0) { ---------------- bcardosolopes wrote:
> I have concerns about upstreaming this infrastructure ahead of the completion > of the implementation Same here, see my comment/question elsewhere in the PR. https://github.com/llvm/llvm-project/pull/136810 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits