annotate graal/GraalCompiler/src/com/sun/c1x/C1XCompiler.java @ 2609:a57e051b33cd

Move Graphviz visualization code to its own project, GraalGraphviz
author Peter Hofer <peter.hofer@jku.at>
date Mon, 09 May 2011 10:43:57 +0200
parents 01c5c0443158
children 3558ca7088c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
1 /*
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
4 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
7 * published by the Free Software Foundation.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
8 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
13 * accompanied this code).
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
14 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
18 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
21 * questions.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
22 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
23 package com.sun.c1x;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
24
2602
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
25 import java.io.*;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
26 import java.util.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
27
2602
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
28 import com.oracle.graal.graph.*;
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
29 import com.oracle.graal.graph.vis.*;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
30 import com.sun.c1x.debug.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
31 import com.sun.c1x.globalstub.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
32 import com.sun.c1x.observer.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
33 import com.sun.c1x.target.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
34 import com.sun.cri.ci.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
35 import com.sun.cri.ri.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
36 import com.sun.cri.xir.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
37
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
38 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
39 * This class implements the compiler interface for C1X.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
40 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
41 * @author Thomas Wuerthinger
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
42 * @author Ben L. Titzer
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
43 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
44 public class C1XCompiler extends ObservableCompiler {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
45
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
46 public final Map<Object, GlobalStub> stubs = new HashMap<Object, GlobalStub>();
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
47
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
48 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
49 * The target that this compiler has been configured for.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
50 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
51 public final CiTarget target;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
52
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
53 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
54 * The runtime that this compiler has been configured for.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
55 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
56 public final RiRuntime runtime;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
57
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
58 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
59 * The XIR generator that lowers Java operations to machine operations.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
60 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
61 public final RiXirGenerator xir;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
62
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
63 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
64 * The backend that this compiler has been configured for.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
65 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
66 public final Backend backend;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
67
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
68 public final RiRegisterConfig globalStubRegisterConfig;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
69
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
70 public C1XCompiler(RiRuntime runtime, CiTarget target, RiXirGenerator xirGen, RiRegisterConfig globalStubRegisterConfig) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
71 this.runtime = runtime;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
72 this.target = target;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
73 this.xir = xirGen;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
74 this.globalStubRegisterConfig = globalStubRegisterConfig;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
75 this.backend = Backend.create(target.arch, this);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
76 init();
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
77 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
78
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
79 public CiResult compileMethod(RiMethod method, int osrBCI, RiXirGenerator xirGenerator, CiStatistics stats) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
80 long startTime = 0;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
81 int index = C1XMetrics.CompiledMethods++;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
82 if (C1XOptions.PrintCompilation) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
83 TTY.print(String.format("C1X %4d %-70s %-45s | ", index, method.holder().name(), method.name()));
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
84 startTime = System.nanoTime();
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
85 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
86
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
87 CiResult result = null;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
88 TTY.Filter filter = new TTY.Filter(C1XOptions.PrintFilter, method);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
89 C1XCompilation compilation = new C1XCompilation(this, method, osrBCI, stats);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
90 try {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
91 result = compilation.compile();
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
92 } finally {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
93 filter.remove();
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
94 compilation.close();
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
95 if (C1XOptions.PrintCompilation && !TTY.isSuppressed()) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
96 long time = (System.nanoTime() - startTime) / 100000;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
97 TTY.println(String.format("%3d.%dms", time / 10, time % 10));
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
98 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
99 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
100
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
101 return result;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
102 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
103
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
104 private void init() {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
105 final List<XirTemplate> xirTemplateStubs = xir.buildTemplates(backend.newXirAssembler());
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
106 final GlobalStubEmitter emitter = backend.newGlobalStubEmitter();
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
107
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
108 if (xirTemplateStubs != null) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
109 for (XirTemplate template : xirTemplateStubs) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
110 TTY.Filter filter = new TTY.Filter(C1XOptions.PrintFilter, template.name);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
111 try {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
112 stubs.put(template, emitter.emit(template, runtime));
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
113 } finally {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
114 filter.remove();
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
115 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
116 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
117 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
118
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
119 for (GlobalStub.Id id : GlobalStub.Id.values()) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
120 TTY.Filter suppressor = new TTY.Filter(C1XOptions.PrintFilter, id);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
121 try {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
122 stubs.put(id, emitter.emit(id, runtime));
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
123 } finally {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
124 suppressor.remove();
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
125 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
126 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
127
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
128 if (C1XOptions.PrintCFGToFile) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
129 addCompilationObserver(new CFGPrinterObserver());
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
130 }
2602
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
131 String dot = System.getProperty("c1x.dot");
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
132 if (dot != null && !dot.isEmpty()) {
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
133 if (!dot.endsWith("$")) {
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
134 dot = dot + ".*";
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
135 }
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
136 if (!dot.startsWith("^")) {
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
137 dot = ".*" + dot;
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
138 }
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
139 final String dotPattern = dot;
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
140 addCompilationObserver(new CompilationObserver() {
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
141 private Graph graph;
2603
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
142 private int n;
2602
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
143 public void compilationStarted(CompilationEvent event) {
2603
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
144 n = 0;
2602
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
145 }
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
146 public void compilationFinished(CompilationEvent event) {
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
147 }
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
148 public void compilationEvent(CompilationEvent event) {
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
149 if (event.getStartBlock() != null) {
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
150 graph = event.getStartBlock().graph();
2603
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
151 String name = event.getMethod().holder().name();
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
152 name = name.substring(1, name.length() - 1).replace('/', '.');
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
153 name = name + "." + event.getMethod().name();
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
154 if (name.matches(dotPattern)) {
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
155 ByteArrayOutputStream out = new ByteArrayOutputStream();
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
156 GraphvizPrinter printer = new GraphvizPrinter(out);
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
157 printer.begin(name);
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
158 printer.print(graph);
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
159 printer.end();
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
160
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
161 try {
2609
a57e051b33cd Move Graphviz visualization code to its own project, GraalGraphviz
Peter Hofer <peter.hofer@jku.at>
parents: 2603
diff changeset
162 GraphvizRunner.process(GraphvizRunner.DOT_LAYOUT, new ByteArrayInputStream(out.toByteArray()),
2603
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
163 new FileOutputStream(name + "_" + (n++) + event.getLabel() + ".pdf"), "pdf");
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
164 } catch (Exception e) {
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
165 e.printStackTrace();
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
166 }
01c5c0443158 new node layout: Phi
Lukas Stadler <lukas.stadler@jku.at>
parents: 2602
diff changeset
167 }
2602
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
168 }
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
169 }
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
170 });
0c6564c254af new node layout: BlockBegin, BlockEnd
Lukas Stadler <lukas.stadler@jku.at>
parents: 2523
diff changeset
171 }
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
172 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
173
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
174 public GlobalStub lookupGlobalStub(GlobalStub.Id id) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
175 GlobalStub globalStub = stubs.get(id);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
176 assert globalStub != null : "no stub for global stub id: " + id;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
177 return globalStub;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
178 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
179
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
180 public GlobalStub lookupGlobalStub(XirTemplate template) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
181 GlobalStub globalStub = stubs.get(template);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
182 assert globalStub != null : "no stub for XirTemplate: " + template;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
183 return globalStub;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
184 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
185
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
186 public GlobalStub lookupGlobalStub(CiRuntimeCall runtimeCall) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
187 GlobalStub globalStub = stubs.get(runtimeCall);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
188 if (globalStub == null) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
189 globalStub = backend.newGlobalStubEmitter().emit(runtimeCall, runtime);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
190 stubs.put(runtimeCall, globalStub);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
191 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
192
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
193 assert globalStub != null : "could not find global stub for runtime call: " + runtimeCall;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
194 return globalStub;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
195 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
196 }