Mercurial > hg > graal-compiler
view graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/LoweringPhase.java @ 4436:cd1e19b72f13
Merge
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Sat, 04 Feb 2012 11:45:35 +0100 |
parents | 19fb5eea48b9 57cb8ec5f6bb |
children | 681e969888a7 |
line wrap: on
line source
/* * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.oracle.max.graal.compiler.phases; import com.oracle.max.graal.compiler.*; import com.oracle.max.graal.compiler.cfg.*; import com.oracle.max.graal.cri.*; import com.oracle.max.graal.graph.*; import com.oracle.max.graal.nodes.*; import com.oracle.max.graal.nodes.spi.*; public class LoweringPhase extends Phase { private final GraalRuntime runtime; public LoweringPhase(GraalRuntime runtime) { this.runtime = runtime; } @Override protected void run(final StructuredGraph graph) { ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, false, true, true); NodeBitMap processed = graph.createNodeBitMap(); NodeBitMap activeGuards = graph.createNodeBitMap(); processBlock(cfg.getStartBlock(), activeGuards, processed, null); processed.negate(); final CiLoweringTool loweringTool = new CiLoweringTool() { @Override public Node getGuardAnchor() { throw new UnsupportedOperationException(); } @Override public GraalRuntime getRuntime() { return runtime; } @Override public Node createGuard(Node condition) { // TODO(tw): Explain why this must not be called on floating nodes. throw new UnsupportedOperationException(); } }; for (Node node : processed) { if (node instanceof Lowerable) { assert !(node instanceof FixedNode) || node.predecessor() == null; ((Lowerable) node).lower(loweringTool); } } } private void processBlock(Block block, NodeBitMap activeGuards, NodeBitMap processed, FixedNode parentAnchor) { FixedNode anchor = parentAnchor; if (anchor == null) { anchor = block.getBeginNode(); } process(block, activeGuards, processed, anchor); // Process always reached block first. Block alwaysReachedBlock = block.getPostdominator(); if (alwaysReachedBlock != null && alwaysReachedBlock.getDominator() == block) { assert alwaysReachedBlock.getDominator() == block; processBlock(alwaysReachedBlock, activeGuards, processed, anchor); } // Now go for the other dominators. for (Block dominated : block.getDominated()) { if (dominated != alwaysReachedBlock) { assert dominated.getDominator() == block; processBlock(dominated, activeGuards, processed, null); } } if (parentAnchor == null) { for (GuardNode guard : anchor.usages().filter(GuardNode.class)) { activeGuards.clear(guard); } } } private void process(final Block b, final NodeBitMap activeGuards, NodeBitMap processed, final Node anchor) { final CiLoweringTool loweringTool = new CiLoweringTool() { @Override public Node getGuardAnchor() { return anchor; } @Override public GraalRuntime getRuntime() { return runtime; } @Override public Node createGuard(Node condition) { FixedNode guardAnchor = (FixedNode) getGuardAnchor(); if (GraalOptions.OptEliminateGuards) { for (Node usage : condition.usages()) { if (activeGuards.isMarked(usage)) { return usage; } } } GuardNode newGuard = guardAnchor.graph().unique(new GuardNode((BooleanNode) condition, guardAnchor)); activeGuards.grow(); activeGuards.mark(newGuard); return newGuard; } }; // Lower the instructions of this block. for (Node node : b.getNodes()) { processed.mark(node); if (node instanceof Lowerable) { ((Lowerable) node).lower(loweringTool); } } } }