]>
Commit | Line | Data |
---|---|---|
81345200 A |
1 | /* |
2 | * Copyright (C) 2013 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 | #ifndef DFGInPlaceAbstractState_h | |
27 | #define DFGInPlaceAbstractState_h | |
28 | ||
29 | #if ENABLE(DFG_JIT) | |
30 | ||
31 | #include "DFGAbstractValue.h" | |
32 | #include "DFGBranchDirection.h" | |
33 | #include "DFGGraph.h" | |
34 | #include "DFGMergeMode.h" | |
35 | #include "DFGNode.h" | |
36 | ||
37 | namespace JSC { namespace DFG { | |
38 | ||
39 | class InPlaceAbstractState { | |
40 | public: | |
41 | InPlaceAbstractState(Graph&); | |
42 | ||
43 | ~InPlaceAbstractState(); | |
44 | ||
45 | void createValueForNode(Node*) { } | |
46 | ||
47 | AbstractValue& forNode(Node* node) | |
48 | { | |
49 | return node->value; | |
50 | } | |
51 | ||
52 | AbstractValue& forNode(Edge edge) | |
53 | { | |
54 | return forNode(edge.node()); | |
55 | } | |
56 | ||
57 | Operands<AbstractValue>& variables() | |
58 | { | |
59 | return m_variables; | |
60 | } | |
61 | ||
62 | // Call this before beginning CFA to initialize the abstract values of | |
63 | // arguments, and to indicate which blocks should be listed for CFA | |
64 | // execution. | |
65 | void initialize(); | |
66 | ||
67 | // Start abstractly executing the given basic block. Initializes the | |
68 | // notion of abstract state to what we believe it to be at the head | |
69 | // of the basic block, according to the basic block's data structures. | |
70 | // This method also sets cfaShouldRevisit to false. | |
71 | void beginBasicBlock(BasicBlock*); | |
72 | ||
73 | BasicBlock* block() const { return m_block; } | |
74 | ||
75 | // Finish abstractly executing a basic block. If MergeToTail or | |
76 | // MergeToSuccessors is passed, then this merges everything we have | |
77 | // learned about how the state changes during this block's execution into | |
78 | // the block's data structures. There are three return modes, depending | |
79 | // on the value of mergeMode: | |
80 | // | |
81 | // DontMerge: | |
82 | // Always returns false. | |
83 | // | |
84 | // MergeToTail: | |
85 | // Returns true if the state of the block at the tail was changed. | |
86 | // This means that you must call mergeToSuccessors(), and if that | |
87 | // returns true, then you must revisit (at least) the successor | |
88 | // blocks. False will always be returned if the block is terminal | |
89 | // (i.e. ends in Throw or Return, or has a ForceOSRExit inside it). | |
90 | // | |
91 | // MergeToSuccessors: | |
92 | // Returns true if the state of the block at the tail was changed, | |
93 | // and, if the state at the heads of successors was changed. | |
94 | // A true return means that you must revisit (at least) the successor | |
95 | // blocks. This also sets cfaShouldRevisit to true for basic blocks | |
96 | // that must be visited next. | |
97 | bool endBasicBlock(MergeMode); | |
98 | ||
99 | // Reset the AbstractState. This throws away any results, and at this point | |
100 | // you can safely call beginBasicBlock() on any basic block. | |
101 | void reset(); | |
102 | ||
103 | // Did the last executed node clobber the world? | |
104 | bool didClobber() const { return m_didClobber; } | |
105 | ||
ed1e77d3 A |
106 | // Are structures currently clobbered? |
107 | StructureClobberState structureClobberState() const { return m_structureClobberState; } | |
108 | ||
81345200 A |
109 | // Is the execution state still valid? This will be false if execute() has |
110 | // returned false previously. | |
111 | bool isValid() const { return m_isValid; } | |
112 | ||
113 | // Merge the abstract state stored at the first block's tail into the second | |
114 | // block's head. Returns true if the second block's state changed. If so, | |
115 | // that block must be abstractly interpreted again. This also sets | |
116 | // to->cfaShouldRevisit to true, if it returns true, or if to has not been | |
117 | // visited yet. | |
118 | bool merge(BasicBlock* from, BasicBlock* to); | |
119 | ||
120 | // Merge the abstract state stored at the block's tail into all of its | |
121 | // successors. Returns true if any of the successors' states changed. Note | |
122 | // that this is automatically called in endBasicBlock() if MergeMode is | |
123 | // MergeToSuccessors. | |
124 | bool mergeToSuccessors(BasicBlock*); | |
125 | ||
126 | // Methods intended to be called from AbstractInterpreter. | |
127 | void setDidClobber(bool didClobber) { m_didClobber = didClobber; } | |
ed1e77d3 | 128 | void setStructureClobberState(StructureClobberState value) { m_structureClobberState = value; } |
81345200 A |
129 | void setIsValid(bool isValid) { m_isValid = isValid; } |
130 | void setBranchDirection(BranchDirection branchDirection) { m_branchDirection = branchDirection; } | |
ed1e77d3 A |
131 | |
132 | // This method is evil - it causes a huge maintenance headache and there is a gross amount of | |
133 | // code devoted to it. It would be much nicer to just always run the constant folder on each | |
134 | // block. But, the last time we did it, it was a 1% SunSpider regression: | |
135 | // https://bugs.webkit.org/show_bug.cgi?id=133947 | |
136 | // So, we should probably keep this method. | |
81345200 | 137 | void setFoundConstants(bool foundConstants) { m_foundConstants = foundConstants; } |
81345200 A |
138 | |
139 | private: | |
140 | bool mergeStateAtTail(AbstractValue& destination, AbstractValue& inVariable, Node*); | |
141 | ||
142 | static bool mergeVariableBetweenBlocks(AbstractValue& destination, AbstractValue& source, Node* destinationNode, Node* sourceNode); | |
143 | ||
144 | Graph& m_graph; | |
145 | ||
146 | Operands<AbstractValue> m_variables; | |
147 | BasicBlock* m_block; | |
148 | ||
81345200 A |
149 | bool m_foundConstants; |
150 | ||
151 | bool m_isValid; | |
152 | bool m_didClobber; | |
ed1e77d3 | 153 | StructureClobberState m_structureClobberState; |
81345200 A |
154 | |
155 | BranchDirection m_branchDirection; // This is only set for blocks that end in Branch and that execute to completion (i.e. m_isValid == true). | |
156 | }; | |
157 | ||
158 | } } // namespace JSC::DFG | |
159 | ||
160 | #endif // ENABLE(DFG_JIT) | |
161 | ||
162 | #endif // DFGInPlaceAbstractState_h | |
163 |