16#include "mlir/IR/BuiltinAttributes.h"
21#include "llvm/Support/ErrorHandling.h"
22#include "llvm/Support/FileSystem.h"
28 case clang::TargetCXXABI::AppleARM64:
29 case clang::TargetCXXABI::Fuchsia:
30 case clang::TargetCXXABI::GenericAArch64:
31 case clang::TargetCXXABI::GenericARM:
32 case clang::TargetCXXABI::iOS:
33 case clang::TargetCXXABI::WatchOS:
34 case clang::TargetCXXABI::GenericMIPS:
35 case clang::TargetCXXABI::GenericItanium:
36 case clang::TargetCXXABI::WebAssembly:
37 case clang::TargetCXXABI::XL:
39 case clang::TargetCXXABI::Microsoft:
43 llvm_unreachable(
"invalid C++ ABI kind");
46static std::unique_ptr<TargetLoweringInfo>
50 switch (triple.getArch()) {
51 case llvm::Triple::amdgpu:
53 case llvm::Triple::nvptx:
54 case llvm::Triple::nvptx64:
56 case llvm::Triple::spir:
57 case llvm::Triple::spir64:
59 case llvm::Triple::spirv:
60 case llvm::Triple::spirv32:
61 case llvm::Triple::spirv64:
65 return std::make_unique<TargetLoweringInfo>();
71 mlir::ModuleOp &module,
72 std::unique_ptr<clang::TargetInfo> target)
73 : module(module), langOpts(
std::move(langOpts)), target(
std::move(target)),
77 if (!targetLoweringInfo)
79 return *targetLoweringInfo;
87 if (!module->hasAttr(cir::CIRDialect::getTripleAttrName()))
91 llvm::Triple triple(mlir::cast<mlir::StringAttr>(
92 module->getAttr(cir::CIRDialect::getTripleAttrName()))
95 targetOptions.
Triple = triple.str();
103 if (
auto loweringLangOpts =
104 mlir::dyn_cast_if_present<cir::LoweringOptionsAttr>(
105 module->getAttr(cir::CIRDialect::getLoweringOptionsAttrName()))) {
106 langOpts.Exceptions = loweringLangOpts.getExceptions();
107 langOpts.ThreadsafeStatics = loweringLangOpts.getThreadsafeStatics();
108 langOpts.CUDA = loweringLangOpts.getCuda();
109 langOpts.CUDAIsDevice = loweringLangOpts.getCudaIsDevice();
110 langOpts.HIP = loweringLangOpts.getHip();
111 langOpts.GPURelocatableDeviceCode = loweringLangOpts.getGpuRdc();
112 langOpts.OpenMP = loweringLangOpts.getOpenmp();
113 langOpts.OpenMPIsTargetDevice = loweringLangOpts.getOpenmpIsTargetDevice();
115 loweringLangOpts.getClangAbiCompat()));
116 langOpts.LongDoubleSize = loweringLangOpts.getLongDoubleSize();
121 if (
auto cxxABI = module->getAttrOfType<mlir::StringAttr>(
122 cir::CIRDialect::getCXXABIAttrName()))
130 if (
auto optInfo = mlir::cast_if_present<cir::OptInfoAttr>(
131 module->getAttr(cir::CIRDialect::getOptInfoAttrName()))) {
132 codeGenOpts.OptimizationLevel = optInfo.getLevel();
133 codeGenOpts.OptimizeSize = optInfo.getSize();
139 targetInfo->adjust(diags, langOpts,
nullptr);
141 return std::make_unique<LowerModule>(std::move(langOpts),
142 std::move(codeGenOpts), module,
143 std::move(targetInfo));
Defines the clang::LangOptions interface.
Defines the clang::TargetOptions class.
LowerModule(clang::LangOptions langOpts, clang::CodeGenOptions codeGenOpts, mlir::ModuleOp &module, std::unique_ptr< clang::TargetInfo > target)
clang::TargetCXXABI::Kind getCXXABIKind() const
const TargetLoweringInfo & getTargetLoweringInfo()
const clang::TargetInfo & getTarget() const
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
static llvm::IntrusiveRefCntPtr< DiagnosticIDs > create()
Options for controlling the compiler diagnostics engine.
Concrete class used by the front-end to report problems and issues.
A diagnostic client that ignores all diagnostics.
ClangABI
Clang versions with different platform ABI conformance.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
std::optional< TargetCXXABI::Kind > CXXABI
C++ ABI to compile with, if specified by the frontend through -fc++-abi=.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Options for controlling the target.
std::string Triple
The name of the target triple to compile for.
Defines the clang::TargetInfo interface.
static std::unique_ptr< TargetLoweringInfo > createTargetLoweringInfo(LowerModule &lm)
std::unique_ptr< TargetLoweringInfo > createCommonSPIRTargetLoweringInfo()
std::unique_ptr< TargetLoweringInfo > createSPIRVTargetLoweringInfo()
std::unique_ptr< CIRCXXABI > createItaniumCXXABI(LowerModule &lm)
Creates an Itanium-family ABI.
static std::unique_ptr< CIRCXXABI > createCXXABI(LowerModule &lm)
std::unique_ptr< TargetLoweringInfo > createNVPTXTargetLoweringInfo()
std::unique_ptr< CIRCXXABI > createMicrosoftCXXABI(LowerModule &lm)
Creates a Microsoft-family ABI.
std::unique_ptr< LowerModule > createLowerModule(mlir::ModuleOp module)
std::unique_ptr< TargetLoweringInfo > createAMDGPUTargetLoweringInfo()
std::unique_ptr< clang::TargetInfo > AllocateTarget(const llvm::Triple &Triple, const clang::TargetOptions &Opts)
static bool lowerModuleLangOpts()
static bool lowerModuleCodeGenOpts()
static bool makeTripleAlwaysPresent()
static bool targetLoweringInfo()