clang  19.0.0git
WatchedLiteralsSolver.h
Go to the documentation of this file.
1 //===- WatchedLiteralsSolver.h ----------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a SAT solver implementation that can be used by dataflow
10 // analyses.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_WATCHEDLITERALSSOLVER_H
15 #define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_WATCHEDLITERALSSOLVER_H
16 
19 #include "llvm/ADT/ArrayRef.h"
20 
21 namespace clang {
22 namespace dataflow {
23 
24 /// A SAT solver that is an implementation of Algorithm D from Knuth's The Art
25 /// of Computer Programming Volume 4: Satisfiability, Fascicle 6. It is based on
26 /// the Davis-Putnam-Logemann-Loveland (DPLL) algorithm [1], keeps references to
27 /// a single "watched" literal per clause, and uses a set of "active" variables
28 /// for unit propagation.
29 //
30 // [1] https://en.wikipedia.org/wiki/DPLL_algorithm
31 class WatchedLiteralsSolver : public Solver {
32  // Count of the iterations of the main loop of the solver. This spans *all*
33  // calls to the underlying solver across the life of this object. It is
34  // reduced with every (non-trivial) call to the solver.
35  //
36  // We give control over the abstract count of iterations instead of concrete
37  // measurements like CPU cycles or time to ensure deterministic results.
39 
40 public:
41  WatchedLiteralsSolver() = default;
42 
43  // `Work` specifies a computational limit on the solver. Units of "work"
44  // roughly correspond to attempts to assign a value to a single
45  // variable. Since the algorithm is exponential in the number of variables,
46  // this is the most direct (abstract) unit to target.
47  explicit WatchedLiteralsSolver(std::int64_t WorkLimit)
48  : MaxIterations(WorkLimit) {}
49 
50  Result solve(llvm::ArrayRef<const Formula *> Vals) override;
51 
52  bool reachedLimit() const override { return MaxIterations == 0; }
53 };
54 
55 } // namespace dataflow
56 } // namespace clang
57 
58 #endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_WATCHEDLITERALSSOLVER_H
__DEVICE__ int max(int __a, int __b)
An interface for a SAT solver that can be used by dataflow analyses.
Definition: Solver.h:28
A SAT solver that is an implementation of Algorithm D from Knuth's The Art of Computer Programming Vo...
Result solve(llvm::ArrayRef< const Formula * > Vals) override
Checks if the conjunction of Vals is satisfiable and returns the corresponding result.
The JSON file list parser is used to communicate input to InstallAPI.
long int64_t