From 1a6491b4fd6054aeca3cc63f0b16a5effb888b4b Mon Sep 17 00:00:00 2001 From: Hanchen Ye Date: Sat, 12 Sep 2020 18:30:04 -0500 Subject: [PATCH] [HLSCppDialect] add ApplyPragmasOp and PragmaOpInterface --- include/Dialect/HLSCpp/CMakeLists.txt | 5 +++++ include/Dialect/HLSCpp/Dialect.h | 20 ------------------- include/Dialect/HLSCpp/Dialect.td | 28 --------------------------- include/Dialect/HLSCpp/HLSCpp.td | 24 +++++++++++++++++++---- include/Dialect/HLSCpp/Interfaces.td | 17 ++++++++++++++++ include/Dialect/HLSCpp/Ops.h | 5 ++++- include/Dialect/HLSCpp/Ops.td | 23 ++++++++++++++++++++++ lib/Dialect/HLSCpp/CMakeLists.txt | 7 ++++--- lib/Dialect/HLSCpp/Dialect.cpp | 19 ------------------ lib/Dialect/HLSCpp/Ops.cpp | 11 +++++++++++ tools/scalehls-opt/scalehls-opt.cpp | 2 +- 11 files changed, 85 insertions(+), 76 deletions(-) delete mode 100644 include/Dialect/HLSCpp/Dialect.h delete mode 100644 include/Dialect/HLSCpp/Dialect.td create mode 100644 include/Dialect/HLSCpp/Interfaces.td delete mode 100644 lib/Dialect/HLSCpp/Dialect.cpp diff --git a/include/Dialect/HLSCpp/CMakeLists.txt b/include/Dialect/HLSCpp/CMakeLists.txt index c13bedf..1389a5b 100644 --- a/include/Dialect/HLSCpp/CMakeLists.txt +++ b/include/Dialect/HLSCpp/CMakeLists.txt @@ -1 +1,6 @@ add_mlir_dialect(HLSCpp hlscpp) + +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) diff --git a/include/Dialect/HLSCpp/Dialect.h b/include/Dialect/HLSCpp/Dialect.h deleted file mode 100644 index 153b7ed..0000000 --- a/include/Dialect/HLSCpp/Dialect.h +++ /dev/null @@ -1,20 +0,0 @@ -//===------------------------------------------------------------*- C++ -*-===// -// -//===----------------------------------------------------------------------===// - -#ifndef SCALEHLS_DIALECT_HLSCPP_DIALECT_H -#define SCALEHLS_DIALECT_HLSCPP_DIALECT_H - -#include "mlir/IR/Dialect.h" - -namespace mlir { -namespace scalehls { -namespace hlscpp { - -#include "Dialect/HLSCpp/HLSCppDialect.h.inc" - -} // namespace hlscpp -} // namespace scalehls -} // namespace mlir - -#endif // SCALEHLS_DIALECT_HLSCPP_DIALECT_H diff --git a/include/Dialect/HLSCpp/Dialect.td b/include/Dialect/HLSCpp/Dialect.td deleted file mode 100644 index 733eb9f..0000000 --- a/include/Dialect/HLSCpp/Dialect.td +++ /dev/null @@ -1,28 +0,0 @@ -//===-------------------------------------------------------*- tablegen -*-===// -// -//===----------------------------------------------------------------------===// - -include "mlir/IR/OpBase.td" - -//===----------------------------------------------------------------------===// -// HLSCpp dialect definition. -//===----------------------------------------------------------------------===// - -def HLSCppDialect : Dialect { - let name = "hlscpp"; - let summary = "An HLSCpp out-of-tree MLIR dialect."; - let description = [{ - This dialect is designed for HLS-specific C++ operations, attributes, and - types. Operations in this dialect can be emitted as optimization directives - decorated C++ code, which is fully synthesizable for commercial HLS tools, - such as Vivado HLS. - }]; - let cppNamespace = "hlscpp"; -} - -//===----------------------------------------------------------------------===// -// Base HLSCpp operation definition. -//===----------------------------------------------------------------------===// - -class HLSCppOp traits = []> : - Op; diff --git a/include/Dialect/HLSCpp/HLSCpp.td b/include/Dialect/HLSCpp/HLSCpp.td index 446663d..5edde5a 100644 --- a/include/Dialect/HLSCpp/HLSCpp.td +++ b/include/Dialect/HLSCpp/HLSCpp.td @@ -2,10 +2,26 @@ // //===----------------------------------------------------------------------===// -#ifndef SCALEHLS_DIALECT_HLSCPP_TD -#define SCALEHLS_DIALECT_HLSCPP_TD +#ifndef SCALEHLS_DIALECT_HLSCPP_HLSCPP_TD +#define SCALEHLS_DIALECT_HLSCPP_HLSCPP_TD + +include "mlir/IR/OpBase.td" + +def HLSCppDialect : Dialect { + let name = "hlscpp"; + let summary = "An HLSCpp out-of-tree MLIR dialect."; + let description = [{ + This dialect is designed for HLS-specific C++ operations, attributes, and + types. Operations in this dialect can be emitted as optimization directives + decorated C++ code, which is fully synthesizable for commercial HLS tools, + such as Vivado HLS. + }]; + let cppNamespace = "hlscpp"; +} + +class HLSCppOp traits = []> : + Op; -include "Dialect.td" include "Ops.td" -#endif // SCALEHLS_DIALECT_HLSCPP_TD +#endif // SCALEHLS_DIALECT_HLSCPP_HLSCPP_TD diff --git a/include/Dialect/HLSCpp/Interfaces.td b/include/Dialect/HLSCpp/Interfaces.td new file mode 100644 index 0000000..8c92f23 --- /dev/null +++ b/include/Dialect/HLSCpp/Interfaces.td @@ -0,0 +1,17 @@ +//===-------------------------------------------------------*- tablegen -*-===// +// +//===----------------------------------------------------------------------===// + +#ifndef SCALEHLS_DIALECT_HLSCPP_INTERFACES_TD +#define SCALEHLS_DIALECT_HLSCPP_INTERFACES_TD + +include "mlir/IR/OpBase.td" + +def PragmaOpInterface : OpInterface<"PragmaOpInterface"> { + let description = [{ + This interface indicates the operation represents one pragma directive or a + set of pragmas. + }]; +} + +#endif // SCALEHLS_DIALECT_HLSCPP_INTERFACES_TD diff --git a/include/Dialect/HLSCpp/Ops.h b/include/Dialect/HLSCpp/Ops.h index c5e4abe..c604837 100644 --- a/include/Dialect/HLSCpp/Ops.h +++ b/include/Dialect/HLSCpp/Ops.h @@ -5,13 +5,16 @@ #ifndef SCALEHLS_DIALECT_HLSCPP_OPS_H #define SCALEHLS_DIALECT_HLSCPP_OPS_H -#include "Dialect/HLSCpp/Dialect.h" +#include "mlir/IR/Dialect.h" #include "mlir/Interfaces/SideEffectInterfaces.h" namespace mlir { namespace scalehls { namespace hlscpp { +#include "Dialect/HLSCpp/HLSCppDialect.h.inc" +#include "Dialect/HLSCpp/HLSCppInterfaces.h.inc" + #define GET_OP_CLASSES #include "Dialect/HLSCpp/HLSCpp.h.inc" diff --git a/include/Dialect/HLSCpp/Ops.td b/include/Dialect/HLSCpp/Ops.td index 9995e72..7b11e8c 100644 --- a/include/Dialect/HLSCpp/Ops.td +++ b/include/Dialect/HLSCpp/Ops.td @@ -2,8 +2,29 @@ // //===----------------------------------------------------------------------===// +#ifndef SCALEHLS_DIALECT_HLSCPP_OPS_TD +#define SCALEHLS_DIALECT_HLSCPP_OPS_TD + +include "Interfaces.td" include "mlir/Interfaces/SideEffectInterfaces.td" +def HLSCppApplyPragmasOp : HLSCppOp<"apply_pragmas", + [NoSideEffect, PragmaOpInterface]> { + let summary = "apply_pragmas operation"; + let description = [{ + This hlscpp.apply_pragmas operation owns one region containing one or more + concrete pragmas, and applies all of them to its parent operation (e.g., + functions, loops, or other regions). This operation should always be + inserted to the front of its parent operation. + + This operations takes nothing and returns nothing. + }]; + + let regions = (region SizedRegion<1> : $pragmaRegion); +} + + + def HLSCppFooOp : HLSCppOp<"foo", [NoSideEffect, SameOperandsAndResultType]> { let summary = "Illustrates how to define an operation."; let description = [{ @@ -28,3 +49,5 @@ def HLSCppFooOp : HLSCppOp<"foo", [NoSideEffect, SameOperandsAndResultType]> { $input attr-dict `:` type($input) }]; } + +#endif // SCALEHLS_DIALECT_HLSCPP_OPS_TD diff --git a/lib/Dialect/HLSCpp/CMakeLists.txt b/lib/Dialect/HLSCpp/CMakeLists.txt index 2670c98..ee60540 100644 --- a/lib/Dialect/HLSCpp/CMakeLists.txt +++ b/lib/Dialect/HLSCpp/CMakeLists.txt @@ -8,7 +8,8 @@ add_mlir_dialect_library(MLIRHLSCpp DEPENDS MLIRHLSCppIncGen + MLIRHLSCppInterfacesIncGen - LINK_LIBS PUBLIC - MLIRIR - ) + LINK_LIBS PUBLIC + MLIRIR + ) diff --git a/lib/Dialect/HLSCpp/Dialect.cpp b/lib/Dialect/HLSCpp/Dialect.cpp deleted file mode 100644 index 7ce92ac..0000000 --- a/lib/Dialect/HLSCpp/Dialect.cpp +++ /dev/null @@ -1,19 +0,0 @@ -//===------------------------------------------------------------*- C++ -*-===// -// -//===----------------------------------------------------------------------===// - -#include "Dialect/HLSCpp/Dialect.h" -#include "Dialect/HLSCpp/Ops.h" - -using namespace mlir; -using namespace scalehls; -using namespace hlscpp; - -HLSCppDialect::HLSCppDialect(mlir::MLIRContext *context) - : Dialect(getDialectNamespace(), context) { - - addOperations< -#define GET_OP_LIST -#include "Dialect/HLSCpp/HLSCpp.cpp.inc" - >(); -} diff --git a/lib/Dialect/HLSCpp/Ops.cpp b/lib/Dialect/HLSCpp/Ops.cpp index a4001ad..6dc5a72 100644 --- a/lib/Dialect/HLSCpp/Ops.cpp +++ b/lib/Dialect/HLSCpp/Ops.cpp @@ -9,5 +9,16 @@ using namespace mlir; using namespace scalehls; using namespace hlscpp; +HLSCppDialect::HLSCppDialect(mlir::MLIRContext *context) + : Dialect(getDialectNamespace(), context) { + + addOperations< +#define GET_OP_LIST +#include "Dialect/HLSCpp/HLSCpp.cpp.inc" + >(); +} + +#include "Dialect/HLSCpp/HLSCppInterfaces.cpp.inc" + #define GET_OP_CLASSES #include "Dialect/HLSCpp/HLSCpp.cpp.inc" diff --git a/tools/scalehls-opt/scalehls-opt.cpp b/tools/scalehls-opt/scalehls-opt.cpp index a91110f..f40accf 100644 --- a/tools/scalehls-opt/scalehls-opt.cpp +++ b/tools/scalehls-opt/scalehls-opt.cpp @@ -15,7 +15,7 @@ #include "llvm/Support/SourceMgr.h" #include "llvm/Support/ToolOutputFile.h" -#include "Dialect/HLSCpp/Dialect.h" +#include "Dialect/HLSCpp/Ops.h" static llvm::cl::opt inputFilename(llvm::cl::Positional, llvm::cl::desc(""),