9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.loop.phases; 24 25 import org.graalvm.compiler.debug.DebugContext; 26 import org.graalvm.compiler.loop.LoopEx; 27 import org.graalvm.compiler.loop.LoopsData; 28 import org.graalvm.compiler.nodes.StructuredGraph; 29 import org.graalvm.compiler.phases.Phase; 30 31 public class ReassociateInvariantPhase extends Phase { 32 33 @SuppressWarnings("try") 34 @Override 35 protected void run(StructuredGraph graph) { 36 if (graph.hasLoops()) { 37 final LoopsData dataReassociate = new LoopsData(graph); 38 DebugContext debug = graph.getDebug(); 39 try (DebugContext.Scope s = debug.scope("ReassociateInvariants")) { 40 for (LoopEx loop : dataReassociate.loops()) { 41 loop.reassociateInvariants(); 42 } 43 } catch (Throwable e) { 44 throw debug.handle(e); 45 } 46 dataReassociate.deleteUnusedNodes(); 47 } 48 } 49 } | 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.loop.phases; 24 25 import org.graalvm.compiler.debug.DebugContext; 26 import org.graalvm.compiler.loop.LoopEx; 27 import org.graalvm.compiler.loop.LoopsData; 28 import org.graalvm.compiler.nodes.StructuredGraph; 29 import org.graalvm.compiler.nodes.calc.BinaryArithmeticNode; 30 import org.graalvm.compiler.phases.Phase; 31 32 /** 33 * Rearrange {@link BinaryArithmeticNode#isAssociative() associative binary operations} so that 34 * invariant parts of the expression can move outside of the loop. 35 */ 36 public class ReassociateInvariantPhase extends Phase { 37 38 @SuppressWarnings("try") 39 @Override 40 protected void run(StructuredGraph graph) { 41 int iterations = 0; 42 DebugContext debug = graph.getDebug(); 43 try (DebugContext.Scope s = debug.scope("ReassociateInvariants")) { 44 boolean changed = true; 45 while (changed) { 46 changed = false; 47 final LoopsData dataReassociate = new LoopsData(graph); 48 for (LoopEx loop : dataReassociate.loops()) { 49 changed |= loop.reassociateInvariants(); 50 } 51 dataReassociate.deleteUnusedNodes(); 52 iterations++; 53 debug.dump(DebugContext.VERBOSE_LEVEL, graph, "after iteration %d", iterations); 54 } 55 } catch (Throwable e) { 56 throw debug.handle(e); 57 } 58 } 59 } |