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"
25#include "llvm/ADT/StringRef.h"
26#include <memory>
27
28namespace cir {
29
31 mlir::ModuleOp module;
32 const clang::LangOptions langOpts;
33 const std::unique_ptr<clang::TargetInfo> target;
34 std::unique_ptr<TargetLoweringInfo> targetLoweringInfo;
35 std::unique_ptr<CIRCXXABI> abi;
36
37public:
39 mlir::ModuleOp &module,
40 std::unique_ptr<clang::TargetInfo> target);
41 ~LowerModule() = default;
42
43 // The lowering-relevant LangOptions, populated by createLowerModule() from
44 // the module's #cir.lowering_options attribute when present (so a
45 // reloaded .cir lowers the same way without a live clang::LangOptions),
46 // otherwise left at their defaults.
47 const clang::LangOptions &getLangOpts() const { return langOpts; }
48
50 if (langOpts.CXXABI)
51 return *langOpts.CXXABI;
52 assert(target &&
53 "No C++ ABI kind without a target (missing/unsupported cir.triple)");
54 return target->getCXXABI().getKind();
55 }
57 assert(abi &&
58 "No C++ ABI without a target (missing/unsupported cir.triple)");
59 return *abi;
60 }
61
62 bool hasTarget() const {
63 // Null target means module had no cir.triple, or clang has no TargetInfo
64 // for it; but when cir.triple becomes mandatory we need to figure out how
65 // to handle cir.triple's without a corresponding TargetInfo / potentially
66 // removing this function.
68 return target != nullptr;
69 }
71 assert(target &&
72 "LowerModule has no target (missing/unsupported cir.triple)");
73 return *target;
74 }
75
76 // FIXME remove this once all ABIs are supported.
77 bool hasCXXABI() const { return abi != nullptr; }
78
79 mlir::MLIRContext *getMLIRContext() { return module.getContext(); }
80
82};
83
84std::unique_ptr<LowerModule> createLowerModule(mlir::ModuleOp module);
85
86} // namespace cir
87
88#endif // CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_LOWERMODULE_H
Defines the clang::LangOptions interface.
bool hasTarget() const
Definition LowerModule.h:62
const clang::LangOptions & getLangOpts() const
Definition LowerModule.h:47
mlir::MLIRContext * getMLIRContext()
Definition LowerModule.h:79
bool hasCXXABI() const
Definition LowerModule.h:77
CIRCXXABI & getCXXABI() const
Definition LowerModule.h:56
LowerModule(clang::LangOptions langOpts, clang::CodeGenOptions codeGenOpts, mlir::ModuleOp &module, std::unique_ptr< clang::TargetInfo > target)
clang::TargetCXXABI::Kind getCXXABIKind() const
Definition LowerModule.h:49
const TargetLoweringInfo & getTargetLoweringInfo()
const clang::TargetInfo & getTarget() const
Definition LowerModule.h:70
~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)
static bool makeTripleAlwaysPresent()