]>
git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGInsertionSet.h
2 * Copyright (C) 2012, 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.
26 #ifndef DFGInsertionSet_h
27 #define DFGInsertionSet_h
32 #include <wtf/Insertion.h>
33 #include <wtf/Vector.h>
35 namespace JSC
{ namespace DFG
{
37 typedef WTF::Insertion
<Node
*> Insertion
;
41 InsertionSet(Graph
& graph
)
46 Graph
& graph() { return m_graph
; }
48 Node
* insert(const Insertion
& insertion
)
50 ASSERT(!m_insertions
.size() || m_insertions
.last().index() <= insertion
.index());
51 m_insertions
.append(insertion
);
52 return insertion
.element();
55 Node
* insert(size_t index
, Node
* element
)
57 return insert(Insertion(index
, element
));
60 template<typename
... Params
>
61 Node
* insertNode(size_t index
, SpeculatedType type
, Params
... params
)
63 return insert(index
, m_graph
.addNode(type
, params
...));
67 size_t index
, NodeOrigin origin
, FrozenValue
* value
,
68 NodeType op
= JSConstant
)
71 index
, speculationFromValue(value
->value()), op
, origin
, OpInfo(value
));
75 size_t index
, CodeOrigin origin
, FrozenValue
* value
, NodeType op
= JSConstant
)
77 return insertConstant(index
, NodeOrigin(origin
), value
, op
);
80 Edge
insertConstantForUse(
81 size_t index
, NodeOrigin origin
, FrozenValue
* value
, UseKind useKind
)
84 if (isDouble(useKind
))
86 else if (useKind
== Int52RepUse
)
90 return Edge(insertConstant(index
, origin
, value
, op
), useKind
);
93 Edge
insertConstantForUse(
94 size_t index
, CodeOrigin origin
, FrozenValue
* value
, UseKind useKind
)
96 return insertConstantForUse(index
, NodeOrigin(origin
), value
, useKind
);
99 Node
* insertConstant(size_t index
, NodeOrigin origin
, JSValue value
, NodeType op
= JSConstant
)
101 return insertConstant(index
, origin
, m_graph
.freeze(value
), op
);
104 Node
* insertConstant(size_t index
, CodeOrigin origin
, JSValue value
, NodeType op
= JSConstant
)
106 return insertConstant(index
, origin
, m_graph
.freeze(value
), op
);
109 Edge
insertConstantForUse(size_t index
, NodeOrigin origin
, JSValue value
, UseKind useKind
)
111 return insertConstantForUse(index
, origin
, m_graph
.freeze(value
), useKind
);
114 Edge
insertConstantForUse(size_t index
, CodeOrigin origin
, JSValue value
, UseKind useKind
)
116 return insertConstantForUse(index
, NodeOrigin(origin
), value
, useKind
);
119 Edge
insertBottomConstantForUse(size_t index
, NodeOrigin origin
, UseKind useKind
)
121 if (isDouble(useKind
))
122 return insertConstantForUse(index
, origin
, jsNumber(PNaN
), useKind
);
123 if (useKind
== Int52RepUse
)
124 return insertConstantForUse(index
, origin
, jsNumber(0), useKind
);
125 return insertConstantForUse(index
, origin
, jsUndefined(), useKind
);
128 Node
* insertCheck(size_t index
, NodeOrigin origin
, AdjacencyList children
)
130 children
= children
.justChecks();
131 if (children
.isEmpty())
133 return insertNode(index
, SpecNone
, Check
, origin
, children
);
136 Node
* insertCheck(size_t index
, Node
* node
)
138 return insertCheck(index
, node
->origin
, node
->children
);
141 Node
* insertCheck(size_t index
, NodeOrigin origin
, Edge edge
)
143 if (edge
.willHaveCheck())
144 return insertNode(index
, SpecNone
, Check
, origin
, edge
);
148 void execute(BasicBlock
* block
)
150 executeInsertions(*block
, m_insertions
);
154 Vector
<Insertion
, 8> m_insertions
;
157 } } // namespace JSC::DFG
159 #endif // ENABLE(DFG_JIT)
161 #endif // DFGInsertionSet_h