[Handshake] `StandardToHandshake` -> `CFToHandshake` (#5938)

... long awaited.
This commit is contained in:
Morten Borup Petersen 2023-08-25 09:24:26 +02:00 committed by GitHub
parent ff169cc489
commit 7a3b9e478b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
47 changed files with 63 additions and 64 deletions

View File

@ -107,7 +107,7 @@ class System:
def set_debug():
ir._GlobalDebug.flag = True
# TODO: Ideally, we'd be able to run the std-to-handshake lowering passes in
# TODO: Ideally, we'd be able to run the cf-to-handshake lowering passes in
# pycde. As of now, however, the cf/memref/arith dialects are not registered
# so the assembly can't be loaded. The right way to do this is to have pycde
# load those dialects, though there isn't a python hook to selectively load
@ -118,7 +118,7 @@ class System:
# "flatten-memref",
# "flatten-memref-calls",
# "func.func(handshake-legalize-memrefs)",
# "lower-std-to-handshake",
# "lower-cf-to-handshake",
# "canonicalize",
# "handshake-lower-extmem-to-hw{wrap-esi}",
# "canonicalize",

View File

@ -1,4 +1,4 @@
//===- StandardToHandshake.h ------------------------------------*- C++ -*-===//
//===- CFToHandshake.h ------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@ -11,8 +11,8 @@
//
//===----------------------------------------------------------------------===//
#ifndef CIRCT_CONVERSION_STANDARDTOHANDSHAKE_H_
#define CIRCT_CONVERSION_STANDARDTOHANDSHAKE_H_
#ifndef CIRCT_CONVERSION_CFTOHANDSHAKE_H_
#define CIRCT_CONVERSION_CFTOHANDSHAKE_H_
#include "circt/Dialect/Handshake/HandshakeOps.h"
#include "circt/Dialect/Handshake/HandshakePasses.h"
@ -289,8 +289,8 @@ std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>>
createHandshakeAnalysisPass();
std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>>
createStandardToHandshakePass(bool sourceConstants = false,
bool disableTaskPipelining = false);
createCFToHandshakePass(bool sourceConstants = false,
bool disableTaskPipelining = false);
std::unique_ptr<mlir::OperationPass<handshake::FuncOp>>
createHandshakeCanonicalizePass();
@ -317,4 +317,4 @@ std::unique_ptr<mlir::Pass> createMaximizeSSAPass();
} // namespace circt
#endif // CIRCT_CONVERSION_STANDARDTOHANDSHAKE_H_
#endif // CIRCT_CONVERSION_CFTOHANDSHAKE_H_

View File

@ -15,6 +15,7 @@
#include "circt/Conversion/AffineToLoopSchedule.h"
#include "circt/Conversion/ArcToLLVM.h"
#include "circt/Conversion/CFToHandshake.h"
#include "circt/Conversion/CalyxNative.h"
#include "circt/Conversion/CalyxToFSM.h"
#include "circt/Conversion/CalyxToHW.h"
@ -38,7 +39,6 @@
#include "circt/Conversion/PipelineToHW.h"
#include "circt/Conversion/SCFToCalyx.h"
#include "circt/Conversion/SeqToSV.h"
#include "circt/Conversion/StandardToHandshake.h"
#include "circt/Conversion/VerifToSV.h"
#include "mlir/IR/DialectRegistry.h"
#include "mlir/Pass/Pass.h"

View File

