summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/dfg/DFGRedundantPhiEliminationPhase.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-03-12 14:11:15 +0100
committerSimon Hausmann <simon.hausmann@nokia.com>2012-03-12 14:11:15 +0100
commitdd91e772430dc294e3bf478c119ef8d43c0a3358 (patch)
tree6f33ce4d5872a5691e0291eb45bf6ab373a5f567 /Source/JavaScriptCore/dfg/DFGRedundantPhiEliminationPhase.cpp
parentad0d549d4cc13433f77c1ac8f0ab379c83d93f28 (diff)
downloadqtwebkit-dd91e772430dc294e3bf478c119ef8d43c0a3358.tar.gz
Imported WebKit commit 3db4eb1820ac8fb03065d7ea73a4d9db1e8fea1a (http://svn.webkit.org/repository/webkit/trunk@110422)
This includes build fixes for the latest qtbase/qtdeclarative as well as the final QML2 API.
Diffstat (limited to 'Source/JavaScriptCore/dfg/DFGRedundantPhiEliminationPhase.cpp')
-rw-r--r--Source/JavaScriptCore/dfg/DFGRedundantPhiEliminationPhase.cpp176
1 files changed, 176 insertions, 0 deletions
diff --git a/Source/JavaScriptCore/dfg/DFGRedundantPhiEliminationPhase.cpp b/Source/JavaScriptCore/dfg/DFGRedundantPhiEliminationPhase.cpp
new file mode 100644
index 000000000..fb30de742
--- /dev/null
+++ b/Source/JavaScriptCore/dfg/DFGRedundantPhiEliminationPhase.cpp
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DFGRedundantPhiEliminationPhase.h"
+
+#if ENABLE(DFG_JIT)
+
+#include "DFGGraph.h"
+
+namespace JSC { namespace DFG {
+
+class RedundantPhiEliminationPhase : public Phase {
+public:
+ RedundantPhiEliminationPhase(Graph& graph)
+ : Phase(graph, "redundant phi elimination")
+ {
+ }
+
+ void run()
+ {
+ bool changed = false;
+ do {
+ changed = fixupPhis();
+ } while (changed);
+
+ updateBlockVariableInformation();
+
+ // Update the Phi references from non-Phi nodes, e.g., the GetLocals.
+ for (NodeIndex index = 0; index < m_graph.size(); ++index) {
+ Node& node = m_graph[index];
+
+ if (!node.shouldGenerate())
+ continue;
+
+ switch (node.op) {
+ case GetLocal:
+ replacePhiChild(node, 0);
+ break;
+ default:
+ break;
+ }
+ }
+
+ }
+
+private:
+ NodeIndex getRedundantReplacement(NodeIndex phi)
+ {
+ NodeIndex child1 = m_graph[phi].child1().indexUnchecked();
+ NodeIndex candidate = child1 == phi ? NoNode : child1;
+
+ NodeIndex child2 = m_graph[phi].child2().indexUnchecked();
+ if (candidate != NoNode) {
+ if (child2 != NoNode && child2 != candidate && child2 != phi)
+ return NoNode;
+ } else if (child2 != phi)
+ candidate = child2;
+
+ NodeIndex child3 = m_graph[phi].child3().indexUnchecked();
+ if (candidate != NoNode) {
+ if (child3 != NoNode && child3 != candidate && child3 != phi)
+ return NoNode;
+ } else if (child3 != phi)
+ candidate = child3;
+
+ return candidate;
+ }
+
+ bool replacePhiChild(Node& node, unsigned childIndex)
+ {
+ ASSERT(childIndex < 3);
+
+ bool replaced = false;
+ NodeIndex child = node.children.child(childIndex).indexUnchecked();
+ if (child != NoNode && m_graph[child].op == Phi) {
+ NodeIndex childReplacement = getRedundantReplacement(child);
+ if (childReplacement != NoNode) {
+ node.children.child(childIndex).setIndex(childReplacement);
+ replaced = true;
+ if (node.refCount()) {
+ m_graph[childReplacement].ref();
+ m_graph.deref(child);
+ }
+ }
+ }
+ return replaced;
+ }
+
+ bool fixupPhis()
+ {
+ bool changed = false;
+
+ for (BlockIndex block = 0; block < m_graph.m_blocks.size(); ++block) {
+ Vector<NodeIndex>& phis = m_graph.m_blocks[block]->phis;
+
+ for (size_t i = 0; i < phis.size(); ++i) {
+ NodeIndex phi = phis[i];
+ Node& phiNode = m_graph[phi];
+
+ changed |= (replacePhiChild(phiNode, 0) && phiNode.refCount());
+ changed |= (replacePhiChild(phiNode, 1) && phiNode.refCount());
+ changed |= (replacePhiChild(phiNode, 2) && phiNode.refCount());
+ }
+ }
+
+ return changed;
+ }
+
+ void updateBlockVariableInformation()
+ {
+ // Redundant Phi nodes are eliminated, we need to update
+ // the variable information if it references them.
+ for (BlockIndex blockIndex = 0; blockIndex < m_graph.m_blocks.size(); ++blockIndex) {
+ BasicBlock* basicBlock = m_graph.m_blocks[blockIndex].get();
+
+ for (size_t arg = 0; arg < basicBlock->variablesAtHead.numberOfArguments(); ++arg) {
+ NodeIndex nodeIndex = basicBlock->variablesAtHead.argument(arg);
+ if (nodeIndex != NoNode && m_graph[nodeIndex].op == Phi && !m_graph[nodeIndex].refCount()) {
+ NodeIndex replacement = getRedundantReplacement(nodeIndex);
+ if (replacement != NoNode) {
+ // This argument must be unused in this block.
+ ASSERT(basicBlock->variablesAtTail.argument(arg) == nodeIndex);
+ basicBlock->variablesAtHead.argument(arg) = replacement;
+ basicBlock->variablesAtTail.argument(arg) = replacement;
+ }
+ }
+ }
+
+ for (size_t local = 0; local < basicBlock->variablesAtHead.numberOfLocals(); ++local) {
+ NodeIndex nodeIndex = basicBlock->variablesAtHead.local(local);
+ if (nodeIndex != NoNode && m_graph[nodeIndex].op == Phi && !m_graph[nodeIndex].refCount()) {
+ NodeIndex replacement = getRedundantReplacement(nodeIndex);
+ if (replacement != NoNode) {
+ // This local variable must be unused in this block.
+ ASSERT(basicBlock->variablesAtTail.local(local) == nodeIndex);
+ basicBlock->variablesAtHead.local(local) = replacement;
+ basicBlock->variablesAtTail.local(local) = replacement;
+ }
+ }
+ }
+ }
+ }
+
+};
+
+void performRedundantPhiElimination(Graph& graph)
+{
+ runPhase<RedundantPhiEliminationPhase>(graph);
+}
+
+} } // namespace JSC::DFG
+
+#endif // ENABLE(DFG_JIT)