From 83e0aab82d2a800c7dd9991de61a849ec33316e4 Mon Sep 17 00:00:00 2001 From: Petr Kurapov Date: Tue, 5 Nov 2024 05:00:54 -0700 Subject: [PATCH] [GPU] Add an empty xevm translation library. --- cmake/functions.cmake | 10 +++ .../Dialect/XeVM/XeVMToLLVMIRTranslation.h | 31 ++++++++ lib/gc/Target/CMakeLists.txt | 1 + lib/gc/Target/LLVMIR/XeVM/CMakeLists.txt | 17 +++++ .../LLVMIR/XeVM/XeVMToLLVMIRTranslation.cpp | 70 +++++++++++++++++++ 5 files changed, 129 insertions(+) create mode 100644 include/gc/Target/LLVMIR/Dialect/XeVM/XeVMToLLVMIRTranslation.h create mode 100644 lib/gc/Target/LLVMIR/XeVM/CMakeLists.txt create mode 100644 lib/gc/Target/LLVMIR/XeVM/XeVMToLLVMIRTranslation.cpp diff --git a/cmake/functions.cmake b/cmake/functions.cmake index 2614d2af..6ee67440 100644 --- a/cmake/functions.cmake +++ b/cmake/functions.cmake @@ -129,6 +129,16 @@ function(gc_add_mlir_conversion_library name) endif() endfunction() +function(gc_add_mlir_translation_library name) + add_mlir_translation_library(${ARGV}) + target_link_libraries(obj.${name} PUBLIC GcInterface) + set_property(GLOBAL APPEND PROPERTY GC_MLIR_LIBS ${name}) + + if(GcInterface IN_LIST ARGN) + target_link_libraries(obj.${name} PUBLIC GcInterface) + endif() +endfunction() + macro(gc_add_mlir_tool name) # the dependency list copied from mlir/tools/mlir-cpu-runner/CMakeLists.txt of upstream if(NOT DEFINED LLVM_LINK_COMPONENTS) diff --git a/include/gc/Target/LLVMIR/Dialect/XeVM/XeVMToLLVMIRTranslation.h b/include/gc/Target/LLVMIR/Dialect/XeVM/XeVMToLLVMIRTranslation.h new file mode 100644 index 00000000..b679656a --- /dev/null +++ b/include/gc/Target/LLVMIR/Dialect/XeVM/XeVMToLLVMIRTranslation.h @@ -0,0 +1,31 @@ +//===-- XeVMToLLVMIRTranslation.h - XeVM to LLVM IR -------------*- C++ -*-===// +// +// This file is licensed under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This provides registration calls for XeVM dialect to LLVM IR translation. +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_TARGET_LLVMIR_DIALECT_XEVM_XEVMTOLLVMIRTRANSLATION_H +#define MLIR_TARGET_LLVMIR_DIALECT_XEVM_XEVMTOLLVMIRTRANSLATION_H + +namespace mlir { + +class DialectRegistry; +class MLIRContext; + +/// Register the XeVM dialect and the translation from it to the LLVM IR in the +/// given registry; +void registerXeVMDialectTranslation(DialectRegistry ®istry); + +/// Register the XeVM dialect and the translation from it in the registry +/// associated with the given context. +void registerXeVMDialectTranslation(MLIRContext &context); + +} // namespace mlir + +#endif // MLIR_TARGET_LLVMIR_DIALECT_XEVM_XEVMTOLLVMIRTRANSLATION_H diff --git a/lib/gc/Target/CMakeLists.txt b/lib/gc/Target/CMakeLists.txt index 8bd31073..219bf75d 100644 --- a/lib/gc/Target/CMakeLists.txt +++ b/lib/gc/Target/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(LLVM) +add_subdirectory(LLVMIR/XeVM) diff --git a/lib/gc/Target/LLVMIR/XeVM/CMakeLists.txt b/lib/gc/Target/LLVMIR/XeVM/CMakeLists.txt new file mode 100644 index 00000000..bcd554c5 --- /dev/null +++ b/lib/gc/Target/LLVMIR/XeVM/CMakeLists.txt @@ -0,0 +1,17 @@ +gc_add_mlir_translation_library(MLIRXeVMToLLVMIRTranslation + XeVMToLLVMIRTranslation.cpp + + DEPENDS + MLIRXeVMConversionsIncGen + + LINK_COMPONENTS + Core + + LINK_LIBS PUBLIC + MLIRIR + MLIRLLVMDialect + MLIRXeVMDialect + MLIRSupport + MLIRTargetLLVMIRExport + GcInterface +) diff --git a/lib/gc/Target/LLVMIR/XeVM/XeVMToLLVMIRTranslation.cpp b/lib/gc/Target/LLVMIR/XeVM/XeVMToLLVMIRTranslation.cpp new file mode 100644 index 00000000..228299c7 --- /dev/null +++ b/lib/gc/Target/LLVMIR/XeVM/XeVMToLLVMIRTranslation.cpp @@ -0,0 +1,70 @@ +//===-- XeVMToLLVMIRTranslation.cpp - Translate XeVM to LLVM IR -*- C++ -*-===// +// +// This file is licensed under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements a translation between the MLIR XeVM dialect and +// LLVM IR. +// +//===----------------------------------------------------------------------===// + +#include "gc/Target/LLVMIR/Dialect/XeVM/XeVMToLLVMIRTranslation.h" +#include "gc/Dialect/LLVMIR/XeVMDialect.h" +#include "mlir/IR/BuiltinAttributes.h" +#include "mlir/IR/Operation.h" +#include "mlir/Target/LLVMIR/ModuleTranslation.h" + +#include "llvm/IR/ConstantRange.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/Support/raw_ostream.h" + +using namespace mlir; +using namespace mlir::LLVM; + +namespace { +/// Implementation of the dialect interface that converts operations belonging +/// to the XeVM dialect to LLVM IR. +class XeVMDialectLLVMIRTranslationInterface + : public LLVMTranslationDialectInterface { +public: + using LLVMTranslationDialectInterface::LLVMTranslationDialectInterface; + + /// Translates the given operation to LLVM IR using the provided IR builder + /// and saving the state in `moduleTranslation`. + LogicalResult + convertOperation(Operation *op, llvm::IRBuilderBase &builder, + LLVM::ModuleTranslation &moduleTranslation) const final { + /* TODO */ + return failure(); + } + + /// Attaches module-level metadata for functions marked as kernels. + LogicalResult + amendOperation(Operation *op, ArrayRef instructions, + NamedAttribute attribute, + LLVM::ModuleTranslation &moduleTranslation) const final { + auto func = dyn_cast(op); + if (!func) + return failure(); + /* TODO */ + + return success(); + } +}; +} // namespace + +void mlir::registerXeVMDialectTranslation(DialectRegistry ®istry) { + registry.insert(); + registry.addExtension(+[](MLIRContext *ctx, xevm::XeVMDialect *dialect) { + dialect->addInterfaces(); + }); +} + +void mlir::registerXeVMDialectTranslation(MLIRContext &context) { + DialectRegistry registry; + registerXeVMDialectTranslation(registry); + context.appendDialectRegistry(registry); +}