1 | /* |
2 | * Copyright (C) 2015-2019 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(DFG_JIT) |
29 | |
30 | #include <wtf/PrintStream.h> |
31 | |
32 | namespace JSC { namespace DFG { |
33 | |
34 | // Utility class for epoch-based analyses. |
35 | |
36 | class Epoch { |
37 | public: |
38 | Epoch() |
39 | : m_epoch(s_none) |
40 | { |
41 | } |
42 | |
43 | static Epoch fromUnsigned(unsigned value) |
44 | { |
45 | Epoch result; |
46 | result.m_epoch = value; |
47 | return result; |
48 | } |
49 | |
50 | unsigned toUnsigned() const |
51 | { |
52 | return m_epoch; |
53 | } |
54 | |
55 | static Epoch first() |
56 | { |
57 | Epoch result; |
58 | result.m_epoch = s_first; |
59 | return result; |
60 | } |
61 | |
62 | bool operator!() const |
63 | { |
64 | return m_epoch == s_none; |
65 | } |
66 | |
67 | Epoch next() const |
68 | { |
69 | Epoch result; |
70 | result.m_epoch = m_epoch + 1; |
71 | return result; |
72 | } |
73 | |
74 | void bump() |
75 | { |
76 | *this = next(); |
77 | } |
78 | |
79 | bool operator==(const Epoch& other) const |
80 | { |
81 | return m_epoch == other.m_epoch; |
82 | } |
83 | |
84 | bool operator!=(const Epoch& other) const |
85 | { |
86 | return !(*this == other); |
87 | } |
88 | |
89 | bool operator<(const Epoch& other) const |
90 | { |
91 | return m_epoch < other.m_epoch; |
92 | } |
93 | |
94 | bool operator>(const Epoch& other) const |
95 | { |
96 | return other < *this; |
97 | } |
98 | |
99 | bool operator<=(const Epoch& other) const |
100 | { |
101 | return !(*this > other); |
102 | } |
103 | |
104 | bool operator>=(const Epoch& other) const |
105 | { |
106 | return !(*this < other); |
107 | } |
108 | |
109 | void dump(PrintStream&) const; |
110 | |
111 | private: |
112 | static constexpr unsigned s_none = 0; |
113 | static constexpr unsigned s_first = 1; |
114 | |
115 | unsigned m_epoch; |
116 | }; |
117 | |
118 | } } // namespace JSC::DFG |
119 | |
120 | #endif // ENABLE(DFG_JIT) |
121 | |