xls icon indicating copy to clipboard operation
xls copied to clipboard

[enhancement] Autogeneration of cover!() for branches

Open ansidu opened this issue 3 months ago • 8 comments

What's hard to do? (limit 100 words)

Covering every if/else branch and match arm requires a hand-written cover!() call at each site. Someone has to remember to insert each call, pick a unique label, and keep the set of covers in sync as branches are added or refactored. There is no way to say "cover all branches" and get complete, up-to-date branch/match coverage for a design.

Current best alternative workaround (limit 100 words)

Add cover!() at the top of each branch and arm by hand, with a manually chosen label per site. This is repeated for every feature and re-reviewed after refactors, with no enforcement that a new branch got its cover or that labels stay unique. Coverage completeness depends on remembering every site, which does not scale across a large code base.

Your view of the "best case XLS enhancement" (limit 100 words)

Have the compiler auto-insert a cover for every if/else branch and match arm, so branch/match coverage is produced automatically instead of by hand. Each synthesized cover should get a stable, unique identity that can be traced back to the source construct it measured, with no manual effort and nothing to keep in sync as control flow changes.

ansidu avatar Sep 03 '26 15:09 ansidu

Actually, I've already had something that worked for me here, so here's a link to a PR with a proposed fix: https://github.com/google/xls/pull/4904

That said, I'm open to discussing other ways to implement the same functionality — and whether this functionality is needed at all.

ansidu avatar Sep 03 '26 15:09 ansidu

Hi, @erinzmoore @richmckeever @dplassgit @allight @ericastor

I realize this may be slightly outside your usual area of focus, but I'd appreciate any feedback you may have.

My main question is not about the implementation details, but whether the proposed functionality itself is something that would be desirable in XLS.

I've implemented a PoC in https://github.com/google/xls/pull/4904 to demonstrate the idea.

If there is someone else who whould be better suited to comment on this area, I'd greatly appreciate any pointers.

Thanks for any thoughts or guidance

ansidu avatar Sep 08 '26 09:09 ansidu

This could well be a nice feature - though I do need to mention that as written, I read this more like you meant this should be on by default. The PR makes it clearer that you meant it as an opt-in feature.

I'll leave it to the DSLX team to decide whether they'd like it as a feature, though. Please give them a bit to actually take a look & give an opinion, since it's only been ~1.5 business days since you sent this here in the US. (Holiday weekend!)

ericastor avatar Sep 08 '26 11:09 ericastor

Quick note: "Each synthesized cover should get a stable, unique identity" seems difficult - and maybe impossible to automate! The name of each auto-generated cover node will presumably change as the source code changes.

That's probably okay, but we do need to be honest about our goals.

ericastor avatar Sep 08 '26 13:09 ericastor

Assigned to @richmckeever to decide if we want this to proceed.

dplassgit avatar Sep 14 '26 15:09 dplassgit

Thumbs up for accepting the feature after your code review is done.

richmckeever avatar Sep 14 '26 15:09 richmckeever

@ansidu sorry for the back and forth and this, we were discussing https://github.com/google/xls/issues/4963 (and https://github.com/google/xls/issues/4903) as a team, and we had some follow-up questions before we consider landing the PR related to this.

I seeded a new discussion https://github.com/google/xls/issues/4963#issuecomment-6181484888

Note: I also wanted to mention that we have a few older issues about improving coverage support (https://github.com/google/xls/issues/2139, https://github.com/google/xls/issues/1126, https://github.com/google/xls/issues/499) and I also acknowledge that our documentation is lacking around what's currently supported (just added https://github.com/google/xls/issues/5145).

proppy avatar Oct 15 '26 00:10 proppy

Hey @ansidu, on this feature, I had a couple concerns:

  • since cover! is currently pretty coupled to SV concurrent properties, turning auto-generation on for all branches in a design seems like the wrong thing to do at the RTL level. It will introduce a lot of slowdown in RTL simulation (SVA concurrent assertions are triggered every clock cycle).
  • it's reasonable in DSLX to generate unreachable branches b/c functions can be used in multiple contexts. Adding auto-generated covers for dead branches of a function (especially without #4963) means we could end up with a large number of unreachable covers. That seems bad for things like formal verification and coverage DBs.

One idea is if you could limit this to annotations at a more granular level, e.g. on specific functions or match expressions. Another idea is to scope this to find a solution at the interpreter/JIT level rather than something that affects SV codegen. That would ameliorate these concerns to a certain extent.

mikex-oss avatar Oct 16 '26 22:10 mikex-oss