annotate modules/javafx.web/src/main/native/Source/JavaScriptCore/dfg/DFGSSALoweringPhase.cpp @ 11208:db2c977a840b

8220147: Cherry pick GTK WebKit 2.22.7 changes Reviewed-by: mbilla, kcr
author arajkumar
date Fri, 08 Mar 2019 14:03:47 +0530
parents ab4db0272524
children a1fb556cdd7d
rev   line source
ant@8798 1 /*
ant@8798 2 * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
ant@8798 3 *
ant@8798 4 * Redistribution and use in source and binary forms, with or without
ant@8798 5 * modification, are permitted provided that the following conditions
ant@8798 6 * are met:
ant@8798 7 * 1. Redistributions of source code must retain the above copyright
ant@8798 8 * notice, this list of conditions and the following disclaimer.
ant@8798 9 * 2. Redistributions in binary form must reproduce the above copyright
ant@8798 10 * notice, this list of conditions and the following disclaimer in the
ant@8798 11 * documentation and/or other materials provided with the distribution.
ant@8798 12 *
ant@8798 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
ant@8798 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ant@8798 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
ant@8798 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
ant@8798 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
ant@8798 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
ant@8798 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
ant@8798 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
ant@8798 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
ant@8798 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
kcr@9542 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ant@8798 24 */
ant@8798 25
ant@8798 26 #include "config.h"
ant@8798 27 #include "DFGSSALoweringPhase.h"
ant@8798 28
ant@8798 29 #if ENABLE(DFG_JIT)
ant@8798 30
ant@8798 31 #include "DFGBasicBlockInlines.h"
ant@8798 32 #include "DFGGraph.h"
ant@8798 33 #include "DFGInsertionSet.h"
ant@8798 34 #include "DFGPhase.h"
ant@8798 35 #include "JSCInlines.h"
ant@8798 36
ant@8798 37 namespace JSC { namespace DFG {
ant@8798 38
ant@8798 39 class SSALoweringPhase : public Phase {
ant@8798 40 static const bool verbose = false;
kcr@9542 41
ant@8798 42 public:
ant@8798 43 SSALoweringPhase(Graph& graph)
ant@8798 44 : Phase(graph, "SSA lowering")
ant@8798 45 , m_insertionSet(graph)
ant@8798 46 {
ant@8798 47 }
kcr@9542 48
ant@8798 49 bool run()
ant@8798 50 {
ant@8798 51 RELEASE_ASSERT(m_graph.m_form == SSA);
kcr@9542 52
ant@8798 53 for (BlockIndex blockIndex = m_graph.numBlocks(); blockIndex--;) {
ant@8798 54 m_block = m_graph.block(blockIndex);
ant@8798 55 if (!m_block)
ant@8798 56 continue;
ant@8798 57 for (m_nodeIndex = 0; m_nodeIndex < m_block->size(); ++m_nodeIndex) {
ant@8798 58 m_node = m_block->at(m_nodeIndex);
ant@8798 59 handleNode();
ant@8798 60 }
ant@8798 61 m_insertionSet.execute(m_block);
ant@8798 62 }
ant@8798 63
ant@8798 64 return true;
ant@8798 65 }
ant@8798 66
ant@8798 67 private:
ant@8798 68 void handleNode()
ant@8798 69 {
ant@8798 70 switch (m_node->op()) {
mbilla@10730 71 case AtomicsAdd:
mbilla@10730 72 case AtomicsAnd:
mbilla@10730 73 case AtomicsCompareExchange:
mbilla@10730 74 case AtomicsExchange:
mbilla@10730 75 case AtomicsLoad:
mbilla@10730 76 case AtomicsOr:
mbilla@10730 77 case AtomicsStore:
mbilla@10730 78 case AtomicsSub:
mbilla@10730 79 case AtomicsXor:
kcr@9800 80 case HasIndexedProperty:
mbilla@10730 81 lowerBoundsCheck(m_graph.child(m_node, 0), m_graph.child(m_node, 1), m_graph.child(m_node, 2));
ant@8798 82 break;
kcr@9542 83
arajkumar@10954 84 case GetByVal: {
arajkumar@10954 85 lowerBoundsCheck(m_graph.varArgChild(m_node, 0), m_graph.varArgChild(m_node, 1), m_graph.varArgChild(m_node, 2));
arajkumar@10954 86 break;
arajkumar@10954 87 }
arajkumar@10954 88
ant@8798 89 case PutByVal:
ant@8798 90 case PutByValDirect: {
ant@8798 91 Edge base = m_graph.varArgChild(m_node, 0);
ant@8798 92 Edge index = m_graph.varArgChild(m_node, 1);
ant@8798 93 Edge storage = m_graph.varArgChild(m_node, 3);
ant@8798 94 if (lowerBoundsCheck(base, index, storage))
ant@8798 95 break;
kcr@9542 96
ant@8798 97 if (m_node->arrayMode().typedArrayType() != NotTypedArray && m_node->arrayMode().isOutOfBounds()) {
ant@8798 98 Node* length = m_insertionSet.insertNode(
arajkumar@10587 99 m_nodeIndex, SpecInt32Only, GetArrayLength, m_node->origin,
ant@8798 100 OpInfo(m_node->arrayMode().asWord()), base, storage);
kcr@9542 101
ant@8798 102 m_graph.varArgChild(m_node, 4) = Edge(length, KnownInt32Use);
ant@8798 103 break;
ant@8798 104 }
ant@8798 105 break;
ant@8798 106 }
kcr@9542 107
ant@8798 108 default:
ant@8798 109 break;
ant@8798 110 }
ant@8798 111 }
kcr@9542 112
ant@8798 113 bool lowerBoundsCheck(Edge base, Edge index, Edge storage)
ant@8798 114 {
ant@8798 115 if (!m_node->arrayMode().permitsBoundsCheckLowering())
ant@8798 116 return false;
kcr@9542 117
ant@8798 118 if (!m_node->arrayMode().lengthNeedsStorage())
ant@8798 119 storage = Edge();
kcr@9542 120
mbilla@10730 121 NodeType op = GetArrayLength;
mbilla@10730 122 switch (m_node->arrayMode().type()) {
mbilla@10730 123 case Array::ArrayStorage:
mbilla@10730 124 case Array::SlowPutArrayStorage:
mbilla@10730 125 op = GetVectorLength;
mbilla@10730 126 break;
mbilla@10730 127 default:
mbilla@10730 128 break;
mbilla@10730 129 }
mbilla@10730 130
ant@8798 131 Node* length = m_insertionSet.insertNode(
mbilla@10730 132 m_nodeIndex, SpecInt32Only, op, m_node->origin,
arajkumar@11208 133 OpInfo(m_node->arrayMode().asWord()), Edge(base.node(), KnownCellUse), storage);
arajkumar@11208 134 Node* checkInBounds = m_insertionSet.insertNode(
arajkumar@10587 135 m_nodeIndex, SpecInt32Only, CheckInBounds, m_node->origin,
ant@8798 136 index, Edge(length, KnownInt32Use));
arajkumar@11208 137
arajkumar@11208 138 AdjacencyList adjacencyList = m_graph.copyVarargChildren(m_node);
arajkumar@11208 139 m_graph.m_varArgChildren.append(Edge(checkInBounds, UntypedUse));
arajkumar@11208 140 adjacencyList.setNumChildren(adjacencyList.numChildren() + 1);
arajkumar@11208 141 m_node->children = adjacencyList;
ant@8798 142 return true;
ant@8798 143 }
kcr@9542 144
ant@8798 145 InsertionSet m_insertionSet;
ant@8798 146 BasicBlock* m_block;
ant@8798 147 unsigned m_nodeIndex;
ant@8798 148 Node* m_node;
ant@8798 149 };
ant@8798 150
ant@8798 151 bool performSSALowering(Graph& graph)
ant@8798 152 {
ant@8798 153 return runPhase<SSALoweringPhase>(graph);
ant@8798 154 }
ant@8798 155
ant@8798 156 } } // namespace JSC::DFG
ant@8798 157
ant@8798 158 #endif // ENABLE(DFG_JIT)
ant@8798 159