Mercurial > hg > graal-compiler
changeset 19272:2b0bc8ad8372
Rename LowLevelPhase to LIRPhase.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Wed, 11 Feb 2015 15:35:41 +0100 |
parents | 421a2bf6dc44 |
children | 63c619b0cc83 |
files | graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LIRPhase.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelHighTierPhase.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelLowTierPhase.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelMidTierPhase.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelPhase.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelPhaseSuite.java |
diffstat | 6 files changed, 121 insertions(+), 121 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LIRPhase.java Wed Feb 11 15:35:41 2015 +0100 @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2015, 2015, 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.graal.lir.phases; + +import java.util.*; +import java.util.regex.*; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.compiler.common.cfg.*; +import com.oracle.graal.debug.*; +import com.oracle.graal.debug.Debug.Scope; +import com.oracle.graal.debug.DebugMemUseTracker.Closeable; +import com.oracle.graal.debug.internal.*; +import com.oracle.graal.lir.*; +import com.oracle.graal.lir.gen.*; + +/** + * Base class for all {@link LIR low-level} phases. Subclasses should be stateless. There will be + * one global instance for each phase that is shared for all compilations. + */ +public abstract class LIRPhase<C> { + + private static final int PHASE_DUMP_LEVEL = 2; + + private CharSequence name; + + /** + * Records time spent within {@link #apply}. + */ + private final DebugTimer timer; + + /** + * Records memory usage within {@link #apply}. + */ + private final DebugMemUseTracker memUseTracker; + + private static final Pattern NAME_PATTERN = Pattern.compile("[A-Z][A-Za-z0-9]+"); + + private static boolean checkName(String name) { + assert name == null || NAME_PATTERN.matcher(name).matches() : "illegal phase name: " + name; + return true; + } + + public LIRPhase() { + timer = Debug.timer("LowLevelPhaseTime_%s", getClass()); + memUseTracker = Debug.memUseTracker("LowLevelPhaseMemUse_%s", getClass()); + } + + protected LIRPhase(String name) { + assert checkName(name); + this.name = name; + timer = Debug.timer("LowLevelPhaseTime_%s", getClass()); + memUseTracker = Debug.memUseTracker("LowLevelPhaseMemUse_%s", getClass()); + } + + public final <B extends AbstractBlock<B>> void apply(TargetDescription target, LIRGenerationResult lirGenRes, List<B> codeEmittingOrder, List<B> linearScanOrder, C context) { + apply(target, lirGenRes, codeEmittingOrder, linearScanOrder, context, true); + } + + public final <B extends AbstractBlock<B>> void apply(TargetDescription target, LIRGenerationResult lirGenRes, List<B> codeEmittingOrder, List<B> linearScanOrder, C context, boolean dumpLIR) { + try (TimerCloseable a = timer.start(); Scope s = Debug.scope(getName(), this); Closeable c = memUseTracker.start()) { + run(target, lirGenRes, codeEmittingOrder, linearScanOrder, context); + if (dumpLIR && Debug.isDumpEnabled(PHASE_DUMP_LEVEL)) { + Debug.dump(PHASE_DUMP_LEVEL, lirGenRes.getLIR(), "After phase %s", getName()); + } + } catch (Throwable e) { + throw Debug.handle(e); + } + } + + protected abstract <B extends AbstractBlock<B>> void run(TargetDescription target, LIRGenerationResult lirGenRes, List<B> codeEmittingOrder, List<B> linearScanOrder, C context); + + protected CharSequence createName() { + String className = LIRPhase.this.getClass().getName(); + String s = className.substring(className.lastIndexOf(".") + 1); // strip the package name + if (s.endsWith("Phase")) { + s = s.substring(0, s.length() - "Phase".length()); + } + return s; + } + + public final CharSequence getName() { + if (name == null) { + name = createName(); + } + return name; + } + +}
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelHighTierPhase.java Wed Feb 11 15:32:33 2015 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelHighTierPhase.java Wed Feb 11 15:35:41 2015 +0100 @@ -28,7 +28,7 @@ import com.oracle.graal.compiler.common.cfg.*; import com.oracle.graal.lir.gen.*; -public abstract class LowLevelHighTierPhase extends LowLevelPhase<LowLevelHighTierPhase.LowLevelHighTierContext> { +public abstract class LowLevelHighTierPhase extends LIRPhase<LowLevelHighTierPhase.LowLevelHighTierContext> { public static final class LowLevelHighTierContext { private final LIRGeneratorTool lirGen;
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelLowTierPhase.java Wed Feb 11 15:32:33 2015 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelLowTierPhase.java Wed Feb 11 15:35:41 2015 +0100 @@ -28,7 +28,7 @@ import com.oracle.graal.compiler.common.cfg.*; import com.oracle.graal.lir.gen.*; -public abstract class LowLevelLowTierPhase extends LowLevelPhase<LowLevelLowTierPhase.LowLevelLowTierContext> { +public abstract class LowLevelLowTierPhase extends LIRPhase<LowLevelLowTierPhase.LowLevelLowTierContext> { public static final class LowLevelLowTierContext { }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelMidTierPhase.java Wed Feb 11 15:32:33 2015 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelMidTierPhase.java Wed Feb 11 15:35:41 2015 +0100 @@ -28,7 +28,7 @@ import com.oracle.graal.compiler.common.cfg.*; import com.oracle.graal.lir.gen.*; -public abstract class LowLevelMidTierPhase extends LowLevelPhase<LowLevelMidTierPhase.LowLevelMidTierContext> { +public abstract class LowLevelMidTierPhase extends LIRPhase<LowLevelMidTierPhase.LowLevelMidTierContext> { public static final class LowLevelMidTierContext { }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelPhase.java Wed Feb 11 15:32:33 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2015, 2015, 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.graal.lir.phases; - -import java.util.*; -import java.util.regex.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.compiler.common.cfg.*; -import com.oracle.graal.debug.*; -import com.oracle.graal.debug.Debug.Scope; -import com.oracle.graal.debug.DebugMemUseTracker.Closeable; -import com.oracle.graal.debug.internal.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.gen.*; - -/** - * Base class for all {@link LIR low-level} phases. Subclasses should be stateless. There will be - * one global instance for each phase that is shared for all compilations. - */ -public abstract class LowLevelPhase<C> { - - private static final int PHASE_DUMP_LEVEL = 2; - - private CharSequence name; - - /** - * Records time spent within {@link #apply}. - */ - private final DebugTimer timer; - - /** - * Records memory usage within {@link #apply}. - */ - private final DebugMemUseTracker memUseTracker; - - private static final Pattern NAME_PATTERN = Pattern.compile("[A-Z][A-Za-z0-9]+"); - - private static boolean checkName(String name) { - assert name == null || NAME_PATTERN.matcher(name).matches() : "illegal phase name: " + name; - return true; - } - - public LowLevelPhase() { - timer = Debug.timer("LowLevelPhaseTime_%s", getClass()); - memUseTracker = Debug.memUseTracker("LowLevelPhaseMemUse_%s", getClass()); - } - - protected LowLevelPhase(String name) { - assert checkName(name); - this.name = name; - timer = Debug.timer("LowLevelPhaseTime_%s", getClass()); - memUseTracker = Debug.memUseTracker("LowLevelPhaseMemUse_%s", getClass()); - } - - public final <B extends AbstractBlock<B>> void apply(TargetDescription target, LIRGenerationResult lirGenRes, List<B> codeEmittingOrder, List<B> linearScanOrder, C context) { - apply(target, lirGenRes, codeEmittingOrder, linearScanOrder, context, true); - } - - public final <B extends AbstractBlock<B>> void apply(TargetDescription target, LIRGenerationResult lirGenRes, List<B> codeEmittingOrder, List<B> linearScanOrder, C context, boolean dumpLIR) { - try (TimerCloseable a = timer.start(); Scope s = Debug.scope(getName(), this); Closeable c = memUseTracker.start()) { - run(target, lirGenRes, codeEmittingOrder, linearScanOrder, context); - if (dumpLIR && Debug.isDumpEnabled(PHASE_DUMP_LEVEL)) { - Debug.dump(PHASE_DUMP_LEVEL, lirGenRes.getLIR(), "After phase %s", getName()); - } - } catch (Throwable e) { - throw Debug.handle(e); - } - } - - protected abstract <B extends AbstractBlock<B>> void run(TargetDescription target, LIRGenerationResult lirGenRes, List<B> codeEmittingOrder, List<B> linearScanOrder, C context); - - protected CharSequence createName() { - String className = LowLevelPhase.this.getClass().getName(); - String s = className.substring(className.lastIndexOf(".") + 1); // strip the package name - if (s.endsWith("Phase")) { - s = s.substring(0, s.length() - "Phase".length()); - } - return s; - } - - public final CharSequence getName() { - if (name == null) { - name = createName(); - } - return name; - } - -}
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelPhaseSuite.java Wed Feb 11 15:32:33 2015 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelPhaseSuite.java Wed Feb 11 15:35:41 2015 +0100 @@ -28,8 +28,8 @@ import com.oracle.graal.compiler.common.cfg.*; import com.oracle.graal.lir.gen.*; -public abstract class LowLevelPhaseSuite<C> extends LowLevelPhase<C> { - private final List<LowLevelPhase<C>> phases; +public abstract class LowLevelPhaseSuite<C> extends LIRPhase<C> { + private final List<LIRPhase<C>> phases; public LowLevelPhaseSuite() { phases = new ArrayList<>(); @@ -38,19 +38,19 @@ /** * Add a new phase at the beginning of this suite. */ - public final void prependPhase(LowLevelPhase<C> phase) { + public final void prependPhase(LIRPhase<C> phase) { phases.add(0, phase); } /** * Add a new phase at the end of this suite. */ - public final void appendPhase(LowLevelPhase<C> phase) { + public final void appendPhase(LIRPhase<C> phase) { phases.add(phase); } - public final ListIterator<LowLevelPhase<C>> findPhase(Class<? extends LowLevelPhase<C>> phaseClass) { - ListIterator<LowLevelPhase<C>> it = phases.listIterator(); + public final ListIterator<LIRPhase<C>> findPhase(Class<? extends LIRPhase<C>> phaseClass) { + ListIterator<LIRPhase<C>> it = phases.listIterator(); if (findNextPhase(it, phaseClass)) { return it; } else { @@ -58,9 +58,9 @@ } } - public static <C> boolean findNextPhase(ListIterator<LowLevelPhase<C>> it, Class<? extends LowLevelPhase<C>> phaseClass) { + public static <C> boolean findNextPhase(ListIterator<LIRPhase<C>> it, Class<? extends LIRPhase<C>> phaseClass) { while (it.hasNext()) { - LowLevelPhase<C> phase = it.next(); + LIRPhase<C> phase = it.next(); if (phaseClass.isInstance(phase)) { return true; } @@ -70,7 +70,7 @@ @Override protected <B extends AbstractBlock<B>> void run(TargetDescription target, LIRGenerationResult lirGenRes, List<B> codeEmittingOrder, List<B> linearScanOrder, C context) { - for (LowLevelPhase<C> phase : phases) { + for (LIRPhase<C> phase : phases) { phase.apply(target, lirGenRes, codeEmittingOrder, linearScanOrder, context); } }