clang 22.0.0git
LowerModule.cpp
Go to the documentation of this file.
1/===--- LowerModule.cpp - Lower CIR Module to a Target -------------------===/
2/
3/ Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4/ See https://llvm.org/LICENSE.txt for license information.
5/ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6/
7/===----------------------------------------------------------------------===/
8/
9/ This file partially mimics clang/lib/CodeGen/CodeGenModule.cpp. The queries
10/ are adapted to operate on the CIR dialect, however.
11/
12/===----------------------------------------------------------------------===/
13
14#include "LowerModule.h"
15#include "CIRCXXABI.h"
16#include "mlir/IR/BuiltinAttributes.h"
17#include "mlir/IR/PatternMatch.h"
22#include "llvm/Support/ErrorHandling.h"
23
24namespace cir {
25
26static std::unique_ptr<CIRCXXABI> createCXXABI(LowerModule &lm) {
27 switch (lm.getCXXABIKind()) {
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:
38 return createItaniumCXXABI(lm);
39 case clang::TargetCXXABI::Microsoft:
40 llvm_unreachable("Windows ABI NYI");
41 }
42
43 llvm_unreachable("invalid C++ ABI kind");
44}
45
47 clang::CodeGenOptions codeGenOpts,
48 mlir::ModuleOp &module,
49 std::unique_ptr<clang::TargetInfo> target,
50 mlir::PatternRewriter &rewriter)
51 : module(module), target(std::move(target)), abi(createCXXABI(*this)),
52 rewriter(rewriter) {}
53
54/ TODO: not to create it every time
55std::unique_ptr<LowerModule>
56createLowerModule(mlir::ModuleOp module, mlir::PatternRewriter &rewriter) {
57 / Fetch target information.
58 llvm::Triple triple(mlir::cast<mlir::StringAttr>(
59 module->getAttr(cir::CIRDialect::getTripleAttrName()))
60 .getValue());
61 clang::TargetOptions targetOptions;
62 targetOptions.Triple = triple.str();
63 auto targetInfo = clang::targets::AllocateTarget(triple, targetOptions);
64
65 / FIXME(cir): This just uses the default language options. We need to account
66 / for custom options.
67 / Create context.
69 clang::LangOptions langOpts;
70
71 / FIXME(cir): This just uses the default code generation options. We need to
72 / account for custom options.
74 clang::CodeGenOptions codeGenOpts;
75
76 if (auto optInfo = mlir::cast_if_present<cir::OptInfoAttr>(
77 module->getAttr(cir::CIRDialect::getOptInfoAttrName()))) {
78 codeGenOpts.OptimizationLevel = optInfo.getLevel();
79 codeGenOpts.OptimizeSize = optInfo.getSize();
80 }
81
82 return std::make_unique<LowerModule>(std::move(langOpts),
83 std::move(codeGenOpts), module,
84 std::move(targetInfo), rewriter);
85}
86
87} / namespace cir
Defines the clang::LangOptions interface.
Defines the clang::TargetOptions class.
clang::TargetCXXABI::Kind getCXXABIKind() const
Definition LowerModule.h:40
LowerModule(clang::LangOptions langOpts, clang::CodeGenOptions codeGenOpts, mlir::ModuleOp &module, std::unique_ptr< clang::TargetInfo > target, mlir::PatternRewriter &rewriter)
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Options for controlling the target.
std::string Triple
The name of the target triple to compile for.
Defines the clang::TargetInfo interface.
std::unique_ptr< CIRCXXABI > createItaniumCXXABI(LowerModule &lm)
Creates an Itanium-family ABI.
std::unique_ptr< LowerModule > createLowerModule(mlir::ModuleOp module, mlir::PatternRewriter &rewriter)
static std::unique_ptr< CIRCXXABI > createCXXABI(LowerModule &lm)
std::unique_ptr< clang::TargetInfo > AllocateTarget(const llvm::Triple &Triple, const clang::TargetOptions &Opts)
Definition Targets.cpp:111
static bool lowerModuleLangOpts()
static bool lowerModuleCodeGenOpts()

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant