1/*
2 * Copyright (C) 2017 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(B3_JIT)
29
30#include "AirTmp.h"
31#include <wtf/IndexSet.h>
32
33namespace JSC { namespace B3 { namespace Air {
34
35class TmpSet {
36public:
37 TmpSet()
38 {
39 }
40
41 bool add(Tmp tmp)
42 {
43 if (tmp.isGP())
44 return m_gp.add(tmp);
45 return m_fp.add(tmp);
46 }
47
48 bool remove(Tmp tmp)
49 {
50 if (tmp.isGP())
51 return m_gp.remove(tmp);
52 return m_fp.remove(tmp);
53 }
54
55 bool contains(Tmp tmp)
56 {
57 if (tmp.isGP())
58 return m_gp.contains(tmp);
59 return m_fp.contains(tmp);
60 }
61
62 size_t size() const
63 {
64 return m_gp.size() + m_fp.size();
65 }
66
67 bool isEmpty() const
68 {
69 return !size();
70 }
71
72 class iterator {
73 public:
74 iterator()
75 {
76 }
77
78 iterator(BitVector::iterator gpIter, BitVector::iterator fpIter)
79 : m_gpIter(gpIter)
80 , m_fpIter(fpIter)
81 {
82 }
83
84 Tmp operator*()
85 {
86 if (!m_gpIter.isAtEnd())
87 return Tmp::tmpForAbsoluteIndex(GP, *m_gpIter);
88 return Tmp::tmpForAbsoluteIndex(FP, *m_fpIter);
89 }
90
91 iterator& operator++()
92 {
93 if (!m_gpIter.isAtEnd()) {
94 ++m_gpIter;
95 return *this;
96 }
97 ++m_fpIter;
98 return *this;
99 }
100
101 bool operator==(const iterator& other) const
102 {
103 return m_gpIter == other.m_gpIter
104 && m_fpIter == other.m_fpIter;
105 }
106
107 bool operator!=(const iterator& other) const
108 {
109 return !(*this == other);
110 }
111
112 private:
113 BitVector::iterator m_gpIter;
114 BitVector::iterator m_fpIter;
115 };
116
117 iterator begin() const { return iterator(m_gp.indices().begin(), m_fp.indices().begin()); }
118 iterator end() const { return iterator(m_gp.indices().end(), m_fp.indices().end()); }
119
120private:
121 IndexSet<Tmp::AbsolutelyIndexed<GP>> m_gp;
122 IndexSet<Tmp::AbsolutelyIndexed<FP>> m_fp;
123};
124
125} } } // namespace JSC::B3::Air
126
127#endif // ENABLE(B3_JIT)
128
129