1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Target-agnostic SSA (Static Single Assignment) intermediate representation core.
//!
//! This module defines the generic SSA IR types used by RASSA. The IR is parameterized
//! over a [`crate::Target`] trait, allowing different host instruction sets (CIL, etc.)
//! to reuse the same SSA infrastructure. Hosts extend these types through their own
//! `Target` implementation and host-specific extension traits or inherent impls.
//!
//! # Architecture
//!
//! The SSA IR is organized into several sub-modules, each handling a specific aspect:
//!
//! | Module | Purpose |
//! |--------|---------|
//! | [`block`] | Basic blocks containing phi nodes and instructions |
//! | [`instruction`] | SSA instruction wrapper with def/use metadata |
//! | [`ops`] | Decomposed SSA operations (`SsaOp` enum with all op variants) |
//! | [`phi`] | Phi nodes for merging values at control flow joins |
//! | [`value`] | Constant values, abstract value lattice, and CSE tracking |
//! | [`variable`] | Variable IDs, origins, def/use sites, and per-function allocators |
//! | [`exception`] | Exception handler preservation through SSA transformations |
//! | [`function`] | Complete SSA function representation with rebuild/repair/canonicalize |
//!
//! # SSA Construction Pipeline
//!
//! 1. **CIL to SSA**: The `SsaConverter` simulates the stack, creates explicit variables,
//! places phi nodes at dominance frontiers, and renames to achieve single-assignment.
//! 2. **Optimization**: Analysis passes operate on the SSA form (constant propagation,
//! copy propagation, DCE, GVN, etc.).
//! 3. **Repair/Rebuild**: After passes, `repair_ssa()` handles instruction-only changes;
//! `rebuild_ssa()` performs full SSA reconstruction after CFG modifications.
//! 4. **Canonicalize**: Final cleanup (strip nops, remove empty blocks, compact indices)
//! before code generation.
//!
//! # Key Design Decisions
//!
//! - **Target genericity**: All types are parameterized on `T: Target`, allowing
//! host-specific metadata (types, methods, fields) without losing SSA structure.
//! - **Dense variable IDs**: `SsaVarId` indices are dense per-function (0, 1, 2, ...)
//! enabling O(1) variable lookup via direct vector indexing.
//! - **Explicit def/use**: Every SSA operation tracks its destination and operands,
//! enabling direct def-use chain construction without scanning.
//! - **Thread safety**: All IR types implement `Send` and `Sync`.
pub use ;
pub use ;
pub use ;
pub use SsaInstruction;
pub use ;
pub use ;
pub use ;
pub use ;