annotate graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanRegisterAllocationPhase.java @ 21511:47c5e0903d06

Add RegisterAllocationConfig to AllocationContext.
author Josef Eisl <josef.eisl@jku.at>
date Thu, 28 May 2015 10:04:46 +0200
parents 1c56b7be2731
children ce2113326bc8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21333
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
1 /*
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
4 *
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
8 *
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
13 * accompanied this code).
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
14 *
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
18 *
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
21 * questions.
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
22 */
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
23 package com.oracle.graal.lir.alloc.lsra;
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
24
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
25 import java.util.*;
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
26
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
27 import com.oracle.graal.api.code.*;
21511
47c5e0903d06 Add RegisterAllocationConfig to AllocationContext.
Josef Eisl <josef.eisl@jku.at>
parents: 21339
diff changeset
28 import com.oracle.graal.compiler.common.alloc.*;
21333
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
29 import com.oracle.graal.compiler.common.cfg.*;
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
30 import com.oracle.graal.debug.*;
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
31 import com.oracle.graal.lir.gen.*;
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
32 import com.oracle.graal.lir.gen.LIRGeneratorTool.*;
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
33 import com.oracle.graal.lir.phases.*;
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
34
21339
1c56b7be2731 LinearScan: renamed sub phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21333
diff changeset
35 final class LinearScanRegisterAllocationPhase extends AllocationPhase {
21333
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
36
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
37 private final LinearScan allocator;
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
38
21339
1c56b7be2731 LinearScan: renamed sub phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21333
diff changeset
39 LinearScanRegisterAllocationPhase(LinearScan allocator) {
21333
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
40 this.allocator = allocator;
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
41 }
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
42
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
43 @Override
21511
47c5e0903d06 Add RegisterAllocationConfig to AllocationContext.
Josef Eisl <josef.eisl@jku.at>
parents: 21339
diff changeset
44 protected <B extends AbstractBlockBase<B>> void run(TargetDescription target, LIRGenerationResult lirGenRes, List<B> codeEmittingOrder, List<B> linearScanOrder, SpillMoveFactory spillMoveFactory,
47c5e0903d06 Add RegisterAllocationConfig to AllocationContext.
Josef Eisl <josef.eisl@jku.at>
parents: 21339
diff changeset
45 RegisterAllocationConfig registerAllocationConfig) {
21333
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
46 allocator.printIntervals("Before register allocation");
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
47 allocateRegisters();
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
48 allocator.printIntervals("After register allocation");
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
49 }
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
50
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
51 void allocateRegisters() {
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
52 try (Indent indent = Debug.logAndIndent("allocate registers")) {
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
53 Interval precoloredIntervals;
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
54 Interval notPrecoloredIntervals;
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
55
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
56 Interval.Pair result = allocator.createUnhandledLists(LinearScan.IS_PRECOLORED_INTERVAL, LinearScan.IS_VARIABLE_INTERVAL);
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
57 precoloredIntervals = result.first;
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
58 notPrecoloredIntervals = result.second;
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
59
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
60 // allocate cpu registers
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
61 LinearScanWalker lsw;
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
62 if (OptimizingLinearScanWalker.Options.LSRAOptimization.getValue()) {
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
63 lsw = new OptimizingLinearScanWalker(allocator, precoloredIntervals, notPrecoloredIntervals);
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
64 } else {
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
65 lsw = new LinearScanWalker(allocator, precoloredIntervals, notPrecoloredIntervals);
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
66 }
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
67 lsw.walk();
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
68 lsw.finishAllocation();
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
69 }
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
70 }
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
71
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
diff changeset
72 }