[Seq] Moved pass definition to a separate header (#3143)

Moved the definiton of `Seq` passes to a separate `SeqPasses.h`, similarly to other dialects.
Exposed the `createSeqLowerToSV` function to be used by other clients.
This commit is contained in:
Nandor Licker 2022-05-19 10:42:27 +03:00 committed by GitHub
parent c9fe11389c
commit 72838a205c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 120 additions and 46 deletions

View File

@ -12,9 +12,7 @@
add_circt_dialect(Seq seq) add_circt_dialect(Seq seq)
add_circt_doc(Seq -gen-dialect-doc Seq Dialects/) add_circt_doc(Seq -gen-dialect-doc Seq Dialects/)
set(LLVM_TARGET_DEFINITIONS Seq.td) set(LLVM_TARGET_DEFINITIONS SeqPasses.td)
mlir_tablegen(SeqPasses.h.inc -gen-pass-decls) mlir_tablegen(SeqPasses.h.inc -gen-pass-decls)
add_public_tablegen_target(CIRCTSeqTransformsIncGen)
add_circt_doc(Seq -gen-pass-doc SeqPasses ./) add_circt_doc(SeqPasses -gen-pass-doc SeqPasses ./)
add_public_tablegen_target(MLIRSeqMiscIncGen)

View File

@ -52,10 +52,4 @@ def CompRegOp : SeqOp<"compreg",
let hasCustomAssemblyFormat = 1; let hasCustomAssemblyFormat = 1;
} }
def LowerSeqToSV: Pass<"lower-seq-to-sv", "mlir::ModuleOp"> {
let summary = "Lower sequential ops to SV.";
let constructor = "circt::seq::createSeqLowerToSVPass()";
let dependentDialects = ["circt::sv::SVDialect"];
}
#endif // SEQ_TD #endif // SEQ_TD

View File

@ -16,14 +16,6 @@
#include "circt/Support/LLVM.h" #include "circt/Support/LLVM.h"
#include "mlir/IR/Dialect.h" #include "mlir/IR/Dialect.h"
namespace circt {
namespace seq {
void registerSeqPasses();
} // namespace seq
} // namespace circt
// Pull in the dialect definition. // Pull in the dialect definition.
#include "circt/Dialect/Seq/SeqDialect.h.inc" #include "circt/Dialect/Seq/SeqDialect.h.inc"

View File

@ -0,0 +1,31 @@
//===- SeqPasses.h - Seq pass entry points ----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This header file defines prototypes that expose pass constructors.
//
//===----------------------------------------------------------------------===//
#ifndef CIRCT_DIALECT_SEQ_SEQPASSES_H
#define CIRCT_DIALECT_SEQ_SEQPASSES_H
#include "mlir/Pass/Pass.h"
#include "llvm/ADT/StringRef.h"
namespace circt {
namespace seq {
std::unique_ptr<mlir::Pass> createSeqLowerToSVPass();
/// Generate the code for registering passes.
#define GEN_PASS_REGISTRATION
#include "circt/Dialect/Seq/SeqPasses.h.inc"
} // namespace seq
} // namespace circt
#endif // CIRCT_DIALECT_SEQ_SEQPASSES_H

View File

@ -0,0 +1,24 @@
//===-- SeqPasses.td - Seq pass definition file ------------*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file contains definitions for passes that work on the Seq dialect.
//
//===----------------------------------------------------------------------===//
#ifndef CIRCT_DIALECT_SEQ_SEQPASSES
#define CIRCT_DIALECT_SEQ_SEQPASSES
include "mlir/Pass/PassBase.td"
def LowerSeqToSV: Pass<"lower-seq-to-sv", "mlir::ModuleOp"> {
let summary = "Lower sequential ops to SV.";
let constructor = "circt::seq::createSeqLowerToSVPass()";
let dependentDialects = ["circt::sv::SVDialect"];
}
#endif // CIRCT_DIALECT_SEQ_SEQPASSES

