Path: blob/main/contrib/llvm-project/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVMIR.cpp
213845 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file implements lowering of CIR attributes and operations directly to9// LLVMIR.10//11//===----------------------------------------------------------------------===//1213#include "mlir/Dialect/LLVMIR/LLVMDialect.h"14#include "mlir/IR/DialectRegistry.h"15#include "mlir/Target/LLVMIR/LLVMTranslationInterface.h"16#include "mlir/Target/LLVMIR/ModuleTranslation.h"17#include "clang/CIR/Dialect/IR/CIRAttrs.h"18#include "clang/CIR/Dialect/IR/CIRDialect.h"19#include "clang/CIR/MissingFeatures.h"20#include "llvm/ADT/ArrayRef.h"21#include "llvm/IR/Constant.h"22#include "llvm/IR/GlobalVariable.h"2324using namespace llvm;2526namespace cir {27namespace direct {2829/// Implementation of the dialect interface that converts CIR attributes to LLVM30/// IR metadata.31class CIRDialectLLVMIRTranslationInterface32: public mlir::LLVMTranslationDialectInterface {33public:34using LLVMTranslationDialectInterface::LLVMTranslationDialectInterface;3536/// Translates the given operation to LLVM IR using the provided IR builder37/// and saving the state in `moduleTranslation`.38mlir::LogicalResult convertOperation(39mlir::Operation *op, llvm::IRBuilderBase &builder,40mlir::LLVM::ModuleTranslation &moduleTranslation) const final {4142if (auto cirOp = llvm::dyn_cast<mlir::LLVM::ZeroOp>(op))43moduleTranslation.mapValue(cirOp.getResult()) =44llvm::Constant::getNullValue(45moduleTranslation.convertType(cirOp.getType()));4647return mlir::success();48}49};5051void registerCIRDialectTranslation(mlir::DialectRegistry ®istry) {52registry.insert<cir::CIRDialect>();53registry.addExtension(+[](mlir::MLIRContext *ctx, cir::CIRDialect *dialect) {54dialect->addInterfaces<CIRDialectLLVMIRTranslationInterface>();55});56}5758} // namespace direct59} // namespace cir6061namespace mlir {62void registerCIRDialectTranslation(mlir::MLIRContext &context) {63mlir::DialectRegistry registry;64cir::direct::registerCIRDialectTranslation(registry);65context.appendDialectRegistry(registry);66}67} // namespace mlir686970