18#ifndef CLANG_LIB_CIR_DIALECT_TRANSFORMS_CIRABICLASSIFIER_H
19#define CLANG_LIB_CIR_DIALECT_TRANSFORMS_CIRABICLASSIFIER_H
21#include "mlir/ABI/ABIRewriteContext.h"
22#include "mlir/ABI/ABITypeMapper.h"
23#include "mlir/IR/BuiltinOps.h"
24#include "mlir/IR/Diagnostics.h"
25#include "mlir/Interfaces/DataLayoutInterfaces.h"
28#include "llvm/ABI/FunctionInfo.h"
29#include "llvm/ABI/TargetInfo.h"
30#include "llvm/ADT/STLFunctionalExtras.h"
31#include "llvm/ADT/StringRef.h"
32#include "llvm/IR/CallingConv.h"
69 virtual std::optional<mlir::abi::FunctionClassification>
76 virtual std::optional<mlir::abi::FunctionClassification>
81 virtual std::optional<mlir::abi::FunctionClassification>
86 virtual std::optional<mlir::abi::ArgClassification>
98 std::optional<mlir::abi::FunctionClassification>
106 std::optional<mlir::abi::FunctionClassification>
108 cir::FuncOp callee)
override;
115 std::optional<mlir::abi::FunctionClassification>
124 virtual const llvm::abi::TargetInfo &
129 std::optional<mlir::abi::ArgClassification>
131 llvm::function_ref<mlir::InFlightDiagnostic()> emitError);
133 const mlir::DataLayout &
dl;
140 std::optional<mlir::abi::FunctionClassification>
141 classifySignature(mlir::Type retCIR, mlir::TypeRange inputs,
142 llvm::abi::RequiredArgs required,
143 const llvm::abi::TargetInfo &targetInfo,
144 llvm::CallingConv::ID callConv,
145 llvm::function_ref<mlir::InFlightDiagnostic()> emitError);
149 std::optional<mlir::abi::FunctionClassification>
151 const llvm::abi::TargetInfo &targetInfo,
152 llvm::CallingConv::ID callConv);
157std::unique_ptr<CIRABIClassifier>
162std::unique_ptr<CIRABIClassifier>
164 llvm::StringRef attrName);
167std::unique_ptr<CIRABIClassifier>
172std::unique_ptr<CIRABIClassifier>
184std::optional<mlir::abi::FunctionClassification>
186 mlir::Type returnType);
190std::optional<mlir::abi::FunctionClassification>
193 llvm::StringRef classificationAttrName);
196llvm::abi::RequiredArgs
requiredArgs(cir::FuncType fnTy);
201 llvm::abi::X86AVXABILevel base);
std::optional< mlir::abi::FunctionClassification > classifyVariadicCall(cir::CIRCallOpInterface call, cir::FuncOp callee) override
The call is classified at the callee's features, not the caller's, because the pass rewrites the defi...
std::optional< mlir::abi::FunctionClassification > classifyIndirectCall(cir::CIRCallOpInterface call) override
A callee resolved at run time carries no features of its own, so the call is classified at the featur...
CIRABIClassifierCommon(const mlir::DataLayout &dl, mlir::ModuleOp modOp)
const mlir::DataLayout & dl
std::optional< mlir::abi::FunctionClassification > classifyFunction(cir::FuncOp func) override
Classify a cir.func using the LLVM ABI library.
virtual const llvm::abi::TargetInfo & getTargetInfo(cir::FuncOp featureSource)=0
The library classifier for a function whose recorded target features may refine the ABI rules.
mlir::abi::ABITypeMapper typeMapper
std::optional< mlir::abi::ArgClassification > classifyVarArgType(mlir::Type ty, const llvm::abi::TargetInfo &targetInfo, llvm::function_ref< mlir::InFlightDiagnostic()> emitError)
Classify ty, the type fetched by a cir.va_arg, as an unnamed argument with every argument register fr...
Produces the classification CallConvLowering rewrites a signature from.
virtual std::optional< mlir::abi::FunctionClassification > classifyIndirectCall(cir::CIRCallOpInterface call)=0
Classify call, whose callee is resolved at run time, from the signature its callee pointer points to.
virtual std::optional< mlir::abi::FunctionClassification > classifyVariadicCall(cir::CIRCallOpInterface call, cir::FuncOp callee)=0
Classify a direct call to the variadic function callee that passes arguments through the ellipsis.
virtual std::optional< mlir::abi::FunctionClassification > classifyFunction(cir::FuncOp func)=0
Classify func's declared signature.
virtual ~CIRABIClassifier()=default
virtual std::optional< mlir::abi::ArgClassification > classifyVAArg(cir::VAArgOp vaArg)=0
Classify the type fetched by vaArg as an unnamed argument with a full register budget.
std::optional< mlir::abi::FunctionClassification > withReturnVoidness(std::optional< mlir::abi::FunctionClassification > fc, mlir::Type returnType)
Record on fc whether returnType is CIR's void.
std::unique_ptr< CIRABIClassifier > createAMDGPUABIClassifier(const mlir::DataLayout &dl, mlir::ModuleOp modOp)
The AMDGPU classifier.
llvm::abi::X86AVXABILevel funcAvxLevel(cir::FuncOp func, llvm::abi::X86AVXABILevel base)
The AVX level to classify func at: base, raised if the function's own recorded feature list enables a...
std::unique_ptr< CIRABIClassifier > createX86_64ABIClassifier(const mlir::DataLayout &dl, mlir::ModuleOp modOp, const ABIClassifierOptions &options)
The x86_64 System V classifier.
llvm::CallingConv::ID convertCallingConv(cir::CallingConv cc)
Map a CIR calling convention to the llvm::CallingConv the ABI classifier uses.
std::optional< mlir::abi::FunctionClassification > classifyFunction(cir::FuncOp func, const mlir::DataLayout &dl, cir::CallConvTarget target, llvm::StringRef classificationAttrName)
Classify func with the test target, or from the attribute named classificationAttrName when that is n...
std::unique_ptr< CIRABIClassifier > createInjectedABIClassifier(const mlir::DataLayout &dl, llvm::StringRef attrName)
A classifier that reads each function's classification from the DictionaryAttr named attrName.
std::unique_ptr< CIRABIClassifier > createTestTargetABIClassifier(const mlir::DataLayout &dl)
The MLIR test ABI target's classifier, whose predictable rules approximate x86_64 SysV.
CallConvTarget
The ABI target whose calling-convention rules drive CallConvLowering.
llvm::abi::RequiredArgs requiredArgs(cir::FuncType fnTy)
Where fnTy's declared parameters end and its ellipsis arguments begin.
The target-specific settings a classifier needs beyond what it can read from the module.
bool allowsX86TargetAttrAvx
Whether a function's own recorded target features may raise its x86_64 AVX level above x86AvxAbiLevel...
llvm::abi::X86ABICompatInfo x86AbiCompat
The x86_64 flags whose value depends on the target and the requested ABI compatibility version.
llvm::abi::X86AVXABILevel x86AvxAbiLevel
The AVX level the x86_64 classifier sizes a native vector at.