1 /*
2 * Copyright (c) 2017, 2018, 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 */
128 StructuredGraph graph,
129 Object stub,
130 RegisterConfig registerConfig,
131 LIRSuites lirSuites,
132 String[] allocationRestrictedTo) {
133 DebugContext debug = graph.getDebug();
134 try (DebugContext.Scope ds = debug.scope("EmitLIR"); DebugCloseable a = EmitLIR.start(debug)) {
135 assert !graph.hasValueProxies();
136
137 ScheduleResult schedule = graph.getLastSchedule();
138 Block[] blocks = schedule.getCFG().getBlocks();
139 Block startBlock = schedule.getCFG().getStartBlock();
140 assert startBlock != null;
141 assert startBlock.getPredecessorCount() == 0;
142
143 AbstractBlockBase<?>[] codeEmittingOrder = ComputeBlockOrder.computeCodeEmittingOrder(blocks.length, startBlock);
144 AbstractBlockBase<?>[] linearScanOrder = ComputeBlockOrder.computeLinearScanOrder(blocks.length, startBlock);
145 LIR lir = new LIR(schedule.getCFG(), linearScanOrder, codeEmittingOrder, graph.getOptions(), graph.getDebug());
146
147 LIRGenerationProvider lirBackend = (LIRGenerationProvider) backend;
148 LIRGenerationResult lirGenRes = lirBackend.newLIRGenerationResult(graph.compilationId(), lir, registerConfig, graph, stub);
149 LIRGeneratorTool lirGen = lirBackend.newLIRGenerator(lirGenRes);
150 NodeLIRBuilderTool nodeLirGen = lirBackend.newNodeLIRBuilder(graph, lirGen);
151
152 // LIR generation
153 LIRGenerationContext context = new LIRGenerationContext(lirGen, nodeLirGen, graph, schedule);
154 new LIRGenerationPhase().apply(backend.getTarget(), lirGenRes, context);
155
156 try (DebugContext.Scope s = debug.scope("LIRStages", nodeLirGen, lirGenRes, lir)) {
157 // Dump LIR along with HIR (the LIR is looked up from context)
158 debug.dump(DebugContext.BASIC_LEVEL, graph.getLastSchedule(), "After LIR generation");
159 LIRGenerationResult result = emitLowLevel(backend.getTarget(), lirGenRes, lirGen, lirSuites, backend.newRegisterAllocationConfig(registerConfig, allocationRestrictedTo));
160 return result;
161 } catch (Throwable e) {
162 throw debug.handle(e);
163 }
164 } catch (Throwable e) {
165 throw debug.handle(e);
166 } finally {
167 graph.checkCancellation();
168 }
169 }
170
171 private static LIRGenerationResult emitLowLevel(TargetDescription target, LIRGenerationResult lirGenRes, LIRGeneratorTool lirGen, LIRSuites lirSuites,
172 RegisterAllocationConfig registerAllocationConfig) {
173 DebugContext debug = lirGenRes.getLIR().getDebug();
174 PreAllocationOptimizationContext preAllocOptContext = new PreAllocationOptimizationContext(lirGen);
175 lirSuites.getPreAllocationOptimizationStage().apply(target, lirGenRes, preAllocOptContext);
176 debug.dump(DebugContext.BASIC_LEVEL, lirGenRes.getLIR(), "After PreAllocationOptimizationStage");
177
178 AllocationContext allocContext = new AllocationContext(lirGen.getSpillMoveFactory(), registerAllocationConfig);
179 lirSuites.getAllocationStage().apply(target, lirGenRes, allocContext);
|
1 /*
2 * Copyright (c) 2017, 2019, 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 */
128 StructuredGraph graph,
129 Object stub,
130 RegisterConfig registerConfig,
131 LIRSuites lirSuites,
132 String[] allocationRestrictedTo) {
133 DebugContext debug = graph.getDebug();
134 try (DebugContext.Scope ds = debug.scope("EmitLIR"); DebugCloseable a = EmitLIR.start(debug)) {
135 assert !graph.hasValueProxies();
136
137 ScheduleResult schedule = graph.getLastSchedule();
138 Block[] blocks = schedule.getCFG().getBlocks();
139 Block startBlock = schedule.getCFG().getStartBlock();
140 assert startBlock != null;
141 assert startBlock.getPredecessorCount() == 0;
142
143 AbstractBlockBase<?>[] codeEmittingOrder = ComputeBlockOrder.computeCodeEmittingOrder(blocks.length, startBlock);
144 AbstractBlockBase<?>[] linearScanOrder = ComputeBlockOrder.computeLinearScanOrder(blocks.length, startBlock);
145 LIR lir = new LIR(schedule.getCFG(), linearScanOrder, codeEmittingOrder, graph.getOptions(), graph.getDebug());
146
147 LIRGenerationProvider lirBackend = (LIRGenerationProvider) backend;
148 RegisterAllocationConfig registerAllocationConfig = backend.newRegisterAllocationConfig(registerConfig, allocationRestrictedTo);
149 LIRGenerationResult lirGenRes = lirBackend.newLIRGenerationResult(graph.compilationId(), lir, registerAllocationConfig, graph, stub);
150 LIRGeneratorTool lirGen = lirBackend.newLIRGenerator(lirGenRes);
151 NodeLIRBuilderTool nodeLirGen = lirBackend.newNodeLIRBuilder(graph, lirGen);
152
153 // LIR generation
154 LIRGenerationContext context = new LIRGenerationContext(lirGen, nodeLirGen, graph, schedule);
155 new LIRGenerationPhase().apply(backend.getTarget(), lirGenRes, context);
156
157 try (DebugContext.Scope s = debug.scope("LIRStages", nodeLirGen, lirGenRes, lir)) {
158 // Dump LIR along with HIR (the LIR is looked up from context)
159 debug.dump(DebugContext.BASIC_LEVEL, graph.getLastSchedule(), "After LIR generation");
160 LIRGenerationResult result = emitLowLevel(backend.getTarget(), lirGenRes, lirGen, lirSuites, registerAllocationConfig);
161 return result;
162 } catch (Throwable e) {
163 throw debug.handle(e);
164 }
165 } catch (Throwable e) {
166 throw debug.handle(e);
167 } finally {
168 graph.checkCancellation();
169 }
170 }
171
172 private static LIRGenerationResult emitLowLevel(TargetDescription target, LIRGenerationResult lirGenRes, LIRGeneratorTool lirGen, LIRSuites lirSuites,
173 RegisterAllocationConfig registerAllocationConfig) {
174 DebugContext debug = lirGenRes.getLIR().getDebug();
175 PreAllocationOptimizationContext preAllocOptContext = new PreAllocationOptimizationContext(lirGen);
176 lirSuites.getPreAllocationOptimizationStage().apply(target, lirGenRes, preAllocOptContext);
177 debug.dump(DebugContext.BASIC_LEVEL, lirGenRes.getLIR(), "After PreAllocationOptimizationStage");
178
179 AllocationContext allocContext = new AllocationContext(lirGen.getSpillMoveFactory(), registerAllocationConfig);
180 lirSuites.getAllocationStage().apply(target, lirGenRes, allocContext);
|