add new HLSCpp dialect and scalehls-opt tool
This commit is contained in:
parent
1f4200e88a
commit
45fe55af67
|
@ -0,0 +1 @@
|
|||
add_mlir_dialect(HLSCpp hlscpp)
|
|
@ -0,0 +1,20 @@
|
|||
//===------------------------------------------------------------*- 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
|
|
@ -0,0 +1,28 @@
|
|||
//===-------------------------------------------------------*- 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<string mnemonic, list<OpTrait> traits = []> :
|
||||
Op<HLSCppDialect, mnemonic, traits>;
|
|
@ -0,0 +1,11 @@
|
|||
//===-------------------------------------------------------*- tablegen -*-===//
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef SCALEHLS_DIALECT_HLSCPP_TD
|
||||
#define SCALEHLS_DIALECT_HLSCPP_TD
|
||||
|
||||
include "Dialect.td"
|
||||
include "Ops.td"
|
||||
|
||||
#endif // SCALEHLS_DIALECT_HLSCPP_TD
|
|
@ -0,0 +1,22 @@
|
|||
//===------------------------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef SCALEHLS_DIALECT_HLSCPP_OPS_H
|
||||
#define SCALEHLS_DIALECT_HLSCPP_OPS_H
|
||||
|
||||
#include "Dialect/HLSCpp/Dialect.h"
|
||||
#include "mlir/Interfaces/SideEffectInterfaces.h"
|
||||
|
||||
namespace mlir {
|
||||
namespace scalehls {
|
||||
namespace hlscpp {
|
||||
|
||||
#define GET_OP_CLASSES
|
||||
#include "Dialect/HLSCpp/HLSCpp.h.inc"
|
||||
|
||||
} // namespace hlscpp
|
||||
} // namespace scalehls
|
||||
} // namespace mlir
|
||||
|
||||
#endif // SCALEHLS_DIALECT_HLSCPP_OPS_H
|
|
@ -0,0 +1,30 @@
|
|||
//===-------------------------------------------------------*- tablegen -*-===//
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
include "mlir/Interfaces/SideEffectInterfaces.td"
|
||||
|
||||
def HLSCppFooOp : HLSCppOp<"foo", [NoSideEffect, SameOperandsAndResultType]> {
|
||||
let summary = "Illustrates how to define an operation.";
|
||||
let description = [{
|
||||
The `hlscpp.foo` operation illustrates how to define a new operation in a
|
||||
dialect.
|
||||
|
||||
This operation takes an integer argument and returns an integer.
|
||||
|
||||
Example:
|
||||
|
||||
```mlir
|
||||
%0 = constant 2 : i32
|
||||
// Apply the foo operation to %0
|
||||
%1 = hlscpp.foo %0 : i32
|
||||
```
|
||||
}];
|
||||
|
||||
let arguments = (ins I32:$input);
|
||||
let results = (outs I32:$res);
|
||||
|
||||
let assemblyFormat = [{
|
||||
$input attr-dict `:` type($input)
|
||||
}];
|
||||
}
|
|
@ -2,11 +2,15 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef SCALEHLS_EMIT_HLSCPP_H
|
||||
#define SCALEHLS_EMIT_HLSCPP_H
|
||||
#ifndef SCALEHLS_EMITHLSCPP_H
|
||||
#define SCALEHLS_EMITHLSCPP_H
|
||||
|
||||
namespace mlir {
|
||||
namespace scalehls {
|
||||
void registerHLSCppEmitterTranslation();
|
||||
} // namespace scalehls
|
||||
|
||||
#endif // SCALEHLS_EMIT_HLSCPP_H
|
||||
void registerHLSCppEmitterTranslation();
|
||||
|
||||
} // namespace scalehls
|
||||
} // namespace mlir
|
||||
|
||||
#endif // SCALEHLS_EMITHLSCPP_H
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
file(GLOB globbed *.cpp)
|
||||
|
||||
add_mlir_dialect_library(MLIRHLSCpp
|
||||
${globbed}
|
||||
|
||||
ADDITIONAL_HEADER_DIRS
|
||||
${PROJECT_SOURCE_DIR}/include/Dialect/HLSCpp
|
||||
|
||||
DEPENDS
|
||||
MLIRHLSCppIncGen
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRIR
|
||||
)
|
|
@ -0,0 +1,19 @@
|
|||
//===------------------------------------------------------------*- 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"
|
||||
>();
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
//===------------------------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "Dialect/HLSCpp/Ops.h"
|
||||
#include "mlir/IR/OpImplementation.h"
|
||||
|
||||
using namespace mlir;
|
||||
using namespace scalehls;
|
||||
using namespace hlscpp;
|
||||
|
||||
#define GET_OP_CLASSES
|
||||
#include "Dialect/HLSCpp/HLSCpp.cpp.inc"
|
|
@ -19,8 +19,9 @@
|
|||
|
||||
#include "EmitHLSCpp.h"
|
||||
|
||||
using namespace mlir;
|
||||
using namespace std;
|
||||
using namespace mlir;
|
||||
using namespace scalehls;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Some Base Classes
|
||||
|
|
|
@ -7,6 +7,7 @@ configure_lit_site_cfg(
|
|||
|
||||
set(SCALEHLS_TEST_DEPENDS
|
||||
FileCheck count not
|
||||
scalehls-opt
|
||||
scalehls-translate
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
|
||||
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
|
||||
|
||||
set(LIBS
|
||||
${dialect_libs}
|
||||
${conversion_libs}
|
||||
MLIROptLib
|
||||
|
||||
MLIRHLSCpp
|
||||
)
|
||||
|
||||
add_llvm_executable(scalehls-opt scalehls-opt.cpp)
|
||||
|
||||
llvm_update_compile_flags(scalehls-opt)
|
||||
target_link_libraries(scalehls-opt PRIVATE ${LIBS})
|
|
@ -0,0 +1,103 @@
|
|||
//===------------------------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "mlir/IR/Dialect.h"
|
||||
#include "mlir/IR/MLIRContext.h"
|
||||
#include "mlir/InitAllDialects.h"
|
||||
#include "mlir/InitAllPasses.h"
|
||||
#include "mlir/Pass/Pass.h"
|
||||
#include "mlir/Pass/PassManager.h"
|
||||
#include "mlir/Support/FileUtilities.h"
|
||||
#include "mlir/Support/MlirOptMain.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "llvm/Support/ToolOutputFile.h"
|
||||
|
||||
#include "Dialect/HLSCpp/Dialect.h"
|
||||
|
||||
static llvm::cl::opt<std::string> inputFilename(llvm::cl::Positional,
|
||||
llvm::cl::desc("<input file>"),
|
||||
llvm::cl::init("-"));
|
||||
|
||||
static llvm::cl::opt<std::string>
|
||||
outputFilename("o", llvm::cl::desc("Output filename"),
|
||||
llvm::cl::value_desc("filename"), llvm::cl::init("-"));
|
||||
|
||||
static llvm::cl::opt<bool> splitInputFile(
|
||||
"split-input-file",
|
||||
llvm::cl::desc("Split the input file into pieces and process each "
|
||||
"chunk independently"),
|
||||
llvm::cl::init(false));
|
||||
|
||||
static llvm::cl::opt<bool> verifyDiagnostics(
|
||||
"verify-diagnostics",
|
||||
llvm::cl::desc("Check that emitted diagnostics match "
|
||||
"expected-* lines on the corresponding line"),
|
||||
llvm::cl::init(false));
|
||||
|
||||
static llvm::cl::opt<bool> verifyPasses(
|
||||
"verify-each",
|
||||
llvm::cl::desc("Run the verifier after each transformation pass"),
|
||||
llvm::cl::init(true));
|
||||
|
||||
static llvm::cl::opt<bool> allowUnregisteredDialects(
|
||||
"allow-unregistered-dialect",
|
||||
llvm::cl::desc("Allow operation with no registered dialects"),
|
||||
llvm::cl::init(false));
|
||||
|
||||
static llvm::cl::opt<bool>
|
||||
showDialects("show-dialects",
|
||||
llvm::cl::desc("Print the list of registered dialects"),
|
||||
llvm::cl::init(false));
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
mlir::registerAllDialects();
|
||||
mlir::registerAllPasses();
|
||||
|
||||
mlir::registerDialect<mlir::scalehls::hlscpp::HLSCppDialect>();
|
||||
// TODO: Register HLSCpp passes here.
|
||||
|
||||
llvm::InitLLVM y(argc, argv);
|
||||
|
||||
// Register any pass manager command line options.
|
||||
mlir::registerPassManagerCLOptions();
|
||||
mlir::PassPipelineCLParser passPipeline("", "Compiler passes to run");
|
||||
|
||||
// Parse pass names in main to ensure static initialization completed.
|
||||
llvm::cl::ParseCommandLineOptions(argc, argv,
|
||||
"MLIR modular optimizer driver\n");
|
||||
|
||||
if (showDialects) {
|
||||
mlir::MLIRContext context;
|
||||
llvm::outs() << "Registered Dialects:\n";
|
||||
for (mlir::Dialect *dialect : context.getRegisteredDialects()) {
|
||||
llvm::outs() << dialect->getNamespace() << "\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Set up the input file.
|
||||
std::string errorMessage;
|
||||
auto file = mlir::openInputFile(inputFilename, &errorMessage);
|
||||
if (!file) {
|
||||
llvm::errs() << errorMessage << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto output = mlir::openOutputFile(outputFilename, &errorMessage);
|
||||
if (!output) {
|
||||
llvm::errs() << errorMessage << "\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (failed(MlirOptMain(output->os(), std::move(file), passPipeline,
|
||||
splitInputFile, verifyDiagnostics, verifyPasses,
|
||||
allowUnregisteredDialects))) {
|
||||
return 1;
|
||||
}
|
||||
// Keep the output file if the invocation of MlirOptMain was successful.
|
||||
output->keep();
|
||||
return 0;
|
||||
}
|
|
@ -42,7 +42,7 @@ int main(int argc, char **argv) {
|
|||
mlir::registerAllDialects();
|
||||
mlir::registerAllTranslations();
|
||||
|
||||
scalehls::registerHLSCppEmitterTranslation();
|
||||
mlir::scalehls::registerHLSCppEmitterTranslation();
|
||||
|
||||
llvm::InitLLVM y(argc, argv);
|
||||
|
||||
|
|
Loading…
Reference in New Issue