Skip to content

Commit 70bf1d8

Browse files
committed
[LLHD] Update Deseq pass to work with process results
Add an updated version of the desequentialization pass. This new version expects all probes and drives to have been hoisted out of processes, and for the processes to produce the interesting signals as a result. Resets can now be distinguished from clocks more reliably. The previous version of the pass is left untouched for now, since it is used in the circt-verilog pipeline. Once process lowering also works with process results, we can get rid of the old pass implementations in one go. This pass is an absolute headache to implement because of the fuzzy and ill-defined Verilog and VHDL semantics it has to match. I expect us to iterate heavily on this in the future, along the definition of `llhd.process` and potentially process flavors that are more convenient to analyze. In particular, the pass has to do a lot of things in one go: it checks whether a process has only a single wait, if the wait carries past values into the present as block arguments, whether the IR expresses a posedge/negedge detection based on past and present values, whether the process properly observes the necessary triggers values, and it has to match the detected triggers against a very narrow list of things that a register can represent. Life would be easier if we had a more restricted form of processes that already express the basic structure of a loop through a single wait, observed triggers, and which past values are required. This would then also allow us to detect and generate latches, which are missing completely right now. The pass currently performs a data flow analysis by propagating DNFs and tables of potential result values across a lattice. I'm not too happy with this implementation, and doing a depth-first traversal of the IR may be a better approach in the future. We should probably revisit this once we have improved the process op a bit and update this pass again. This commit also adds an implementation of the Disjunctive Normal Form as a way of expressing and manipulating boolean functions. This is necessary to reliably detect if a process computes the posedge or negedge of a value. In the future we may want to switch this to a more compact representation of the underlying truth table, which can be done fairly efficiently using APInt. The current implementation of `DNF::optimize()` already does this internally. Note that DNFs are very inefficient at representing arbitrary boolean functions, as they have a tendency to grow exponentially. Therefore care must be taken that only operations on potential trigger values of sequential processes are captured in the DNF, and all other values are kept as opaque values. This keeps the complexity bounded.
1 parent 06d0c5d commit 70bf1d8

File tree

10 files changed

+3395
-0
lines changed

10 files changed

+3395
-0
lines changed

include/circt/Dialect/LLHD/IR/LLHDStructureOps.td

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def FinalOp : LLHDOp<"final", [
9191
def WaitOp : LLHDOp<"wait", [
9292
AttrSizedOperandSegments,
9393
HasParent<"ProcessOp">,
94+
Pure,
9495
Terminator,
9596
]> {
9697
let summary = "Suspend execution of a process";
@@ -131,6 +132,7 @@ def WaitOp : LLHDOp<"wait", [
131132

132133
def HaltOp : LLHDOp<"halt", [
133134
ParentOneOf<["ProcessOp", "FinalOp"]>,
135+
Pure,
134136
Terminator,
135137
]> {
136138
let summary = "Terminate execution of a process";

include/circt/Dialect/LLHD/Transforms/LLHDPasses.td

+10
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,14 @@ def LowerProcessesPass : Pass<"llhd-lower-processes", "hw::HWModuleOp"> {
162162
];
163163
}
164164

165+
def DeseqPass : Pass<"llhd-deseq", "hw::HWModuleOp"> {
166+
let summary = "Convert sequential processes to registers";
167+
let dependentDialects = [
168+
"comb::CombDialect",
169+
"hw::HWDialect",
170+
"mlir::scf::SCFDialect",
171+
"seq::SeqDialect",
172+
];
173+
}
174+
165175
#endif // CIRCT_DIALECT_LLHD_TRANSFORMS_PASSES

lib/Dialect/LLHD/Transforms/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
add_circt_dialect_library(CIRCTLLHDTransforms
2+
Deseq.cpp
23
DesequentializationPass.cpp
4+
DNF.cpp
35
EarlyCodeMotionPass.cpp
46
FunctionEliminationPass.cpp
57
HoistSignals.cpp

0 commit comments

Comments
 (0)