18#include "llvm/ADT/StringExtras.h"
24using namespace mlir::abi;
30 llvm::abi::X86AVXABILevel base) {
35 auto features = func->getAttrOfType<mlir::StringAttr>(
"cir.target-features");
42 for (llvm::StringRef feature : llvm::split(features.getValue(),
',')) {
43 if (!feature.consume_front(
"+"))
45 if (feature ==
"avx512f")
46 return std::max(base, llvm::abi::X86AVXABILevel::AVX512);
47 avx |= feature ==
"avx";
49 return avx ? std::max(base, llvm::abi::X86AVXABILevel::AVX) : base;
56 X86_64ABIClassifier(
const mlir::DataLayout &dl, mlir::ModuleOp modOp,
57 const ABIClassifierOptions &options)
58 : CIRABIClassifierCommon(dl, modOp), baseAvxLevel(options.x86AvxAbiLevel),
60 abiCompat(options.x86AbiCompat) {}
65 mlir::FailureOr<ArgClassification>
66 classifyVAArg(cir::VAArgOp vaArg)
override {
67 return classifyVarArgType(
68 vaArg.getType(), getTargetInfo(vaArg->getParentOfType<cir::FuncOp>()),
69 [&]() { return vaArg->emitOpError(); });
75 const llvm::abi::TargetInfo &
76 getTargetInfo(cir::FuncOp featureSource)
override;
81 static constexpr unsigned numAvxLevels =
82 static_cast<unsigned>(llvm::abi::X86AVXABILevel::Last) + 1;
83 std::array<std::unique_ptr<llvm::abi::TargetInfo>, numAvxLevels> targets;
85 llvm::abi::X86AVXABILevel baseAvxLevel;
86 bool allowsTargetAttrAvx;
90 llvm::abi::X86ABICompatInfo abiCompat;
93const llvm::abi::TargetInfo &
94X86_64ABIClassifier::getTargetInfo(cir::FuncOp featureSource) {
95 llvm::abi::X86AVXABILevel level = baseAvxLevel;
96 assert(featureSource &&
"function required for getTargetInfo");
97 if (allowsTargetAttrAvx)
99 assert(
static_cast<unsigned>(level) < numAvxLevels &&
100 "a new X86AVXABILevel must move X86AVXABILevel::Last");
101 std::unique_ptr<llvm::abi::TargetInfo> &slot =
102 targets[
static_cast<unsigned>(level)];
105 llvm::abi::createX86_64TargetInfo(typeMapper.getTypeBuilder(), level,
112std::unique_ptr<CIRABIClassifier>
115 return std::make_unique<X86_64ABIClassifier>(dl, modOp, options);
static 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...
Classifies through the LLVM ABI Lowering Library.
static bool allowsX86TargetAttrAvx(const llvm::Triple &triple, clang::LangOptions::ClangABI compat)
Whether __attribute__((target(...))) on a function may raise its AVX ABI level above the command line...
std::unique_ptr< CIRABIClassifier > createX86_64ABIClassifier(const mlir::DataLayout &dl, mlir::ModuleOp modOp, const ABIClassifierOptions &options)
The x86_64 System V classifier.
The target-specific settings a classifier needs beyond what it can read from the module.
static bool opFuncMultiVersioning()