Skip to content

Commit 1377cc3

Browse files
[GPU] Add an empty xevm translation library. (#404)
This adds the placeholder for xevm to llvm ir translation library.
1 parent 6feea7f commit 1377cc3

File tree

5 files changed

+129
-0
lines changed

5 files changed

+129
-0
lines changed

cmake/functions.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ function(gc_add_mlir_conversion_library name)
129129
endif()
130130
endfunction()
131131

132+
function(gc_add_mlir_translation_library name)
133+
add_mlir_translation_library(${ARGV})
134+
target_link_libraries(obj.${name} PUBLIC GcInterface)
135+
set_property(GLOBAL APPEND PROPERTY GC_MLIR_LIBS ${name})
136+
137+
if(GcInterface IN_LIST ARGN)
138+
target_link_libraries(obj.${name} PUBLIC GcInterface)
139+
endif()
140+
endfunction()
141+
132142
macro(gc_add_mlir_tool name)
133143
# the dependency list copied from mlir/tools/mlir-cpu-runner/CMakeLists.txt of upstream
134144
if(NOT DEFINED LLVM_LINK_COMPONENTS)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===-- XeVMToLLVMIRTranslation.h - 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 provides registration calls for XeVM dialect to LLVM IR translation.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef MLIR_TARGET_LLVMIR_DIALECT_XEVM_XEVMTOLLVMIRTRANSLATION_H
14+
#define MLIR_TARGET_LLVMIR_DIALECT_XEVM_XEVMTOLLVMIRTRANSLATION_H
15+
16+
namespace mlir {
17+
18+
class DialectRegistry;
19+
class MLIRContext;
20+
21+
/// Register the XeVM dialect and the translation from it to the LLVM IR in the
22+
/// given registry;
23+
void registerXeVMDialectTranslation(DialectRegistry &registry);
24+
25+
/// Register the XeVM dialect and the translation from it in the registry
26+
/// associated with the given context.
27+
void registerXeVMDialectTranslation(MLIRContext &context);
28+
29+
} // namespace mlir
30+
31+
#endif // MLIR_TARGET_LLVMIR_DIALECT_XEVM_XEVMTOLLVMIRTRANSLATION_H

lib/gc/Target/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
add_subdirectory(LLVM)
2+
add_subdirectory(LLVMIR/XeVM)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
gc_add_mlir_translation_library(MLIRXeVMToLLVMIRTranslation
2+
XeVMToLLVMIRTranslation.cpp
3+
4+
DEPENDS
5+
MLIRXeVMConversionsIncGen
6+
7+
LINK_COMPONENTS
8+
Core
9+
10+
LINK_LIBS PUBLIC
11+
MLIRIR
12+
MLIRLLVMDialect
13+
MLIRXeVMDialect
14+
MLIRSupport
15+
MLIRTargetLLVMIRExport
16+
GcInterface
17+
)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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 &registry) {
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

Comments
 (0)