How llvm/circt works
The CIRCT project is a highly modular, compiler-style infrastructure built on top of the LLVM/MLIR ecosystem. At its core, it provides a framework for compiling and translating various circuit intermediate representations (IRs) (such as FIRRTL, HW, ESI, etc.) using the modern compiler techniques established in LLVM. In essence, the system can be seen as a “full-stack” compiler and toolset that integrates with MLIR and exposes a series of dialects, conversion passes, and frontend/back-end tools.
Main Components
• Core Compiler Infrastructure: This includes the central libraries in the “lib” directory and the “include” files that define CIRCT APIs, dialect definitions, conversion passes, and transformation utilities.
• Dialect Implementations: CIRCT supports many hardware IR dialects. Each dialect is implemented in its own subdirectory (for example, in include/circt/Dialect, lib/Dialect, and unittests/Dialect) and has associated transformation passes and lowering utilities.
• Frontends and Bindings: The “frontends” directory (including the PyCDE and PyRTG subdirectories) and the “lib/Bindings” (Python and C API) show how CIRCT offers integration with higher-level languages and interactive environments.
• Conversion and Transformation Passes: There is extensive conversion infrastructure (the “lib/Conversion” directory) that translates from one IR or dialect to another (for example, FIRRTLToHW, CombToLLVM, etc.). Group these as the “Compiler Passes” component.
• Tools and Executables: The “tools” directory contains command-line programs (e.g., circt-as, circt-opt, circt-bmc, circt-synth, etc.) that provide different functionalities such as assembly/disassembly, RTL simulation, formal verification, and more.
• Testing Infrastructure: With “test”, “integration_test”, “unittests”, and “docs”, CIRCT places strong emphasis on validation. This component not only tests individual components and dialects but also ensures the correctness of end-to-end flows.
• External Dependencies and Build Infrastructure: The system deeply integrates LLVM/MLIR as a submodule (set up and built with CMake and Ninja). Also include support scripts in “utils” that help set up or interface with external EDA tools.
Relationships and Data Flow
• Once inside the compiler pipeline, the IR traverses a series of dialect-specific passes (conversion, lowering, optimization) that eventually lead to output formats such as Verilog, SystemC, or other hardware configuration formats.
Architectural Patterns and Design Principles
• Layered Design: The system is layered from high-level frontend interfaces (e.g., Python and TCL) on top, with core C++ libraries in the middle, and low-level backends emitting target-specific output.
• Reusability and Extensibility: Emphasize that many of these modules (e.g., the transformation passes) are designed to be plug‐in in nature, which enables the reusability of infrastructure across different parts of the hardware design space.
• Testability: Include a testing layer that interacts with nearly every component, demonstrating the drive for both unit and integration testing.
Practical Steps for the Principal Software Engineer
• Drill down into the “Core Compiler” block by including interrelated modules from the “lib” and “include” directories.
• Out major dialect-specific paths – for instance, indicate that the FIRRTL dialect is processed by dedicated conversion passes leading to hardware outputs.