annotate graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java @ 2981:42681ed31c4d

Some LoopCounter work
author Gilles Duboscq <gilles.duboscq@oracle.com>
date Wed, 15 Jun 2011 11:20:26 +0200
parents 9d80049e76bd
children 53dcb0794619
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2839
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
1 /*
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
2 * Copyright (c) 2011, 2011, Oracle and/or its affiliates. All rights reserved.
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
4 *
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
7 * published by the Free Software Foundation.
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
8 *
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
13 * accompanied this code).
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
14 *
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
18 *
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
21 * questions.
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
22 */
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
23 package com.oracle.max.graal.compiler.phases;
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
24
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
25 import com.oracle.max.graal.compiler.*;
2981
42681ed31c4d Some LoopCounter work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2917
diff changeset
26 import com.oracle.max.graal.compiler.observer.*;
42681ed31c4d Some LoopCounter work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2917
diff changeset
27 import com.oracle.max.graal.compiler.schedule.*;
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
28 import com.oracle.max.graal.graph.Graph;
2839
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
29
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
30 public abstract class Phase {
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
31
2879
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
32 private final String name;
2902
434d71eec7a9 Ensure that only one phase timer is running at one time.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2901
diff changeset
33 private static final ThreadLocal<Phase> currentPhase = new ThreadLocal<Phase>();
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
34
2879
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
35 public Phase() {
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
36 this.name = this.getClass().getSimpleName();
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
37 }
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
38
2879
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
39 public Phase(String name) {
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
40 this.name = name;
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
41 }
2839
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
42
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
43 public final void apply(Graph graph) {
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
44 assert graph != null;
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
45
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
46 int startDeletedNodeCount = graph.getDeletedNodeCount();
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
47 int startNodeCount = graph.getNodeCount();
2903
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
48 Phase oldCurrentPhase = null;
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
49 if (GraalOptions.Time) {
2903
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
50 oldCurrentPhase = currentPhase.get();
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
51 currentPhase.set(this);
2902
434d71eec7a9 Ensure that only one phase timer is running at one time.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2901
diff changeset
52 if (oldCurrentPhase != null) {
434d71eec7a9 Ensure that only one phase timer is running at one time.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2901
diff changeset
53 GraalTimers.get(oldCurrentPhase.getName()).stop();
434d71eec7a9 Ensure that only one phase timer is running at one time.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2901
diff changeset
54 }
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
55 GraalTimers.get(getName()).start();
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
56 }
2839
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
57 run(graph);
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
58 if (GraalOptions.Time) {
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
59 GraalTimers.get(getName()).stop();
2902
434d71eec7a9 Ensure that only one phase timer is running at one time.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2901
diff changeset
60 if (oldCurrentPhase != null) {
434d71eec7a9 Ensure that only one phase timer is running at one time.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2901
diff changeset
61 GraalTimers.get(oldCurrentPhase.getName()).start();
434d71eec7a9 Ensure that only one phase timer is running at one time.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2901
diff changeset
62 }
2903
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
63 currentPhase.set(oldCurrentPhase);
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
64 }
2903
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
65 if (GraalOptions.Meter) {
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
66 int deletedNodeCount = graph.getDeletedNodeCount() - startDeletedNodeCount;
2917
9d80049e76bd Fix created node count metric, Fix wrong asserts in graalVMExits & FloatAdd
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2903
diff changeset
67 int createdNodeCount = graph.getNodeCount() - startNodeCount + deletedNodeCount;
2903
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
68 GraalMetrics.get(getName().concat(".executed")).increment();
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
69 GraalMetrics.get(getName().concat(".deletedNodes")).increment(deletedNodeCount);
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
70 GraalMetrics.get(getName().concat(".createdNodes")).increment(createdNodeCount);
eb3a82946429 Measure nodes created and nodes deleted for nodes. New option -G:+Meter.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2902
diff changeset
71 }
2981
42681ed31c4d Some LoopCounter work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2917
diff changeset
72 GraalCompilation compilation = GraalCompilation.compilation();
42681ed31c4d Some LoopCounter work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2917
diff changeset
73 if (compilation.compiler.isObserved() && this.getClass() != IdentifyBlocksPhase.class) {
42681ed31c4d Some LoopCounter work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2917
diff changeset
74 compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, "After " + getName(), graph, true, false));
42681ed31c4d Some LoopCounter work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2917
diff changeset
75 }
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
76
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
77 // (Item|Graph|Phase|Value)
2839
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
78 }
2901
d577d07cedec Added time measurement for phases.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2879
diff changeset
79
2879
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
80 public final String getName() {
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
81 return name;
7f584bf507ed Renamed and moved phase subclasses.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2874
diff changeset
82 }
2839
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
83
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
84 protected abstract void run(Graph graph);
87018b9c8304 Added Op and Phase class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
85 }