From a0dfafe60ba58d878c6a050cf1fe5e0ef815d656 Mon Sep 17 00:00:00 2001 From: Hideto Ueno Date: Fri, 29 May 2026 20:06:20 -0700 Subject: [PATCH 1/2] Add CIRCT standalone example --- .../workflows/unifiedBuildTestAndInstall.yml | 6 ++ CMakeLists.txt | 5 ++ examples/CMakeLists.txt | 1 + examples/circt-standalone/CMakeLists.txt | 56 +++++++++++++++++++ examples/circt-standalone/README.md | 34 +++++++++++ .../circt-standalone-opt/CMakeLists.txt | 25 +++++++++ .../circt-standalone-opt.cpp | 33 +++++++++++ .../circt-standalone-plugin/CMakeLists.txt | 17 ++++++ .../circt-standalone-plugin.cpp | 29 ++++++++++ .../CIRCTStandalone/CIRCTStandaloneDialect.h | 16 ++++++ .../CIRCTStandalone/CIRCTStandaloneDialect.td | 27 +++++++++ .../CIRCTStandalone/CIRCTStandaloneOps.h | 22 ++++++++ .../CIRCTStandalone/CIRCTStandaloneOps.td | 25 +++++++++ .../CIRCTStandalone/CIRCTStandalonePasses.h | 26 +++++++++ .../CIRCTStandalone/CIRCTStandalonePasses.td | 24 ++++++++ .../include/CIRCTStandalone/CMakeLists.txt | 5 ++ .../circt-standalone/include/CMakeLists.txt | 1 + .../CIRCTStandaloneDialect.cpp | 22 ++++++++ .../CIRCTStandalone/CIRCTStandaloneOps.cpp | 15 +++++ .../CIRCTStandalone/CIRCTStandalonePasses.cpp | 31 ++++++++++ .../lib/CIRCTStandalone/CMakeLists.txt | 19 +++++++ examples/circt-standalone/lib/CMakeLists.txt | 1 + .../test/CIRCTStandalone/dialect.mlir | 6 ++ .../test/CIRCTStandalone/pass.mlir | 5 ++ .../test/CIRCTStandalone/plugin.mlir | 7 +++ examples/circt-standalone/test/CMakeLists.txt | 29 ++++++++++ examples/circt-standalone/test/lit.cfg.py | 39 +++++++++++++ .../circt-standalone/test/lit.site.cfg.py.in | 14 +++++ llvm | 2 +- 29 files changed, 541 insertions(+), 1 deletion(-) create mode 100644 examples/CMakeLists.txt create mode 100644 examples/circt-standalone/CMakeLists.txt create mode 100644 examples/circt-standalone/README.md create mode 100644 examples/circt-standalone/circt-standalone-opt/CMakeLists.txt create mode 100644 examples/circt-standalone/circt-standalone-opt/circt-standalone-opt.cpp create mode 100644 examples/circt-standalone/circt-standalone-plugin/CMakeLists.txt create mode 100644 examples/circt-standalone/circt-standalone-plugin/circt-standalone-plugin.cpp create mode 100644 examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneDialect.h create mode 100644 examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneDialect.td create mode 100644 examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneOps.h create mode 100644 examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneOps.td create mode 100644 examples/circt-standalone/include/CIRCTStandalone/CIRCTStandalonePasses.h create mode 100644 examples/circt-standalone/include/CIRCTStandalone/CIRCTStandalonePasses.td create mode 100644 examples/circt-standalone/include/CIRCTStandalone/CMakeLists.txt create mode 100644 examples/circt-standalone/include/CMakeLists.txt create mode 100644 examples/circt-standalone/lib/CIRCTStandalone/CIRCTStandaloneDialect.cpp create mode 100644 examples/circt-standalone/lib/CIRCTStandalone/CIRCTStandaloneOps.cpp create mode 100644 examples/circt-standalone/lib/CIRCTStandalone/CIRCTStandalonePasses.cpp create mode 100644 examples/circt-standalone/lib/CIRCTStandalone/CMakeLists.txt create mode 100644 examples/circt-standalone/lib/CMakeLists.txt create mode 100644 examples/circt-standalone/test/CIRCTStandalone/dialect.mlir create mode 100644 examples/circt-standalone/test/CIRCTStandalone/pass.mlir create mode 100644 examples/circt-standalone/test/CIRCTStandalone/plugin.mlir create mode 100644 examples/circt-standalone/test/CMakeLists.txt create mode 100644 examples/circt-standalone/test/lit.cfg.py create mode 100644 examples/circt-standalone/test/lit.site.cfg.py.in diff --git a/.github/workflows/unifiedBuildTestAndInstall.yml b/.github/workflows/unifiedBuildTestAndInstall.yml index 4391b81603a3..01dcc6d94841 100644 --- a/.github/workflows/unifiedBuildTestAndInstall.yml +++ b/.github/workflows/unifiedBuildTestAndInstall.yml @@ -401,6 +401,12 @@ jobs: run: | ${{ steps.setup-windows.outputs.setup }} ninja -C build check-circt-capi check-circt-integration + - name: Check CIRCT Standalone Example + if: inputs.run_tests + run: | + ${{ steps.setup-windows.outputs.setup }} + cmake -G Ninja -S "$(pwd)/examples/circt-standalone" -B "$(pwd)/build-circt-standalone" -DCMAKE_BUILD_TYPE=${{ inputs.cmake_build_type }} -DCMAKE_C_COMPILER=${{ steps.set-cmake-options.outputs.cmake_c_compiler }} -DCMAKE_CXX_COMPILER=${{ steps.set-cmake-options.outputs.cmake_cxx_compiler }} -DCIRCT_DIR="$(pwd)/build/lib/cmake/circt" -DMLIR_DIR="$(pwd)/build/lib/cmake/mlir" + cmake --build "$(pwd)/build-circt-standalone" --target check-circt-standalone - name: Install if: inputs.install_target run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 764681eab908..9f8ac5c9c5f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -783,6 +783,11 @@ if(CIRCT_INCLUDE_TOOLS) endif() add_subdirectory(frontends) +option(CIRCT_INCLUDE_EXAMPLES "Generate build targets for the CIRCT examples.") +if (CIRCT_INCLUDE_EXAMPLES) + add_subdirectory(examples) +endif() + if (CIRCT_INCLUDE_TESTS) # Test directories are added after everything else so their cmake files can # use targets and target properties defined by the things they test. diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 000000000000..8cc77ab4eca6 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(circt-standalone) diff --git a/examples/circt-standalone/CMakeLists.txt b/examples/circt-standalone/CMakeLists.txt new file mode 100644 index 000000000000..0e3eadeeccbc --- /dev/null +++ b/examples/circt-standalone/CMakeLists.txt @@ -0,0 +1,56 @@ +cmake_minimum_required(VERSION 3.20.0) +project(circt-standalone LANGUAGES CXX C) + +set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON) + +set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to") +set(CMAKE_CXX_STANDARD_REQUIRED YES) + +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + find_package(CIRCT REQUIRED CONFIG) + + message(STATUS "Using CIRCTConfig.cmake in: ${CIRCT_DIR}") + message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") + message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") + + set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin) + set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib) + set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR}) + + list(APPEND CMAKE_MODULE_PATH "${CIRCT_CMAKE_DIR}") + list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") + list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") + + include(TableGen) + include(AddLLVM) + include(AddMLIR) + include(AddCIRCT) + include(HandleLLVMOptions) +endif() + +set(CIRCT_STANDALONE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(CIRCT_STANDALONE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) + +include_directories(${LLVM_INCLUDE_DIRS}) +include_directories(${MLIR_INCLUDE_DIRS}) +include_directories(${CIRCT_INCLUDE_DIRS}) +include_directories(${CIRCT_STANDALONE_SOURCE_DIR}/include) +include_directories(${CIRCT_STANDALONE_BINARY_DIR}/include) +link_directories(${LLVM_BUILD_LIBRARY_DIR}) +link_directories(${CIRCT_LIBRARY_DIRS}) +add_definitions(${LLVM_DEFINITIONS}) + +option(CIRCT_STANDALONE_INCLUDE_TESTS + "Generate build targets for the CIRCT standalone tests." ON) + +add_subdirectory(include) +add_subdirectory(lib) +add_subdirectory(circt-standalone-opt) +set(CIRCT_STANDALONE_HAS_PLUGIN OFF) +if(NOT WIN32 AND TARGET circt-opt) + add_subdirectory(circt-standalone-plugin) + set(CIRCT_STANDALONE_HAS_PLUGIN ON) +endif() +if(CIRCT_STANDALONE_INCLUDE_TESTS) + add_subdirectory(test) +endif() diff --git a/examples/circt-standalone/README.md b/examples/circt-standalone/README.md new file mode 100644 index 000000000000..8df1074d10b4 --- /dev/null +++ b/examples/circt-standalone/README.md @@ -0,0 +1,34 @@ +# CIRCT Standalone Example + +This is a minimal out-of-tree CIRCT project, modeled after MLIR's +`examples/standalone`, for bootstrapping a dialect, pass library, optimizer +driver, and plugin. + +Configure it against a CIRCT build or install tree: + +```sh +cd examples/circt-standalone +mkdir build-circt-standalone +CIRCT_BUILD_DIR= +# This the same as CIRCT_BUILD_DIR when unified build is used +MLIR_BUILD_DIR= +cmake -G Ninja -S . -B build-circt-standalone \ + -DCIRCT_DIR=$CIRCT_BUILD_DIR/lib/cmake/circt \ + -DMLIR_DIR=$MLIR_BUILD_DIR/lib/cmake/mlir +``` + +Build the optimizer, plugin, and tests: + +```sh +ninja -C build-circt-standalone check-circt-standalone +``` + +It can also be enabled in the CIRCT tree with `-DCIRCT_INCLUDE_EXAMPLES=ON`. + +The plugin can be loaded into `circt-opt`: + +```sh +circt-opt input.mlir \ + --load-dialect-plugin=build-circt-standalone/lib/CIRCTStandalonePlugin.so \ + --pass-pipeline='builtin.module(circt-standalone-rename-hw-module)' +``` diff --git a/examples/circt-standalone/circt-standalone-opt/CMakeLists.txt b/examples/circt-standalone/circt-standalone-opt/CMakeLists.txt new file mode 100644 index 000000000000..410f031db655 --- /dev/null +++ b/examples/circt-standalone/circt-standalone-opt/CMakeLists.txt @@ -0,0 +1,25 @@ +set(LLVM_LINK_COMPONENTS + Support +) + +add_llvm_executable(circt-standalone-opt + circt-standalone-opt.cpp + + DEPENDS + SUPPORT_PLUGINS +) + +llvm_update_compile_flags(circt-standalone-opt) + +target_link_libraries(circt-standalone-opt + PRIVATE + CIRCTStandalone + CIRCTHW + MLIRIR + MLIROptLib + MLIRParser + MLIRSupport + MLIRTransforms +) + +export_executable_symbols_for_plugins(circt-standalone-opt) diff --git a/examples/circt-standalone/circt-standalone-opt/circt-standalone-opt.cpp b/examples/circt-standalone/circt-standalone-opt/circt-standalone-opt.cpp new file mode 100644 index 000000000000..3298ce2a86ca --- /dev/null +++ b/examples/circt-standalone/circt-standalone-opt/circt-standalone-opt.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "CIRCTStandalone/CIRCTStandaloneDialect.h" +#include "CIRCTStandalone/CIRCTStandalonePasses.h" +#include "circt/Dialect/HW/HWDialect.h" +#include "circt/Support/Version.h" +#include "mlir/Pass/PassRegistry.h" +#include "mlir/Tools/mlir-opt/MlirOptMain.h" +#include "mlir/Transforms/Passes.h" +#include "llvm/Support/PrettyStackTrace.h" + +int main(int argc, char **argv) { + llvm::setBugReportMsg(circt::circtBugReportMsg); + + mlir::DialectRegistry registry; + registry.insert(); + registry.insert(); + + circt::standalone::registerPasses(); + mlir::registerCanonicalizerPass(); + mlir::registerCSEPass(); + llvm::cl::AddExtraVersionPrinter( + [](llvm::raw_ostream &os) { os << circt::getCirctVersion() << '\n'; }); + + return mlir::failed(mlir::MlirOptMain( + argc, argv, "CIRCT standalone optimizer driver", registry)); +} diff --git a/examples/circt-standalone/circt-standalone-plugin/CMakeLists.txt b/examples/circt-standalone/circt-standalone-plugin/CMakeLists.txt new file mode 100644 index 000000000000..fea787cf2381 --- /dev/null +++ b/examples/circt-standalone/circt-standalone-plugin/CMakeLists.txt @@ -0,0 +1,17 @@ +add_llvm_library(CIRCTStandalonePlugin + MODULE BUILDTREE_ONLY + circt-standalone-plugin.cpp + + DEPENDS + CIRCTStandalone + PLUGIN_TOOL + circt-opt + + LINK_LIBS + CIRCTStandalone +) + +target_include_directories(CIRCTStandalonePlugin + PRIVATE + "${CIRCT_STANDALONE_BINARY_DIR}/include" +) diff --git a/examples/circt-standalone/circt-standalone-plugin/circt-standalone-plugin.cpp b/examples/circt-standalone/circt-standalone-plugin/circt-standalone-plugin.cpp new file mode 100644 index 000000000000..6fb92800edc4 --- /dev/null +++ b/examples/circt-standalone/circt-standalone-plugin/circt-standalone-plugin.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "CIRCTStandalone/CIRCTStandaloneDialect.h" +#include "CIRCTStandalone/CIRCTStandalonePasses.h" +#include "mlir/Tools/Plugins/DialectPlugin.h" +#include "mlir/Tools/Plugins/PassPlugin.h" +#include "llvm/Config/llvm-config.h" +#include "llvm/Support/Compiler.h" + +extern "C" LLVM_ATTRIBUTE_WEAK mlir::DialectPluginLibraryInfo +mlirGetDialectPluginInfo() { + return {MLIR_PLUGIN_API_VERSION, "CIRCTStandalone", LLVM_VERSION_STRING, + [](mlir::DialectRegistry *registry) { + registry->insert(); + circt::standalone::registerPasses(); + }}; +} + +extern "C" LLVM_ATTRIBUTE_WEAK mlir::PassPluginLibraryInfo +mlirGetPassPluginInfo() { + return {MLIR_PLUGIN_API_VERSION, "CIRCTStandalonePasses", LLVM_VERSION_STRING, + []() { circt::standalone::registerPasses(); }}; +} diff --git a/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneDialect.h b/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneDialect.h new file mode 100644 index 000000000000..bbc8dfb04a0b --- /dev/null +++ b/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneDialect.h @@ -0,0 +1,16 @@ +//===- CIRCTStandaloneDialect.h - CIRCT standalone dialect ------*- 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 +// +//===----------------------------------------------------------------------===// + +#ifndef CIRCT_STANDALONE_CIRCTSTANDALONEDIALECT_H +#define CIRCT_STANDALONE_CIRCTSTANDALONEDIALECT_H + +#include "mlir/IR/Dialect.h" + +#include "CIRCTStandalone/CIRCTStandaloneOpsDialect.h.inc" + +#endif // CIRCT_STANDALONE_CIRCTSTANDALONEDIALECT_H diff --git a/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneDialect.td b/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneDialect.td new file mode 100644 index 000000000000..6d7215a2e1fe --- /dev/null +++ b/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneDialect.td @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef CIRCT_STANDALONE_DIALECT +#define CIRCT_STANDALONE_DIALECT + +include "mlir/IR/OpBase.td" + +def CIRCTStandaloneDialect : Dialect { + let name = "circt_standalone"; + let summary = "An out-of-tree CIRCT example dialect"; + let description = [{ + This dialect demonstrates the boilerplate required to build an out-of-tree + CIRCT project with a dialect, passes, an optimizer driver, and a plugin. + }]; + let cppNamespace = "::circt::standalone"; +} + +class CIRCTStandaloneOp traits = []> : + Op; + +#endif // CIRCT_STANDALONE_DIALECT diff --git a/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneOps.h b/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneOps.h new file mode 100644 index 000000000000..106071394fa7 --- /dev/null +++ b/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneOps.h @@ -0,0 +1,22 @@ +//===- CIRCTStandaloneOps.h - CIRCT standalone ops -------------*- 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 +// +//===----------------------------------------------------------------------===// + +#ifndef CIRCT_STANDALONE_CIRCTSTANDALONEOPS_H +#define CIRCT_STANDALONE_CIRCTSTANDALONEOPS_H + +#include "CIRCTStandalone/CIRCTStandaloneDialect.h" +#include "mlir/IR/Builders.h" +#include "mlir/IR/BuiltinTypes.h" +#include "mlir/IR/OpDefinition.h" +#include "mlir/IR/OpImplementation.h" +#include "mlir/Interfaces/SideEffectInterfaces.h" + +#define GET_OP_CLASSES +#include "CIRCTStandalone/CIRCTStandaloneOps.h.inc" + +#endif // CIRCT_STANDALONE_CIRCTSTANDALONEOPS_H diff --git a/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneOps.td b/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneOps.td new file mode 100644 index 000000000000..a5ce32cbb1ca --- /dev/null +++ b/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneOps.td @@ -0,0 +1,25 @@ +//===- CIRCTStandaloneOps.td - CIRCT standalone ops --------*- 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 +// +//===----------------------------------------------------------------------===// + +#ifndef CIRCT_STANDALONE_OPS +#define CIRCT_STANDALONE_OPS + +include "CIRCTStandalone/CIRCTStandaloneDialect.td" +include "mlir/Interfaces/SideEffectInterfaces.td" + +def CIRCTStandalone_FooOp : CIRCTStandaloneOp<"foo", [Pure]> { + let summary = "Illustrates how to define an operation"; + let description = [{ + The `circt_standalone.foo` operation illustrates the minimum TableGen + needed for a custom operation in an out-of-tree CIRCT dialect. + }]; + + let assemblyFormat = "attr-dict"; +} + +#endif // CIRCT_STANDALONE_OPS diff --git a/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandalonePasses.h b/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandalonePasses.h new file mode 100644 index 000000000000..e15c8b446732 --- /dev/null +++ b/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandalonePasses.h @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef CIRCT_STANDALONE_CIRCTSTANDALONEPASSES_H +#define CIRCT_STANDALONE_CIRCTSTANDALONEPASSES_H + +#include "mlir/Pass/Pass.h" + +namespace circt { +namespace standalone { + +#define GEN_PASS_DECL +#include "CIRCTStandalone/CIRCTStandalonePasses.h.inc" + +#define GEN_PASS_REGISTRATION +#include "CIRCTStandalone/CIRCTStandalonePasses.h.inc" + +} // namespace standalone +} // namespace circt + +#endif // CIRCT_STANDALONE_CIRCTSTANDALONEPASSES_H diff --git a/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandalonePasses.td b/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandalonePasses.td new file mode 100644 index 000000000000..bffbf5902874 --- /dev/null +++ b/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandalonePasses.td @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef CIRCT_STANDALONE_PASSES +#define CIRCT_STANDALONE_PASSES + +include "mlir/Pass/PassBase.td" + +def RenameHWModule + : Pass<"circt-standalone-rename-hw-module", "::mlir::ModuleOp"> { + let summary = "Rename a hw.module named `bar` to `foo`"; + let description = [{ + This pass is intentionally small and CIRCT-specific: it finds a top-level + `hw.module @bar` and renames it to `hw.module @foo`. + }]; + let dependentDialects = ["::circt::hw::HWDialect"]; +} + +#endif // CIRCT_STANDALONE_PASSES diff --git a/examples/circt-standalone/include/CIRCTStandalone/CMakeLists.txt b/examples/circt-standalone/include/CIRCTStandalone/CMakeLists.txt new file mode 100644 index 000000000000..277c59809699 --- /dev/null +++ b/examples/circt-standalone/include/CIRCTStandalone/CMakeLists.txt @@ -0,0 +1,5 @@ +add_mlir_dialect(CIRCTStandaloneOps circt_standalone) + +set(LLVM_TARGET_DEFINITIONS CIRCTStandalonePasses.td) +mlir_tablegen(CIRCTStandalonePasses.h.inc -gen-pass-decls) +add_public_tablegen_target(CIRCTStandalonePassesIncGen) diff --git a/examples/circt-standalone/include/CMakeLists.txt b/examples/circt-standalone/include/CMakeLists.txt new file mode 100644 index 000000000000..2f89cd71cce0 --- /dev/null +++ b/examples/circt-standalone/include/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(CIRCTStandalone) diff --git a/examples/circt-standalone/lib/CIRCTStandalone/CIRCTStandaloneDialect.cpp b/examples/circt-standalone/lib/CIRCTStandalone/CIRCTStandaloneDialect.cpp new file mode 100644 index 000000000000..8009dbbd9dbe --- /dev/null +++ b/examples/circt-standalone/lib/CIRCTStandalone/CIRCTStandaloneDialect.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "CIRCTStandalone/CIRCTStandaloneDialect.h" +#include "CIRCTStandalone/CIRCTStandaloneOps.h" + +using namespace circt; +using namespace circt::standalone; + +#include "CIRCTStandalone/CIRCTStandaloneOpsDialect.cpp.inc" + +void CIRCTStandaloneDialect::initialize() { + addOperations< +#define GET_OP_LIST +#include "CIRCTStandalone/CIRCTStandaloneOps.cpp.inc" + >(); +} diff --git a/examples/circt-standalone/lib/CIRCTStandalone/CIRCTStandaloneOps.cpp b/examples/circt-standalone/lib/CIRCTStandalone/CIRCTStandaloneOps.cpp new file mode 100644 index 000000000000..d4b6c312fb00 --- /dev/null +++ b/examples/circt-standalone/lib/CIRCTStandalone/CIRCTStandaloneOps.cpp @@ -0,0 +1,15 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "CIRCTStandalone/CIRCTStandaloneOps.h" + +using namespace circt; +using namespace circt::standalone; + +#define GET_OP_CLASSES +#include "CIRCTStandalone/CIRCTStandaloneOps.cpp.inc" diff --git a/examples/circt-standalone/lib/CIRCTStandalone/CIRCTStandalonePasses.cpp b/examples/circt-standalone/lib/CIRCTStandalone/CIRCTStandalonePasses.cpp new file mode 100644 index 000000000000..5e506f6370ca --- /dev/null +++ b/examples/circt-standalone/lib/CIRCTStandalone/CIRCTStandalonePasses.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "CIRCTStandalone/CIRCTStandalonePasses.h" +#include "circt/Dialect/HW/HWOps.h" +#include "mlir/IR/BuiltinOps.h" + +namespace circt { +namespace standalone { +#define GEN_PASS_DEF_RENAMEHWMODULE +#include "CIRCTStandalone/CIRCTStandalonePasses.h.inc" + +namespace { +struct RenameHWModule : public impl::RenameHWModuleBase { + using impl::RenameHWModuleBase::RenameHWModuleBase; + + void runOnOperation() override { + for (auto module : getOperation().getOps()) + if (module.getName() == "bar") + module.setName("foo"); + } +}; +} // namespace + +} // namespace standalone +} // namespace circt diff --git a/examples/circt-standalone/lib/CIRCTStandalone/CMakeLists.txt b/examples/circt-standalone/lib/CIRCTStandalone/CMakeLists.txt new file mode 100644 index 000000000000..7daa3f7c43a4 --- /dev/null +++ b/examples/circt-standalone/lib/CIRCTStandalone/CMakeLists.txt @@ -0,0 +1,19 @@ +add_mlir_dialect_library(CIRCTStandalone + CIRCTStandaloneDialect.cpp + CIRCTStandaloneOps.cpp + CIRCTStandalonePasses.cpp + + ADDITIONAL_HEADER_DIRS + ${CIRCT_STANDALONE_SOURCE_DIR}/include/CIRCTStandalone + + DEPENDS + MLIRCIRCTStandaloneOpsIncGen + CIRCTStandalonePassesIncGen + + LINK_LIBS PUBLIC + CIRCTHW + MLIRIR + MLIRPass + MLIRSupport + MLIRTransforms +) diff --git a/examples/circt-standalone/lib/CMakeLists.txt b/examples/circt-standalone/lib/CMakeLists.txt new file mode 100644 index 000000000000..2f89cd71cce0 --- /dev/null +++ b/examples/circt-standalone/lib/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(CIRCTStandalone) diff --git a/examples/circt-standalone/test/CIRCTStandalone/dialect.mlir b/examples/circt-standalone/test/CIRCTStandalone/dialect.mlir new file mode 100644 index 000000000000..4df16cc842f4 --- /dev/null +++ b/examples/circt-standalone/test/CIRCTStandalone/dialect.mlir @@ -0,0 +1,6 @@ +// RUN: circt-standalone-opt %s | FileCheck %s + +module { + // CHECK: circt_standalone.foo + circt_standalone.foo +} diff --git a/examples/circt-standalone/test/CIRCTStandalone/pass.mlir b/examples/circt-standalone/test/CIRCTStandalone/pass.mlir new file mode 100644 index 000000000000..99dad38fd52f --- /dev/null +++ b/examples/circt-standalone/test/CIRCTStandalone/pass.mlir @@ -0,0 +1,5 @@ +// RUN: circt-standalone-opt %s --pass-pipeline="builtin.module(circt-standalone-rename-hw-module)" | FileCheck %s + +// CHECK-LABEL: hw.module @foo() +hw.module @bar() { +} diff --git a/examples/circt-standalone/test/CIRCTStandalone/plugin.mlir b/examples/circt-standalone/test/CIRCTStandalone/plugin.mlir new file mode 100644 index 000000000000..786f1ac0ced2 --- /dev/null +++ b/examples/circt-standalone/test/CIRCTStandalone/plugin.mlir @@ -0,0 +1,7 @@ +// UNSUPPORTED: system-windows +// UNSUPPORTED: no-circt-standalone-plugin +// RUN: circt-opt %s --load-dialect-plugin=%circt_standalone_libs/CIRCTStandalonePlugin%shlibext --pass-pipeline="builtin.module(circt-standalone-rename-hw-module)" | FileCheck %s + +// CHECK-LABEL: hw.module @foo() +hw.module @bar() { +} diff --git a/examples/circt-standalone/test/CMakeLists.txt b/examples/circt-standalone/test/CMakeLists.txt new file mode 100644 index 000000000000..ec553d92c35e --- /dev/null +++ b/examples/circt-standalone/test/CMakeLists.txt @@ -0,0 +1,29 @@ +llvm_canonicalize_cmake_booleans( + CIRCT_STANDALONE_HAS_PLUGIN +) + +configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in + ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py + MAIN_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py +) + +set(CIRCT_STANDALONE_TEST_DEPENDS + FileCheck + circt-standalone-opt +) +if(TARGET CIRCTStandalonePlugin) + list(APPEND CIRCT_STANDALONE_TEST_DEPENDS CIRCTStandalonePlugin) +endif() + +add_lit_testsuite(check-circt-standalone + "Running the CIRCT standalone regression tests" + ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${CIRCT_STANDALONE_TEST_DEPENDS} +) +set_target_properties(check-circt-standalone PROPERTIES FOLDER "Tests") + +add_lit_testsuites(CIRCT_STANDALONE ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${CIRCT_STANDALONE_TEST_DEPENDS} +) diff --git a/examples/circt-standalone/test/lit.cfg.py b/examples/circt-standalone/test/lit.cfg.py new file mode 100644 index 000000000000..c45f8ff354d2 --- /dev/null +++ b/examples/circt-standalone/test/lit.cfg.py @@ -0,0 +1,39 @@ +# -*- Python -*- + +import os + +import lit.formats +from lit.llvm import llvm_config + +config.name = "CIRCT_STANDALONE" +config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) +config.suffixes = [".mlir"] +config.test_source_root = os.path.dirname(__file__) +config.test_exec_root = os.path.join(config.circt_standalone_obj_root, "test") + +config.substitutions.append(("%PATH%", config.environment["PATH"])) +config.substitutions.append(("%shlibext", config.llvm_shlib_ext)) +config.substitutions.append( + ("%circt_standalone_libs", config.circt_standalone_libs_dir) +) + +llvm_config.with_system_environment(["HOME", "INCLUDE", "LIB", "TMP", "TEMP"]) +llvm_config.use_default_substitutions() + +config.excludes = ["Inputs", "CMakeLists.txt", "README.txt", "LICENSE.txt"] + +tool_dirs = [ + config.circt_standalone_tools_dir, + config.circt_tools_dir, + config.llvm_tools_dir, +] +tools = [ + "circt-standalone-opt", +] +if config.circt_standalone_has_plugin: + tools.append("circt-opt") + +llvm_config.add_tool_substitutions(tools, tool_dirs) + +if not config.circt_standalone_has_plugin: + config.available_features.add("no-circt-standalone-plugin") diff --git a/examples/circt-standalone/test/lit.site.cfg.py.in b/examples/circt-standalone/test/lit.site.cfg.py.in new file mode 100644 index 000000000000..be64c0f4ecb7 --- /dev/null +++ b/examples/circt-standalone/test/lit.site.cfg.py.in @@ -0,0 +1,14 @@ +@LIT_SITE_CFG_IN_HEADER@ + +config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@") +config.circt_tools_dir = lit_config.substitute("@CIRCT_TOOLS_DIR@") +config.circt_standalone_obj_root = "@CIRCT_STANDALONE_BINARY_DIR@" +config.circt_standalone_tools_dir = "@LLVM_RUNTIME_OUTPUT_INTDIR@" +config.circt_standalone_libs_dir = "@LLVM_LIBRARY_OUTPUT_INTDIR@" +config.circt_standalone_has_plugin = @CIRCT_STANDALONE_HAS_PLUGIN@ +config.llvm_shlib_ext = "@SHLIBEXT@" + +import lit.llvm +lit.llvm.initialize(lit_config, config) + +lit_config.load_config(config, "@CIRCT_STANDALONE_SOURCE_DIR@/test/lit.cfg.py") diff --git a/llvm b/llvm index fb8243f32c95..e6566c571aea 160000 --- a/llvm +++ b/llvm @@ -1 +1 @@ -Subproject commit fb8243f32c955690ebdfdd32eb9aaaf0c391b648 +Subproject commit e6566c571aead7b48bdf13a8c170515abaeea74e From 5c79494661e33f7423e96703dbdc1c700a699f4b Mon Sep 17 00:00:00 2001 From: Hideto Ueno Date: Fri, 29 May 2026 20:41:55 -0700 Subject: [PATCH 2/2] Move wire rename example pass to standalone --- .../workflows/unifiedBuildTestAndInstall.yml | 2 +- CMakeLists.txt | 5 --- examples/CMakeLists.txt | 1 - examples/circt-standalone/README.md | 5 ++- .../CIRCTStandalone/CIRCTStandaloneOps.td | 2 +- .../CIRCTStandalone/CIRCTStandalonePasses.td | 10 ++--- .../CIRCTStandalone/CIRCTStandalonePasses.cpp | 21 ++++++---- .../test/CIRCTStandalone/pass.mlir | 10 +++-- .../test/CIRCTStandalone/plugin.mlir | 8 ++-- examples/circt-standalone/test/lit.cfg.py | 7 ++-- include/circt/Dialect/HW/Passes.td | 11 ----- lib/Dialect/HW/Transforms/CMakeLists.txt | 1 - lib/Dialect/HW/Transforms/FooWires.cpp | 40 ------------------- llvm | 2 +- test/Dialect/HW/foo.mlir | 22 ---------- 15 files changed, 40 insertions(+), 107 deletions(-) delete mode 100644 examples/CMakeLists.txt delete mode 100644 lib/Dialect/HW/Transforms/FooWires.cpp delete mode 100644 test/Dialect/HW/foo.mlir diff --git a/.github/workflows/unifiedBuildTestAndInstall.yml b/.github/workflows/unifiedBuildTestAndInstall.yml index 01dcc6d94841..1fd95e17c7ca 100644 --- a/.github/workflows/unifiedBuildTestAndInstall.yml +++ b/.github/workflows/unifiedBuildTestAndInstall.yml @@ -389,7 +389,7 @@ jobs: # Run cmake. Use one long line for `cmake` so that this works on # Linux/macOS AND Windows. - cmake -G Ninja -S "$(pwd)/../llvm/llvm" -DCMAKE_BUILD_TYPE=${{ inputs.cmake_build_type }} -DBUILD_SHARED_LIBS=${{ inputs.build_shared_libs }} -DLLVM_BUILD_TOOLS=ON -DLLVM_BUILD_EXAMPLES=OFF -DLLVM_ENABLE_ASSERTIONS=${{ inputs.llvm_enable_assertions }} -DLLVM_ENABLE_PROJECTS=mlir -DLLVM_EXTERNAL_PROJECTS=circt -DLLVM_EXTERNAL_CIRCT_SOURCE_DIR=".." -DLLVM_STATIC_LINK_CXX_STDLIB=ON -DLLVM_PARALLEL_LINK_JOBS=1 -DLLVM_TARGETS_TO_BUILD="host" -DLLVM_FORCE_ENABLE_STATS=ON -DLLVM_ENABLE_ZSTD=OFF -DCIRCT_RELEASE_TAG_ENABLED=ON -DCIRCT_RELEASE_TAG=firtool -DCMAKE_EXPORT_COMPILE_COMMANDS=OFF -DCMAKE_C_COMPILER=${{ steps.set-cmake-options.outputs.cmake_c_compiler }} -DCMAKE_CXX_COMPILER=${{ steps.set-cmake-options.outputs.cmake_cxx_compiler }} ${{ steps.configure-sccache.outputs.enable_sccache }} -DCMAKE_INSTALL_PREFIX="$(pwd)/../install" -DLLVM_INSTALL_UTILS=ON -DCIRCT_SLANG_FRONTEND_ENABLED=ON -DLLVM_LIT_ARGS="${{ steps.set-cmake-options.outputs.llvm_lit_args }}" ${{ steps.setup-linux.outputs.cmake }} ${{ steps.setup-macos.outputs.cmake }} ${{ steps.setup-macos-integration.outputs.cmake }} ${{ steps.setup-windows.outputs.cmake }} ${{ steps.integration-test-setup-generic.outputs.cmake }} ${{ inputs.extra_cmake_args }} + cmake -G Ninja -S "$(pwd)/../llvm/llvm" -DCMAKE_BUILD_TYPE=${{ inputs.cmake_build_type }} -DBUILD_SHARED_LIBS=${{ inputs.build_shared_libs }} -DLLVM_BUILD_TOOLS=ON -DLLVM_BUILD_EXAMPLES=OFF -DLLVM_ENABLE_ASSERTIONS=${{ inputs.llvm_enable_assertions }} -DLLVM_ENABLE_PROJECTS=mlir -DLLVM_EXTERNAL_PROJECTS=circt -DLLVM_EXTERNAL_CIRCT_SOURCE_DIR=".." -DLLVM_STATIC_LINK_CXX_STDLIB=ON -DLLVM_PARALLEL_LINK_JOBS=1 -DLLVM_TARGETS_TO_BUILD="host" -DLLVM_FORCE_ENABLE_STATS=ON -DLLVM_ENABLE_ZSTD=OFF -DCIRCT_RELEASE_TAG_ENABLED=ON -DCIRCT_RELEASE_TAG=firtool -DCMAKE_EXPORT_COMPILE_COMMANDS=OFF -DCMAKE_C_COMPILER=${{ steps.set-cmake-options.outputs.cmake_c_compiler }} -DCMAKE_CXX_COMPILER=${{ steps.set-cmake-options.outputs.cmake_cxx_compiler }} ${{ steps.configure-sccache.outputs.enable_sccache }} -DCMAKE_INSTALL_PREFIX="$(pwd)/../install" -DLLVM_INSTALL_UTILS=ON -DCIRCT_SLANG_FRONTEND_ENABLED=ON -DCIRCT_INCLUDE_EXAMPLES=ON -DLLVM_LIT_ARGS="${{ steps.set-cmake-options.outputs.llvm_lit_args }}" ${{ steps.setup-linux.outputs.cmake }} ${{ steps.setup-macos.outputs.cmake }} ${{ steps.setup-macos-integration.outputs.cmake }} ${{ steps.setup-windows.outputs.cmake }} ${{ steps.integration-test-setup-generic.outputs.cmake }} ${{ inputs.extra_cmake_args }} # Optionally test - name: Test CIRCT if: inputs.run_tests diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f8ac5c9c5f7..764681eab908 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -783,11 +783,6 @@ if(CIRCT_INCLUDE_TOOLS) endif() add_subdirectory(frontends) -option(CIRCT_INCLUDE_EXAMPLES "Generate build targets for the CIRCT examples.") -if (CIRCT_INCLUDE_EXAMPLES) - add_subdirectory(examples) -endif() - if (CIRCT_INCLUDE_TESTS) # Test directories are added after everything else so their cmake files can # use targets and target properties defined by the things they test. diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt deleted file mode 100644 index 8cc77ab4eca6..000000000000 --- a/examples/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(circt-standalone) diff --git a/examples/circt-standalone/README.md b/examples/circt-standalone/README.md index 8df1074d10b4..4c3f490270e0 100644 --- a/examples/circt-standalone/README.md +++ b/examples/circt-standalone/README.md @@ -23,12 +23,13 @@ Build the optimizer, plugin, and tests: ninja -C build-circt-standalone check-circt-standalone ``` -It can also be enabled in the CIRCT tree with `-DCIRCT_INCLUDE_EXAMPLES=ON`. +Like MLIR's `examples/standalone`, this example is not built by the in-tree +examples target. Configure it separately as shown above. The plugin can be loaded into `circt-opt`: ```sh circt-opt input.mlir \ --load-dialect-plugin=build-circt-standalone/lib/CIRCTStandalonePlugin.so \ - --pass-pipeline='builtin.module(circt-standalone-rename-hw-module)' + --pass-pipeline='builtin.module(hw.module(circt-standalone-rename-wires))' ``` diff --git a/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneOps.td b/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneOps.td index a5ce32cbb1ca..8cffaacdd9dc 100644 --- a/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneOps.td +++ b/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandaloneOps.td @@ -1,4 +1,4 @@ -//===- CIRCTStandaloneOps.td - CIRCT standalone ops --------*- tablegen -*-===// +//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandalonePasses.td b/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandalonePasses.td index bffbf5902874..116d8403edb2 100644 --- a/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandalonePasses.td +++ b/examples/circt-standalone/include/CIRCTStandalone/CIRCTStandalonePasses.td @@ -11,12 +11,12 @@ include "mlir/Pass/PassBase.td" -def RenameHWModule - : Pass<"circt-standalone-rename-hw-module", "::mlir::ModuleOp"> { - let summary = "Rename a hw.module named `bar` to `foo`"; +def RenameWires + : Pass<"circt-standalone-rename-wires", "hw::HWModuleOp"> { + let summary = "Rename all hw.wire operations in a module"; let description = [{ - This pass is intentionally small and CIRCT-specific: it finds a top-level - `hw.module @bar` and renames it to `hw.module @foo`. + This pass is intentionally small and CIRCT-specific: it walks a hardware + module and renames each `hw.wire` operation to `foo_`. }]; let dependentDialects = ["::circt::hw::HWDialect"]; } diff --git a/examples/circt-standalone/lib/CIRCTStandalone/CIRCTStandalonePasses.cpp b/examples/circt-standalone/lib/CIRCTStandalone/CIRCTStandalonePasses.cpp index 5e506f6370ca..43472096c978 100644 --- a/examples/circt-standalone/lib/CIRCTStandalone/CIRCTStandalonePasses.cpp +++ b/examples/circt-standalone/lib/CIRCTStandalone/CIRCTStandalonePasses.cpp @@ -3,26 +3,33 @@ // 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 +//===----------------------------------------------------------------------===// +// +// Replace all wire names with foo. // //===----------------------------------------------------------------------===// #include "CIRCTStandalone/CIRCTStandalonePasses.h" #include "circt/Dialect/HW/HWOps.h" -#include "mlir/IR/BuiltinOps.h" + +#include namespace circt { namespace standalone { -#define GEN_PASS_DEF_RENAMEHWMODULE +#define GEN_PASS_DEF_RENAMEWIRES #include "CIRCTStandalone/CIRCTStandalonePasses.h.inc" namespace { -struct RenameHWModule : public impl::RenameHWModuleBase { - using impl::RenameHWModuleBase::RenameHWModuleBase; +// A test pass that simply replaces all wire names with foo_. +struct RenameWires : public impl::RenameWiresBase { + using impl::RenameWiresBase::RenameWiresBase; void runOnOperation() override { - for (auto module : getOperation().getOps()) - if (module.getName() == "bar") - module.setName("foo"); + size_t nWires = 0; // Counts the number of wires modified. + getOperation().walk( + [&](hw::WireOp wire) { // Walk over every wire in the module. + wire.setName("foo_" + std::to_string(nWires++)); // Rename said wire. + }); } }; } // namespace diff --git a/examples/circt-standalone/test/CIRCTStandalone/pass.mlir b/examples/circt-standalone/test/CIRCTStandalone/pass.mlir index 99dad38fd52f..e16279e953e4 100644 --- a/examples/circt-standalone/test/CIRCTStandalone/pass.mlir +++ b/examples/circt-standalone/test/CIRCTStandalone/pass.mlir @@ -1,5 +1,9 @@ -// RUN: circt-standalone-opt %s --pass-pipeline="builtin.module(circt-standalone-rename-hw-module)" | FileCheck %s +// RUN: circt-standalone-opt %s --circt-standalone-rename-wires | FileCheck %s -// CHECK-LABEL: hw.module @foo() -hw.module @bar() { +hw.module @foo(in %a: i32, out out: i32) { + // CHECK: %foo_0 = hw.wire %a + // CHECK: %foo_1 = hw.wire %foo_0 + %wire_a = hw.wire %a name "wire_a" : i32 + %wire_b = hw.wire %wire_a name "wire_b" : i32 + hw.output %wire_b : i32 } diff --git a/examples/circt-standalone/test/CIRCTStandalone/plugin.mlir b/examples/circt-standalone/test/CIRCTStandalone/plugin.mlir index 786f1ac0ced2..0913d3e12b86 100644 --- a/examples/circt-standalone/test/CIRCTStandalone/plugin.mlir +++ b/examples/circt-standalone/test/CIRCTStandalone/plugin.mlir @@ -1,7 +1,9 @@ // UNSUPPORTED: system-windows // UNSUPPORTED: no-circt-standalone-plugin -// RUN: circt-opt %s --load-dialect-plugin=%circt_standalone_libs/CIRCTStandalonePlugin%shlibext --pass-pipeline="builtin.module(circt-standalone-rename-hw-module)" | FileCheck %s +// RUN: circt-opt %s --load-dialect-plugin=%circt_standalone_libs/CIRCTStandalonePlugin%shlibext --pass-pipeline="builtin.module(hw.module(circt-standalone-rename-wires))" | FileCheck %s -// CHECK-LABEL: hw.module @foo() -hw.module @bar() { +hw.module @foo(in %a: i32, out out: i32) { + // CHECK: %foo_0 = hw.wire %a + %wire_a = hw.wire %a name "wire_a" : i32 + hw.output %wire_a : i32 } diff --git a/examples/circt-standalone/test/lit.cfg.py b/examples/circt-standalone/test/lit.cfg.py index c45f8ff354d2..b38ad07a21bf 100644 --- a/examples/circt-standalone/test/lit.cfg.py +++ b/examples/circt-standalone/test/lit.cfg.py @@ -14,8 +14,7 @@ config.substitutions.append(("%PATH%", config.environment["PATH"])) config.substitutions.append(("%shlibext", config.llvm_shlib_ext)) config.substitutions.append( - ("%circt_standalone_libs", config.circt_standalone_libs_dir) -) + ("%circt_standalone_libs", config.circt_standalone_libs_dir)) llvm_config.with_system_environment(["HOME", "INCLUDE", "LIB", "TMP", "TEMP"]) llvm_config.use_default_substitutions() @@ -31,9 +30,9 @@ "circt-standalone-opt", ] if config.circt_standalone_has_plugin: - tools.append("circt-opt") + tools.append("circt-opt") llvm_config.add_tool_substitutions(tools, tool_dirs) if not config.circt_standalone_has_plugin: - config.available_features.add("no-circt-standalone-plugin") + config.available_features.add("no-circt-standalone-plugin") diff --git a/include/circt/Dialect/HW/Passes.td b/include/circt/Dialect/HW/Passes.td index fea4baac78b4..d5d7585bdd18 100644 --- a/include/circt/Dialect/HW/Passes.td +++ b/include/circt/Dialect/HW/Passes.td @@ -109,17 +109,6 @@ def VerifyInnerRefNamespace : Pass<"hw-verify-irn"> { let summary = "Verify InnerRefNamespaceLike operations, if not self-verifying."; } -/** - * Tutorial Pass, doesn't do anything interesting - */ -def FooWires : Pass<"hw-foo-wires", "hw::HWModuleOp"> { - let summary = "Change all wires' name to foo_."; - let description = [{ - Very basic pass that numbers all of the wires in a given module. - The wires' names are then all converte to foo_. - }]; -} - def HWAggregateToComb : Pass<"hw-aggregate-to-comb", "hw::HWModuleOp"> { let summary = "Lower aggregate operations to comb operations"; let description = [{ diff --git a/lib/Dialect/HW/Transforms/CMakeLists.txt b/lib/Dialect/HW/Transforms/CMakeLists.txt index d63933bb4d0e..c3e3ce1ff4cb 100644 --- a/lib/Dialect/HW/Transforms/CMakeLists.txt +++ b/lib/Dialect/HW/Transforms/CMakeLists.txt @@ -10,7 +10,6 @@ add_circt_dialect_library(CIRCTHWTransforms FlattenIO.cpp VerifyInnerRefNamespace.cpp FlattenModules.cpp - FooWires.cpp HWVectorization.cpp DEPENDS diff --git a/lib/Dialect/HW/Transforms/FooWires.cpp b/lib/Dialect/HW/Transforms/FooWires.cpp deleted file mode 100644 index 993b884639b4..000000000000 --- a/lib/Dialect/HW/Transforms/FooWires.cpp +++ /dev/null @@ -1,40 +0,0 @@ -//===- FooWires.cpp - Replace all wire names with foo ------*- 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 -//===----------------------------------------------------------------------===// -// -// Replace all wire names with foo. -// -//===----------------------------------------------------------------------===// - -#include "circt/Dialect/HW/HWOps.h" -#include "circt/Dialect/HW/HWPasses.h" -#include "circt/Dialect/HW/HWTypes.h" -#include "mlir/Pass/Pass.h" - -namespace circt { -namespace hw { -#define GEN_PASS_DEF_FOOWIRES -#include "circt/Dialect/HW/Passes.h.inc" -} // namespace hw -} // namespace circt - -using namespace circt; -using namespace hw; - -namespace { -// A test pass that simply replaces all wire names with foo_ -struct FooWiresPass : circt::hw::impl::FooWiresBase { - void runOnOperation() override; -}; -} // namespace - -void FooWiresPass::runOnOperation() { - size_t nWires = 0; // Counts the number of wires modified - getOperation().walk( - [&](hw::WireOp wire) { // Walk over every wire in the module - wire.setName("foo_" + std::to_string(nWires++)); // Rename said wire - }); -} diff --git a/llvm b/llvm index e6566c571aea..fb8243f32c95 160000 --- a/llvm +++ b/llvm @@ -1 +1 @@ -Subproject commit e6566c571aead7b48bdf13a8c170515abaeea74e +Subproject commit fb8243f32c955690ebdfdd32eb9aaaf0c391b648 diff --git a/test/Dialect/HW/foo.mlir b/test/Dialect/HW/foo.mlir deleted file mode 100644 index 02f8b4aecf61..000000000000 --- a/test/Dialect/HW/foo.mlir +++ /dev/null @@ -1,22 +0,0 @@ -// RUN: circt-opt --hw-foo-wires %s | FileCheck %s - -hw.module @foo(in %a: i32, in %b: i32, out out: i32) { - // CHECK: %c1_i32 = hw.constant 1 : i32 - // CHECK: %foo_0 = hw.wire %c1_i32 : i32 - // CHECK: %foo_1 = hw.wire %a : i32 - // CHECK: %foo_2 = hw.wire %b : i32 - // CHECK: %0 = comb.add bin %foo_1, %foo_0 : i32 - // CHECK: %foo_3 = hw.wire %0 : i32 - // CHECK: %1 = comb.add bin %foo_3, %foo_2 : i32 - // CHECK: %foo_4 = hw.wire %1 : i32 - // CHECK: hw.output %foo_4 : i32 - %c1 = hw.constant 1 : i32 - %wire_1 = hw.wire %c1 name "wire_1" : i32 - %wire_a = hw.wire %a name "wire_a" : i32 - %wire_b = hw.wire %b name "wire_b" : i32 - %ap1 = comb.add bin %wire_a, %wire_1 : i32 - %wire_ap1 = hw.wire %ap1 name "wire_ap1" : i32 - %ap1pb = comb.add bin %wire_ap1, %wire_b : i32 - %wire_ap1pb = hw.wire %ap1pb : i32 - hw.output %wire_ap1pb : i32 -}