|
| 1 | +//====- LowerAttrToLLVMIR.cpp - Lowering CIR attributes to LLVMIR ---------===// |
| 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 implements lowering of CIR attributes to LLVMIR. |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#include "mlir/IR/DialectRegistry.h" |
| 14 | +#include "mlir/Target/LLVMIR/LLVMTranslationInterface.h" |
| 15 | +#include "clang/CIR/Dialect/IR/CIRDialect.h" |
| 16 | +#include "clang/CIR/Passes.h" |
| 17 | + |
| 18 | +using namespace cir; |
| 19 | +using namespace llvm; |
| 20 | + |
| 21 | +namespace cir { |
| 22 | +namespace direct { |
| 23 | + |
| 24 | +/// Implementation of the dialect interface that converts CIR attributes to LLVM |
| 25 | +/// IR metadata. |
| 26 | +class CIRDialectLLVMIRTranslationInterface |
| 27 | + : public mlir::LLVMTranslationDialectInterface { |
| 28 | +public: |
| 29 | + using LLVMTranslationDialectInterface::LLVMTranslationDialectInterface; |
| 30 | + |
| 31 | + /// Any named attribute in the CIR dialect, i.e, with name started with |
| 32 | + /// "cir.", will be handled here. |
| 33 | + mlir::LogicalResult |
| 34 | + amendOperation(mlir::Operation *op, mlir::NamedAttribute attribute, |
| 35 | + mlir::LLVM::ModuleTranslation &moduleTranslation) const final { |
| 36 | + // TODO: Implement this |
| 37 | + return mlir::success(); |
| 38 | + } |
| 39 | +}; |
| 40 | + |
| 41 | +void registerCIRDialectTranslation(mlir::DialectRegistry ®istry) { |
| 42 | + registry.insert<mlir::cir::CIRDialect>(); |
| 43 | + registry.addExtension(+[](mlir::MLIRContext *ctx, mlir::cir::CIRDialect *dialect) { |
| 44 | + dialect->addInterfaces<CIRDialectLLVMIRTranslationInterface>(); |
| 45 | + }); |
| 46 | +} |
| 47 | + |
| 48 | +void registerCIRDialectTranslation(mlir::MLIRContext &context) { |
| 49 | + mlir::DialectRegistry registry; |
| 50 | + registerCIRDialectTranslation(registry); |
| 51 | + context.appendDialectRegistry(registry); |
| 52 | +} |
| 53 | +} // namespace direct |
| 54 | +} // namespace cir |
0 commit comments