clang 20.0.0git
Solver.h
Go to the documentation of this file.
1//===- Solver.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 an interface for a SAT solver that can be used by
10// dataflow analyses.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SOLVER_H
15#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SOLVER_H
16
18#include "clang/Basic/LLVM.h"
19#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/DenseMap.h"
21#include <optional>
22#include <vector>
23
24namespace clang {
25namespace dataflow {
26
27/// An interface for a SAT solver that can be used by dataflow analyses.
28class Solver {
29public:
30 struct Result {
31 enum class Status {
32 /// Indicates that there exists a satisfying assignment for a boolean
33 /// formula.
35
36 /// Indicates that there is no satisfying assignment for a boolean
37 /// formula.
39
40 /// Indicates that the solver gave up trying to find a satisfying
41 /// assignment for a boolean formula.
43 };
44
45 /// A boolean value is set to true or false in a truth assignment.
46 enum class Assignment : uint8_t { AssignedFalse = 0, AssignedTrue = 1 };
47
48 /// Constructs a result indicating that the queried boolean formula is
49 /// satisfiable. The result will hold a solution found by the solver.
50 static Result Satisfiable(llvm::DenseMap<Atom, Assignment> Solution) {
51 return Result(Status::Satisfiable, std::move(Solution));
52 }
53
54 /// Constructs a result indicating that the queried boolean formula is
55 /// unsatisfiable.