View File

@ -25,7 +25,7 @@
#include "circt/Dialect/LLHD/Transforms/Passes.h" #include "circt/Dialect/LLHD/Transforms/Passes.h"
#include "circt/Dialect/MSFT/MSFTDialect.h" #include "circt/Dialect/MSFT/MSFTDialect.h"
#include "circt/Dialect/SV/SVPasses.h" #include "circt/Dialect/SV/SVPasses.h"
#include "circt/Dialect/Seq/SeqDialect.h" #include "circt/Dialect/Seq/SeqPasses.h"
#include "circt/Transforms/Passes.h" #include "circt/Transforms/Passes.h"
namespace circt { namespace circt {
@ -44,7 +44,7 @@ inline void registerAllPasses() {
fsm::registerPasses(); fsm::registerPasses();
llhd::initLLHDTransformationPasses(); llhd::initLLHDTransformationPasses();
msft::registerMSFTPasses(); msft::registerMSFTPasses();
seq::registerSeqPasses(); seq::registerPasses();
sv::registerPasses(); sv::registerPasses();
handshake::registerPasses(); handshake::registerPasses();
hw::registerPasses(); hw::registerPasses();

View File

@ -68,6 +68,7 @@ add_mlir_public_c_api_library(CIRCTCAPISeq
LINK_LIBS PUBLIC LINK_LIBS PUBLIC
MLIRCAPIIR MLIRCAPIIR
CIRCTSeq CIRCTSeq
CIRCTSeqTransforms
) )
add_mlir_public_c_api_library(CIRCTCAPISV add_mlir_public_c_api_library(CIRCTCAPISV

View File

@ -8,9 +8,10 @@
#include "circt-c/Dialect/Seq.h" #include "circt-c/Dialect/Seq.h"
#include "circt/Dialect/Seq/SeqDialect.h" #include "circt/Dialect/Seq/SeqDialect.h"
#include "circt/Dialect/Seq/SeqPasses.h"
#include "mlir/CAPI/Registration.h" #include "mlir/CAPI/Registration.h"
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Sequential, seq, circt::seq::SeqDialect) MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Sequential, seq, circt::seq::SeqDialect)
void registerSeqPasses() { circt::seq::registerSeqPasses(); } void registerSeqPasses() { circt::seq::registerPasses(); }

View File

@ -12,7 +12,6 @@
add_circt_dialect_library(CIRCTSeq add_circt_dialect_library(CIRCTSeq
SeqDialect.cpp SeqDialect.cpp
SeqOps.cpp SeqOps.cpp
SeqPasses.cpp
ADDITIONAL_HEADER_DIRS ADDITIONAL_HEADER_DIRS
${CIRCT_MAIN_INCLUDE_DIR}/circt/Dialect/Seq ${CIRCT_MAIN_INCLUDE_DIR}/circt/Dialect/Seq
@ -21,7 +20,6 @@ add_circt_dialect_library(CIRCTSeq
CIRCTHW CIRCTHW
CIRCTSV CIRCTSV
MLIRSeqIncGen MLIRSeqIncGen
MLIRSeqMiscIncGen
LINK_COMPONENTS LINK_COMPONENTS
Support Support
@ -35,3 +33,5 @@ add_circt_dialect_library(CIRCTSeq
) )
add_dependencies(circt-headers MLIRSeqIncGen) add_dependencies(circt-headers MLIRSeqIncGen)
add_subdirectory(Transforms)

View File

@ -0,0 +1,15 @@
add_circt_dialect_library(CIRCTSeqTransforms
LowerSeqToSV.cpp
DEPENDS
CIRCTSeqTransformsIncGen
LINK_LIBS PUBLIC
CIRCTHW
CIRCTSeq
CIRCTSupport
CIRCTSV
MLIRIR
MLIRPass
MLIRTransformUtils
)

View File

@ -1,29 +1,27 @@
//===- SeqPasses.cpp - Implement Seq passes -------------------------------===// //===- LowerSeqToSV.cpp - Seq to SV lowering ------------------------------===//
// //
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information. // See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
//
// This transform translate Seq ops to SV.
//
//===----------------------------------------------------------------------===//
#include "PassDetails.h"
#include "circt/Dialect/SV/SVOps.h" #include "circt/Dialect/SV/SVOps.h"
#include "circt/Dialect/Seq/SeqOps.h" #include "circt/Dialect/Seq/SeqOps.h"
#include "circt/Dialect/Seq/SeqPasses.h"
#include "mlir/IR/Builders.h" #include "mlir/IR/Builders.h"
#include "mlir/IR/DialectImplementation.h" #include "mlir/IR/DialectImplementation.h"
#include "mlir/Pass/Pass.h" #include "mlir/Pass/Pass.h"
#include "mlir/Transforms/DialectConversion.h" #include "mlir/Transforms/DialectConversion.h"
using namespace mlir;
using namespace circt; using namespace circt;
using namespace seq; using namespace seq;
namespace circt {
namespace seq {
#define GEN_PASS_CLASSES
#include "circt/Dialect/Seq/SeqPasses.h.inc"
} // namespace seq
} // namespace circt
namespace { namespace {
struct SeqToSVPass : public LowerSeqToSVBase<SeqToSVPass> { struct SeqToSVPass : public LowerSeqToSVBase<SeqToSVPass> {
void runOnOperation() override; void runOnOperation() override;
@ -70,8 +68,8 @@ public:
return success(); return success();
} }
}; };
} // namespace } // namespace
void SeqToSVPass::runOnOperation() { void SeqToSVPass::runOnOperation() {
ModuleOp top = getOperation(); ModuleOp top = getOperation();
MLIRContext &ctxt = getContext(); MLIRContext &ctxt = getContext();
@ -86,17 +84,6 @@ void SeqToSVPass::runOnOperation() {
signalPassFailure(); signalPassFailure();
} }
namespace circt { std::unique_ptr<Pass> circt::seq::createSeqLowerToSVPass() {
namespace seq {
std::unique_ptr<OperationPass<ModuleOp>> createSeqLowerToSVPass() {
return std::make_unique<SeqToSVPass>(); return std::make_unique<SeqToSVPass>();
} }
} // namespace seq
} // namespace circt
namespace {
#define GEN_PASS_REGISTRATION
#include "circt/Dialect/Seq/SeqPasses.h.inc"
} // namespace
void circt::seq::registerSeqPasses() { registerPasses(); }

View File

@ -0,0 +1,30 @@
//===- PassDetails.h - Seq pass class details -----------===-----*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Stuff shared between the different Seq passes.
//
//===----------------------------------------------------------------------===//
// NOLINTNEXTLINE(llvm-header-guard)
#ifndef DIALECT_SEQ_TRANSFORMS_PASSDETAILS_H
#define DIALECT_SEQ_TRANSFORMS_PASSDETAILS_H
#include "circt/Dialect/SV/SVDialect.h"
#include "circt/Dialect/Seq/SeqOps.h"
#include "mlir/Pass/Pass.h"
namespace circt {
namespace seq {
#define GEN_PASS_CLASSES
#include "circt/Dialect/Seq/SeqPasses.h.inc"
} // namespace seq
} // namespace circt
#endif // DIALECT_SEQ_TRANSFORMS_PASSDETAILS_H

View File

@ -37,6 +37,7 @@ target_link_libraries(circt-opt
CIRCTScheduling CIRCTScheduling
CIRCTSchedulingTestPasses CIRCTSchedulingTestPasses
CIRCTSeq CIRCTSeq
CIRCTSeqTransforms
CIRCTStandardToHandshake CIRCTStandardToHandshake
CIRCTStandardToStaticLogic CIRCTStandardToStaticLogic
CIRCTStaticLogicOps CIRCTStaticLogicOps