/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Analysis/FlowSensitive/Arena.cpp
Line | Count | Source |
1 | | //===-- Arena.cpp ---------------------------------------------------------===// |
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 | | #include "clang/Analysis/FlowSensitive/Arena.h" |
10 | | |
11 | | namespace clang::dataflow { |
12 | | |
13 | | static std::pair<BoolValue *, BoolValue *> |
14 | 15.6k | makeCanonicalBoolValuePair(BoolValue &LHS, BoolValue &RHS) { |
15 | 15.6k | auto Res = std::make_pair(&LHS, &RHS); |
16 | 15.6k | if (&RHS < &LHS) |
17 | 9.92k | std::swap(Res.first, Res.second); |
18 | 15.6k | return Res; |
19 | 15.6k | } |
20 | | |
21 | 2.57k | BoolValue &Arena::makeAnd(BoolValue &LHS, BoolValue &RHS) { |
22 | 2.57k | if (&LHS == &RHS) |
23 | 2 | return LHS; |
24 | | |
25 | 2.57k | auto Res = ConjunctionVals.try_emplace(makeCanonicalBoolValuePair(LHS, RHS), |
26 | 2.57k | nullptr); |
27 | 2.57k | if (Res.second) |
28 | 1.83k | Res.first->second = &create<ConjunctionValue>(LHS, RHS); |
29 | 2.57k | return *Res.first->second; |
30 | 2.57k | } |
31 | | |
32 | 1.15k | BoolValue &Arena::makeOr(BoolValue &LHS, BoolValue &RHS) { |
33 | 1.15k | if (&LHS == &RHS) |
34 | 2 | return LHS; |
35 | | |
36 | 1.15k | auto Res = DisjunctionVals.try_emplace(makeCanonicalBoolValuePair(LHS, RHS), |
37 | 1.15k | nullptr); |
38 | 1.15k | if (Res.second) |
39 | 1.12k | Res.first->second = &create<DisjunctionValue>(LHS, RHS); |
40 | 1.15k | return *Res.first->second; |
41 | 1.15k | } |
42 | | |
43 | 4.25k | BoolValue &Arena::makeNot(BoolValue &Val) { |
44 | 4.25k | auto Res = NegationVals.try_emplace(&Val, nullptr); |
45 | 4.25k | if (Res.second) |
46 | 1.72k | Res.first->second = &create<NegationValue>(Val); |
47 | 4.25k | return *Res.first->second; |
48 | 4.25k | } |
49 | | |
50 | 421 | BoolValue &Arena::makeImplies(BoolValue &LHS, BoolValue &RHS) { |
51 | 421 | if (&LHS == &RHS) |
52 | 1 | return makeLiteral(true); |
53 | | |
54 | 420 | auto Res = ImplicationVals.try_emplace(std::make_pair(&LHS, &RHS), nullptr); |
55 | 420 | if (Res.second) |
56 | 364 | Res.first->second = &create<ImplicationValue>(LHS, RHS); |
57 | 420 | return *Res.first->second; |
58 | 421 | } |
59 | | |
60 | 11.9k | BoolValue &Arena::makeEquals(BoolValue &LHS, BoolValue &RHS) { |
61 | 11.9k | if (&LHS == &RHS) |
62 | 8 | return makeLiteral(true); |
63 | | |
64 | 11.9k | auto Res = BiconditionalVals.try_emplace(makeCanonicalBoolValuePair(LHS, RHS), |
65 | 11.9k | nullptr); |
66 | 11.9k | if (Res.second) |
67 | 3.77k | Res.first->second = &create<BiconditionalValue>(LHS, RHS); |
68 | 11.9k | return *Res.first->second; |
69 | 11.9k | } |
70 | | |
71 | | } // namespace clang::dataflow |