@ -577,12 +577,12 @@ def LowerVerifToSV : Pass<"lower-verif-to-sv", "hw::HWModuleOp"> {
}
//===----------------------------------------------------------------------===//
// StandardToHandshake
// CFToHandshake
//===----------------------------------------------------------------------===//
def StandardToHandshake : Pass<"lower-std-to-handshake", "mlir::ModuleOp"> {
let summary = "Lower Standard MLIR into Handshake IR";
let constructor = "circt::createStandardToHandshakePass()";
def CFToHandshake : Pass<"lower-cf-to-handshake", "mlir::ModuleOp"> {
let summary = "Lower func and CF into Handshake IR";
let constructor = "circt::createCFToHandshakePass()";
let dependentDialects = ["handshake::HandshakeDialect"];
let options =
[Option<"sourceConstants", "source-constants", "bool", "false",

View File

@ -117,7 +117,7 @@ def HandshakeLegalizeMemrefs : Pass<"handshake-legalize-memrefs", "mlir::func::F
let summary = "Memref legalization and lowering pass.";
let description = [{
Lowers various memref operations to a state suitable for passing to the
StandardToHandshake lowering.
CFToHandshake lowering.
}];
let constructor = "circt::handshake::createHandshakeLegalizeMemrefsPass()";
let dependentDialects = ["mlir::scf::SCFDialect"];

View File

@ -1,5 +1,5 @@
// RUN: handshake-runner %s | FileCheck %s
// RUN: circt-opt -lower-std-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// CHECK: 763 2996
module {
func.func @muladd(%1:index, %2:index, %3:index) -> (index) {

View File

@ -1,5 +1,5 @@
// RUN: handshake-runner %s 3 2 1 | FileCheck %s
// RUN: circt-opt -lower-std-to-handshake -handshake-materialize-forks-sinks %s > handshake.mlir
// RUN: circt-opt -lower-cf-to-handshake -handshake-materialize-forks-sinks %s > handshake.mlir
// RUN handshake-runner handshake.mlir 3 2 1 | FileCheck %s
// CHECK: 5

View File

@ -1,5 +1,5 @@
// RUN: handshake-runner %s 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 1,0,1,0 | FileCheck %s
// RUN: circt-opt -lower-std-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner - 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 1,0,1,0 | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner - 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 1,0,1,0 | FileCheck %s
// CHECK: 0 2,3,4,5 2,3,4,5 1,1431655763,3,858993455 3,4,5,6 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 0,-1,0,-1
module {

View File

@ -1,5 +1,5 @@
// RUN: handshake-runner %s | FileCheck %s
// RUN: circt-opt -lower-std-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// CHECK: 0
module {

View File

@ -1,5 +1,5 @@
// RUN: handshake-runner %s | FileCheck %s
// RUN: circt-opt -lower-std-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// CHECK: 763 2996
module {
func.func @main() -> (index, index) {

View File

@ -1,5 +1,5 @@
// RUN: handshake-runner %s | FileCheck %s
// RUN: circt-opt -lower-std-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// CHECK: 0
module {

View File

@ -1,5 +1,5 @@
// RUN: handshake-runner %s | FileCheck %s
// RUN: circt-opt -lower-std-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// CHECK: 0
module {

View File

@ -1,5 +1,5 @@
// RUN: handshake-runner %s 2 | FileCheck %s
// RUN: circt-opt -lower-std-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner - 2 | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner - 2 | FileCheck %s
// CHECK: 1
module {

View File

@ -1,5 +1,5 @@
// RUN: handshake-runner %s | FileCheck %s
// RUN: circt-opt -lower-std-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// CHECK: 10
module {

View File

@ -1,5 +1,5 @@
// RUN: handshake-runner %s | FileCheck %s
// RUN: circt-opt -lower-std-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// CHECK: 10
module {

View File

@ -1,5 +1,5 @@
// RUN: handshake-runner %s | FileCheck %s
// RUN: circt-opt -lower-std-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// CHECK: 200

View File

@ -1,5 +1,5 @@
// RUN: handshake-runner %s | FileCheck %s
// RUN: circt-opt -lower-std-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// CHECK: 0
module {

View File

@ -1,5 +1,5 @@
// RUN: handshake-runner %s 2,3,4,5 | FileCheck %s
// RUN: circt-opt -lower-std-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner - 2,3,4,5 | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner - 2,3,4,5 | FileCheck %s
// CHECK: 5 5,3,4,5
module {

View File

@ -1,5 +1,5 @@
// RUN: handshake-runner %s 2,3,4,5 | FileCheck %s
// RUN: circt-opt -lower-std-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner - 2,3,4,5 | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner - 2,3,4,5 | FileCheck %s
// CHECK: 2 2,3,4,5
module {

View File

@ -1,4 +1,4 @@
// RUN: circt-opt -lower-std-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake -handshake-materialize-forks-sinks %s | handshake-runner | FileCheck %s
// RUN: handshake-runner %s | FileCheck %s
// CHECK: 42
module {

View File

@ -1,4 +1,4 @@
// RUN: circt-opt -lower-std-to-handshake -handshake-materialize-forks-sinks %s \
// RUN: circt-opt -lower-cf-to-handshake -handshake-materialize-forks-sinks %s \
// RUN: | circt-opt --handshake-insert-buffers="strategy=all" \
// RUN: | handshake-runner | FileCheck %s
// CHECK: 42

View File

@ -28,7 +28,7 @@ add_mlir_public_c_api_library(CIRCTCAPIConversion
CIRCTPipelineToHW
CIRCTSCFToCalyx
CIRCTSeqToSV
CIRCTStandardToHandshake
CIRCTCFToHandshake
CIRCTVerifToSV
)

View File

@ -130,7 +130,7 @@ add_mlir_public_c_api_library(CIRCTCAPIHandshake
CIRCTHandshake
CIRCTHandshakeTransforms
CIRCTHandshakeToHW
CIRCTStandardToHandshake
CIRCTCFToHandshake
)
add_mlir_public_c_api_library(CIRCTCAPIHWArith

View File

@ -15,7 +15,7 @@
void registerHandshakePasses() {
circt::handshake::registerPasses();
circt::registerStandardToHandshakePass();
circt::registerCFToHandshakePass();
circt::registerHandshakeToHWPass();
}
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Handshake, handshake,

View File

@ -1,4 +1,4 @@
//===- StandardToHandshake.cpp - Convert standard MLIR into dataflow IR ---===//
//===- CFToHandshake.cpp - Convert standard MLIR into dataflow IR ---------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
#include "circt/Conversion/StandardToHandshake.h"
#include "circt/Conversion/CFToHandshake.h"
#include "../PassDetail.h"
#include "circt/Dialect/Handshake/HandshakeOps.h"
#include "circt/Dialect/Handshake/HandshakePasses.h"
@ -1635,7 +1635,7 @@ HandshakeLowering::replaceCallOps(ConversionPatternRewriter &rewriter) {
}
namespace {
/// Strategy class for SSA maximization during std-to-handshake conversion.
/// Strategy class for SSA maximization during cf-to-handshake conversion.
/// Block arguments of type MemRefType and allocation operations are not
/// considered for SSA maximization.
class HandshakeLoweringSSAStrategy : public SSAMaximizationStrategy {
@ -1721,9 +1721,8 @@ struct HandshakeRemoveBlockPass
void runOnOperation() override { removeBasicBlocks(getOperation()); }
};
struct StandardToHandshakePass
: public StandardToHandshakeBase<StandardToHandshakePass> {
StandardToHandshakePass(bool sourceConstants, bool disableTaskPipelining) {
struct CFToHandshakePass : public CFToHandshakeBase<CFToHandshakePass> {
CFToHandshakePass(bool sourceConstants, bool disableTaskPipelining) {
this->sourceConstants = sourceConstants;
this->disableTaskPipelining = disableTaskPipelining;
}
@ -1748,10 +1747,10 @@ struct StandardToHandshakePass
} // namespace
std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>>
circt::createStandardToHandshakePass(bool sourceConstants,
bool disableTaskPipelining) {
return std::make_unique<StandardToHandshakePass>(sourceConstants,
disableTaskPipelining);
circt::createCFToHandshakePass(bool sourceConstants,
bool disableTaskPipelining) {
return std::make_unique<CFToHandshakePass>(sourceConstants,
disableTaskPipelining);
}
std::unique_ptr<mlir::OperationPass<handshake::FuncOp>>

View File

@ -1,10 +1,10 @@
add_circt_library(CIRCTStandardToHandshake
StandardToHandshake.cpp
add_circt_library(CIRCTCFToHandshake
CFToHandshake.cpp
InsertMergeBlocks.cpp
MaximizeSSA.cpp
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Conversion/StandardToHandshake
${MLIR_MAIN_INCLUDE_DIR}/mlir/Conversion/CFToHandshake
DEPENDS
CIRCTConversionPassIncGen

View File

@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "../PassDetail.h"
#include "circt/Conversion/StandardToHandshake.h"
#include "circt/Conversion/CFToHandshake.h"
#include "mlir/Analysis/CFGLoopInfo.h"
#include "mlir/Conversion/LLVMCommon/ConversionTarget.h"
#include "mlir/Conversion/LLVMCommon/Pattern.h"

View File

@ -12,7 +12,7 @@
//===----------------------------------------------------------------------===//
#include "../PassDetail.h"
#include "circt/Conversion/StandardToHandshake.h"
#include "circt/Conversion/CFToHandshake.h"
#include "circt/Transforms/Passes.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/IR/MLIRContext.h"

View File

@ -23,6 +23,6 @@ add_subdirectory(MooreToCore)
add_subdirectory(PipelineToHW)
add_subdirectory(SCFToCalyx)
add_subdirectory(SeqToSV)
add_subdirectory(StandardToHandshake)
add_subdirectory(CFToHandshake)
add_subdirectory(VerifToSV)
add_subdirectory(CalyxNative)

View File

@ -1,5 +1,5 @@
// NOTE: Assertions have been autogenerated by utils/update_mlir_test_checks.py
// RUN: circt-opt -lower-std-to-handshake %s | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake %s | FileCheck %s
// CHECK: handshake.func @ops(%[[VAL_0:.*]]: f32, %[[VAL_1:.*]]: f32, %[[VAL_2:.*]]: i32, %[[VAL_3:.*]]: i32, %[[VAL_4:.*]]: none, ...) -> (f32, i32, none)
// CHECK: %[[VAL_5:.*]] = merge %[[VAL_0]] : f32

View File

@ -1,4 +1,4 @@
// RUN: circt-opt -lower-std-to-handshake -split-input-file %s | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake -split-input-file %s | FileCheck %s
// CHECK-LABEL: handshake.func @bar(
// CHECK-SAME: %[[VAL_0:.*]]: i32,

View File

@ -1,5 +1,5 @@
// NOTE: Assertions have been autogenerated by utils/update_mlir_test_checks.py
// RUN: circt-opt -lower-std-to-handshake="disable-task-pipelining" %s --split-input-file | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake="disable-task-pipelining" %s --split-input-file | FileCheck %s
// CHECK-LABEL: handshake.func @simple_loop(
// CHECK-SAME: %[[VAL_0:.*]]: none, ...) -> none

View File

@ -1,4 +1,4 @@
// RUN: circt-opt -lower-std-to-handshake %s --split-input-file | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake %s --split-input-file | FileCheck %s
// CHECK-LABEL: handshake.func @main(
// CHECK-SAME: %[[VAL_0:.*]]: memref<4xi32>,

View File

@ -1,4 +1,4 @@
// RUN: circt-opt --split-input-file -lower-std-to-handshake %s | FileCheck %s
// RUN: circt-opt --split-input-file -lower-cf-to-handshake %s | FileCheck %s
// CHECK-LABEL: handshake.func @foo(
// CHECK-SAME: %[[CTRL:.*]]: none, ...) -> none

View File

@ -1,4 +1,4 @@
// RUN: circt-opt -lower-std-to-handshake %s -split-input-file -verify-diagnostics
// RUN: circt-opt -lower-cf-to-handshake %s -split-input-file -verify-diagnostics
func.func @multidim() -> i32 {
// expected-error @+1 {{memref's must be both statically sized and unidimensional.}}

View File

@ -1,4 +1,4 @@
// RUN: circt-opt -lower-std-to-handshake %s --split-input-file | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake %s --split-input-file | FileCheck %s
// CHECK-LABEL: handshake.func @remove_unused_mem(
// CHECK-SAME: %[[VAL_0:.*]]: none, ...) -> none

View File

@ -1,4 +1,4 @@
// RUN: circt-opt -lower-std-to-handshake %s | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake %s | FileCheck %s
// CHECK-LABEL: handshake.func @main(%arg0: i32, %arg1: i32, %arg2: i32, %arg3: none, ...) -> (i32, none) attributes {argNames = ["a", "b", "c", "in3"], resNames = ["res", "outCtrl"]} {
func.func @main(%arg0 : i32, %b : i32, %c: i32) -> i32 attributes {argNames = ["a", "b", "c"], resNames = ["res", "outCtrl"]} {

View File

@ -1,4 +1,4 @@
// RUN: circt-opt -lower-std-to-handshake="source-constants" %s | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake="source-constants" %s | FileCheck %s
// CHECK-LABEL: handshake.func @foo(
// CHECK-SAME: %[[VAL_1:.*]]: none, ...) -> (i32, none)

View File

@ -1,4 +1,4 @@
// RUN: circt-opt -lower-std-to-handshake %s --canonicalize --split-input-file --verify-diagnostics
// RUN: circt-opt -lower-cf-to-handshake %s --canonicalize --split-input-file --verify-diagnostics
// expected-error @+1 {{expected a merge block to have two predecessors.}}
func.func @missingMergeBlocks(%arg0: i1) {

View File

@ -1,6 +1,6 @@
// NOTE: Assertions have been autogenerated by utils/generate-test-checks.py
// RUN: circt-opt -lower-std-to-handshake %s --split-input-file | FileCheck %s
// RUN: circt-opt -lower-cf-to-handshake %s --split-input-file | FileCheck %s
// CHECK-LABEL: handshake.func @simpleDiamond(
// CHECK-SAME: %[[VAL_0:.*]]: i1,

View File

@ -67,7 +67,7 @@ target_link_libraries(circt-opt
CIRCTSeqTransforms
CIRCTSSP
CIRCTSSPTransforms
CIRCTStandardToHandshake
CIRCTCFToHandshake
CIRCTOM
CIRCTOMTransforms
CIRCTPipelineOps

View File

@ -3,7 +3,7 @@ add_llvm_executable(handshake-runner handshake-runner.cpp Simulation.cpp)
llvm_update_compile_flags(handshake-runner)
target_link_libraries(handshake-runner PRIVATE
CIRCTHandshake
CIRCTStandardToHandshake
CIRCTCFToHandshake
MLIRArithDialect
MLIRControlFlowDialect
MLIRFuncDialect

View File

@ -20,7 +20,7 @@ target_link_libraries(hlstool
CIRCTSeq
CIRCTSeqToSV
CIRCTSeqTransforms
CIRCTStandardToHandshake
CIRCTCFToHandshake
CIRCTSV
CIRCTSVTransforms
CIRCTSCFToCalyx

View File

@ -242,7 +242,7 @@ static void loadDHLSPipeline(OpPassManager &pm) {
pm.nest<handshake::FuncOp>().addPass(createSimpleCanonicalizerPass());
// DHLS conversion
pm.addPass(circt::createStandardToHandshakePass(
pm.addPass(circt::createCFToHandshakePass(
/*sourceConstants=*/false,
/*disableTaskPipelining=*/dynParallelism != Pipelining));
pm.addPass(circt::handshake::createHandshakeLowerExtmemToHWPass(withESI));