Skip to content

Commit 28431af

Browse files
committed
[GPU] Add xevm-to-llvm pass structure
1 parent df152b7 commit 28431af

File tree

10 files changed

+171
-0
lines changed

10 files changed

+171
-0
lines changed

cmake/functions.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ function(gc_add_mlir_dialect_library name)
119119
endif()
120120
endfunction()
121121

122+
function(gc_add_mlir_conversion_library name)
123+
add_mlir_conversion_library(${ARGV})
124+
target_link_libraries(obj.${name} PUBLIC GcInterface)
125+
set_property(GLOBAL APPEND PROPERTY GC_PASS_LIBS ${name})
126+
127+
if(GcInterface IN_LIST ARGN)
128+
target_link_libraries(obj.${name} PUBLIC GcInterface)
129+
endif()
130+
endfunction()
131+
122132
macro(gc_add_mlir_tool name)
123133
# the dependency list copied from mlir/tools/mlir-cpu-runner/CMakeLists.txt of upstream
124134
if(NOT DEFINED LLVM_LINK_COMPONENTS)

include/gc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
add_subdirectory(Dialect)
22
add_subdirectory(Transforms)
3+
add_subdirectory(Conversion)

include/gc/Conversion/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set(LLVM_TARGET_DEFINITIONS Passes.td)
2+
mlir_tablegen(Passes.h.inc -gen-pass-decls -name GCConversion)
3+
mlir_tablegen(Passes.capi.h.inc -gen-pass-capi-header --prefix GCConversion)
4+
mlir_tablegen(Passes.capi.cpp.inc -gen-pass-capi-impl --prefix GCConversion)
5+
add_public_tablegen_target(GCConversionPassIncGen)
6+
7+
add_mlir_doc(Passes GCConversionPasses ./ -gen-pass-doc)

include/gc/Conversion/Passes.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===- Passes.h - Conversion Pass Construction and Registration -----------===//
2+
//
3+
// Part of the LLVM Project, 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+
#ifndef GC_CONVERSION_PASSES_H
10+
#define GC_CONVERSION_PASSES_H
11+
12+
#include "gc/Conversion/XeVMToLLVM.h"
13+
14+
namespace mlir {
15+
16+
/// Generate the code for registering conversion passes.
17+
#define GEN_PASS_REGISTRATION
18+
#include "gc/Conversion/Passes.h.inc"
19+
20+
} // namespace mlir
21+
22+
#endif // GC_CONVERSION_PASSES_H

include/gc/Conversion/Passes.td

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===-- Passes.td - Conversion pass definition file --------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, 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+
#ifndef GC_CONVERSION_PASSES
10+
#define GC_CONVERSION_PASSES
11+
12+
include "mlir/Pass/PassBase.td"
13+
14+
//===----------------------------------------------------------------------===//
15+
// XeVMToLLVM
16+
//===----------------------------------------------------------------------===//
17+
18+
def ConvertXeVMToLLVMPass : Pass<"convert-xevm-to-llvm"> {
19+
let summary = "Convert XeVM to LLVM dialect";
20+
let dependentDialects = [
21+
"xevm::XeVMDialect",
22+
];
23+
}
24+
25+
#endif // GC_CONVERSION_PASSES
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===- XeVMTOLLVMPass.h - Convert XeVM to LLVM dialect ----------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, 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+
#ifndef MLIR_CONVERSION_XEVMTOLLVM_XEVMTOLLVMPASS_H_
9+
#define MLIR_CONVERSION_XEVMTOLLVM_XEVMTOLLVMPASS_H_
10+
11+
#include <memory>
12+
13+
namespace mlir {
14+
class DialectRegistry;
15+
class LLVMTypeConverter;
16+
class RewritePatternSet;
17+
class Pass;
18+
19+
#define GEN_PASS_DECL_CONVERTXEVMTOLLVMPASS
20+
#include "mlir/Conversion/Passes.h.inc"
21+
22+
void populateXeVMToLLVMConversionPatterns(RewritePatternSet &patterns);
23+
24+
void registerConvertXeVMToLLVMInterface(DialectRegistry &registry);
25+
26+
} // namespace mlir
27+
28+
#endif // MLIR_CONVERSION_XEVMTOLLVM_XEVMTOLLVMPASS_H_

lib/gc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
add_subdirectory(Analysis)
22
add_subdirectory(CAPI)
3+
add_subdirectory(Conversion)
34
add_subdirectory(Dialect)
45
add_subdirectory(Transforms)
56
add_subdirectory(ExecutionEngine)

lib/gc/Conversion/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(XeVMToLLVM)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
gc_add_mlir_conversion_library(MLIRXeVMToLLVM
2+
XeVMToLLVM.cpp
3+
4+
ADDITIONAL_HEADER_DIRS
5+
${PROJECT_SOURCE_DIR}/include/gc/Conversion/XeVMToLLVM
6+
7+
DEPENDS
8+
GCConversionPassIncGen
9+
10+
LINK_COMPONENTS
11+
Core
12+
13+
LINK_LIBS PUBLIC
14+
MLIRFuncDialect
15+
MLIRGPUDialect
16+
MLIRLLVMCommonConversion
17+
MLIRLLVMDialect
18+
MLIRXeVMDialect
19+
MLIRPass
20+
MLIRTransforms
21+
)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//===- XeVMToLLVM.cpp - XeVM to LLVM dialect conversion -------------------===//
2+
//
3+
// Part of the LLVM Project, 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+
#include "gc/Conversion/XeVMToLLVM/XeVMToLLVM.h"
10+
11+
#include "gc/Dialect/LLVMIR/XeVMDialect.h"
12+
#include "mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h"
13+
#include "mlir/Conversion/LLVMCommon/Pattern.h"
14+
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
15+
#include "mlir/Pass/Pass.h"
16+
#include "mlir/Support/LLVM.h"
17+
18+
#define DEBUG_TYPE "xevm-to-llvm"
19+
20+
namespace mlir {
21+
#define GEN_PASS_DEF_CONVERTXEVMTOLLVMPASS
22+
#include "gc/Conversion/Passes.h.inc"
23+
} // namespace mlir
24+
25+
using namespace mlir;
26+
using namespace xevm;
27+
28+
namespace {
29+
struct ConvertXeVMToLLVMPass
30+
: public impl::ConvertXeVMToLLVMPassBase<ConvertXeVMToLLVMPass> {
31+
using Base::Base;
32+
33+
void getDependentDialects(DialectRegistry &registry) const override {
34+
registry.insert<LLVM::LLVMDialect, xevm::XeVMDialect>();
35+
}
36+
37+
void runOnOperation() override {
38+
ConversionTarget target(getContext());
39+
target.addLegalDialect<::mlir::LLVM::LLVMDialect>();
40+
RewritePatternSet pattern(&getContext());
41+
mlir::populateXeVMToLLVMConversionPatterns(pattern);
42+
if (failed(
43+
applyPartialConversion(getOperation(), target, std::move(pattern))))
44+
signalPassFailure();
45+
}
46+
};
47+
} // namespace
48+
49+
void mlir::populateXeVMToLLVMConversionPatterns(RewritePatternSet &patterns) {
50+
/*TODO*/
51+
}
52+
53+
void mlir::registerConvertXeVMToLLVMInterface(DialectRegistry &registry) {
54+
/*TODO*/
55+
}

0 commit comments

Comments
 (0)