]>
git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGClobberSet.cpp
2 * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "DFGClobberSet.h"
31 #include "DFGClobberize.h"
32 #include "JSCInlines.h"
33 #include <wtf/ListDump.h>
35 namespace JSC
{ namespace DFG
{
37 ClobberSet::ClobberSet() { }
38 ClobberSet::~ClobberSet() { }
40 void ClobberSet::add(AbstractHeap heap
)
42 HashMap
<AbstractHeap
, bool>::AddResult result
= m_clobbers
.add(heap
, true);
43 if (!result
.isNewEntry
) {
44 if (result
.iterator
->value
)
46 result
.iterator
->value
= true;
48 while (heap
.kind() != World
) {
49 heap
= heap
.supertype();
50 if (!m_clobbers
.add(heap
, false).isNewEntry
)
55 void ClobberSet::addAll(const ClobberSet
& other
)
57 // If the other set has a direct heap, we make sure we have it and we set its
60 // If the other heap has a super heap, we make sure it's present but don't
61 // modify its value - so we had it directly already then this doesn't change.
66 HashMap
<AbstractHeap
, bool>::const_iterator iter
= other
.m_clobbers
.begin();
67 HashMap
<AbstractHeap
, bool>::const_iterator end
= other
.m_clobbers
.end();
68 for (; iter
!= end
; ++iter
)
69 m_clobbers
.add(iter
->key
, iter
->value
).iterator
->value
|= iter
->value
;
72 bool ClobberSet::contains(AbstractHeap heap
) const
74 HashMap
<AbstractHeap
, bool>::const_iterator iter
= m_clobbers
.find(heap
);
75 if (iter
== m_clobbers
.end())
80 bool ClobberSet::overlaps(AbstractHeap heap
) const
82 if (m_clobbers
.find(heap
) != m_clobbers
.end())
84 while (heap
.kind() != World
) {
85 heap
= heap
.supertype();
92 void ClobberSet::clear()
97 HashSet
<AbstractHeap
> ClobberSet::direct() const
102 HashSet
<AbstractHeap
> ClobberSet::super() const
107 void ClobberSet::dump(PrintStream
& out
) const
109 out
.print("(Direct:[", sortedListDump(direct()), "], Super:[", sortedListDump(super()), "])");
112 HashSet
<AbstractHeap
> ClobberSet::setOf(bool direct
) const
114 HashSet
<AbstractHeap
> result
;
115 for (HashMap
<AbstractHeap
, bool>::const_iterator iter
= m_clobbers
.begin(); iter
!= m_clobbers
.end(); ++iter
) {
116 if (iter
->value
== direct
)
117 result
.add(iter
->key
);
122 void addReads(Graph
& graph
, Node
* node
, ClobberSet
& readSet
)
124 ClobberSetAdd
addRead(readSet
);
126 clobberize(graph
, node
, addRead
, noOp
, noOp
);
129 void addWrites(Graph
& graph
, Node
* node
, ClobberSet
& writeSet
)
132 ClobberSetAdd
addWrite(writeSet
);
133 clobberize(graph
, node
, noOp
, addWrite
, noOp
);
136 void addReadsAndWrites(Graph
& graph
, Node
* node
, ClobberSet
& readSet
, ClobberSet
& writeSet
)
138 ClobberSetAdd
addRead(readSet
);
139 ClobberSetAdd
addWrite(writeSet
);
141 clobberize(graph
, node
, addRead
, addWrite
, noOp
);
144 bool readsOverlap(Graph
& graph
, Node
* node
, ClobberSet
& readSet
)
146 ClobberSetOverlaps
addRead(readSet
);
148 clobberize(graph
, node
, addRead
, noOp
, noOp
);
149 return addRead
.result();
152 bool writesOverlap(Graph
& graph
, Node
* node
, ClobberSet
& writeSet
)
155 ClobberSetOverlaps
addWrite(writeSet
);
156 clobberize(graph
, node
, noOp
, addWrite
, noOp
);
157 return addWrite
.result();
160 } } // namespace JSC::DFG
162 #endif // ENABLE(DFG_JIT)