Mercurial > hg > graal-compiler
comparison graal/GraalCompiler/src/com/sun/c1x/C1XCompiler.java @ 2509:16b9a8b5ad39
Renamings Runtime=>GraalRuntime and Compiler=>GraalCompiler
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 27 Apr 2011 11:50:44 +0200 |
parents | graal/Compiler/src/com/sun/c1x/C1XCompiler.java@9ec15d6914ca |
children | 268b8eb84b6e |
comparison
equal
deleted
inserted
replaced
2508:fea94949e0a2 | 2509:16b9a8b5ad39 |
---|---|
1 /* | |
2 * Copyright (c) 2009, 2011, 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.sun.c1x; | |
24 | |
25 import java.util.*; | |
26 | |
27 import com.sun.c1x.debug.*; | |
28 import com.sun.c1x.globalstub.*; | |
29 import com.sun.c1x.observer.*; | |
30 import com.sun.c1x.target.*; | |
31 import com.sun.cri.ci.*; | |
32 import com.sun.cri.ri.*; | |
33 import com.sun.cri.xir.*; | |
34 | |
35 /** | |
36 * This class implements the compiler interface for C1X. | |
37 * | |
38 * @author Thomas Wuerthinger | |
39 * @author Ben L. Titzer | |
40 */ | |
41 public class C1XCompiler extends ObservableCompiler { | |
42 | |
43 public final Map<Object, GlobalStub> stubs = new HashMap<Object, GlobalStub>(); | |
44 | |
45 /** | |
46 * The target that this compiler has been configured for. | |
47 */ | |
48 public final CiTarget target; | |
49 | |
50 /** | |
51 * The runtime that this compiler has been configured for. | |
52 */ | |
53 public final RiRuntime runtime; | |
54 | |
55 /** | |
56 * The XIR generator that lowers Java operations to machine operations. | |
57 */ | |
58 public final RiXirGenerator xir; | |
59 | |
60 /** | |
61 * The ordered set of compiler extensions. | |
62 */ | |
63 public List<C1XCompilerExtension> extensions; | |
64 | |
65 /** | |
66 * The backend that this compiler has been configured for. | |
67 */ | |
68 public final Backend backend; | |
69 | |
70 public final RiRegisterConfig globalStubRegisterConfig; | |
71 | |
72 public C1XCompiler(RiRuntime runtime, CiTarget target, RiXirGenerator xirGen, RiRegisterConfig globalStubRegisterConfig) { | |
73 this.runtime = runtime; | |
74 this.target = target; | |
75 this.xir = xirGen; | |
76 this.globalStubRegisterConfig = globalStubRegisterConfig; | |
77 this.backend = Backend.create(target.arch, this); | |
78 init(); | |
79 } | |
80 | |
81 public CiResult compileMethod(RiMethod method, int osrBCI, RiXirGenerator xirGenerator, CiStatistics stats) { | |
82 long startTime = 0; | |
83 int index = C1XMetrics.CompiledMethods++; | |
84 if (C1XOptions.PrintCompilation) { | |
85 TTY.print(String.format("C1X %4d %-70s %-45s | ", index, method.holder().name(), method.name())); | |
86 startTime = System.nanoTime(); | |
87 } | |
88 | |
89 CiResult result = null; | |
90 TTY.Filter filter = new TTY.Filter(C1XOptions.PrintFilter, method); | |
91 C1XCompilation compilation = new C1XCompilation(this, method, osrBCI, stats); | |
92 try { | |
93 result = compilation.compile(); | |
94 } finally { | |
95 filter.remove(); | |
96 compilation.close(); | |
97 if (C1XOptions.PrintCompilation && !TTY.isSuppressed()) { | |
98 long time = (System.nanoTime() - startTime) / 100000; | |
99 TTY.println(String.format("%3d.%dms", time / 10, time % 10)); | |
100 } | |
101 } | |
102 | |
103 return result; | |
104 } | |
105 | |
106 private void init() { | |
107 final List<XirTemplate> xirTemplateStubs = xir.buildTemplates(backend.newXirAssembler()); | |
108 final GlobalStubEmitter emitter = backend.newGlobalStubEmitter(); | |
109 | |
110 if (xirTemplateStubs != null) { | |
111 for (XirTemplate template : xirTemplateStubs) { | |
112 TTY.Filter filter = new TTY.Filter(C1XOptions.PrintFilter, template.name); | |
113 try { | |
114 stubs.put(template, emitter.emit(template, runtime)); | |
115 } finally { | |
116 filter.remove(); | |
117 } | |
118 } | |
119 } | |
120 | |
121 for (GlobalStub.Id id : GlobalStub.Id.values()) { | |
122 TTY.Filter suppressor = new TTY.Filter(C1XOptions.PrintFilter, id); | |
123 try { | |
124 stubs.put(id, emitter.emit(id, runtime)); | |
125 } finally { | |
126 suppressor.remove(); | |
127 } | |
128 } | |
129 | |
130 if (C1XOptions.PrintCFGToFile) { | |
131 addCompilationObserver(new CFGPrinterObserver()); | |
132 } | |
133 } | |
134 | |
135 public GlobalStub lookupGlobalStub(GlobalStub.Id id) { | |
136 GlobalStub globalStub = stubs.get(id); | |
137 assert globalStub != null : "no stub for global stub id: " + id; | |
138 return globalStub; | |
139 } | |
140 | |
141 public GlobalStub lookupGlobalStub(XirTemplate template) { | |
142 GlobalStub globalStub = stubs.get(template); | |
143 assert globalStub != null : "no stub for XirTemplate: " + template; | |
144 return globalStub; | |
145 } | |
146 | |
147 public GlobalStub lookupGlobalStub(CiRuntimeCall runtimeCall) { | |
148 GlobalStub globalStub = stubs.get(runtimeCall); | |
149 if (globalStub == null) { | |
150 globalStub = backend.newGlobalStubEmitter().emit(runtimeCall, runtime); | |
151 stubs.put(runtimeCall, globalStub); | |
152 } | |
153 | |
154 assert globalStub != null : "could not find global stub for runtime call: " + runtimeCall; | |
155 return globalStub; | |
156 } | |
157 } |