Skip to content

[GPU] XeVM to LLVM pass structure #395

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
Oct 29, 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 @@ -119,6 +119,16 @@ function(gc_add_mlir_dialect_library name)
endif()
endfunction()

function(gc_add_mlir_conversion_library name)
add_mlir_conversion_library(${ARGV})
target_link_libraries(obj.${name} PUBLIC GcInterface)
set_property(GLOBAL APPEND PROPERTY GC_PASS_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
1 change: 1 addition & 0 deletions include/gc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(Dialect)
add_subdirectory(Transforms)
add_subdirectory(Conversion)
7 changes: 7 additions & 0 deletions include/gc/Conversion/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name GCConversion)
mlir_tablegen(Passes.capi.h.inc -gen-pass-capi-header --prefix GCConversion)
mlir_tablegen(Passes.capi.cpp.inc -gen-pass-capi-impl --prefix GCConversion)
add_public_tablegen_target(GCConversionPassIncGen)

add_mlir_doc(Passes GCConversionPasses ./ -gen-pass-doc)
22 changes: 22 additions & 0 deletions include/gc/Conversion/Passes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Passes.h - Conversion Passes ---------------------------*- 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
//
//===----------------------------------------------------------------------===//

#ifndef GC_CONVERSION_PASSES_H
#define GC_CONVERSION_PASSES_H

#include "gc/Conversion/XeVMToLLVM.h"

namespace mlir {

/// Generate the code for registering conversion passes.
#define GEN_PASS_REGISTRATION
#include "gc/Conversion/Passes.h.inc"

} // namespace mlir

#endif // GC_CONVERSION_PASSES_H
25 changes: 25 additions & 0 deletions include/gc/Conversion/Passes.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===-- Passes.td - Conversion pass definition file --------*- tablegen -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//

#ifndef GC_CONVERSION_PASSES
#define GC_CONVERSION_PASSES

include "mlir/Pass/PassBase.td"

//===----------------------------------------------------------------------===//
// XeVMToLLVM
//===----------------------------------------------------------------------===//

def ConvertXeVMToLLVMPass : Pass<"convert-xevm-to-llvm"> {
let summary = "Convert XeVM to LLVM dialect";
let dependentDialects = [
"xevm::XeVMDialect",
];
}

#endif // GC_CONVERSION_PASSES
28 changes: 28 additions & 0 deletions include/gc/Conversion/XeVMToLLVM/XeVMToLLVM.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//===-- XeVMToLLVM.h - Convert XeVM to LLVM dialect -------------*- 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
//
//===----------------------------------------------------------------------===//
#ifndef MLIR_CONVERSION_XEVMTOLLVM_XEVMTOLLVMPASS_H_
#define MLIR_CONVERSION_XEVMTOLLVM_XEVMTOLLVMPASS_H_

#include <memory>

namespace mlir {
class DialectRegistry;
class LLVMTypeConverter;
class RewritePatternSet;
class Pass;

#define GEN_PASS_DECL_CONVERTXEVMTOLLVMPASS
#include "mlir/Conversion/Passes.h.inc"

void populateXeVMToLLVMConversionPatterns(RewritePatternSet &patterns);

void registerConvertXeVMToLLVMInterface(DialectRegistry &registry);

} // namespace mlir

#endif // MLIR_CONVERSION_XEVMTOLLVM_XEVMTOLLVMPASS_H_
1 change: 1 addition & 0 deletions lib/gc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_subdirectory(Analysis)
add_subdirectory(CAPI)
add_subdirectory(Conversion)
add_subdirectory(Dialect)
add_subdirectory(Transforms)
add_subdirectory(ExecutionEngine)
1 change: 1 addition & 0 deletions lib/gc/Conversion/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(XeVMToLLVM)
21 changes: 21 additions & 0 deletions lib/gc/Conversion/XeVMToLLVM/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
gc_add_mlir_conversion_library(MLIRXeVMToLLVM
XeVMToLLVM.cpp

ADDITIONAL_HEADER_DIRS
${PROJECT_SOURCE_DIR}/include/gc/Conversion/XeVMToLLVM

DEPENDS
GCConversionPassIncGen

LINK_COMPONENTS
Core

LINK_LIBS PUBLIC
MLIRFuncDialect
MLIRGPUDialect
MLIRLLVMCommonConversion
MLIRLLVMDialect
MLIRXeVMDialect
MLIRPass
MLIRTransforms
)
55 changes: 55 additions & 0 deletions lib/gc/Conversion/XeVMToLLVM/XeVMToLLVM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//===-- XeVMToLLVM.cpp - XeVM to LLVM dialect conversion --------*- 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
//
//===----------------------------------------------------------------------===//

#include "gc/Conversion/XeVMToLLVM/XeVMToLLVM.h"

#include "gc/Dialect/LLVMIR/XeVMDialect.h"
#include "mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h"
#include "mlir/Conversion/LLVMCommon/Pattern.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Support/LLVM.h"

#define DEBUG_TYPE "xevm-to-llvm"

namespace mlir {
#define GEN_PASS_DEF_CONVERTXEVMTOLLVMPASS
#include "gc/Conversion/Passes.h.inc"
} // namespace mlir

using namespace mlir;
using namespace xevm;

namespace {
struct ConvertXeVMToLLVMPass
: public impl::ConvertXeVMToLLVMPassBase<ConvertXeVMToLLVMPass> {
using Base::Base;

void getDependentDialects(DialectRegistry &registry) const override {
registry.insert<LLVM::LLVMDialect, xevm::XeVMDialect>();
}

void runOnOperation() override {
ConversionTarget target(getContext());
target.addLegalDialect<::mlir::LLVM::LLVMDialect>();
RewritePatternSet pattern(&getContext());
mlir::populateXeVMToLLVMConversionPatterns(pattern);
if (failed(
applyPartialConversion(getOperation(), target, std::move(pattern))))
signalPassFailure();
}
};
} // namespace

void mlir::populateXeVMToLLVMConversionPatterns(RewritePatternSet &patterns) {
/*TODO*/
}

void mlir::registerConvertXeVMToLLVMInterface(DialectRegistry &registry) {
/*TODO*/
}