K-CIRCT: A Layered, Composable, and Executable Formal Semantics for CIRCT Hardware IRs

Jianhong Zhao, Jinhui Kang, Yongwang ZhaoarXiv 2024 · DOI

TL;DR

This paper introduces K-CIRCT, the first formal semantics for CIRCT, an LLVM-like compiler infrastructure for hardware description languages. By employing a layered approach and a novel generic hardware model, K-CIRCT enables composable and extensible formalization of CIRCT dialects, paving the way for rigorous hardware verification and bug-finding tools.

What Problem Does This Paper Address?

Modern hardware design relies on complex compiler infrastructures like CIRCT, which, similar to LLVM for software, aims to unify various hardware description languages (HDLs) and modern hardware design languages. However, CIRCT currently lacks formal semantics. This absence is a significant hurdle for formal hardware verification, as it prevents proving the correctness of hardware designs, compilers, and synthesized circuits. Furthermore, crucial tools like symbolic test generators and bounded model checkers cannot function reliably without a definitive formal semantics. The challenge is compounded by CIRCT's multi-dialect nature, requiring semantics that are both composable (handling multiple dialects together) and extensible (adapting to new or modified dialects).

Methods

The authors propose K-CIRCT, a formal semantics for CIRCT built using the K framework. Their approach is layered:

  1. MLIR Static Semantics: This foundational layer formalizes the generic MLIR syntax and provides a state (Smlir) to manage preprocessed information. It acts as a domain-agnostic interface for higher layers.
  2. CIRCT Common Semantics: This layer introduces a generic hardware model that captures essential hardware features across different CIRCT dialects. It uses effectful functions to provide a unified interface for accessing hardware-specific details without being tied to any particular dialect. This layer is crucial for handling hardware's inherent concurrency and sequential logic.
  3. Specific Dialect Semantics: Individual CIRCT dialects (like hw, comb, seq, sv) are then formalized using a unified approach. This involves breaking down operations into minimal semantic units and composing their semantics.

A key innovation is the use of "effectful functions" (EFs) which act as interfaces, allowing different semantic layers to interact and share state without tight coupling. Some EFs are "auto-triggered," simplifying the formalization process. The authors also developed a simulator, Kimulator, based on their K semantics for executable validation.

Datasets

The paper does not explicitly mention training datasets. For evaluation, they used:

  • Full-Rule Coverage Test Suite: A custom suite of 86 CIRCT/MLIR programs designed to test all semantic rules and formalized operations.
  • RISC-V Design (riscv-mini): A popular, simplified 3-stage RISC-V pipeline implemented in Chisel. This design, compiled into over 1000 lines of CIRCT code, was used to assess the practicality and coverage of the formalized semantics for complex hardware designs.

Key Insights and Ideas

  • Layered Semantics for Composability: The hierarchical structure (MLIR -> CIRCT Common -> Specific Dialects) is key to managing the complexity of multi-dialect systems like CIRCT. Upper layers provide composability and extensibility for lower layers.
  • Generic Hardware Model: Abstracting common hardware features (combinational logic, sequential logic, concurrency) into a single model simplifies the formalization of individual, specialized dialects.
  • Effectful Functions as Unifying Interfaces: EFs are critical for decoupling semantic layers and enabling seamless interaction, making the system more modular and easier to extend.
  • Formal Semantics as a Foundation for Tools: The K-based formal semantics directly enables the creation of executable simulators (Kimulator), symbolic executors, and formal verifiers, which are essential for robust hardware development.
  • MLIR's Potential and Challenges: While MLIR aims to unify compiler infrastructure, its formalization is complex due to its extensibility and multi-dialect nature, highlighting the need for approaches like K-CIRCT.

Key Results

  • K-CIRCT provides the first formal semantics for CIRCT, enabling simulation of complex hardware designs like a RISC-V processor.
  • The semantics successfully passed all operation-level validation tests, demonstrating its correctness.
  • The approach successfully formalized core CIRCT dialects (hw, comb, seq, sv).
  • The developed simulator, Kimulator, provides a user-friendly interface for hardware designers to leverage the formal semantics.
  • The validation process uncovered over 20 flaws in the MLIR documentation and numerous issues in CIRCT documentation, highlighting the importance of formalization for identifying such discrepancies.

Limitations and Future Work

  • Documentation Gaps: The authors identified significant issues with MLIR and CIRCT documentation, including missing definitions, inconsistent syntax, and lack of version change tracking. This necessitates repeated checks and manual inference of semantics.
  • Dialect Interdependencies: While aiming for isolation, some operations inherently depend on others (e.g., comb.add within hw.module), requiring careful program adaptation for testing.
  • Underutilized Operations: The hardware-level validation revealed that some operations compiled at the hw-level were underutilized, suggesting potential areas for improvement in capturing the full essence of CIRCT.

Future work includes collaborating with the CIRCT and K communities to enhance scalability, further integrate formal methods into CIRCT tools, and potentially develop more advanced formal analysis tools like equivalence checkers and formal verification frameworks.

Summary updated

BibTeX
@misc{zhao2024k,
  author = {Jianhong Zhao and Jinhui Kang and Yongwang Zhao},
  title = {{K-CIRCT: A Layered, Composable, and Executable Formal Semantics for CIRCT Hardware IRs}},
  year = {2024},
  eprint = {2404.18756},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2404.18756},
}

Loading related content...

Figure