2 * Copyright (C) 2013, 2016 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.
30 #include "DFGAbstractValue.h"
31 #include "DFGBranchDirection.h"
32 #include "DFGFlowMap.h"
36 namespace JSC { namespace DFG {
38 class InPlaceAbstractState {
39 WTF_MAKE_FAST_ALLOCATED;
41 InPlaceAbstractState(Graph&);
43 ~InPlaceAbstractState();
45 explicit operator bool() const { return true; }
47 void createValueForNode(NodeFlowProjection) { }
49 AbstractValue& forNode(NodeFlowProjection node)
51 return m_abstractValues.at(node);
54 AbstractValue& forNode(Edge edge)
56 return forNode(edge.node());
59 Operands<AbstractValue>& variables()
64 // Call this before beginning CFA to initialize the abstract values of
65 // arguments, and to indicate which blocks should be listed for CFA
69 // Start abstractly executing the given basic block. Initializes the
70 // notion of abstract state to what we believe it to be at the head
71 // of the basic block, according to the basic block's data structures.
72 // This method also sets cfaShouldRevisit to false.
73 void beginBasicBlock(BasicBlock*);
75 BasicBlock* block() const { return m_block; }
77 // Finish abstractly executing a basic block. If MergeToTail or
78 // MergeToSuccessors is passed, then this merges everything we have
79 // learned about how the state changes during this block's execution into
80 // the block's data structures.
82 // Returns true if the state of the block at the tail was changed,
83 // and, if the state at the heads of successors was changed.
84 // A true return means that you must revisit (at least) the successor
85 // blocks. This also sets cfaShouldRevisit to true for basic blocks
86 // that must be visited next.
89 // Reset the AbstractState. This throws away any results, and at this point
90 // you can safely call beginBasicBlock() on any basic block.
93 // Did the last executed node clobber the world?
94 bool didClobber() const { return m_didClobber; }
96 // Are structures currently clobbered?
97 StructureClobberState structureClobberState() const { return m_structureClobberState; }
99 // Is the execution state still valid? This will be false if execute() has
100 // returned false previously.
101 bool isValid() const { return m_isValid; }
103 // Merge the abstract state stored at the first block's tail into the second
104 // block's head. Returns true if the second block's state changed. If so,
105 // that block must be abstractly interpreted again. This also sets
106 // to->cfaShouldRevisit to true, if it returns true, or if to has not been
108 bool merge(BasicBlock* from, BasicBlock* to);
110 // Merge the abstract state stored at the block's tail into all of its
111 // successors. Returns true if any of the successors' states changed. Note
112 // that this is automatically called in endBasicBlock() if MergeMode is
113 // MergeToSuccessors.
114 bool mergeToSuccessors(BasicBlock*);
116 // Methods intended to be called from AbstractInterpreter.
117 void setDidClobber(bool didClobber) { m_didClobber = didClobber; }
118 void setStructureClobberState(StructureClobberState value) { m_structureClobberState = value; }
119 void setIsValid(bool isValid) { m_isValid = isValid; }
120 void setBranchDirection(BranchDirection branchDirection) { m_branchDirection = branchDirection; }
122 // This method is evil - it causes a huge maintenance headache and there is a gross amount of
123 // code devoted to it. It would be much nicer to just always run the constant folder on each
124 // block. But, the last time we did it, it was a 1% SunSpider regression:
125 // https://bugs.webkit.org/show_bug.cgi?id=133947
126 // So, we should probably keep this method.
127 void setFoundConstants(bool foundConstants) { m_foundConstants = foundConstants; }
129 void setProofStatus(Edge& edge, ProofStatus status)
131 edge.setProofStatus(status);
135 void mergeStateAtTail(AbstractValue& destination, AbstractValue& inVariable, Node*);
137 static bool mergeVariableBetweenBlocks(AbstractValue& destination, AbstractValue& source, Node* destinationNode, Node* sourceNode);
141 FlowMap<AbstractValue>& m_abstractValues;
142 Operands<AbstractValue> m_variables;
145 bool m_foundConstants;
149 StructureClobberState m_structureClobberState;
151 BranchDirection m_branchDirection; // This is only set for blocks that end in Branch and that execute to completion (i.e. m_isValid == true).
154 } } // namespace JSC::DFG
156 #endif // ENABLE(DFG_JIT)