[Conversion] update all conversion passes definition to TableGen

This commit is contained in:
Hanchen Ye 2020-12-04 18:34:24 -06:00
parent b499026303
commit 1fa7700ae8
13 changed files with 102 additions and 70 deletions

View File

@ -0,0 +1,3 @@
set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls)
add_public_tablegen_target(MLIRScaleHLSConversionIncGen)

View File

@ -1,18 +0,0 @@
//===------------------------------------------------------------*- C++ -*-===//
//
//===----------------------------------------------------------------------===//
#ifndef SCALEHLS_CONVERSION_CONVERTTOHLSCPP_H_
#define SCALEHLS_CONVERSION_CONVERTTOHLSCPP_H_
namespace mlir {
namespace scalehls {
namespace hlscpp {
void registerConvertToHLSCppPass();
} // namespace hlscpp
} // namespace scalehls
} // namespace mlir
#endif // SCALEHLS_CONVERSION_CONVERTTOHLSCPP_H_

View File

@ -1,18 +0,0 @@
//===------------------------------------------------------------*- C++ -*-===//
//
//===----------------------------------------------------------------------===//
#ifndef SCALEHLS_CONVERSION_HLSKERNELTOAFFINE_H_
#define SCALEHLS_CONVERSION_HLSKERNELTOAFFINE_H_
namespace mlir {
namespace scalehls {
namespace hlskernel {
void registerHLSKernelToAffinePass();
} // namespace hlskernel
} // namespace scalehls
} // namespace mlir
#endif // SCALEHLS_CONVERSION_HLSKERNELTOAFFINE_H_

View File

@ -0,0 +1,29 @@
//===------------------------------------------------------------*- C++ -*-===//
//
//===----------------------------------------------------------------------===//
#ifndef SCALEHLS_CONVERSION_PASSES_H
#define SCALEHLS_CONVERSION_PASSES_H
#include "mlir/Pass/Pass.h"
#include <memory>
namespace mlir {
class Pass;
} // namespace mlir
namespace mlir {
namespace scalehls {
std::unique_ptr<mlir::Pass> createConvertToHLSCppPass();
std::unique_ptr<mlir::Pass> createHLSKernelToAffinePass();
void registerConversionPasses();
#define GEN_PASS_CLASSES
#include "Conversion/Passes.h.inc"
} // namespace scalehls
} // namespace mlir
#endif // SCALEHLS_CONVERSION_PASSES_H

View File

@ -0,0 +1,30 @@
//===-------------------------------------------------------*- tablegen -*-===//
//
//===----------------------------------------------------------------------===//
#ifndef SCALEHLS_CONVERSION_PASSES_TD
#define SCALEHLS_CONVERSION_PASSES_TD
include "mlir/Pass/PassBase.td"
def ConvertToHLSCpp : Pass<"convert-to-hlscpp", "ModuleOp"> {
let summary = "Convert to emittable MLIR code";
let description = [{
This convert-to-hlscpp converts MLIR code in Affine/Standard/SCF level to
emittable MLIR code.
}];
let constructor = "mlir::scalehls::createConvertToHLSCppPass()";
}
def HLSKernelToAffine : Pass<"hlskernel-to-affine", "ModuleOp"> {
let summary = "Convert HLSKernel operation to Affine loops";
let description = [{
This hlskernel-to-affine converts HLSKernel operations to their Affine level
representations.
}];
let constructor = "mlir::scalehls::createHLSKernelToAffinePass()";
}
#endif // SCALEHLS_CONVERSION_PASSES_TD

View File

@ -1,2 +1,12 @@
add_subdirectory(ConvertToHLSCpp)
add_subdirectory(HLSKernelToAffine)
file(GLOB globbed *.cpp)
add_mlir_library(MLIRScaleHLSConversion
${globbed}
DEPENDS
MLIRScaleHLSConversionIncGen
LINK_LIBS PUBLIC
MLIRHLSCpp
MLIRHLSKernel
)

View File

