]>
git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGStoreBarrierElisionPhase.cpp
421755261292c357f497a400ee6f211956a1fab3
2 * Copyright (C) 2013 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. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "DFGStoreBarrierElisionPhase.h"
31 #include "DFGBasicBlock.h"
32 #include "DFGClobberize.h"
35 #include "JSCInlines.h"
36 #include <wtf/HashSet.h>
38 namespace JSC
{ namespace DFG
{
40 class StoreBarrierElisionPhase
: public Phase
{
42 StoreBarrierElisionPhase(Graph
& graph
)
43 : Phase(graph
, "store barrier elision")
51 for (BlockIndex blockIndex
= 0; blockIndex
< m_graph
.numBlocks(); ++blockIndex
) {
52 m_currentBlock
= m_graph
.block(blockIndex
);
55 handleBlock(m_currentBlock
);
61 bool couldCauseGC(Node
* node
)
63 return writesOverlap(m_graph
, node
, GCState
);
66 bool allocatesFreshObject(Node
* node
)
71 case NewArrayWithSize
:
81 void noticeFreshObject(HashSet
<Node
*>& dontNeedBarriers
, Node
* node
)
83 ASSERT(allocatesFreshObject(node
));
84 dontNeedBarriers
.add(node
);
87 Node
* getBaseOfStore(Node
* barrierNode
)
89 ASSERT(barrierNode
->isStoreBarrier());
90 return barrierNode
->child1().node();
93 bool shouldBeElided(HashSet
<Node
*>& dontNeedBarriers
, Node
* node
)
95 ASSERT(node
->isStoreBarrier());
96 return dontNeedBarriers
.contains(node
->child1().node());
99 void elideBarrier(Node
* node
)
101 ASSERT(node
->isStoreBarrier());
102 node
->convertToPhantom();
105 void handleNode(HashSet
<Node
*>& dontNeedBarriers
, Node
* node
)
107 if (couldCauseGC(node
))
108 dontNeedBarriers
.clear();
110 if (allocatesFreshObject(node
))
111 noticeFreshObject(dontNeedBarriers
, node
);
113 if (!node
->isStoreBarrier())
116 if (shouldBeElided(dontNeedBarriers
, node
)) {
121 Node
* base
= getBaseOfStore(node
);
125 if (dontNeedBarriers
.contains(base
))
127 dontNeedBarriers
.add(base
);
130 bool handleBlock(BasicBlock
* block
)
132 HashSet
<Node
*> dontNeedBarriers
;
133 for (unsigned indexInBlock
= 0; indexInBlock
< block
->size(); ++indexInBlock
) {
134 m_currentIndex
= indexInBlock
;
135 Node
* node
= block
->at(indexInBlock
);
136 handleNode(dontNeedBarriers
, node
);
141 BasicBlock
* m_currentBlock
;
142 unsigned m_currentIndex
;
145 bool performStoreBarrierElision(Graph
& graph
)
147 SamplingRegion
samplingRegion("DFG Store Barrier Elision Phase");
148 return runPhase
<StoreBarrierElisionPhase
>(graph
);
152 } } // namespace JSC::DFG
154 #endif // ENABLE(DFG_JIT)