Mercurial > hg > truffle
annotate graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelPhaseSuite.java @ 19226:9c47b23fb0a2
LowLevelPhase: add support for custom name.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Mon, 09 Feb 2015 15:10:13 +0100 |
parents | 1487207db440 |
children | 6340d851894b |
rev | line source |
---|---|
19220
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
1 /* |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
4 * |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
8 * |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
14 * |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
18 * |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
21 * questions. |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
22 */ |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
23 package com.oracle.graal.lir.phases; |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
24 |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
25 import java.util.*; |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
26 |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
27 import com.oracle.graal.api.code.*; |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
28 import com.oracle.graal.compiler.common.cfg.*; |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
29 import com.oracle.graal.lir.gen.*; |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
30 |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
31 public class LowLevelPhaseSuite<C, B extends AbstractBlock<B>> extends LowLevelPhase<C, B> { |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
32 private final List<LowLevelPhase<C, B>> phases; |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
33 |
19226
9c47b23fb0a2
LowLevelPhase: add support for custom name.
Josef Eisl <josef.eisl@jku.at>
parents:
19220
diff
changeset
|
34 public LowLevelPhaseSuite(Class<C> contextClass) { |
9c47b23fb0a2
LowLevelPhase: add support for custom name.
Josef Eisl <josef.eisl@jku.at>
parents:
19220
diff
changeset
|
35 super(getNameFromContext(contextClass)); |
19220
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
36 phases = new ArrayList<>(); |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
37 } |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
38 |
19226
9c47b23fb0a2
LowLevelPhase: add support for custom name.
Josef Eisl <josef.eisl@jku.at>
parents:
19220
diff
changeset
|
39 private static <C> String getNameFromContext(Class<C> contextClass) { |
9c47b23fb0a2
LowLevelPhase: add support for custom name.
Josef Eisl <josef.eisl@jku.at>
parents:
19220
diff
changeset
|
40 String className = contextClass.getName(); |
9c47b23fb0a2
LowLevelPhase: add support for custom name.
Josef Eisl <josef.eisl@jku.at>
parents:
19220
diff
changeset
|
41 String s0 = className.substring(className.lastIndexOf(".") + 1); // strip the package name |
9c47b23fb0a2
LowLevelPhase: add support for custom name.
Josef Eisl <josef.eisl@jku.at>
parents:
19220
diff
changeset
|
42 String s = s0.substring(s0.lastIndexOf("$") + 1); // strip the enclosing class name |
9c47b23fb0a2
LowLevelPhase: add support for custom name.
Josef Eisl <josef.eisl@jku.at>
parents:
19220
diff
changeset
|
43 if (s.endsWith("Context")) { |
9c47b23fb0a2
LowLevelPhase: add support for custom name.
Josef Eisl <josef.eisl@jku.at>
parents:
19220
diff
changeset
|
44 s = s.substring(0, s.length() - "Context".length()); |
9c47b23fb0a2
LowLevelPhase: add support for custom name.
Josef Eisl <josef.eisl@jku.at>
parents:
19220
diff
changeset
|
45 } |
9c47b23fb0a2
LowLevelPhase: add support for custom name.
Josef Eisl <josef.eisl@jku.at>
parents:
19220
diff
changeset
|
46 return s; |
9c47b23fb0a2
LowLevelPhase: add support for custom name.
Josef Eisl <josef.eisl@jku.at>
parents:
19220
diff
changeset
|
47 } |
9c47b23fb0a2
LowLevelPhase: add support for custom name.
Josef Eisl <josef.eisl@jku.at>
parents:
19220
diff
changeset
|
48 |
19220
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
49 /** |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
50 * Add a new phase at the beginning of this suite. |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
51 */ |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
52 public final void prependPhase(LowLevelPhase<C, B> phase) { |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
53 phases.add(0, phase); |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
54 } |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
55 |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
56 /** |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
57 * Add a new phase at the end of this suite. |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
58 */ |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
59 public final void appendPhase(LowLevelPhase<C, B> phase) { |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
60 phases.add(phase); |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
61 } |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
62 |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
63 public final ListIterator<LowLevelPhase<C, B>> findPhase(Class<? extends LowLevelPhase<C, B>> phaseClass) { |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
64 ListIterator<LowLevelPhase<C, B>> it = phases.listIterator(); |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
65 if (findNextPhase(it, phaseClass)) { |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
66 return it; |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
67 } else { |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
68 return null; |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
69 } |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
70 } |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
71 |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
72 public static <C, B extends AbstractBlock<B>> boolean findNextPhase(ListIterator<LowLevelPhase<C, B>> it, Class<? extends LowLevelPhase<C, B>> phaseClass) { |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
73 while (it.hasNext()) { |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
74 LowLevelPhase<C, B> phase = it.next(); |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
75 if (phaseClass.isInstance(phase)) { |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
76 return true; |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
77 } |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
78 } |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
79 return false; |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
80 } |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
81 |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
82 @Override |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
83 protected void run(TargetDescription target, LIRGenerationResult lirGenRes, List<B> codeEmittingOrder, List<B> linearScanOrder, C context) { |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
84 for (LowLevelPhase<C, B> phase : phases) { |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
85 phase.apply(target, lirGenRes, codeEmittingOrder, linearScanOrder, context); |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
86 } |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
87 } |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
88 |
1487207db440
Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
89 } |