Skip to content

[GPU] Add an empty xevm translation library. #404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cmake/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 31 additions & 0 deletions include/gc/Target/LLVMIR/Dialect/XeVM/XeVMToLLVMIRTranslation.h
Original file line number Diff line number Diff line change
@@ -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 &registry);

/// 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
1 change: 1 addition & 0 deletions lib/gc/Target/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(LLVM)
add_subdirectory(LLVMIR/XeVM)
17 changes: 17 additions & 0 deletions lib/gc/Target/LLVMIR/XeVM/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
70 changes: 70 additions & 0 deletions lib/gc/Target/LLVMIR/XeVM/XeVMToLLVMIRTranslation.cpp
Original file line number Diff line number Diff line change
@@ -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<llvm::Instruction *> instructions,
NamedAttribute attribute,
LLVM::ModuleTranslation &moduleTranslation) const final {
auto func = dyn_cast<LLVM::LLVMFuncOp>(op);
if (!func)
return failure();
/* TODO */

return success();
}
};
} // namespace

void mlir::registerXeVMDialectTranslation(DialectRegistry &registry) {
registry.insert<xevm::XeVMDialect>();
registry.addExtension(+[](MLIRContext *ctx, xevm::XeVMDialect *dialect) {
dialect->addInterfaces<XeVMDialectLLVMIRTranslationInterface>();
});
}

void mlir::registerXeVMDialectTranslation(MLIRContext &context) {
DialectRegistry registry;
registerXeVMDialectTranslation(registry);
context.appendDialectRegistry(registry);
}