clang 24.0.0git
LowerModule.h
Go to the documentation of this file.
1//===--- LowerModule.h - Abstracts CIR's module lowering --------*- C++ -*-===//
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.h. The queries are
10// adapted to operate on the CIR dialect, however.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_LOWERMODULE_H
15#define CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_LOWERMODULE_H
16
17#include "CIRCXXABI.h"
18#include "TargetLoweringInfo.h"
19#include "mlir/IR/BuiltinOps.h"
24#include "llvm/ADT/StringRef.h"
25#include <memory>
26
27namespace cir {
28
30 mlir::ModuleOp module;
31 const clang::LangOptions langOpts;
32 const std::unique_ptr<clang::TargetInfo> target;
33 std::unique_ptr<TargetLoweringInfo> targetLoweringInfo;
34 std::unique_ptr<CIRCXXABI> abi;
35
36public:
38 mlir::ModuleOp &module,
39 std::unique_ptr<clang::TargetInfo> target);
40 ~LowerModule() = default;
41
42 // The lowering-relevant LangOptions, populated by createLowerModule() from
43 // the module's #cir.lowering_options attribute when present (so a
44 // reloaded .cir lowers the same way without a live clang::LangOptions),
45 // otherwise left at their defaults.
46 const clang::LangOptions &getLangOpts() const { return langOpts; }
47
49 return langOpts.CXXABI.value_or(target->getCXXABI().getKind());
50 }
51
52 CIRCXXABI &getCXXABI() const { return *abi; }
53
54 // FIXME remove this once all ABIs are supported.
55 bool hasCXXABI() const { return abi != nullptr; }
56
57 const clang::TargetInfo &getTarget() const { return *target; }
58 mlir::MLIRContext *getMLIRContext() { return module.getContext(); }
59
61};
62
63std::unique_ptr<LowerModule> createLowerModule(mlir::ModuleOp module);
64
65} // namespace cir
66
67#endif // CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_LOWERMODULE_H
Defines the clang::LangOptions interface.
const clang::LangOptions & getLangOpts() const
Definition LowerModule.h:46
mlir::MLIRContext * getMLIRContext()
Definition LowerModule.h:58
bool hasCXXABI() const
Definition LowerModule.h:55
CIRCXXABI & getCXXABI() const
Definition LowerModule.h:52
LowerModule(clang::LangOptions langOpts, clang::CodeGenOptions codeGenOpts, mlir::ModuleOp &module, std::unique_ptr< clang::TargetInfo > target)
clang::TargetCXXABI::Kind getCXXABIKind() const
Definition LowerModule.h:48
const TargetLoweringInfo & getTargetLoweringInfo()
const clang::TargetInfo & getTarget() const
Definition LowerModule.h:57
~LowerModule()=default
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...
Kind
The basic C++ ABI kind.
Exposes information about the current target.
Definition TargetInfo.h:228
Defines the clang::TargetInfo interface.
std::unique_ptr< LowerModule > createLowerModule(mlir::ModuleOp module)