Find UNUSED and UNDRIVEN components in structs
At present Verilator cannot detect unused bits or fields within a struct, due to their representation by nested
AstSel nodes in the AST. I have written a patch to add support for this. It includes a new regression test case.
At present this just reports the bits affected in the flattened struct. In the long term it would be good to be able to report the field names of these parts of the struct. However by the time we get to V3Undriven, this information is gone from the AST. The solution will be either to run this pass earlier, or to carry struct field information forward.
Please review and pull the code from branch unused-structs at https://github.com/jeremybennett/verilator
#1 Updated by Jeremy Bennett about 4 years ago
Some further testing indicates that this doesn't get nested packed multidimensional arrays right. It often seems to report the entire array as undriven, when it is not the case. I'll investigate further, but if you can see what I have got wrong that will be useful.
#2 Updated by Wilson Snyder about 4 years ago
Per variable I think you should make an ordered map which contains a <lsb,width> pair, as you need to handle finding bits in any order. You should not use a vector or map per bit as it will be too memory intensive.
When something is used lookup the newlsb and match if within the range of the entry that is found (foundlsb <= newlsb <= foundlsb+width-1 ) or immediately proceeds it (foundlsb <= newlsb <= foundlsb+width-1). If not found, look at any entry before the hit and possibly extend its width (if foundlsb+width==foundlsb then foundwidth++), or look at the next sequential entry and (if lsb=found+1 decrement foundlsb and increment the foundwidth).
Also available in: Atom