Skip to content

Commit

Permalink
[MSFT] Move ExportQuartusTcl from a translation to a pass. (llvm#2075)
Browse files Browse the repository at this point in the history
This keeps the existing functionality based on attributes, and exports
to llvm::outs as part of the pass, in order to keep the existing
tests. Further changes based on the approach in llvm#2068 will follow.
  • Loading branch information
mikeurbach authored Nov 4, 2021
1 parent a2edaea commit e43d978
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 45 deletions.
3 changes: 0 additions & 3 deletions include/circt/Dialect/MSFT/ExportTcl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ namespace msft {
mlir::LogicalResult exportQuartusTcl(hw::HWModuleOp module,
llvm::raw_ostream &os);

/// Register the Tcl exports.
void registerMSFTTclTranslation();

} // namespace msft
} // namespace circt

Expand Down
6 changes: 6 additions & 0 deletions include/circt/Dialect/MSFT/MSFTPasses.td
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ def LowerToHW: Pass<"lower-msft-to-hw", "mlir::ModuleOp"> {
let constructor = "circt::msft::createLowerToHWPass()";
let dependentDialects = ["circt::sv::SVDialect", "circt::hw::HWDialect"];
}

def ExportQuartusTcl: Pass<"export-quartus-tcl", "mlir::ModuleOp"> {
let summary = "Export Quartus-flavored Tcl into sv.verbatim node(s)";
let constructor = "circt::msft::createExportQuartusTclPass()";
let dependentDialects = ["circt::msft::MSFTDialect", "circt::hw::HWDialect"];
}
1 change: 0 additions & 1 deletion include/circt/InitAllTranslations.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ inline void registerAllTranslations() {
firrtl::registerFromFIRFileTranslation();
firrtl::registerToFIRFileTranslation();
llhd::registerToVerilogTranslation();
msft::registerMSFTTclTranslation();
return true;
}();
(void)initOnce;
Expand Down
1 change: 0 additions & 1 deletion lib/CAPI/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ add_mlir_public_c_api_library(CIRCTCAPIMSFT
LINK_LIBS PUBLIC
MLIRCAPIIR
CIRCTMSFT
CIRCTMSFTExportTcl
)

add_mlir_public_c_api_library(CIRCTCAPIHW
Expand Down
3 changes: 1 addition & 2 deletions lib/Dialect/MSFT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ add_circt_dialect_library(CIRCTMSFT
MSFTDialect.cpp
MSFTOps.cpp
MSFTPasses.cpp
ExportQuartusTcl.cpp

ADDITIONAL_HEADER_DIRS
${CIRCT_MAIN_INCLUDE_DIR}/circt/Dialect/MSFT
Expand All @@ -33,5 +34,3 @@ add_circt_dialect_library(CIRCTMSFT
)

add_dependencies(circt-headers MLIRMSFTIncGen)

add_subdirectory(TclExport)
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,3 @@ LogicalResult circt::msft::exportQuartusTcl(hw::HWModuleOp hwMod,
os << "}\n\n";
return success();
}

static LogicalResult exportQuartusTclForAll(mlir::ModuleOp mod,
llvm::raw_ostream &os) {
for (Operation &op : mod.getBody()->getOperations()) {
if (auto hwmod = dyn_cast<hw::HWModuleOp>(op))
if (failed(exportQuartusTcl(hwmod, os)))
return failure();
}
return success();
}

void circt::msft::registerMSFTTclTranslation() {
mlir::TranslateFromMLIRRegistration toQuartusTcl(
"export-quartus-tcl", exportQuartusTclForAll,
[](mlir::DialectRegistry &registry) {
registry.insert<MSFTDialect, HWDialect>();
});
}
17 changes: 17 additions & 0 deletions lib/Dialect/MSFT/MSFTPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "circt/Dialect/MSFT/ExportTcl.h"
#include "circt/Dialect/MSFT/MSFTDialect.h"
#include "circt/Dialect/MSFT/MSFTOps.h"
#include "circt/Dialect/SV/SVOps.h"
Expand Down Expand Up @@ -149,11 +150,27 @@ void LowerToHWPass::runOnOperation() {
signalPassFailure();
}

namespace {
struct ExportQuartusTclPass
: public ExportQuartusTclBase<ExportQuartusTclPass> {
void runOnOperation() override;
};
} // anonymous namespace

void ExportQuartusTclPass::runOnOperation() {
for (auto hwmod : getOperation().getBody()->getOps<hw::HWModuleOp>())
if (failed(exportQuartusTcl(hwmod, llvm::outs())))
return signalPassFailure();
}

namespace circt {
namespace msft {
std::unique_ptr<Pass> createLowerToHWPass() {
return std::make_unique<LowerToHWPass>();
}
std::unique_ptr<Pass> createExportQuartusTclPass() {
return std::make_unique<ExportQuartusTclPass>();
}
} // namespace msft
} // namespace circt

Expand Down
18 changes: 0 additions & 18 deletions lib/Dialect/MSFT/TclExport/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion test/Dialect/MSFT/location.mlir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: circt-opt %s -verify-diagnostics | circt-opt -verify-diagnostics | FileCheck %s
// RUN: circt-translate %s --export-quartus-tcl | FileCheck %s --check-prefix=TCL
// RUN: circt-opt %s --export-quartus-tcl | FileCheck %s --check-prefix=TCL

hw.module.extern @Foo()

Expand Down
2 changes: 1 addition & 1 deletion test/Dialect/MSFT/translate-errors.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: circt-translate %s --export-quartus-tcl -verify-diagnostics -split-input-file
// RUN: circt-opt %s --export-quartus-tcl -verify-diagnostics -split-input-file

hw.module.extern @Foo()

Expand Down

0 comments on commit e43d978

Please sign in to comment.