src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/util/GraphOrder.java
changeset 58299 6df94ce3ab2f
parent 54084 84f10bbf993f
equal deleted inserted replaced
58298:0152ad7b38b8 58299:6df94ce3ab2f
     1 /*
     1 /*
     2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   156      */
   156      */
   157     @SuppressWarnings("try")
   157     @SuppressWarnings("try")
   158     public static boolean assertSchedulableGraph(final StructuredGraph graph) {
   158     public static boolean assertSchedulableGraph(final StructuredGraph graph) {
   159         assert graph.getGuardsStage() != GuardsStage.AFTER_FSA : "Cannot use the BlockIteratorClosure after FrameState Assignment, HIR Loop Data Structures are no longer valid.";
   159         assert graph.getGuardsStage() != GuardsStage.AFTER_FSA : "Cannot use the BlockIteratorClosure after FrameState Assignment, HIR Loop Data Structures are no longer valid.";
   160         try (DebugContext.Scope s = graph.getDebug().scope("AssertSchedulableGraph")) {
   160         try (DebugContext.Scope s = graph.getDebug().scope("AssertSchedulableGraph")) {
   161             final SchedulePhase schedulePhase = new SchedulePhase(SchedulingStrategy.LATEST_OUT_OF_LOOPS, true);
   161             final SchedulePhase schedulePhase = new SchedulePhase(getSchedulingPolicy(graph), true);
   162             final EconomicMap<LoopBeginNode, NodeBitMap> loopEntryStates = EconomicMap.create(Equivalence.IDENTITY);
   162             final EconomicMap<LoopBeginNode, NodeBitMap> loopEntryStates = EconomicMap.create(Equivalence.IDENTITY);
   163             schedulePhase.apply(graph, false);
   163             schedulePhase.apply(graph, false);
   164             final ScheduleResult schedule = graph.getLastSchedule();
   164             final ScheduleResult schedule = graph.getLastSchedule();
   165 
   165 
   166             BlockIteratorClosure<NodeBitMap> closure = new BlockIteratorClosure<NodeBitMap>() {
   166             BlockIteratorClosure<NodeBitMap> closure = new BlockIteratorClosure<NodeBitMap>() {
   214                                             if (input != proxy.proxyPoint()) {
   214                                             if (input != proxy.proxyPoint()) {
   215                                                 assert currentState.isMarked(input) : input + " not available at " + proxy + " in block " + block + "\n" + list;
   215                                                 assert currentState.isMarked(input) : input + " not available at " + proxy + " in block " + block + "\n" + list;
   216                                             }
   216                                             }
   217                                         }
   217                                         }
   218                                     }
   218                                     }
   219 
       
   220                                     // loop contents are only accessible via proxies at the exit
   219                                     // loop contents are only accessible via proxies at the exit
   221                                     currentState.clearAll();
   220                                     currentState.clearAll();
   222                                     currentState.markAll(loopEntryStates.get(((LoopExitNode) node).loopBegin()));
   221                                     currentState.markAll(loopEntryStates.get(((LoopExitNode) node).loopBegin()));
   223                                 }
   222                                 }
       
   223 
   224                                 // Loop proxies aren't scheduled, so they need to be added
   224                                 // Loop proxies aren't scheduled, so they need to be added
   225                                 // explicitly
   225                                 // explicitly
   226                                 currentState.markAll(((LoopExitNode) node).proxies());
   226                                 currentState.markAll(((LoopExitNode) node).proxies());
   227                             } else {
   227                             } else {
   228                                 for (Node input : node.inputs()) {
   228                                 for (Node input : node.inputs()) {
   295         } catch (Throwable t) {
   295         } catch (Throwable t) {
   296             graph.getDebug().handle(t);
   296             graph.getDebug().handle(t);
   297         }
   297         }
   298         return true;
   298         return true;
   299     }
   299     }
       
   300 
       
   301     /*
       
   302      * Complexity of verification for LATEST_OUT_OF_LOOPS with value proxies exceeds the benefits.
       
   303      * The problem are floating values that can be scheduled before the loop and have proxies only
       
   304      * on some use edges after the loop. These values, which are hard to detect, get scheduled
       
   305      * before the loop exit and are not visible in the state after the loop exit.
       
   306      */
       
   307     private static SchedulingStrategy getSchedulingPolicy(StructuredGraph graph) {
       
   308         return graph.hasValueProxies() ? SchedulingStrategy.EARLIEST : SchedulingStrategy.LATEST_OUT_OF_LOOPS;
       
   309     }
   300 }
   310 }