src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/LIRGenerationPhase.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/LIRGenerationPhase.java

Print this page




   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.core;
  24 
  25 import java.util.List;
  26 
  27 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
  28 import org.graalvm.compiler.core.common.cfg.BlockMap;
  29 import org.graalvm.compiler.debug.Debug;
  30 import org.graalvm.compiler.debug.DebugCounter;
  31 import org.graalvm.compiler.graph.Node;

  32 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
  33 import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
  34 import org.graalvm.compiler.lir.phases.LIRPhase;
  35 import org.graalvm.compiler.lir.ssa.SSAUtil;
  36 import org.graalvm.compiler.nodes.StructuredGraph;
  37 import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult;
  38 import org.graalvm.compiler.nodes.cfg.Block;
  39 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
  40 
  41 import jdk.vm.ci.code.TargetDescription;
  42 
  43 public class LIRGenerationPhase extends LIRPhase<LIRGenerationPhase.LIRGenerationContext> {
  44 
  45     public static final class LIRGenerationContext {
  46         private final NodeLIRBuilderTool nodeLirBuilder;
  47         private final LIRGeneratorTool lirGen;
  48         private final StructuredGraph graph;
  49         private final ScheduleResult schedule;
  50 
  51         public LIRGenerationContext(LIRGeneratorTool lirGen, NodeLIRBuilderTool nodeLirBuilder, StructuredGraph graph, ScheduleResult schedule) {
  52             this.nodeLirBuilder = nodeLirBuilder;
  53             this.lirGen = lirGen;
  54             this.graph = graph;
  55             this.schedule = schedule;
  56         }
  57     }
  58 
  59     private static final DebugCounter instructionCounter = Debug.counter("GeneratedLIRInstructions");
  60     private static final DebugCounter nodeCount = Debug.counter("FinalNodeCount");
  61 
  62     @Override
  63     protected final void run(TargetDescription target, LIRGenerationResult lirGenRes, LIRGenerationPhase.LIRGenerationContext context) {
  64         NodeLIRBuilderTool nodeLirBuilder = context.nodeLirBuilder;
  65         StructuredGraph graph = context.graph;
  66         ScheduleResult schedule = context.schedule;
  67         for (AbstractBlockBase<?> b : lirGenRes.getLIR().getControlFlowGraph().getBlocks()) {
  68             emitBlock(nodeLirBuilder, lirGenRes, (Block) b, graph, schedule.getBlockToNodesMap());
  69         }
  70         context.lirGen.beforeRegisterAllocation();
  71         assert SSAUtil.verifySSAForm(lirGenRes.getLIR());
  72         if (nodeCount.isEnabled()) {
  73             nodeCount.add(graph.getNodeCount());
  74         }
  75     }
  76 
  77     private static void emitBlock(NodeLIRBuilderTool nodeLirGen, LIRGenerationResult lirGenRes, Block b, StructuredGraph graph, BlockMap<List<Node>> blockMap) {
  78         assert !isProcessed(lirGenRes, b) : "Block already processed " + b;
  79         assert verifyPredecessors(lirGenRes, b);
  80         nodeLirGen.doBlock(b, graph, blockMap);
  81         if (instructionCounter.isEnabled()) {
  82             instructionCounter.add(lirGenRes.getLIR().getLIRforBlock(b).size());
  83         }
  84     }
  85 
  86     private static boolean verifyPredecessors(LIRGenerationResult lirGenRes, Block block) {
  87         for (Block pred : block.getPredecessors()) {
  88             if (!block.isLoopHeader() || !pred.isLoopEnd()) {
  89                 assert isProcessed(lirGenRes, pred) : "Predecessor not yet processed " + pred;
  90             }
  91         }
  92         return true;
  93     }
  94 
  95     private static boolean isProcessed(LIRGenerationResult lirGenRes, Block b) {
  96         return lirGenRes.getLIR().getLIRforBlock(b) != null;
  97     }
  98 
  99 }


   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.core;
  24 
  25 import java.util.List;
  26 
  27 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
  28 import org.graalvm.compiler.core.common.cfg.BlockMap;
  29 import org.graalvm.compiler.debug.CounterKey;
  30 import org.graalvm.compiler.debug.DebugContext;
  31 import org.graalvm.compiler.graph.Node;
  32 import org.graalvm.compiler.lir.LIR;
  33 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
  34 import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
  35 import org.graalvm.compiler.lir.phases.LIRPhase;
  36 import org.graalvm.compiler.lir.ssa.SSAUtil;
  37 import org.graalvm.compiler.nodes.StructuredGraph;
  38 import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult;
  39 import org.graalvm.compiler.nodes.cfg.Block;
  40 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
  41 
  42 import jdk.vm.ci.code.TargetDescription;
  43 
  44 public class LIRGenerationPhase extends LIRPhase<LIRGenerationPhase.LIRGenerationContext> {
  45 
  46     public static final class LIRGenerationContext {
  47         private final NodeLIRBuilderTool nodeLirBuilder;
  48         private final LIRGeneratorTool lirGen;
  49         private final StructuredGraph graph;
  50         private final ScheduleResult schedule;
  51 
  52         public LIRGenerationContext(LIRGeneratorTool lirGen, NodeLIRBuilderTool nodeLirBuilder, StructuredGraph graph, ScheduleResult schedule) {
  53             this.nodeLirBuilder = nodeLirBuilder;
  54             this.lirGen = lirGen;
  55             this.graph = graph;
  56             this.schedule = schedule;
  57         }
  58     }
  59 
  60     private static final CounterKey instructionCounter = DebugContext.counter("GeneratedLIRInstructions");
  61     private static final CounterKey nodeCount = DebugContext.counter("FinalNodeCount");
  62 
  63     @Override
  64     protected final void run(TargetDescription target, LIRGenerationResult lirGenRes, LIRGenerationPhase.LIRGenerationContext context) {
  65         NodeLIRBuilderTool nodeLirBuilder = context.nodeLirBuilder;
  66         StructuredGraph graph = context.graph;
  67         ScheduleResult schedule = context.schedule;
  68         for (AbstractBlockBase<?> b : lirGenRes.getLIR().getControlFlowGraph().getBlocks()) {
  69             emitBlock(nodeLirBuilder, lirGenRes, (Block) b, graph, schedule.getBlockToNodesMap());
  70         }
  71         context.lirGen.beforeRegisterAllocation();
  72         assert SSAUtil.verifySSAForm(lirGenRes.getLIR());
  73         nodeCount.add(graph.getDebug(), graph.getNodeCount());


  74     }
  75 
  76     private static void emitBlock(NodeLIRBuilderTool nodeLirGen, LIRGenerationResult lirGenRes, Block b, StructuredGraph graph, BlockMap<List<Node>> blockMap) {
  77         assert !isProcessed(lirGenRes, b) : "Block already processed " + b;
  78         assert verifyPredecessors(lirGenRes, b);
  79         nodeLirGen.doBlock(b, graph, blockMap);
  80         LIR lir = lirGenRes.getLIR();
  81         DebugContext debug = lir.getDebug();
  82         instructionCounter.add(debug, lir.getLIRforBlock(b).size());
  83     }
  84 
  85     private static boolean verifyPredecessors(LIRGenerationResult lirGenRes, Block block) {
  86         for (Block pred : block.getPredecessors()) {
  87             if (!block.isLoopHeader() || !pred.isLoopEnd()) {
  88                 assert isProcessed(lirGenRes, pred) : "Predecessor not yet processed " + pred;
  89             }
  90         }
  91         return true;
  92     }
  93 
  94     private static boolean isProcessed(LIRGenerationResult lirGenRes, Block b) {
  95         return lirGenRes.getLIR().getLIRforBlock(b) != null;
  96     }
  97 
  98 }
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/LIRGenerationPhase.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File