|
| 1 | +//===-- XeVMToLLVMIRTranslation.cpp - Translate XeVM to LLVM IR -*- C++ -*-===// |
| 2 | +// |
| 3 | +// This file is licensed 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 a translation between the MLIR XeVM dialect and |
| 10 | +// LLVM IR. |
| 11 | +// |
| 12 | +//===----------------------------------------------------------------------===// |
| 13 | + |
| 14 | +#include "gc/Target/LLVMIR/Dialect/XeVM/XeVMToLLVMIRTranslation.h" |
| 15 | +#include "gc/Dialect/LLVMIR/XeVMDialect.h" |
| 16 | +#include "mlir/IR/BuiltinAttributes.h" |
| 17 | +#include "mlir/IR/Operation.h" |
| 18 | +#include "mlir/Target/LLVMIR/ModuleTranslation.h" |
| 19 | + |
| 20 | +#include "llvm/IR/ConstantRange.h" |
| 21 | +#include "llvm/IR/IRBuilder.h" |
| 22 | +#include "llvm/Support/raw_ostream.h" |
| 23 | + |
| 24 | +using namespace mlir; |
| 25 | +using namespace mlir::LLVM; |
| 26 | + |
| 27 | +namespace { |
| 28 | +/// Implementation of the dialect interface that converts operations belonging |
| 29 | +/// to the XeVM dialect to LLVM IR. |
| 30 | +class XeVMDialectLLVMIRTranslationInterface |
| 31 | + : public LLVMTranslationDialectInterface { |
| 32 | +public: |
| 33 | + using LLVMTranslationDialectInterface::LLVMTranslationDialectInterface; |
| 34 | + |
| 35 | + /// Translates the given operation to LLVM IR using the provided IR builder |
| 36 | + /// and saving the state in `moduleTranslation`. |
| 37 | + LogicalResult |
| 38 | + convertOperation(Operation *op, llvm::IRBuilderBase &builder, |
| 39 | + LLVM::ModuleTranslation &moduleTranslation) const final { |
| 40 | + /* TODO */ |
| 41 | + return failure(); |
| 42 | + } |
| 43 | + |
| 44 | + /// Attaches module-level metadata for functions marked as kernels. |
| 45 | + LogicalResult |
| 46 | + amendOperation(Operation *op, ArrayRef<llvm::Instruction *> instructions, |
| 47 | + NamedAttribute attribute, |
| 48 | + LLVM::ModuleTranslation &moduleTranslation) const final { |
| 49 | + auto func = dyn_cast<LLVM::LLVMFuncOp>(op); |
| 50 | + if (!func) |
| 51 | + return failure(); |
| 52 | + /* TODO */ |
| 53 | + |
| 54 | + return success(); |
| 55 | + } |
| 56 | +}; |
| 57 | +} // namespace |
| 58 | + |
| 59 | +void mlir::registerXeVMDialectTranslation(DialectRegistry ®istry) { |
| 60 | + registry.insert<xevm::XeVMDialect>(); |
| 61 | + registry.addExtension(+[](MLIRContext *ctx, xevm::XeVMDialect *dialect) { |
| 62 | + dialect->addInterfaces<XeVMDialectLLVMIRTranslationInterface>(); |
| 63 | + }); |
| 64 | +} |
| 65 | + |
| 66 | +void mlir::registerXeVMDialectTranslation(MLIRContext &context) { |
| 67 | + DialectRegistry registry; |
| 68 | + registerXeVMDialectTranslation(registry); |
| 69 | + context.appendDialectRegistry(registry); |
| 70 | +} |
0 commit comments