From b6055032360928963a840f04bf92f197e08c3741 Mon Sep 17 00:00:00 2001 From: Hanchen Ye Date: Wed, 23 Sep 2020 14:10:34 -0500 Subject: [PATCH] remove global dialect registration; update file structure --- config/target-spec.ini | 2 + config/tool-config.ini | 2 - include/CMakeLists.txt | 1 + include/Dialect/HLSCpp/CMakeLists.txt | 4 -- include/Dialect/HLSCpp/Passes.td | 43 ------------------- include/Transforms/CMakeLists.txt | 3 ++ include/{ => Transforms}/INIReader.h | 0 .../{Dialect/HLSCpp => Transforms}/Passes.h | 12 +++--- include/Transforms/Passes.td | 43 +++++++++++++++++++ lib/CMakeLists.txt | 1 + lib/Dialect/HLSCpp/CMakeLists.txt | 1 - lib/Dialect/HLSCpp/PragmaOps.cpp | 9 ++++ lib/EmitHLSCpp/CMakeLists.txt | 2 +- lib/Transforms/CMakeLists.txt | 11 +++++ lib/{Dialect/HLSCpp => Transforms}/Passes.cpp | 7 ++- .../HLSCpp => Transforms}/PragmaDSE.cpp | 6 +-- .../HLSCpp => Transforms}/QoREstimation.cpp | 7 ++- test/Dialect/HLSCpp/test_pragma.mlir | 2 +- tools/scalehls-opt/CMakeLists.txt | 1 + tools/scalehls-opt/scalehls-opt.cpp | 8 ++-- tools/scalehls-translate/CMakeLists.txt | 2 +- .../scalehls-translate/scalehls-translate.cpp | 10 ++--- 22 files changed, 96 insertions(+), 81 deletions(-) delete mode 100644 config/tool-config.ini delete mode 100644 include/Dialect/HLSCpp/Passes.td create mode 100644 include/Transforms/CMakeLists.txt rename include/{ => Transforms}/INIReader.h (100%) rename include/{Dialect/HLSCpp => Transforms}/Passes.h (66%) create mode 100644 include/Transforms/Passes.td create mode 100644 lib/Dialect/HLSCpp/PragmaOps.cpp create mode 100644 lib/Transforms/CMakeLists.txt rename lib/{Dialect/HLSCpp => Transforms}/Passes.cpp (62%) rename lib/{Dialect/HLSCpp => Transforms}/PragmaDSE.cpp (76%) rename lib/{Dialect/HLSCpp => Transforms}/QoREstimation.cpp (96%) diff --git a/config/target-spec.ini b/config/target-spec.ini index e69de29..41a9cad 100644 --- a/config/target-spec.ini +++ b/config/target-spec.ini @@ -0,0 +1,2 @@ +[config] +frequency=200MHz diff --git a/config/tool-config.ini b/config/tool-config.ini deleted file mode 100644 index 41a9cad..0000000 --- a/config/tool-config.ini +++ /dev/null @@ -1,2 +0,0 @@ -[config] -frequency=200MHz diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 629c08a..495310c 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(Conversion) add_subdirectory(Dialect) +add_subdirectory(Transforms) diff --git a/include/Dialect/HLSCpp/CMakeLists.txt b/include/Dialect/HLSCpp/CMakeLists.txt index 374e2ad..1389a5b 100644 --- a/include/Dialect/HLSCpp/CMakeLists.txt +++ b/include/Dialect/HLSCpp/CMakeLists.txt @@ -4,7 +4,3 @@ set(LLVM_TARGET_DEFINITIONS Interfaces.td) mlir_tablegen(HLSCppInterfaces.h.inc -gen-op-interface-decls) mlir_tablegen(HLSCppInterfaces.cpp.inc -gen-op-interface-defs) add_public_tablegen_target(MLIRHLSCppInterfacesIncGen) - -set(LLVM_TARGET_DEFINITIONS Passes.td) -mlir_tablegen(HLSCppPasses.h.inc -gen-pass-decls) -add_public_tablegen_target(MLIRHLSCppPassesIncGen) diff --git a/include/Dialect/HLSCpp/Passes.td b/include/Dialect/HLSCpp/Passes.td deleted file mode 100644 index bbc4f98..0000000 --- a/include/Dialect/HLSCpp/Passes.td +++ /dev/null @@ -1,43 +0,0 @@ -//===-------------------------------------------------------*- tablegen -*-===// -// -//===----------------------------------------------------------------------===// - -#ifndef SCALEHLS_DIALECT_HLSCPP_PASSES_TD -#define SCALEHLS_DIALECT_HLSCPP_PASSES_TD - -include "mlir/Pass/PassBase.td" - -def QoREstimation : Pass<"hlscpp-qor-estimation", "ModuleOp"> { - let summary = "Estimate the performance and resource utilization"; - let description = [{ - This hlscpp-qor-estimation pass will analyze the input CDFG and pragma - operations (if applied) for estimating performance and resource utilization - of the HLS results. - }]; - - let constructor = "mlir::scalehls::hlscpp::createQoREstimationPass()"; - - let options = [ - Option<"toolConfig", "tool-config", "std::string", - /*default=*/"\"../config/tool-config.ini\"", - "Config file path: global configurations for the ScaleHLS tools">, - Option<"opLatency", "op-latency", "std::string", - /*default=*/"\"../config/op-latency.ini\"", - "Config file path: profiling data for operation latency"> - ]; -} - -def PragmaDSE : Pass<"hlscpp-pragma-dse", "ModuleOp"> { - let summary = "Optimize pragma configuration of each optimizable region"; - let description = [{ - This hlscpp-pragma-dse pass will automatically tune HLS pragma insertion and - configuration for performance and area optimization. By calling methods - provided by hlscpp-qor-estimation, this pass is able to rapidly obtain the - QoR estimation of the current design point, and feed it back to the design - space exploration engine for an efficient convergence. - }]; - - let constructor = "mlir::scalehls::hlscpp::createPragmaDSEPass()"; -} - -#endif // SCALEHLS_DIALECT_HLSCPP_PASSES_TD diff --git a/include/Transforms/CMakeLists.txt b/include/Transforms/CMakeLists.txt new file mode 100644 index 0000000..5764735 --- /dev/null +++ b/include/Transforms/CMakeLists.txt @@ -0,0 +1,3 @@ +set(LLVM_TARGET_DEFINITIONS Passes.td) +mlir_tablegen(Passes.h.inc -gen-pass-decls) +add_public_tablegen_target(MLIRScaleHLSTransformsIncGen) diff --git a/include/INIReader.h b/include/Transforms/INIReader.h similarity index 100% rename from include/INIReader.h rename to include/Transforms/INIReader.h diff --git a/include/Dialect/HLSCpp/Passes.h b/include/Transforms/Passes.h similarity index 66% rename from include/Dialect/HLSCpp/Passes.h rename to include/Transforms/Passes.h index b9b624e..139be4a 100644 --- a/include/Dialect/HLSCpp/Passes.h +++ b/include/Transforms/Passes.h @@ -2,8 +2,8 @@ // //===----------------------------------------------------------------------===// -#ifndef SCALEHLS_DIALECT_HLSCPP_PASSES_H -#define SCALEHLS_DIALECT_HLSCPP_PASSES_H +#ifndef SCALEHLS_TRANSFORMS_PASSES_H +#define SCALEHLS_TRANSFORMS_PASSES_H #include "mlir/Pass/Pass.h" #include @@ -14,18 +14,16 @@ class Pass; namespace mlir { namespace scalehls { -namespace hlscpp { std::unique_ptr createQoREstimationPass(); std::unique_ptr createPragmaDSEPass(); -void registerHLSCppPasses(); +void registerTransformsPasses(); #define GEN_PASS_CLASSES -#include "Dialect/HLSCpp/HLSCppPasses.h.inc" +#include "Transforms/Passes.h.inc" -} // namespace hlscpp } // namespace scalehls } // namespace mlir -#endif // SCALEHLS_DIALECT_HLSCPP_PASSES_H +#endif // SCALEHLS_TRANSFORMS_PASSES_H diff --git a/include/Transforms/Passes.td b/include/Transforms/Passes.td new file mode 100644 index 0000000..49954b0 --- /dev/null +++ b/include/Transforms/Passes.td @@ -0,0 +1,43 @@ +//===-------------------------------------------------------*- tablegen -*-===// +// +//===----------------------------------------------------------------------===// + +#ifndef SCALEHLS_TRANSFORMS_PASSES_TD +#define SCALEHLS_TRANSFORMS_PASSES_TD + +include "mlir/Pass/PassBase.td" + +def QoREstimation : Pass<"qor-estimation", "ModuleOp"> { + let summary = "Estimate the performance and resource utilization"; + let description = [{ + This qor-estimation pass will analyze the input CDFG and pragma operations + (if applied) for estimating performance and resource utilization of the HLS + results. + }]; + + let constructor = "mlir::scalehls::createQoREstimationPass()"; + + let options = [ + Option<"targetSpec", "target-spec", "std::string", + /*default=*/"\"../config/target-spec.ini\"", + "File path: target backend specifications and configurations">, + Option<"opLatency", "op-latency", "std::string", + /*default=*/"\"../config/op-latency.ini\"", + "File path: profiling data for operation latency"> + ]; +} + +def PragmaDSE : Pass<"pragma-dse", "ModuleOp"> { + let summary = "Optimize pragma configuration of each optimizable region"; + let description = [{ + This pragma-dse pass will automatically tune HLS pragma insertion and + configuration for performance and area optimization. By calling methods + provided by hlscpp-qor-estimation, this pass is able to rapidly obtain the + QoR estimation of the current design point, and feed it back to the design + space exploration engine for an efficient convergence. + }]; + + let constructor = "mlir::scalehls::createPragmaDSEPass()"; +} + +#endif // SCALEHLS_TRANSFORMS_PASSES_TD diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 2258586..331acb6 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,3 +1,4 @@ add_subdirectory(Conversion) add_subdirectory(Dialect) add_subdirectory(EmitHLSCpp) +add_subdirectory(Transforms) diff --git a/lib/Dialect/HLSCpp/CMakeLists.txt b/lib/Dialect/HLSCpp/CMakeLists.txt index d3647b3..b020714 100644 --- a/lib/Dialect/HLSCpp/CMakeLists.txt +++ b/lib/Dialect/HLSCpp/CMakeLists.txt @@ -6,5 +6,4 @@ add_mlir_dialect_library(MLIRHLSCpp DEPENDS MLIRHLSCppIncGen MLIRHLSCppInterfacesIncGen - MLIRHLSCppPassesIncGen ) diff --git a/lib/Dialect/HLSCpp/PragmaOps.cpp b/lib/Dialect/HLSCpp/PragmaOps.cpp new file mode 100644 index 0000000..a9fa9fe --- /dev/null +++ b/lib/Dialect/HLSCpp/PragmaOps.cpp @@ -0,0 +1,9 @@ +//===------------------------------------------------------------*- C++ -*-===// +// +//===----------------------------------------------------------------------===// + +#include "Dialect/HLSCpp/HLSCpp.h" + +using namespace mlir; +using namespace scalehls; +using namespace hlscpp; diff --git a/lib/EmitHLSCpp/CMakeLists.txt b/lib/EmitHLSCpp/CMakeLists.txt index d022a4c..96252da 100644 --- a/lib/EmitHLSCpp/CMakeLists.txt +++ b/lib/EmitHLSCpp/CMakeLists.txt @@ -1,6 +1,6 @@ file(GLOB globbed *.cpp) -add_mlir_library(MLIREmitHLSCpp +add_mlir_library(MLIRScaleHLSEmitHLSCpp ${globbed} LINK_LIBS PUBLIC diff --git a/lib/Transforms/CMakeLists.txt b/lib/Transforms/CMakeLists.txt new file mode 100644 index 0000000..83777ca --- /dev/null +++ b/lib/Transforms/CMakeLists.txt @@ -0,0 +1,11 @@ +file(GLOB globbed *.cpp) + +add_mlir_library(MLIRScaleHLSTransforms + ${globbed} + + DEPENDS + MLIRScaleHLSTransformsIncGen + + LINK_LIBS PUBLIC + MLIRHLSCpp + ) diff --git a/lib/Dialect/HLSCpp/Passes.cpp b/lib/Transforms/Passes.cpp similarity index 62% rename from lib/Dialect/HLSCpp/Passes.cpp rename to lib/Transforms/Passes.cpp index 732924f..9469e02 100644 --- a/lib/Dialect/HLSCpp/Passes.cpp +++ b/lib/Transforms/Passes.cpp @@ -2,15 +2,14 @@ // //===----------------------------------------------------------------------===// -#include "Dialect/HLSCpp/Passes.h" +#include "Transforms/Passes.h" using namespace mlir; using namespace scalehls; -using namespace hlscpp; namespace { #define GEN_PASS_REGISTRATION -#include "Dialect/HLSCpp/HLSCppPasses.h.inc" +#include "Transforms/Passes.h.inc" } // namespace -void hlscpp::registerHLSCppPasses() { registerPasses(); } +void scalehls::registerTransformsPasses() { registerPasses(); } diff --git a/lib/Dialect/HLSCpp/PragmaDSE.cpp b/lib/Transforms/PragmaDSE.cpp similarity index 76% rename from lib/Dialect/HLSCpp/PragmaDSE.cpp rename to lib/Transforms/PragmaDSE.cpp index 0a45364..0d4e706 100644 --- a/lib/Dialect/HLSCpp/PragmaDSE.cpp +++ b/lib/Transforms/PragmaDSE.cpp @@ -3,11 +3,11 @@ //===----------------------------------------------------------------------===// #include "Dialect/HLSCpp/HLSCpp.h" -#include "Dialect/HLSCpp/Passes.h" +#include "Transforms/INIReader.h" +#include "Transforms/Passes.h" using namespace mlir; using namespace scalehls; -using namespace hlscpp; namespace { struct PragmaDSE : public PragmaDSEBase { @@ -15,6 +15,6 @@ struct PragmaDSE : public PragmaDSEBase { }; } // namespace -std::unique_ptr hlscpp::createPragmaDSEPass() { +std::unique_ptr scalehls::createPragmaDSEPass() { return std::make_unique(); } diff --git a/lib/Dialect/HLSCpp/QoREstimation.cpp b/lib/Transforms/QoREstimation.cpp similarity index 96% rename from lib/Dialect/HLSCpp/QoREstimation.cpp rename to lib/Transforms/QoREstimation.cpp index 4e8e26d..9128e8b 100644 --- a/lib/Dialect/HLSCpp/QoREstimation.cpp +++ b/lib/Transforms/QoREstimation.cpp @@ -3,12 +3,11 @@ //===----------------------------------------------------------------------===// #include "Dialect/HLSCpp/HLSCpp.h" -#include "Dialect/HLSCpp/Passes.h" -#include "INIReader.h" +#include "Transforms/INIReader.h" +#include "Transforms/Passes.h" using namespace mlir; using namespace scalehls; -using namespace hlscpp; /* namespace { @@ -115,6 +114,6 @@ struct QoREstimation : public QoREstimationBase { }; } // namespace -std::unique_ptr hlscpp::createQoREstimationPass() { +std::unique_ptr scalehls::createQoREstimationPass() { return std::make_unique(); } diff --git a/test/Dialect/HLSCpp/test_pragma.mlir b/test/Dialect/HLSCpp/test_pragma.mlir index 68e4e52..1b1af62 100644 --- a/test/Dialect/HLSCpp/test_pragma.mlir +++ b/test/Dialect/HLSCpp/test_pragma.mlir @@ -1,4 +1,4 @@ -// RUN: scalehls-opt -hlscpp-pragma-dse %s | FileCheck %s +// RUN: scalehls-opt -pragma-dse %s | FileCheck %s // CHECK-LABEL: func @test_pragma() func @test_pragma() { diff --git a/tools/scalehls-opt/CMakeLists.txt b/tools/scalehls-opt/CMakeLists.txt index 8ed574c..5274b53 100644 --- a/tools/scalehls-opt/CMakeLists.txt +++ b/tools/scalehls-opt/CMakeLists.txt @@ -8,6 +8,7 @@ set(LIBS MLIRHLSCpp MLIRConvertToHLSCpp + MLIRScaleHLSTransforms ) add_llvm_executable(scalehls-opt scalehls-opt.cpp) diff --git a/tools/scalehls-opt/scalehls-opt.cpp b/tools/scalehls-opt/scalehls-opt.cpp index a01c5cf..da778fd 100644 --- a/tools/scalehls-opt/scalehls-opt.cpp +++ b/tools/scalehls-opt/scalehls-opt.cpp @@ -4,7 +4,7 @@ #include "Conversion/ConvertToHLSCpp.h" #include "Dialect/HLSCpp/HLSCpp.h" -#include "Dialect/HLSCpp/Passes.h" +#include "Transforms/Passes.h" #include "mlir/IR/Dialect.h" #include "mlir/IR/MLIRContext.h" #include "mlir/InitAllDialects.h" @@ -62,7 +62,7 @@ int main(int argc, char **argv) { registry.insert(); registry.insert(); - mlir::scalehls::hlscpp::registerHLSCppPasses(); + mlir::scalehls::registerTransformsPasses(); mlir::scalehls::hlscpp::registerConvertToHLSCppPass(); @@ -79,8 +79,8 @@ int main(int argc, char **argv) { mlir::MLIRContext context; if (showDialects) { llvm::outs() << "Registered Dialects:\n"; - for (mlir::Dialect *dialect : context.getLoadedDialects()) { - llvm::outs() << dialect->getNamespace() << "\n"; + for (const auto &nameAndRegistrationIt : registry) { + llvm::outs() << nameAndRegistrationIt.first << "\n"; } return 0; } diff --git a/tools/scalehls-translate/CMakeLists.txt b/tools/scalehls-translate/CMakeLists.txt index 10cd233..59f5707 100644 --- a/tools/scalehls-translate/CMakeLists.txt +++ b/tools/scalehls-translate/CMakeLists.txt @@ -14,7 +14,7 @@ set(LIBS MLIRTranslation MLIRSupport - MLIREmitHLSCpp + MLIRScaleHLSEmitHLSCpp ) add_llvm_executable(scalehls-translate scalehls-translate.cpp) diff --git a/tools/scalehls-translate/scalehls-translate.cpp b/tools/scalehls-translate/scalehls-translate.cpp index 04f6c44..3e709f1 100644 --- a/tools/scalehls-translate/scalehls-translate.cpp +++ b/tools/scalehls-translate/scalehls-translate.cpp @@ -39,15 +39,9 @@ static llvm::cl::opt verifyDiagnostics( llvm::cl::init(false)); int main(int argc, char **argv) { - mlir::enableGlobalDialectRegistry(true); - mlir::registerAllDialects(); mlir::registerAllTranslations(); - mlir::registerDialect(); - mlir::registerDialect(); - mlir::registerDialect(); - mlir::scalehls::registerHLSCppEmitterTranslation(); llvm::InitLLVM y(argc, argv); @@ -77,6 +71,10 @@ int main(int argc, char **argv) { auto processBuffer = [&](std::unique_ptr ownedBuffer, llvm::raw_ostream &os) { mlir::MLIRContext context; + + context.loadDialect(); + context.allowUnregisteredDialects(); context.printOpOnDiagnostic(!verifyDiagnostics); llvm::SourceMgr sourceMgr;