43972
|
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 org.graalvm.compiler.lir.alloc.lsra;
|
|
24 |
|
48861
|
25 |
import org.graalvm.collections.Pair;
|
43972
|
26 |
import org.graalvm.compiler.debug.Indent;
|
|
27 |
import org.graalvm.compiler.lir.gen.LIRGenerationResult;
|
46393
|
28 |
import org.graalvm.compiler.lir.phases.AllocationPhase.AllocationContext;
|
43972
|
29 |
|
|
30 |
import jdk.vm.ci.code.TargetDescription;
|
|
31 |
|
46393
|
32 |
public final class LinearScanRegisterAllocationPhase extends LinearScanAllocationPhase {
|
43972
|
33 |
|
|
34 |
private final LinearScan allocator;
|
|
35 |
|
|
36 |
LinearScanRegisterAllocationPhase(LinearScan allocator) {
|
|
37 |
this.allocator = allocator;
|
|
38 |
}
|
|
39 |
|
|
40 |
@Override
|
46344
|
41 |
protected void run(TargetDescription target, LIRGenerationResult result, AllocationContext context) {
|
43972
|
42 |
allocator.printIntervals("Before register allocation");
|
|
43 |
allocateRegisters();
|
|
44 |
allocator.printIntervals("After register allocation");
|
|
45 |
}
|
|
46 |
|
|
47 |
@SuppressWarnings("try")
|
|
48 |
void allocateRegisters() {
|
46640
|
49 |
try (Indent indent = allocator.getDebug().logAndIndent("allocate registers")) {
|
43972
|
50 |
Interval precoloredIntervals;
|
|
51 |
Interval notPrecoloredIntervals;
|
|
52 |
|
46344
|
53 |
Pair<Interval, Interval> result = allocator.createUnhandledLists(LinearScan.IS_PRECOLORED_INTERVAL, LinearScan.IS_VARIABLE_INTERVAL);
|
|
54 |
precoloredIntervals = result.getLeft();
|
|
55 |
notPrecoloredIntervals = result.getRight();
|
43972
|
56 |
|
|
57 |
// allocate cpu registers
|
|
58 |
LinearScanWalker lsw;
|
46344
|
59 |
if (OptimizingLinearScanWalker.Options.LSRAOptimization.getValue(allocator.getOptions())) {
|
43972
|
60 |
lsw = new OptimizingLinearScanWalker(allocator, precoloredIntervals, notPrecoloredIntervals);
|
|
61 |
} else {
|
|
62 |
lsw = new LinearScanWalker(allocator, precoloredIntervals, notPrecoloredIntervals);
|
|
63 |
}
|
|
64 |
lsw.walk();
|
|
65 |
lsw.finishAllocation();
|
|
66 |
}
|
|
67 |
}
|
|
68 |
|
|
69 |
}
|