@ -2,7 +2,7 @@
//
//===----------------------------------------------------------------------===//
#include "Conversion/ConvertToHLSCpp.h"
#include "Conversion/Passes.h"
#include "Dialect/HLSCpp/HLSCpp.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/Pass/Pass.h"
@ -12,8 +12,7 @@ using namespace scalehls;
using namespace hlscpp;
namespace {
class ConvertToHLSCppPass
: public mlir::PassWrapper<ConvertToHLSCppPass, OperationPass<ModuleOp>> {
struct ConvertToHLSCpp : public ConvertToHLSCppBase<ConvertToHLSCpp> {
public:
void runOnOperation() override;
};
@ -72,7 +71,7 @@ static void convertBlock(Block &block) {
}
}
void ConvertToHLSCppPass::runOnOperation() {
void ConvertToHLSCpp::runOnOperation() {
for (auto func : getOperation().getOps<FuncOp>()) {
auto b = OpBuilder(func);
@ -106,7 +105,6 @@ void ConvertToHLSCppPass::runOnOperation() {
}
}
void hlscpp::registerConvertToHLSCppPass() {
PassRegistration<ConvertToHLSCppPass>(
"convert-to-hlscpp", "Convert to HLS C++ emittable representation.");
std::unique_ptr<mlir::Pass> scalehls::createConvertToHLSCppPass() {
return std::make_unique<ConvertToHLSCpp>();
}

View File

@ -1,5 +0,0 @@
file(GLOB globbed *.cpp)
add_mlir_library(MLIRConvertToHLSCpp
${globbed}
)

View File

@ -2,7 +2,7 @@
//
//===----------------------------------------------------------------------===//
#include "Conversion/HLSKernelToAffine.h"
#include "Conversion/Passes.h"
#include "Dialect/HLSKernel/HLSKernel.h"
#include "Dialect/HLSKernel/Visitor.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
@ -575,14 +575,13 @@ bool HLSKernelVisitor::visitOp(TrmmOp op) {
//===----------------------------------------------------------------------===//
namespace {
class HLSKernelToAffinePass
: public mlir::PassWrapper<HLSKernelToAffinePass, OperationPass<ModuleOp>> {
struct HLSKernelToAffine : public HLSKernelToAffineBase<HLSKernelToAffine> {
public:
void runOnOperation() override;
};
} // namespace
void HLSKernelToAffinePass::runOnOperation() {
void HLSKernelToAffine::runOnOperation() {
auto module = getOperation();
OpBuilder builder(module);
HLSKernelVisitor visitor(builder, module.getLoc());
@ -600,8 +599,6 @@ void HLSKernelToAffinePass::runOnOperation() {
}
}
void hlskernel::registerHLSKernelToAffinePass() {
PassRegistration<HLSKernelToAffinePass>(
"hlskernel-to-affine",
"Lower hlskernel operations to corresponding affine representation.");
std::unique_ptr<mlir::Pass> scalehls::createHLSKernelToAffinePass() {
return std::make_unique<HLSKernelToAffine>();
}

View File

@ -1,5 +0,0 @@
file(GLOB globbed *.cpp)
add_mlir_library(MLIRHLSKernelToAffine
${globbed}
)

15
lib/Conversion/Passes.cpp Normal file
View File

@ -0,0 +1,15 @@
//===------------------------------------------------------------*- C++ -*-===//
//
//===----------------------------------------------------------------------===//
#include "Conversion/Passes.h"
using namespace mlir;
using namespace scalehls;
namespace {
#define GEN_PASS_REGISTRATION
#include "Conversion/Passes.h.inc"
} // namespace
void scalehls::registerConversionPasses() { registerPasses(); }

View File

@ -8,8 +8,7 @@ set(LIBS
MLIRHLSKernel
MLIRHLSCpp
MLIRHLSKernelToAffine
MLIRConvertToHLSCpp
MLIRScaleHLSConversion
MLIRScaleHLSTransforms
MLIRScaleHLSAnalysis
)

View File

@ -3,8 +3,7 @@
//===----------------------------------------------------------------------===//
#include "Analysis/Passes.h"
#include "Conversion/ConvertToHLSCpp.h"
#include "Conversion/HLSKernelToAffine.h"
#include "Conversion/Passes.h"
#include "Dialect/HLSCpp/HLSCpp.h"
#include "Dialect/HLSKernel/HLSKernel.h"
#include "Transforms/Passes.h"
@ -68,9 +67,7 @@ int main(int argc, char **argv) {
mlir::scalehls::registerTransformsPasses();
mlir::scalehls::registerAnalysisPasses();
mlir::scalehls::hlscpp::registerConvertToHLSCppPass();
mlir::scalehls::hlskernel::registerHLSKernelToAffinePass();
mlir::scalehls::registerConversionPasses();
llvm::InitLLVM y(argc, argv);