comparison graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelPhaseSuite.java @ 19220:1487207db440

Introduce LowLevelPhaseSuite and LowLevelCompilerConfiguration.
author Josef Eisl <josef.eisl@jku.at>
date Mon, 09 Feb 2015 13:20:04 +0100
parents
children 9c47b23fb0a2
comparison
equal deleted inserted replaced
19219:edd93c34d015 19220:1487207db440
1 /*
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
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 com.oracle.graal.lir.phases;
24
25 import java.util.*;
26
27 import com.oracle.graal.api.code.*;
28 import com.oracle.graal.compiler.common.cfg.*;
29 import com.oracle.graal.lir.gen.*;
30
31 public class LowLevelPhaseSuite<C, B extends AbstractBlock<B>> extends LowLevelPhase<C, B> {
32 private final List<LowLevelPhase<C, B>> phases;
33
34 public LowLevelPhaseSuite() {
35 phases = new ArrayList<>();
36 }
37
38 /**
39 * Add a new phase at the beginning of this suite.
40 */
41 public final void prependPhase(LowLevelPhase<C, B> phase) {
42 phases.add(0, phase);
43 }
44
45 /**
46 * Add a new phase at the end of this suite.
47 */
48 public final void appendPhase(LowLevelPhase<C, B> phase) {
49 phases.add(phase);
50 }
51
52 public final ListIterator<LowLevelPhase<C, B>> findPhase(Class<? extends LowLevelPhase<C, B>> phaseClass) {
53 ListIterator<LowLevelPhase<C, B>> it = phases.listIterator();
54 if (findNextPhase(it, phaseClass)) {
55 return it;
56 } else {
57 return null;
58 }
59 }
60
61 public static <C, B extends AbstractBlock<B>> boolean findNextPhase(ListIterator<LowLevelPhase<C, B>> it, Class<? extends LowLevelPhase<C, B>> phaseClass) {
62 while (it.hasNext()) {
63 LowLevelPhase<C, B> phase = it.next();
64 if (phaseClass.isInstance(phase)) {
65 return true;
66 }
67 }
68 return false;
69 }
70
71 @Override
72 protected void run(TargetDescription target, LIRGenerationResult lirGenRes, List<B> codeEmittingOrder, List<B> linearScanOrder, C context) {
73 for (LowLevelPhase<C, B> phase : phases) {
74 phase.apply(target, lirGenRes, codeEmittingOrder, linearScanOrder, context);
75 }
76 }
77
78 }