| 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 "mlir/IR/BuiltinOps.h" |
| 19 |
#include "clang/Basic/CodeGenOptions.h" |
| 20 |
#include "clang/Basic/LangOptions.h" |
| 21 |
#include "clang/Basic/TargetInfo.h" |
| 22 |
#include "clang/CIR/Dialect/IR/CIRDialect.h" |
| 23 |
#include "clang/CIR/MissingFeatures.h" |
| 24 |
#include <memory> |
| 25 |
|
| 26 |
namespace cir { |
| 27 |
|
| 28 |
class LowerModule { |
| 29 |
mlir::ModuleOp module; |
| 30 |
const std::unique_ptr<clang::TargetInfo> target; |
| 31 |
std::unique_ptr<CIRCXXABI> abi; |
| 32 |
[[maybe_unused]] mlir::PatternRewriter &rewriter; |
| 33 |
|
| 34 |
public: |
| 35 |
LowerModule(clang::LangOptions langOpts, clang::CodeGenOptions codeGenOpts, |
| 36 |
mlir::ModuleOp &module, std::unique_ptr<clang::TargetInfo> target, |
| 37 |
mlir::PatternRewriter &rewriter); |
| 38 |
~LowerModule() = default; |
| 39 |
|
| 40 |
clang::TargetCXXABI::Kind getCXXABIKind() const { |
| 41 |
assert(!cir::MissingFeatures::lowerModuleLangOpts()); |
| 42 |
return target->getCXXABI().getKind(); |
| 43 |
} |
| 44 |
|
| 45 |
CIRCXXABI &getCXXABI() const { return *abi; } |
| 46 |
const clang::TargetInfo &getTarget() const { return *target; } |
| 47 |
mlir::MLIRContext *getMLIRContext() { return module.getContext(); } |
| 48 |
}; |
| 49 |
|
| 50 |
std::unique_ptr<LowerModule> createLowerModule(mlir::ModuleOp module, |
| 51 |
mlir::PatternRewriter &rewriter); |
| 52 |
|
| 53 |
} // namespace cir |
| 54 |
|
| 55 |
#endif // CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_LOWERMODULE_H |