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. ``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 DFGInPlaceAbstractState_h
27 #define DFGInPlaceAbstractState_h
31 #include "DFGAbstractValue.h"
32 #include "DFGBranchDirection.h"
34 #include "DFGMergeMode.h"
37 namespace JSC
{ namespace DFG
{
39 class InPlaceAbstractState
{
41 InPlaceAbstractState(Graph
&);
43 ~InPlaceAbstractState();
45 void createValueForNode(Node
*) { }
47 AbstractValue
& forNode(Node
* node
)
52 AbstractValue
& forNode(Edge edge
)
54 return forNode(edge
.node());
57 Operands
<AbstractValue
>& variables()
62 // Call this before beginning CFA to initialize the abstract values of
63 // arguments, and to indicate which blocks should be listed for CFA
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
*);
73 BasicBlock
* block() const { return m_block
; }
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:
82 // Always returns false.
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).
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
);
99 // Reset the AbstractState. This throws away any results, and at this point
100 // you can safely call beginBasicBlock() on any basic block.
103 // Did the last executed node clobber the world?
104 bool didClobber() const { return m_didClobber
; }
106 // Is the execution state still valid? This will be false if execute() has
107 // returned false previously.
108 bool isValid() const { return m_isValid
; }
110 // Merge the abstract state stored at the first block's tail into the second
111 // block's head. Returns true if the second block's state changed. If so,
112 // that block must be abstractly interpreted again. This also sets
113 // to->cfaShouldRevisit to true, if it returns true, or if to has not been
115 bool merge(BasicBlock
* from
, BasicBlock
* to
);
117 // Merge the abstract state stored at the block's tail into all of its
118 // successors. Returns true if any of the successors' states changed. Note
119 // that this is automatically called in endBasicBlock() if MergeMode is
120 // MergeToSuccessors.
121 bool mergeToSuccessors(BasicBlock
*);
123 // Methods intended to be called from AbstractInterpreter.
124 void setDidClobber(bool didClobber
) { m_didClobber
= didClobber
; }
125 void setIsValid(bool isValid
) { m_isValid
= isValid
; }
126 void setBranchDirection(BranchDirection branchDirection
) { m_branchDirection
= branchDirection
; }
127 void setFoundConstants(bool foundConstants
) { m_foundConstants
= foundConstants
; }
128 bool haveStructures() const { return m_haveStructures
; } // It's always safe to return true.
129 void setHaveStructures(bool haveStructures
) { m_haveStructures
= haveStructures
; }
132 bool mergeStateAtTail(AbstractValue
& destination
, AbstractValue
& inVariable
, Node
*);
134 static bool mergeVariableBetweenBlocks(AbstractValue
& destination
, AbstractValue
& source
, Node
* destinationNode
, Node
* sourceNode
);
138 Operands
<AbstractValue
> m_variables
;
141 bool m_haveStructures
;
142 bool m_foundConstants
;
147 BranchDirection m_branchDirection
; // This is only set for blocks that end in Branch and that execute to completion (i.e. m_isValid == true).
150 } } // namespace JSC::DFG
152 #endif // ENABLE(DFG_JIT)
154 #endif // DFGInPlaceAbstractState_h