001/* 002 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package com.oracle.graal.compiler; 024 025import static com.oracle.graal.compiler.common.BackendOptions.*; 026 027import java.util.*; 028 029import jdk.internal.jvmci.code.*; 030 031import com.oracle.graal.compiler.common.cfg.*; 032import com.oracle.graal.graph.*; 033import com.oracle.graal.lir.gen.*; 034import com.oracle.graal.lir.phases.*; 035import com.oracle.graal.lir.ssa.*; 036import com.oracle.graal.nodes.*; 037import com.oracle.graal.nodes.cfg.*; 038import com.oracle.graal.nodes.spi.*; 039import com.oracle.graal.phases.schedule.*; 040 041public class LIRGenerationPhase extends LIRPhase<LIRGenerationPhase.LIRGenerationContext> { 042 043 public static final class LIRGenerationContext { 044 private final NodeLIRBuilderTool nodeLirBuilder; 045 private final LIRGeneratorTool lirGen; 046 private final StructuredGraph graph; 047 private final SchedulePhase schedule; 048 049 public LIRGenerationContext(LIRGeneratorTool lirGen, NodeLIRBuilderTool nodeLirBuilder, StructuredGraph graph, SchedulePhase schedule) { 050 this.nodeLirBuilder = nodeLirBuilder; 051 this.lirGen = lirGen; 052 this.graph = graph; 053 this.schedule = schedule; 054 } 055 } 056 057 @Override 058 protected final <B extends AbstractBlockBase<B>> void run(TargetDescription target, LIRGenerationResult lirGenRes, List<B> codeEmittingOrder, List<B> linearScanOrder, 059 LIRGenerationPhase.LIRGenerationContext context) { 060 NodeLIRBuilderTool nodeLirBuilder = context.nodeLirBuilder; 061 StructuredGraph graph = context.graph; 062 SchedulePhase schedule = context.schedule; 063 for (B b : linearScanOrder) { 064 emitBlock(nodeLirBuilder, lirGenRes, (Block) b, graph, schedule.getBlockToNodesMap()); 065 } 066 context.lirGen.beforeRegisterAllocation(); 067 assert !ConstructionSSAlirDuringLirBuilding.getValue() || SSAUtil.verifySSAForm(lirGenRes.getLIR()); 068 } 069 070 private static void emitBlock(NodeLIRBuilderTool nodeLirGen, LIRGenerationResult lirGenRes, Block b, StructuredGraph graph, BlockMap<List<Node>> blockMap) { 071 if (lirGenRes.getLIR().getLIRforBlock(b) == null) { 072 for (Block pred : b.getPredecessors()) { 073 if (!b.isLoopHeader() || !pred.isLoopEnd()) { 074 emitBlock(nodeLirGen, lirGenRes, pred, graph, blockMap); 075 } 076 } 077 nodeLirGen.doBlock(b, graph, blockMap); 078 } 079 } 080 081}