13#include "mlir/IR/BuiltinOps.h"
14#include "mlir/Pass/PassManager.h"
19#include "llvm/Support/TimeProfiler.h"
20#include "llvm/TargetParser/Triple.h"
28 cir::LoweringOptionsAttr loweringLangOpts) {
30 if (triple.getArch() == llvm::Triple::x86_64 && !triple.isOSWindowsOrUEFI())
32 if (triple.isAMDGPU())
34 if (triple.isAArch64() && !triple.isOSWindows() &&
35 triple.getArch() != llvm::Triple::aarch64_32)
37 bool isHLSL = loweringLangOpts && loweringLangOpts.getHlsl();
39 loweringLangOpts && loweringLangOpts.getOpenmpIsTargetDevice();
43 if (triple.isSPIRV() && triple.getVendor() != llvm::Triple::AMD && !isHLSL &&
53 return llvm::abi::X86AVXABILevel::AVX512;
55 return llvm::abi::X86AVXABILevel::AVX;
56 return llvm::abi::X86AVXABILevel::None;
64 return !triple.isPS() && compat > clang::LangOptions::ClangABI::Ver23;
72static llvm::abi::X86ABICompatInfo
75 llvm::abi::X86ABICompatInfo abiCompat;
76 abiCompat.HonorsRevision98 = !triple.isOSDarwin();
77 abiCompat.ClassifyIntegerMMXAsSSE =
78 compat > clang::LangOptions::ClangABI::Ver3_8 && !triple.isOSDarwin() &&
79 !triple.isPS() && !triple.isOSFreeBSD();
80 abiCompat.PassInt128VectorsInMem =
81 compat > clang::LangOptions::ClangABI::Ver9 &&
82 (triple.isOSLinux() || triple.isOSNetBSD());
83 abiCompat.ReturnCXXRecordGreaterThan128InMem =
84 compat > clang::LangOptions::ClangABI::Ver20 && !triple.isPS();
85 abiCompat.Clang11Compat =
86 compat <= clang::LangOptions::ClangABI::Ver11 || triple.isPS();
89 abiCompat.SmallIntABICompat = triple.isOSDarwin() || triple.isPS()
90 ? llvm::abi::SmallIntABICompatKind::Clang23
91 : llvm::abi::SmallIntABICompatKind::Both;
97 bool enableVerifier,
bool enableIdiomRecognizer,
98 bool enableCIRSimplify,
bool enableLibOpt,
99 llvm::StringRef libOptOptions,
bool enableCallConvLowering) {
101 llvm::TimeTraceScope scope(
"CIR To CIR Passes");
105 return theModule.emitError()
106 <<
"missing '" << cir::CIRDialect::getTripleAttrName()
109 auto abiAttr = theModule->getAttrOfType<mlir::StringAttr>(
110 cir::CIRDialect::getTargetABIAttrName());
112 return theModule.emitError()
113 <<
"missing '" << cir::CIRDialect::getTargetABIAttrName()
116 mlir::PassManager pm(&mlirContext);
119 if (enableCIRSimplify)
122 if (enableIdiomRecognizer)
127 auto errorHandler = [](
const llvm::Twine &) -> mlir::LogicalResult {
128 return mlir::LogicalResult::failure();
131 if (libOptPass->initializeOptions(libOptOptions, errorHandler).failed())
132 return mlir::failure();
134 pm.addPass(std::move(libOptPass));
146 if (enableCallConvLowering) {
150 auto loweringLangOpts = theModule->getAttrOfType<cir::LoweringOptionsAttr>(
151 cir::CIRDialect::getLoweringOptionsAttrName());
159 auto compat = clang::LangOptions::ClangABI::Latest;
160 if (loweringLangOpts)
162 loweringLangOpts.getClangAbiCompat());
170 pm.enableVerifier(enableVerifier);
171 (void)mlir::applyPassManagerCLOptions(pm);
172 return pm.run(theModule);
Defines the clang::LangOptions interface.
ClangABI
Clang versions with different platform ABI conformance.
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...
static CallConvTarget getCallConvTarget(const llvm::Triple &triple, cir::LoweringOptionsAttr loweringLangOpts)
Map a target triple to the ABI target that drives CallConvLowering.
mlir::LogicalResult runCIRToCIRPasses(mlir::ModuleOp theModule, mlir::MLIRContext &mlirCtx, bool enableVerifier, bool enableIdiomRecognizer, bool enableCIRSimplify, bool enableLibOpt, llvm::StringRef libOptOptions, bool enableCallConvLowering)
static llvm::abi::X86AVXABILevel getX86AVXABILevel(llvm::StringRef abi)
The AVX level the classifier uses to size a native vector, read from the target ABI name.
static llvm::abi::X86ABICompatInfo getX86ABICompatInfo(const llvm::Triple &triple, clang::LangOptions::ClangABI compat)
The x86_64 ABI-compatibility flags, derived from the target and the requested compatibility version.
std::optional< llvm::Triple > getTripleFromModule(mlir::ModuleOp mod)
Attempts to construct an llvm::Triple from a module's cir.triple attribute.
CallConvTarget
The ABI target whose calling-convention rules drive CallConvLowering.
std::unique_ptr< Pass > createCallConvLoweringPass()
std::unique_ptr< Pass > createCIREHABILoweringPass()
std::unique_ptr< Pass > createCIRCanonicalizePass()
std::unique_ptr< Pass > createCIRFlattenCFGPass()
std::unique_ptr< Pass > createLibOptPass()
std::unique_ptr< Pass > createIdiomRecognizerPass()
void populateCIRPreLoweringPasses(mlir::OpPassManager &pm)
std::unique_ptr< Pass > createTargetLoweringPass()
std::unique_ptr< Pass > createGotoSolverPass()
std::unique_ptr< Pass > createLoweringPreparePass()
std::unique_ptr< Pass > createCIRForwardReturnSlotPass()
std::unique_ptr< Pass > createCIRSimplifyPass()
std::unique_ptr< Pass > createCXXABILoweringPass()
std::unique_ptr< Pass > createHoistAllocasPass()
std::unique_ptr< Pass > createCIRFoldEmptyBranchesPass()
static bool smallIntABICompatOption()