This is an archive of the discontinued LLVM Phabricator instance.

[dataflow] Make SAT solver deterministic
ClosedPublic

Authored by sammccall on Jun 22 2023, 12:56 PM.

Details

Summary

The SAT solver imported its constraints by iterating over an unordered DenseSet.
The path taken, and ultimately the runtime, the specific solution found, and
whether it would time out or complete could depend on the iteration order.

Instead, have the caller specify an ordered collection of constraints.
If this is built in a deterministic way, the system can have deterministic
behavior.
(The main alternative is to sort the constraints by value, but this option
is simpler today).

A lot of nondeterminism still appears to be remain in the framework, so today
the solver's inputs themselves are not deterministic yet.

Diff Detail

Event Timeline

sammccall created this revision.Jun 22 2023, 12:56 PM
Herald added a project: Restricted Project. · View Herald Transcript
sammccall requested review of this revision.Jun 22 2023, 12:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 22 2023, 12:56 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Is there a measurable perf cost for this determinism?

gribozavr2 accepted this revision.Jun 23 2023, 3:21 AM
This revision is now accepted and ready to land.Jun 23 2023, 3:21 AM

Is there a measurable perf cost for this determinism?

I'm going to say no...
All the extra cost is paid in addTransitiveFlowConditionConstraints. (We were building a set, now we're building a set + vector. The sat solver is actually doing *less* work now). I can't measure any difference in that function's runtime, and it's cheap enough to be trivial anyway.

On all of ClangAnalysisFlowSensitiveTests (release+asserts), with this patch:

  • total time is 7.5s
  • clang parsing is 6.1s (81%)
  • sat solving in DataflowAnalysisContext is 75ms (1.0%)
  • addTransitiveFlowConditionConstraints is 2.5ms (0.033%)

even if 100% of addTransitiveFlowConditionConstraints was added by this patch, it's still negligible compared to actual sat solving. These are toy examples, but sat solving scales worse almost by definition.

This revision was landed with ongoing or failed builds.Jun 26 2023, 12:16 PM
This revision was automatically updated to reflect the committed changes.