annotate graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScan.java @ 21338:5010ea46630a

LinearScan: move changeSpillState to LinearScanWalker.
author Josef Eisl <josef.eisl@jku.at>
date Tue, 12 May 2015 14:04:40 +0200
parents 5661a921e123
children 1c56b7be2731
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
16094
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents: 15927
diff changeset
2 * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
19166
39e99cf01468 Move LinearScan to c.o.g.lir.alloc.lsra.
Josef Eisl <josef.eisl@jku.at>
parents: 19165
diff changeset
23 package com.oracle.graal.lir.alloc.lsra;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5542
diff changeset
25 import static com.oracle.graal.api.code.CodeUtil.*;
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5711
diff changeset
26 import static com.oracle.graal.api.code.ValueUtil.*;
19163
0751ebc54c13 Move DetailedAsserts Option to GraalOptions.
Josef Eisl <josef.eisl@jku.at>
parents: 19162
diff changeset
27 import static com.oracle.graal.compiler.common.GraalOptions.*;
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5711
diff changeset
28 import static com.oracle.graal.lir.LIRValueUtil.*;
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5711
diff changeset
29
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30 import java.util.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31
5510
426c605c9d3c Move cri.ci to api.code.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
32 import com.oracle.graal.api.code.*;
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5506
diff changeset
33 import com.oracle.graal.api.meta.*;
15193
96bb07a5d667 Spit up and move GraalInternalError.
Josef Eisl <josef.eisl@jku.at>
parents: 15192
diff changeset
34 import com.oracle.graal.compiler.common.*;
19165
b3b81dfff200 Move ComputeBlockOrder to compiler.common and delete c.o.g.alloc project.
Josef Eisl <josef.eisl@jku.at>
parents: 19164
diff changeset
35 import com.oracle.graal.compiler.common.alloc.*;
15192
644dfe49c0f4 Move packages com.oracle.graal.cfg to com.oracle.graal.compiler.common.cfg.
Josef Eisl <josef.eisl@jku.at>
parents: 15157
diff changeset
36 import com.oracle.graal.compiler.common.cfg.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
37 import com.oracle.graal.debug.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
38 import com.oracle.graal.lir.*;
5733
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5711
diff changeset
39 import com.oracle.graal.lir.LIRInstruction.OperandFlag;
141b15521a39 use annotated fields for operands of LIR instructions
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5711
diff changeset
40 import com.oracle.graal.lir.LIRInstruction.OperandMode;
19166
39e99cf01468 Move LinearScan to c.o.g.lir.alloc.lsra.
Josef Eisl <josef.eisl@jku.at>
parents: 19165
diff changeset
41 import com.oracle.graal.lir.alloc.lsra.Interval.RegisterBinding;
18443
1c92d437179b FrameMapBuilder: move into package.
Josef Eisl <josef.eisl@jku.at>
parents: 18441
diff changeset
42 import com.oracle.graal.lir.framemap.*;
18152
ff694c40bdee LIRGenerationResult: add buildFrameMap() and getFrameMap().
Josef Eisl <josef.eisl@jku.at>
parents: 18151
diff changeset
43 import com.oracle.graal.lir.gen.*;
19549
1cf73c50e3dc Move SpillMoveFactory from LIR to LIRGeneratorTool.
Josef Eisl <josef.eisl@jku.at>
parents: 19212
diff changeset
44 import com.oracle.graal.lir.gen.LIRGeneratorTool.SpillMoveFactory;
21312
8ecb442fc864 LinearScan: split into sub-phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21246
diff changeset
45 import com.oracle.graal.lir.phases.AllocationPhase.AllocationContext;
16362
b100bd079fff LSRA spill optimization: add -G:+LSRAOptimizeSpillPosition option (default: enabled).
Josef Eisl <josef.eisl@jku.at>
parents: 16361
diff changeset
46 import com.oracle.graal.options.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
49 * An implementation of the linear scan register allocator algorithm described in <a
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
50 * href="http://doi.acm.org/10.1145/1064979.1064998"
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
51 * >"Optimized Interval Splitting in a Linear Scan Register Allocator"</a> by Christian Wimmer and
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
52 * Hanspeter Moessenboeck.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53 */
21240
1e9242c9735e Introduce SSALinearScan and SSAMoveResolver.
Josef Eisl <josef.eisl@jku.at>
parents: 21236
diff changeset
54 class LinearScan {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55
18152
ff694c40bdee LIRGenerationResult: add buildFrameMap() and getFrameMap().
Josef Eisl <josef.eisl@jku.at>
parents: 18151
diff changeset
56 final LIRGenerationResult res;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57 final LIR ir;
18150
22f2e42923de Use FrameMapBuilder in LinearScan (except for location marking).
Josef Eisl <josef.eisl@jku.at>
parents: 18123
diff changeset
58 final FrameMapBuilder frameMapBuilder;
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5542
diff changeset
59 final RegisterAttributes[] registerAttributes;
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5542
diff changeset
60 final Register[] registers;
20915
916aac9fe6f7 LinearScan: use RegisterAllocationConfig.
Josef Eisl <josef.eisl@jku.at>
parents: 20151
diff changeset
61 final RegisterAllocationConfig regAllocConfig;
21312
8ecb442fc864 LinearScan: split into sub-phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21246
diff changeset
62 private final SpillMoveFactory moveFactory;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63
18512
bcf66634c55c Make LinearScan.callKillsRegisters final.
Josef Eisl <josef.eisl@jku.at>
parents: 18446
diff changeset
64 final boolean callKillsRegisters;
10961
d0c9278fe471 move callKillsRegisters to LinearScan
twisti
parents: 9966
diff changeset
65
16380
8057279ec60e LSRA spill optimization: use DOMINATOR_SPILL_MOVE_ID to mark moves.
Josef Eisl <josef.eisl@jku.at>
parents: 16379
diff changeset
66 public static final int DOMINATOR_SPILL_MOVE_ID = -2;
21316
fd18bffefcc1 LinearScan: outsource LifetimeAnalysis.
Josef Eisl <josef.eisl@jku.at>
parents: 21315
diff changeset
67 static final int SPLIT_INTERVALS_CAPACITY_RIGHT_SHIFT = 1;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68
16362
b100bd079fff LSRA spill optimization: add -G:+LSRAOptimizeSpillPosition option (default: enabled).
Josef Eisl <josef.eisl@jku.at>
parents: 16361
diff changeset
69 public static class Options {
b100bd079fff LSRA spill optimization: add -G:+LSRAOptimizeSpillPosition option (default: enabled).
Josef Eisl <josef.eisl@jku.at>
parents: 16361
diff changeset
70 // @formatter:off
18674
ecb9d0cedbab First draft of option classification.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18610
diff changeset
71 @Option(help = "Enable spill position optimization", type = OptionType.Debug)
16362
b100bd079fff LSRA spill optimization: add -G:+LSRAOptimizeSpillPosition option (default: enabled).
Josef Eisl <josef.eisl@jku.at>
parents: 16361
diff changeset
72 public static final OptionValue<Boolean> LSRAOptimizeSpillPosition = new OptionValue<>(true);
b100bd079fff LSRA spill optimization: add -G:+LSRAOptimizeSpillPosition option (default: enabled).
Josef Eisl <josef.eisl@jku.at>
parents: 16361
diff changeset
73 // @formatter:on
b100bd079fff LSRA spill optimization: add -G:+LSRAOptimizeSpillPosition option (default: enabled).
Josef Eisl <josef.eisl@jku.at>
parents: 16361
diff changeset
74 }
b100bd079fff LSRA spill optimization: add -G:+LSRAOptimizeSpillPosition option (default: enabled).
Josef Eisl <josef.eisl@jku.at>
parents: 16361
diff changeset
75
4435
57cb8ec5f6bb Restructure block and control flow graph data structures
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4394
diff changeset
76 public static class BlockData {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
77
4435
57cb8ec5f6bb Restructure block and control flow graph data structures
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4394
diff changeset
78 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
79 * Bit map specifying which operands are live upon entry to this block. These are values
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
80 * used in this block or any of its successors where such value are not defined in this
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
81 * block. The bit index of an operand is its {@linkplain LinearScan#operandNumber(Value)
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
82 * operand number}.
4435
57cb8ec5f6bb Restructure block and control flow graph data structures
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4394
diff changeset
83 */
5541
b4c406861c33 More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5540
diff changeset
84 public BitSet liveIn;
4435
57cb8ec5f6bb Restructure block and control flow graph data structures
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4394
diff changeset
85
57cb8ec5f6bb Restructure block and control flow graph data structures
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4394
diff changeset
86 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
87 * Bit map specifying which operands are live upon exit from this block. These are values
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
88 * used in a successor block that are either defined in this block or were live upon entry
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
89 * to this block. The bit index of an operand is its
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
90 * {@linkplain LinearScan#operandNumber(Value) operand number}.
4435
57cb8ec5f6bb Restructure block and control flow graph data structures
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4394
diff changeset
91 */
5541
b4c406861c33 More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5540
diff changeset
92 public BitSet liveOut;
4435
57cb8ec5f6bb Restructure block and control flow graph data structures
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4394
diff changeset
93
57cb8ec5f6bb Restructure block and control flow graph data structures
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4394
diff changeset
94 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
95 * Bit map specifying which operands are used (before being defined) in this block. That is,
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
96 * these are the values that are live upon entry to the block. The bit index of an operand
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
97 * is its {@linkplain LinearScan#operandNumber(Value) operand number}.
4435
57cb8ec5f6bb Restructure block and control flow graph data structures
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4394
diff changeset
98 */
5541
b4c406861c33 More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5540
diff changeset
99 public BitSet liveGen;
4435
57cb8ec5f6bb Restructure block and control flow graph data structures
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4394
diff changeset
100
57cb8ec5f6bb Restructure block and control flow graph data structures
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4394
diff changeset
101 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
102 * Bit map specifying which operands are defined/overwritten in this block. The bit index of
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
103 * an operand is its {@linkplain LinearScan#operandNumber(Value) operand number}.
4435
57cb8ec5f6bb Restructure block and control flow graph data structures
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4394
diff changeset
104 */
5541
b4c406861c33 More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5540
diff changeset
105 public BitSet liveKill;
4435
57cb8ec5f6bb Restructure block and control flow graph data structures
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4394
diff changeset
106 }
57cb8ec5f6bb Restructure block and control flow graph data structures
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4394
diff changeset
107
21326
8cef2c3f389b LinearScan: encapsulate blockData.
Josef Eisl <josef.eisl@jku.at>
parents: 21325
diff changeset
108 private final BlockMap<BlockData> blockData;
4435
57cb8ec5f6bb Restructure block and control flow graph data structures
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4394
diff changeset
109
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
110 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
111 * List of blocks in linear-scan order. This is only correct as long as the CFG does not change.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
112 */
19560
4d70d150944f Remove AbstractBlock interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19212
diff changeset
113 final List<? extends AbstractBlockBase<?>> sortedBlocks;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
114
21327
b8dcf353b822 LinearScan: encapsulate intervals.
Josef Eisl <josef.eisl@jku.at>
parents: 21326
diff changeset
115 /** @see #intervals() */
b8dcf353b822 LinearScan: encapsulate intervals.
Josef Eisl <josef.eisl@jku.at>
parents: 21326
diff changeset
116 private Interval[] intervals;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
117
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
118 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
119 * The number of valid entries in {@link #intervals}.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
120 */
21327
b8dcf353b822 LinearScan: encapsulate intervals.
Josef Eisl <josef.eisl@jku.at>
parents: 21326
diff changeset
121 private int intervalsSize;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
122
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
123 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
124 * The index of the first entry in {@link #intervals} for a
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
125 * {@linkplain #createDerivedInterval(Interval) derived interval}.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
126 */
21327
b8dcf353b822 LinearScan: encapsulate intervals.
Josef Eisl <josef.eisl@jku.at>
parents: 21326
diff changeset
127 private int firstDerivedIntervalIndex = -1;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
128
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
129 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
130 * Intervals sorted by {@link Interval#from()}.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
131 */
21327
b8dcf353b822 LinearScan: encapsulate intervals.
Josef Eisl <josef.eisl@jku.at>
parents: 21326
diff changeset
132 private Interval[] sortedIntervals;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
133
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
134 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
135 * Map from an instruction {@linkplain LIRInstruction#id id} to the instruction. Entries should
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
136 * be retrieved with {@link #instructionForId(int)} as the id is not simply an index into this
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
137 * array.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
138 */
21328
de17f6676a43 LinearScan: encapsulate opIdToBlockMap and opIdToInstructionMap.
Josef Eisl <josef.eisl@jku.at>
parents: 21327
diff changeset
139 private LIRInstruction[] opIdToInstructionMap;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
140
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
141 /**
19565
9bb45bec2b1f Run eclipseformat.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19563
diff changeset
142 * Map from an instruction {@linkplain LIRInstruction#id id} to the
9bb45bec2b1f Run eclipseformat.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19563
diff changeset
143 * {@linkplain AbstractBlockBase block} containing the instruction. Entries should be retrieved
9bb45bec2b1f Run eclipseformat.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19563
diff changeset
144 * with {@link #blockForId(int)} as the id is not simply an index into this array.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
145 */
21328
de17f6676a43 LinearScan: encapsulate opIdToBlockMap and opIdToInstructionMap.
Josef Eisl <josef.eisl@jku.at>
parents: 21327
diff changeset
146 private AbstractBlockBase<?>[] opIdToBlockMap;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
147
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
148 /**
5711
4d7175cf3526 enabled Eclipse/JDT javadoc checking and fixed resulting warnings
Doug Simon <doug.simon@oracle.com>
parents: 5552
diff changeset
149 * The {@linkplain #operandNumber(Value) number} of the first variable operand allocated.
4206
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
150 */
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
151 private final int firstVariableNumber;
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
152
20915
916aac9fe6f7 LinearScan: use RegisterAllocationConfig.
Josef Eisl <josef.eisl@jku.at>
parents: 20151
diff changeset
153 LinearScan(TargetDescription target, LIRGenerationResult res, SpillMoveFactory spillMoveFactory, RegisterAllocationConfig regAllocConfig) {
18152
ff694c40bdee LIRGenerationResult: add buildFrameMap() and getFrameMap().
Josef Eisl <josef.eisl@jku.at>
parents: 18151
diff changeset
154 this.res = res;
ff694c40bdee LIRGenerationResult: add buildFrameMap() and getFrameMap().
Josef Eisl <josef.eisl@jku.at>
parents: 18151
diff changeset
155 this.ir = res.getLIR();
21312
8ecb442fc864 LinearScan: split into sub-phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21246
diff changeset
156 this.moveFactory = spillMoveFactory;
18152
ff694c40bdee LIRGenerationResult: add buildFrameMap() and getFrameMap().
Josef Eisl <josef.eisl@jku.at>
parents: 18151
diff changeset
157 this.frameMapBuilder = res.getFrameMapBuilder();
7501
799dd373fcb6 Remove caching of sorted blocks in LSRA.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7499
diff changeset
158 this.sortedBlocks = ir.linearScanOrder();
20915
916aac9fe6f7 LinearScan: use RegisterAllocationConfig.
Josef Eisl <josef.eisl@jku.at>
parents: 20151
diff changeset
159 this.registerAttributes = regAllocConfig.getRegisterConfig().getAttributesMap();
916aac9fe6f7 LinearScan: use RegisterAllocationConfig.
Josef Eisl <josef.eisl@jku.at>
parents: 20151
diff changeset
160 this.regAllocConfig = regAllocConfig;
4206
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
161
6582
cc32ce37eddc deleted Architecture.twoOperandMode() and encapsulated all public fields in Architecture with getters
Doug Simon <doug.simon@oracle.com>
parents: 6581
diff changeset
162 this.registers = target.arch.getRegisters();
4206
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
163 this.firstVariableNumber = registers.length;
14145
4ff08c0366ae Encapsulate LIR class fields.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14142
diff changeset
164 this.blockData = new BlockMap<>(ir.getControlFlowGraph());
18512
bcf66634c55c Make LinearScan.callKillsRegisters final.
Josef Eisl <josef.eisl@jku.at>
parents: 18446
diff changeset
165
21319
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
166 /*
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
167 * If all allocatable registers are caller saved, then no registers are live across a call
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
168 * site. The register allocator can save time not trying to find a register at a call site.
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
169 */
20915
916aac9fe6f7 LinearScan: use RegisterAllocationConfig.
Josef Eisl <josef.eisl@jku.at>
parents: 20151
diff changeset
170 this.callKillsRegisters = regAllocConfig.getRegisterConfig().areAllAllocatableRegistersCallerSaved();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
171 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
172
19560
4d70d150944f Remove AbstractBlock interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19212
diff changeset
173 int getFirstLirInstructionId(AbstractBlockBase<?> block) {
14806
a8723f1ff542 LIR renamed setter and getter functions.
Josef Eisl <josef.eisl@jku.at>
parents: 14789
diff changeset
174 int result = ir.getLIRforBlock(block).get(0).id();
6411
c5afcc2ebd3d change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents: 6352
diff changeset
175 assert result >= 0;
c5afcc2ebd3d change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents: 6352
diff changeset
176 return result;
c5afcc2ebd3d change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents: 6352
diff changeset
177 }
c5afcc2ebd3d change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents: 6352
diff changeset
178
19560
4d70d150944f Remove AbstractBlock interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19212
diff changeset
179 int getLastLirInstructionId(AbstractBlockBase<?> block) {
14806
a8723f1ff542 LIR renamed setter and getter functions.
Josef Eisl <josef.eisl@jku.at>
parents: 14789
diff changeset
180 List<LIRInstruction> instructions = ir.getLIRforBlock(block);
6411
c5afcc2ebd3d change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents: 6352
diff changeset
181 int result = instructions.get(instructions.size() - 1).id();
c5afcc2ebd3d change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents: 6352
diff changeset
182 assert result >= 0;
c5afcc2ebd3d change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents: 6352
diff changeset
183 return result;
c5afcc2ebd3d change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents: 6352
diff changeset
184 }
c5afcc2ebd3d change of project structure: separate compiler and LIR, put EA into separate project
Lukas Stadler <lukas.stadler@jku.at>
parents: 6352
diff changeset
185
19549
1cf73c50e3dc Move SpillMoveFactory from LIR to LIRGeneratorTool.
Josef Eisl <josef.eisl@jku.at>
parents: 19212
diff changeset
186 SpillMoveFactory getSpillMoveFactory() {
21312
8ecb442fc864 LinearScan: split into sub-phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21246
diff changeset
187 return moveFactory;
19549
1cf73c50e3dc Move SpillMoveFactory from LIR to LIRGeneratorTool.
Josef Eisl <josef.eisl@jku.at>
parents: 19212
diff changeset
188 }
1cf73c50e3dc Move SpillMoveFactory from LIR to LIRGeneratorTool.
Josef Eisl <josef.eisl@jku.at>
parents: 19212
diff changeset
189
21203
9f45587ad8f5 LinearScan: add createMoveResolver().
Josef Eisl <josef.eisl@jku.at>
parents: 21193
diff changeset
190 protected MoveResolver createMoveResolver() {
21246
b2b3c514a391 MoveResolver: don't call check from constructor.
Josef Eisl <josef.eisl@jku.at>
parents: 21240
diff changeset
191 MoveResolver moveResolver = new MoveResolver(this);
b2b3c514a391 MoveResolver: don't call check from constructor.
Josef Eisl <josef.eisl@jku.at>
parents: 21240
diff changeset
192 assert moveResolver.checkEmpty();
b2b3c514a391 MoveResolver: don't call check from constructor.
Josef Eisl <josef.eisl@jku.at>
parents: 21240
diff changeset
193 return moveResolver;
21203
9f45587ad8f5 LinearScan: add createMoveResolver().
Josef Eisl <josef.eisl@jku.at>
parents: 21193
diff changeset
194 }
9f45587ad8f5 LinearScan: add createMoveResolver().
Josef Eisl <josef.eisl@jku.at>
parents: 21193
diff changeset
195
5539
bc647d8b0080 Renaming RiValue => Value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5536
diff changeset
196 public static boolean isVariableOrRegister(Value value) {
4183
9e0c1b4cfef5 Move all isXxx and asXxx out of CiValue and into their own util class.
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4181
diff changeset
197 return isVariable(value) || isRegister(value);
9e0c1b4cfef5 Move all isXxx and asXxx out of CiValue and into their own util class.
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4181
diff changeset
198 }
9e0c1b4cfef5 Move all isXxx and asXxx out of CiValue and into their own util class.
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4181
diff changeset
199
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
200 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
201 * Converts an operand (variable or register) to an index in a flat address space covering all
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
202 * the {@linkplain Variable variables} and {@linkplain RegisterValue registers} being processed
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
203 * by this allocator.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
204 */
21316
fd18bffefcc1 LinearScan: outsource LifetimeAnalysis.
Josef Eisl <josef.eisl@jku.at>
parents: 21315
diff changeset
205 int operandNumber(Value operand) {
4206
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
206 if (isRegister(operand)) {
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
207 int number = asRegister(operand).number;
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
208 assert number < firstVariableNumber;
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
209 return number;
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
210 }
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
211 assert isVariable(operand) : operand;
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
212 return firstVariableNumber + ((Variable) operand).index;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
213 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
214
4206
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
215 /**
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
216 * Gets the number of operands. This value will increase by 1 for new variable.
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
217 */
21316
fd18bffefcc1 LinearScan: outsource LifetimeAnalysis.
Josef Eisl <josef.eisl@jku.at>
parents: 21315
diff changeset
218 int operandSize() {
4206
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
219 return firstVariableNumber + ir.numVariables();
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
220 }
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
221
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
222 /**
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
223 * Gets the highest operand number for a register operand. This value will never change.
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
224 */
19212
95a7954ea155 Add LinearScanPhase.
Josef Eisl <josef.eisl@jku.at>
parents: 19166
diff changeset
225 int maxRegisterNumber() {
4206
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
226 return firstVariableNumber - 1;
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
227 }
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
228
21326
8cef2c3f389b LinearScan: encapsulate blockData.
Josef Eisl <josef.eisl@jku.at>
parents: 21325
diff changeset
229 BlockData getBlockData(AbstractBlockBase<?> block) {
8cef2c3f389b LinearScan: encapsulate blockData.
Josef Eisl <josef.eisl@jku.at>
parents: 21325
diff changeset
230 return blockData.get(block);
8cef2c3f389b LinearScan: encapsulate blockData.
Josef Eisl <josef.eisl@jku.at>
parents: 21325
diff changeset
231 }
8cef2c3f389b LinearScan: encapsulate blockData.
Josef Eisl <josef.eisl@jku.at>
parents: 21325
diff changeset
232
8cef2c3f389b LinearScan: encapsulate blockData.
Josef Eisl <josef.eisl@jku.at>
parents: 21325
diff changeset
233 void initBlockData(AbstractBlockBase<?> block) {
8cef2c3f389b LinearScan: encapsulate blockData.
Josef Eisl <josef.eisl@jku.at>
parents: 21325
diff changeset
234 blockData.put(block, new BlockData());
8cef2c3f389b LinearScan: encapsulate blockData.
Josef Eisl <josef.eisl@jku.at>
parents: 21325
diff changeset
235 }
8cef2c3f389b LinearScan: encapsulate blockData.
Josef Eisl <josef.eisl@jku.at>
parents: 21325
diff changeset
236
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
237 static final IntervalPredicate IS_PRECOLORED_INTERVAL = new IntervalPredicate() {
4206
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
238
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
239 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
240 public boolean apply(Interval i) {
4183
9e0c1b4cfef5 Move all isXxx and asXxx out of CiValue and into their own util class.
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4181
diff changeset
241 return isRegister(i.operand);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
242 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
243 };
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
244
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
245 static final IntervalPredicate IS_VARIABLE_INTERVAL = new IntervalPredicate() {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
246
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
247 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
248 public boolean apply(Interval i) {
4183
9e0c1b4cfef5 Move all isXxx and asXxx out of CiValue and into their own util class.
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4181
diff changeset
249 return isVariable(i.operand);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
250 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
251 };
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
252
13340
9423a38d6437 added rematerialization of constants in LinearScan, but still disabled
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13339
diff changeset
253 static final IntervalPredicate IS_STACK_INTERVAL = new IntervalPredicate() {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
254
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
255 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
256 public boolean apply(Interval i) {
13340
9423a38d6437 added rematerialization of constants in LinearScan, but still disabled
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13339
diff changeset
257 return !isRegister(i.operand);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
258 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
259 };
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
260
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
261 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
262 * Gets an object describing the attributes of a given register according to this register
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
263 * configuration.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
264 */
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5542
diff changeset
265 RegisterAttributes attributes(Register reg) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
266 return registerAttributes[reg.number];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
267 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
268
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
269 void assignSpillSlot(Interval interval) {
21319
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
270 /*
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
271 * Assign the canonical spill slot of the parent (if a part of the interval is already
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
272 * spilled) or allocate a new spill slot.
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
273 */
13340
9423a38d6437 added rematerialization of constants in LinearScan, but still disabled
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13339
diff changeset
274 if (interval.canMaterialize()) {
9423a38d6437 added rematerialization of constants in LinearScan, but still disabled
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13339
diff changeset
275 interval.assignLocation(Value.ILLEGAL);
9423a38d6437 added rematerialization of constants in LinearScan, but still disabled
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13339
diff changeset
276 } else if (interval.spillSlot() != null) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
277 interval.assignLocation(interval.spillSlot());
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
278 } else {
18425
b856446ff7e0 Introduce StackSlotValue and VirtualStackSlot.
Josef Eisl <josef.eisl@jku.at>
parents: 18420
diff changeset
279 VirtualStackSlot slot = frameMapBuilder.allocateSpillSlot(interval.kind());
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
280 interval.setSpillSlot(slot);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
281 interval.assignLocation(slot);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
282 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
283 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
284
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
285 /**
21327
b8dcf353b822 LinearScan: encapsulate intervals.
Josef Eisl <josef.eisl@jku.at>
parents: 21326
diff changeset
286 * Map from {@linkplain #operandNumber(Value) operand numbers} to intervals.
b8dcf353b822 LinearScan: encapsulate intervals.
Josef Eisl <josef.eisl@jku.at>
parents: 21326
diff changeset
287 */
b8dcf353b822 LinearScan: encapsulate intervals.
Josef Eisl <josef.eisl@jku.at>
parents: 21326
diff changeset
288 Interval[] intervals() {
b8dcf353b822 LinearScan: encapsulate intervals.
Josef Eisl <josef.eisl@jku.at>
parents: 21326
diff changeset
289 return intervals;
b8dcf353b822 LinearScan: encapsulate intervals.
Josef Eisl <josef.eisl@jku.at>
parents: 21326
diff changeset
290 }
b8dcf353b822 LinearScan: encapsulate intervals.
Josef Eisl <josef.eisl@jku.at>
parents: 21326
diff changeset
291
b8dcf353b822 LinearScan: encapsulate intervals.
Josef Eisl <josef.eisl@jku.at>
parents: 21326
diff changeset
292 void initIntervals() {
b8dcf353b822 LinearScan: encapsulate intervals.
Josef Eisl <josef.eisl@jku.at>
parents: 21326
diff changeset
293 intervalsSize = operandSize();
b8dcf353b822 LinearScan: encapsulate intervals.
Josef Eisl <josef.eisl@jku.at>
parents: 21326
diff changeset
294 intervals = new Interval[intervalsSize + (intervalsSize >> SPLIT_INTERVALS_CAPACITY_RIGHT_SHIFT)];
b8dcf353b822 LinearScan: encapsulate intervals.
Josef Eisl <josef.eisl@jku.at>
parents: 21326
diff changeset
295 }
b8dcf353b822 LinearScan: encapsulate intervals.
Josef Eisl <josef.eisl@jku.at>
parents: 21326
diff changeset
296
b8dcf353b822 LinearScan: encapsulate intervals.
Josef Eisl <josef.eisl@jku.at>
parents: 21326
diff changeset
297 /**
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
298 * Creates a new interval.
14871
667710021ea1 removed methods in Indent that are redundant with those in Debug
Doug Simon <doug.simon@oracle.com>
parents: 14841
diff changeset
299 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
300 * @param operand the operand for the interval
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
301 * @return the created interval
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
302 */
9297
a5f2b9012865 Interval locations can only be AllocatableValues.
Roland Schatz <roland.schatz@oracle.com>
parents: 8402
diff changeset
303 Interval createInterval(AllocatableValue operand) {
4183
9e0c1b4cfef5 Move all isXxx and asXxx out of CiValue and into their own util class.
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4181
diff changeset
304 assert isLegal(operand);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
305 int operandNumber = operandNumber(operand);
4352
5a84f5548fc4 More work on new debug infrastructure.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4350
diff changeset
306 Interval interval = new Interval(operand, operandNumber);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
307 assert operandNumber < intervalsSize;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
308 assert intervals[operandNumber] == null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
309 intervals[operandNumber] = interval;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
310 return interval;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
311 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
312
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
313 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
314 * Creates an interval as a result of splitting or spilling another interval.
14871
667710021ea1 removed methods in Indent that are redundant with those in Debug
Doug Simon <doug.simon@oracle.com>
parents: 14841
diff changeset
315 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
316 * @param source an interval being split of spilled
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
317 * @return a new interval derived from {@code source}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
318 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
319 Interval createDerivedInterval(Interval source) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
320 if (firstDerivedIntervalIndex == -1) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
321 firstDerivedIntervalIndex = intervalsSize;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
322 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
323 if (intervalsSize == intervals.length) {
15885
4d18c6bb6b3a LinearScan: Improve initialization and resizing of intervals array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15884
diff changeset
324 intervals = Arrays.copyOf(intervals, intervals.length + (intervals.length >> SPLIT_INTERVALS_CAPACITY_RIGHT_SHIFT));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
325 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
326 intervalsSize++;
9425
3ec29630cfb4 Use register categories instead of register flags.
Roland Schatz <roland.schatz@oracle.com>
parents: 9422
diff changeset
327 Variable variable = new Variable(source.kind(), ir.nextVariable());
4206
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
328
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
329 Interval interval = createInterval(variable);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
330 assert intervals[intervalsSize - 1] == interval;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
331 return interval;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
332 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
333
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
334 // access to block list (sorted in linear scan order)
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
335 int blockCount() {
7501
799dd373fcb6 Remove caching of sorted blocks in LSRA.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7499
diff changeset
336 return sortedBlocks.size();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
337 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
338
19560
4d70d150944f Remove AbstractBlock interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19212
diff changeset
339 AbstractBlockBase<?> blockAt(int index) {
7501
799dd373fcb6 Remove caching of sorted blocks in LSRA.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7499
diff changeset
340 return sortedBlocks.get(index);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
341 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
342
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
343 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
344 * Gets the size of the {@link BlockData#liveIn} and {@link BlockData#liveOut} sets for a basic
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
345 * block. These sets do not include any operands allocated as a result of creating
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
346 * {@linkplain #createDerivedInterval(Interval) derived intervals}.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
347 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
348 int liveSetSize() {
4206
430b5db3e6f8 Remove CiVariable from the CRI
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
349 return firstDerivedIntervalIndex == -1 ? operandSize() : firstDerivedIntervalIndex;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
350 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
351
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
352 int numLoops() {
15107
1bf700e19e84 Make Loop generic.
Josef Eisl <josef.eisl@jku.at>
parents: 15026
diff changeset
353 return ir.getControlFlowGraph().getLoops().size();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
354 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
355
15884
0e6f83eeb0ab Clean up in LinearScan: Remove the need for a mapping of variable index to variable object.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15850
diff changeset
356 Interval intervalFor(int operandNumber) {
0e6f83eeb0ab Clean up in LinearScan: Remove the need for a mapping of variable index to variable object.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15850
diff changeset
357 return intervals[operandNumber];
0e6f83eeb0ab Clean up in LinearScan: Remove the need for a mapping of variable index to variable object.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15850
diff changeset
358 }
0e6f83eeb0ab Clean up in LinearScan: Remove the need for a mapping of variable index to variable object.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15850
diff changeset
359
5539
bc647d8b0080 Renaming RiValue => Value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5536
diff changeset
360 Interval intervalFor(Value operand) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
361 int operandNumber = operandNumber(operand);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
362 assert operandNumber < intervalsSize;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
363 return intervals[operandNumber];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
364 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
365
9297
a5f2b9012865 Interval locations can only be AllocatableValues.
Roland Schatz <roland.schatz@oracle.com>
parents: 8402
diff changeset
366 Interval getOrCreateInterval(AllocatableValue operand) {
8220
2c5df42999dd Fix hinting in register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents: 7648
diff changeset
367 Interval ret = intervalFor(operand);
2c5df42999dd Fix hinting in register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents: 7648
diff changeset
368 if (ret == null) {
2c5df42999dd Fix hinting in register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents: 7648
diff changeset
369 return createInterval(operand);
2c5df42999dd Fix hinting in register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents: 7648
diff changeset
370 } else {
2c5df42999dd Fix hinting in register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents: 7648
diff changeset
371 return ret;
2c5df42999dd Fix hinting in register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents: 7648
diff changeset
372 }
2c5df42999dd Fix hinting in register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents: 7648
diff changeset
373 }
2c5df42999dd Fix hinting in register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents: 7648
diff changeset
374
21328
de17f6676a43 LinearScan: encapsulate opIdToBlockMap and opIdToInstructionMap.
Josef Eisl <josef.eisl@jku.at>
parents: 21327
diff changeset
375 void initOpIdMaps(int numInstructions) {
de17f6676a43 LinearScan: encapsulate opIdToBlockMap and opIdToInstructionMap.
Josef Eisl <josef.eisl@jku.at>
parents: 21327
diff changeset
376 opIdToInstructionMap = new LIRInstruction[numInstructions];
de17f6676a43 LinearScan: encapsulate opIdToBlockMap and opIdToInstructionMap.
Josef Eisl <josef.eisl@jku.at>
parents: 21327
diff changeset
377 opIdToBlockMap = new AbstractBlockBase<?>[numInstructions];
de17f6676a43 LinearScan: encapsulate opIdToBlockMap and opIdToInstructionMap.
Josef Eisl <josef.eisl@jku.at>
parents: 21327
diff changeset
378 }
de17f6676a43 LinearScan: encapsulate opIdToBlockMap and opIdToInstructionMap.
Josef Eisl <josef.eisl@jku.at>
parents: 21327
diff changeset
379
de17f6676a43 LinearScan: encapsulate opIdToBlockMap and opIdToInstructionMap.
Josef Eisl <josef.eisl@jku.at>
parents: 21327
diff changeset
380 void putOpIdMaps(int index, LIRInstruction op, AbstractBlockBase<?> block) {
de17f6676a43 LinearScan: encapsulate opIdToBlockMap and opIdToInstructionMap.
Josef Eisl <josef.eisl@jku.at>
parents: 21327
diff changeset
381 opIdToInstructionMap[index] = op;
de17f6676a43 LinearScan: encapsulate opIdToBlockMap and opIdToInstructionMap.
Josef Eisl <josef.eisl@jku.at>
parents: 21327
diff changeset
382 opIdToBlockMap[index] = block;
de17f6676a43 LinearScan: encapsulate opIdToBlockMap and opIdToInstructionMap.
Josef Eisl <josef.eisl@jku.at>
parents: 21327
diff changeset
383 }
de17f6676a43 LinearScan: encapsulate opIdToBlockMap and opIdToInstructionMap.
Josef Eisl <josef.eisl@jku.at>
parents: 21327
diff changeset
384
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
385 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
386 * Gets the highest instruction id allocated by this object.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
387 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
388 int maxOpId() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
389 assert opIdToInstructionMap.length > 0 : "no operations";
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
390 return (opIdToInstructionMap.length - 1) << 1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
391 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
392
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
393 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
394 * Converts an {@linkplain LIRInstruction#id instruction id} to an instruction index. All LIR
21329
6a32034ace1b LinearScan: make opIdToIndex private.
Josef Eisl <josef.eisl@jku.at>
parents: 21328
diff changeset
395 * instructions in a method have an index one greater than their linear-scan order predecessor
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
396 * with the first instruction having an index of 0.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
397 */
21329
6a32034ace1b LinearScan: make opIdToIndex private.
Josef Eisl <josef.eisl@jku.at>
parents: 21328
diff changeset
398 private static int opIdToIndex(int opId) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
399 return opId >> 1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
400 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
401
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
402 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
403 * Retrieves the {@link LIRInstruction} based on its {@linkplain LIRInstruction#id id}.
14871
667710021ea1 removed methods in Indent that are redundant with those in Debug
Doug Simon <doug.simon@oracle.com>
parents: 14841
diff changeset
404 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
405 * @param opId an instruction {@linkplain LIRInstruction#id id}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
406 * @return the instruction whose {@linkplain LIRInstruction#id} {@code == id}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
407 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
408 LIRInstruction instructionForId(int opId) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
409 assert isEven(opId) : "opId not even";
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
410 LIRInstruction instr = opIdToInstructionMap[opIdToIndex(opId)];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
411 assert instr.id() == opId;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
412 return instr;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
413 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
414
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
415 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
416 * Gets the block containing a given instruction.
14871
667710021ea1 removed methods in Indent that are redundant with those in Debug
Doug Simon <doug.simon@oracle.com>
parents: 14841
diff changeset
417 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
418 * @param opId an instruction {@linkplain LIRInstruction#id id}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
419 * @return the block containing the instruction denoted by {@code opId}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
420 */
19560
4d70d150944f Remove AbstractBlock interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19212
diff changeset
421 AbstractBlockBase<?> blockForId(int opId) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
422 assert opIdToBlockMap.length > 0 && opId >= 0 && opId <= maxOpId() + 1 : "opId out of range";
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
423 return opIdToBlockMap[opIdToIndex(opId)];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
424 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
425
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
426 boolean isBlockBegin(int opId) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
427 return opId == 0 || blockForId(opId) != blockForId(opId - 1);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
428 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
429
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
430 boolean coversBlockBegin(int opId1, int opId2) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
431 return blockForId(opId1) != blockForId(opId2);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
432 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
433
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
434 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
435 * Determines if an {@link LIRInstruction} destroys all caller saved registers.
14871
667710021ea1 removed methods in Indent that are redundant with those in Debug
Doug Simon <doug.simon@oracle.com>
parents: 14841
diff changeset
436 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
437 * @param opId an instruction {@linkplain LIRInstruction#id id}
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
438 * @return {@code true} if the instruction denoted by {@code id} destroys all caller saved
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
439 * registers.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
440 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
441 boolean hasCall(int opId) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
442 assert isEven(opId) : "opId not even";
9454
85a836bcd796 renaming for improved clarity: hasCall -> destroysCallerSavedRegisters
Doug Simon <doug.simon@oracle.com>
parents: 9425
diff changeset
443 return instructionForId(opId).destroysCallerSavedRegisters();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
444 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
445
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
446 abstract static class IntervalPredicate {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
447
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
448 abstract boolean apply(Interval i);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
449 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
450
21316
fd18bffefcc1 LinearScan: outsource LifetimeAnalysis.
Josef Eisl <josef.eisl@jku.at>
parents: 21315
diff changeset
451 boolean isProcessed(Value operand) {
fd18bffefcc1 LinearScan: outsource LifetimeAnalysis.
Josef Eisl <josef.eisl@jku.at>
parents: 21315
diff changeset
452 return !isRegister(operand) || attributes(asRegister(operand)).isAllocatable();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
453 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
454
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
455 // * Phase 5: actual register allocation
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
456
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
457 private static boolean isSorted(Interval[] intervals) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
458 int from = -1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
459 for (Interval interval : intervals) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
460 assert interval != null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
461 assert from <= interval.from();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
462 from = interval.from();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
463 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
464 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
465 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
466
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
467 static Interval addToList(Interval first, Interval prev, Interval interval) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
468 Interval newFirst = first;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
469 if (prev != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
470 prev.next = interval;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
471 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
472 newFirst = interval;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
473 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
474 return newFirst;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
475 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
476
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
477 Interval.Pair createUnhandledLists(IntervalPredicate isList1, IntervalPredicate isList2) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
478 assert isSorted(sortedIntervals) : "interval list is not sorted";
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
479
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
480 Interval list1 = Interval.EndMarker;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
481 Interval list2 = Interval.EndMarker;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
482
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
483 Interval list1Prev = null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
484 Interval list2Prev = null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
485 Interval v;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
486
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
487 int n = sortedIntervals.length;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
488 for (int i = 0; i < n; i++) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
489 v = sortedIntervals[i];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
490 if (v == null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
491 continue;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
492 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
493
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
494 if (isList1.apply(v)) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
495 list1 = addToList(list1, list1Prev, v);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
496 list1Prev = v;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
497 } else if (isList2 == null || isList2.apply(v)) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
498 list2 = addToList(list2, list2Prev, v);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
499 list2Prev = v;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
500 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
501 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
502
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
503 if (list1Prev != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
504 list1Prev.next = Interval.EndMarker;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
505 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
506 if (list2Prev != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
507 list2Prev.next = Interval.EndMarker;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
508 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
509
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
510 assert list1Prev == null || list1Prev.next == Interval.EndMarker : "linear list ends not with sentinel";
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
511 assert list2Prev == null || list2Prev.next == Interval.EndMarker : "linear list ends not with sentinel";
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
512
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
513 return new Interval.Pair(list1, list2);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
514 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
515
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
516 void sortIntervalsBeforeAllocation() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
517 int sortedLen = 0;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
518 for (Interval interval : intervals) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
519 if (interval != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
520 sortedLen++;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
521 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
522 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
523
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
524 Interval[] sortedList = new Interval[sortedLen];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
525 int sortedIdx = 0;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
526 int sortedFromMax = -1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
527
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
528 // special sorting algorithm: the original interval-list is almost sorted,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
529 // only some intervals are swapped. So this is much faster than a complete QuickSort
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
530 for (Interval interval : intervals) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
531 if (interval != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
532 int from = interval.from();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
533
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
534 if (sortedFromMax <= from) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
535 sortedList[sortedIdx++] = interval;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
536 sortedFromMax = interval.from();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
537 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
538 // the assumption that the intervals are already sorted failed,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
539 // so this interval must be sorted in manually
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
540 int j;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
541 for (j = sortedIdx - 1; j >= 0 && from < sortedList[j].from(); j--) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
542 sortedList[j + 1] = sortedList[j];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
543 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
544 sortedList[j + 1] = interval;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
545 sortedIdx++;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
546 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
547 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
548 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
549 sortedIntervals = sortedList;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
550 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
551
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
552 void sortIntervalsAfterAllocation() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
553 if (firstDerivedIntervalIndex == -1) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
554 // no intervals have been added during allocation, so sorted list is already up to date
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
555 return;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
556 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
557
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
558 Interval[] oldList = sortedIntervals;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
559 Interval[] newList = Arrays.copyOfRange(intervals, firstDerivedIntervalIndex, intervalsSize);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
560 int oldLen = oldList.length;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
561 int newLen = newList.length;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
562
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
563 // conventional sort-algorithm for new intervals
15886
e5e7d9dfff1a LinearScan: Clean up interval comparator and replace with lambda form.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15885
diff changeset
564 Arrays.sort(newList, (Interval a, Interval b) -> a.from() - b.from());
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
565
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
566 // merge old and new list (both already sorted) into one combined list
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
567 Interval[] combinedList = new Interval[oldLen + newLen];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
568 int oldIdx = 0;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
569 int newIdx = 0;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
570
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
571 while (oldIdx + newIdx < combinedList.length) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
572 if (newIdx >= newLen || (oldIdx < oldLen && oldList[oldIdx].from() <= newList[newIdx].from())) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
573 combinedList[oldIdx + newIdx] = oldList[oldIdx];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
574 oldIdx++;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
575 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
576 combinedList[oldIdx + newIdx] = newList[newIdx];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
577 newIdx++;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
578 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
579 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
580
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
581 sortedIntervals = combinedList;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
582 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
583
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
584 // wrapper for Interval.splitChildAtOpId that performs a bailout in product mode
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
585 // instead of returning null
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
586 Interval splitChildAtOpId(Interval interval, int opId, LIRInstruction.OperandMode mode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
587 Interval result = interval.getSplitChildAtOpId(opId, mode, this);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
588
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
589 if (result != null) {
20980
abc059cb0acf Guard usages of Debug.log in LinearScan
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 20979
diff changeset
590 if (Debug.isLogEnabled()) {
abc059cb0acf Guard usages of Debug.log in LinearScan
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 20979
diff changeset
591 Debug.log("Split child at pos %d of interval %s is %s", opId, interval, result);
abc059cb0acf Guard usages of Debug.log in LinearScan
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 20979
diff changeset
592 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
593 return result;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
594 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
595
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5542
diff changeset
596 throw new BailoutException("LinearScan: interval is null");
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
597 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
598
18425
b856446ff7e0 Introduce StackSlotValue and VirtualStackSlot.
Josef Eisl <josef.eisl@jku.at>
parents: 18420
diff changeset
599 static StackSlotValue canonicalSpillOpr(Interval interval) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
600 assert interval.spillSlot() != null : "canonical spill slot not set";
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
601 return interval.spillSlot();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
602 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
603
21325
e0400193edca LinearScan: outsource AssignLocations.
Josef Eisl <josef.eisl@jku.at>
parents: 21324
diff changeset
604 boolean isMaterialized(AllocatableValue operand, int opId, OperandMode mode) {
13377
40530019af02 enable rematerialization of constants in LinearScan, including a bug fix
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13376
diff changeset
605 Interval interval = intervalFor(operand);
40530019af02 enable rematerialization of constants in LinearScan, including a bug fix
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13376
diff changeset
606 assert interval != null : "interval must exist";
40530019af02 enable rematerialization of constants in LinearScan, including a bug fix
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13376
diff changeset
607
40530019af02 enable rematerialization of constants in LinearScan, including a bug fix
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13376
diff changeset
608 if (opId != -1) {
21319
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
609 /*
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
610 * Operands are not changed when an interval is split during allocation, so search the
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
611 * right interval here.
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
612 */
13377
40530019af02 enable rematerialization of constants in LinearScan, including a bug fix
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13376
diff changeset
613 interval = splitChildAtOpId(interval, opId, mode);
40530019af02 enable rematerialization of constants in LinearScan, including a bug fix
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13376
diff changeset
614 }
40530019af02 enable rematerialization of constants in LinearScan, including a bug fix
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13376
diff changeset
615
40530019af02 enable rematerialization of constants in LinearScan, including a bug fix
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13376
diff changeset
616 return isIllegal(interval.location()) && interval.canMaterialize();
40530019af02 enable rematerialization of constants in LinearScan, including a bug fix
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13376
diff changeset
617 }
40530019af02 enable rematerialization of constants in LinearScan, including a bug fix
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13376
diff changeset
618
21325
e0400193edca LinearScan: outsource AssignLocations.
Josef Eisl <josef.eisl@jku.at>
parents: 21324
diff changeset
619 boolean isCallerSave(Value operand) {
5552
69a8969dbf40 Reduce public fields in api.code project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5547
diff changeset
620 return attributes(asRegister(operand)).isCallerSave();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
621 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
622
21312
8ecb442fc864 LinearScan: split into sub-phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21246
diff changeset
623 <B extends AbstractBlockBase<B>> void allocate(TargetDescription target, LIRGenerationResult lirGenRes, List<B> codeEmittingOrder, List<B> linearScanOrder, SpillMoveFactory spillMoveFactory) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
624
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
625 /*
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
626 * This is the point to enable debug logging for the whole register allocation.
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
627 */
14871
667710021ea1 removed methods in Indent that are redundant with those in Debug
Doug Simon <doug.simon@oracle.com>
parents: 14841
diff changeset
628 try (Indent indent = Debug.logAndIndent("LinearScan allocate")) {
21312
8ecb442fc864 LinearScan: split into sub-phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21246
diff changeset
629 AllocationContext context = new AllocationContext(spillMoveFactory);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
630
21323
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
631 createLifetimeAnalysisPhase().apply(target, lirGenRes, codeEmittingOrder, linearScanOrder, context, false);
21331
45ff3423d4c4 LinearScan: call sortIntervalsBeforeAllocation in allocate().
Josef Eisl <josef.eisl@jku.at>
parents: 21330
diff changeset
632
45ff3423d4c4 LinearScan: call sortIntervalsBeforeAllocation in allocate().
Josef Eisl <josef.eisl@jku.at>
parents: 21330
diff changeset
633 sortIntervalsBeforeAllocation();
45ff3423d4c4 LinearScan: call sortIntervalsBeforeAllocation in allocate().
Josef Eisl <josef.eisl@jku.at>
parents: 21330
diff changeset
634
21323
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
635 createRegisterAllocationPhase().apply(target, lirGenRes, codeEmittingOrder, linearScanOrder, context, false);
21313
bb9d3f0616a3 LinearScan: reorganize LIR and Interval dumping.
Josef Eisl <josef.eisl@jku.at>
parents: 21312
diff changeset
636
21312
8ecb442fc864 LinearScan: split into sub-phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21246
diff changeset
637 if (LinearScan.Options.LSRAOptimizeSpillPosition.getValue()) {
21323
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
638 createOptimizeSpillPositionPhase().apply(target, lirGenRes, codeEmittingOrder, linearScanOrder, context, false);
14871
667710021ea1 removed methods in Indent that are redundant with those in Debug
Doug Simon <doug.simon@oracle.com>
parents: 14841
diff changeset
639 }
21323
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
640 createResolveDataFlowPhase().apply(target, lirGenRes, codeEmittingOrder, linearScanOrder, context);
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
641
21312
8ecb442fc864 LinearScan: split into sub-phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21246
diff changeset
642 sortIntervalsAfterAllocation();
8ecb442fc864 LinearScan: split into sub-phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21246
diff changeset
643
8ecb442fc864 LinearScan: split into sub-phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21246
diff changeset
644 if (DetailedAsserts.getValue()) {
8ecb442fc864 LinearScan: split into sub-phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21246
diff changeset
645 verify();
16357
a07492ccaf52 LSRA spill optimization: calculate optimized spill position.
Josef Eisl <josef.eisl@jku.at>
parents: 16355
diff changeset
646 }
a07492ccaf52 LSRA spill optimization: calculate optimized spill position.
Josef Eisl <josef.eisl@jku.at>
parents: 16355
diff changeset
647
21323
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
648 createSpillMoveEliminationPhase().apply(target, lirGenRes, codeEmittingOrder, linearScanOrder, context);
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
649 createAssignLocationsPhase().apply(target, lirGenRes, codeEmittingOrder, linearScanOrder, context);
21236
8d21d631a82d LinearScan: minor refactoring and comment cleanup.
Josef Eisl <josef.eisl@jku.at>
parents: 21203
diff changeset
650
21312
8ecb442fc864 LinearScan: split into sub-phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21246
diff changeset
651 if (DetailedAsserts.getValue()) {
8ecb442fc864 LinearScan: split into sub-phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21246
diff changeset
652 verifyIntervals();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
653 }
14871
667710021ea1 removed methods in Indent that are redundant with those in Debug
Doug Simon <doug.simon@oracle.com>
parents: 14841
diff changeset
654 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
655 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
656
21323
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
657 protected LifetimeAnalysis createLifetimeAnalysisPhase() {
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
658 return new LifetimeAnalysis(this);
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
659 }
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
660
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
661 protected RegisterAllocation createRegisterAllocationPhase() {
21333
a6e1a98f47e2 LinearScan: outsource RegisterAllocation.
Josef Eisl <josef.eisl@jku.at>
parents: 21332
diff changeset
662 return new RegisterAllocation(this);
21323
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
663 }
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
664
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
665 protected OptimizeSpillPosition createOptimizeSpillPositionPhase() {
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
666 return new OptimizeSpillPosition(this);
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
667 }
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
668
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
669 protected ResolveDataFlow createResolveDataFlowPhase() {
21334
4f68c2550646 LinearScan: outsource ResolveDataFlow.
Josef Eisl <josef.eisl@jku.at>
parents: 21333
diff changeset
670 return new ResolveDataFlow(this);
21323
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
671 }
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
672
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
673 protected EliminateSpillMove createSpillMoveEliminationPhase() {
21336
5661a921e123 LinearScan: outsource EliminateSpillMove.
Josef Eisl <josef.eisl@jku.at>
parents: 21334
diff changeset
674 return new EliminateSpillMove(this);
21323
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
675 }
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
676
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
677 protected AssignLocations createAssignLocationsPhase() {
21325
e0400193edca LinearScan: outsource AssignLocations.
Josef Eisl <josef.eisl@jku.at>
parents: 21324
diff changeset
678 return new AssignLocations(this);
21323
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
679 }
3570b7d1a6f9 LinearScan: create factory methods for subr- phases.
Josef Eisl <josef.eisl@jku.at>
parents: 21322
diff changeset
680
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
681 void printIntervals(String label) {
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
682 if (Debug.isLogEnabled()) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
683 try (Indent indent = Debug.logAndIndent("intervals %s", label)) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
684 for (Interval interval : intervals) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
685 if (interval != null) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
686 Debug.log("%s", interval.logString(this));
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
687 }
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
688 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
689
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
690 try (Indent indent2 = Debug.logAndIndent("Basic Blocks")) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
691 for (int i = 0; i < blockCount(); i++) {
19560
4d70d150944f Remove AbstractBlock interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19212
diff changeset
692 AbstractBlockBase<?> block = blockAt(i);
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
693 Debug.log("B%d [%d, %d, %s] ", block.getId(), getFirstLirInstructionId(block), getLastLirInstructionId(block), block.getLoop());
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
694 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
695 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
696 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
697 }
4353
043bec543161 More work on debug framework. Removed concept of GraalContext.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
698 Debug.dump(Arrays.copyOf(intervals, intervalsSize), label);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
699 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
700
7556
630ea5001e33 Modified formatter settings to not insert line break after annotation on parameters.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
701 void printLir(String label, @SuppressWarnings("unused") boolean hirValid) {
4353
043bec543161 More work on debug framework. Removed concept of GraalContext.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4352
diff changeset
702 Debug.dump(ir, label);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
703 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
704
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
705 boolean verify() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
706 // (check that all intervals have a correct register and that no registers are overwritten)
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
707 verifyIntervals();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
708
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
709 verifyRegisters();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
710
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
711 Debug.log("no errors found");
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
712
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
713 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
714 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
715
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
716 private void verifyRegisters() {
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
717 // Enable this logging to get output for the verification process.
13546
43bd3d7254d1 don?t explicitly disable debug log output in linear scan and graphbuilder
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13467
diff changeset
718 try (Indent indent = Debug.logAndIndent("verifying register allocation")) {
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
719 RegisterVerifier verifier = new RegisterVerifier(this);
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
720 verifier.verify(blockAt(0));
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
721 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
722 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
723
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
724 void verifyIntervals() {
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
725 try (Indent indent = Debug.logAndIndent("verifying intervals")) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
726 int len = intervalsSize;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
727
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
728 for (int i = 0; i < len; i++) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
729 Interval i1 = intervals[i];
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
730 if (i1 == null) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
731 continue;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
732 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
733
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
734 i1.checkSplitChildren();
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
735
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
736 if (i1.operandNumber != i) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
737 Debug.log("Interval %d is on position %d in list", i1.operandNumber, i);
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
738 Debug.log(i1.logString(this));
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
739 throw new GraalInternalError("");
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
740 }
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
741
16118
5cbaad0b7387 Verify usage of equals method in LIRKind.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
742 if (isVariable(i1.operand) && i1.kind().equals(LIRKind.Illegal)) {
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
743 Debug.log("Interval %d has no type assigned", i1.operandNumber);
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
744 Debug.log(i1.logString(this));
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
745 throw new GraalInternalError("");
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
746 }
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
747
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
748 if (i1.location() == null) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
749 Debug.log("Interval %d has no register assigned", i1.operandNumber);
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
750 Debug.log(i1.logString(this));
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
751 throw new GraalInternalError("");
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
752 }
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
753
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
754 if (i1.first() == Range.EndMarker) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
755 Debug.log("Interval %d has no Range", i1.operandNumber);
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
756 Debug.log(i1.logString(this));
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
757 throw new GraalInternalError("");
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
758 }
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
759
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
760 for (Range r = i1.first(); r != Range.EndMarker; r = r.next) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
761 if (r.from >= r.to) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
762 Debug.log("Interval %d has zero length range", i1.operandNumber);
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
763 Debug.log(i1.logString(this));
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
764 throw new GraalInternalError("");
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
765 }
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
766 }
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
767
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
768 for (int j = i + 1; j < len; j++) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
769 Interval i2 = intervals[j];
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
770 if (i2 == null) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
771 continue;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
772 }
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
773
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
774 // special intervals that are created in MoveResolver
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
775 // . ignore them because the range information has no meaning there
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
776 if (i1.from() == 1 && i1.to() == 2) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
777 continue;
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
778 }
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
779 if (i2.from() == 1 && i2.to() == 2) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
780 continue;
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
781 }
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
782 Value l1 = i1.location();
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
783 Value l2 = i2.location();
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
784 if (i1.intersects(i2) && !isIllegal(l1) && (l1.equals(l2))) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
785 if (DetailedAsserts.getValue()) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
786 Debug.log("Intervals %d and %d overlap and have the same register assigned", i1.operandNumber, i2.operandNumber);
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
787 Debug.log(i1.logString(this));
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
788 Debug.log(i2.logString(this));
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
789 }
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
790 throw new BailoutException("");
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
791 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
792 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
793 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
794 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
795 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
796
17285
3a834111a632 Make [Instruction]ValueProcedure and [Instruction]ValueConsumer a FunctionalInterface.
Josef Eisl <josef.eisl@jku.at>
parents: 17284
diff changeset
797 class CheckConsumer implements ValueConsumer {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7512
diff changeset
798
4245
75c620f90ab9 Support stack-operands and register hints in new register allocator API
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4214
diff changeset
799 boolean ok;
75c620f90ab9 Support stack-operands and register hints in new register allocator API
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4214
diff changeset
800 Interval curInterval;
75c620f90ab9 Support stack-operands and register hints in new register allocator API
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4214
diff changeset
801
75c620f90ab9 Support stack-operands and register hints in new register allocator API
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4214
diff changeset
802 @Override
17284
d21962ea9617 Remove ValueConsumer.visitValue(Value).
Josef Eisl <josef.eisl@jku.at>
parents: 17283
diff changeset
803 public void visitValue(Value operand, OperandMode mode, EnumSet<OperandFlag> flags) {
4245
75c620f90ab9 Support stack-operands and register hints in new register allocator API
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4214
diff changeset
804 if (isRegister(operand)) {
75c620f90ab9 Support stack-operands and register hints in new register allocator API
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4214
diff changeset
805 if (intervalFor(operand) == curInterval) {
75c620f90ab9 Support stack-operands and register hints in new register allocator API
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4214
diff changeset
806 ok = true;
75c620f90ab9 Support stack-operands and register hints in new register allocator API
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4214
diff changeset
807 }
75c620f90ab9 Support stack-operands and register hints in new register allocator API
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4214
diff changeset
808 }
75c620f90ab9 Support stack-operands and register hints in new register allocator API
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4214
diff changeset
809 }
75c620f90ab9 Support stack-operands and register hints in new register allocator API
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4214
diff changeset
810 }
75c620f90ab9 Support stack-operands and register hints in new register allocator API
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4214
diff changeset
811
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
812 void verifyNoOopsInFixedIntervals() {
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
813 try (Indent indent = Debug.logAndIndent("verifying that no oops are in fixed intervals *")) {
16801
067dbd8e7114 Use ValueConsumer in LinearScan where possible.
Josef Eisl <josef.eisl@jku.at>
parents: 16796
diff changeset
814 CheckConsumer checkConsumer = new CheckConsumer();
4245
75c620f90ab9 Support stack-operands and register hints in new register allocator API
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4214
diff changeset
815
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
816 Interval fixedIntervals;
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
817 Interval otherIntervals;
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
818 fixedIntervals = createUnhandledLists(IS_PRECOLORED_INTERVAL, null).first;
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
819 // to ensure a walking until the last instruction id, add a dummy interval
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
820 // with a high operation id
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
821 otherIntervals = new Interval(Value.ILLEGAL, -1);
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
822 otherIntervals.addRange(Integer.MAX_VALUE - 2, Integer.MAX_VALUE - 1);
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
823 IntervalWalker iw = new IntervalWalker(this, fixedIntervals, otherIntervals);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
824
19560
4d70d150944f Remove AbstractBlock interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19212
diff changeset
825 for (AbstractBlockBase<?> block : sortedBlocks) {
14806
a8723f1ff542 LIR renamed setter and getter functions.
Josef Eisl <josef.eisl@jku.at>
parents: 14789
diff changeset
826 List<LIRInstruction> instructions = ir.getLIRforBlock(block);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
827
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
828 for (int j = 0; j < instructions.size(); j++) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
829 LIRInstruction op = instructions.get(j);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
830
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
831 if (op.hasState()) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
832 iw.walkBefore(op.id());
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
833 boolean checkLive = true;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
834
21319
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
835 /*
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
836 * Make sure none of the fixed registers is live across an oopmap since we
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
837 * can't handle that correctly.
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
838 */
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
839 if (checkLive) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
840 for (Interval interval = iw.activeLists.get(RegisterBinding.Fixed); interval != Interval.EndMarker; interval = interval.next) {
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
841 if (interval.currentTo() > op.id() + 1) {
21319
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
842 /*
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
843 * This interval is live out of this op so make sure that this
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
844 * interval represents some value that's referenced by this op
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
845 * either as an input or output.
9ddb5a749eab LinearScan: use multiline comments.
Josef Eisl <josef.eisl@jku.at>
parents: 21318
diff changeset
846 */
16801
067dbd8e7114 Use ValueConsumer in LinearScan where possible.
Josef Eisl <josef.eisl@jku.at>
parents: 16796
diff changeset
847 checkConsumer.curInterval = interval;
067dbd8e7114 Use ValueConsumer in LinearScan where possible.
Josef Eisl <josef.eisl@jku.at>
parents: 16796
diff changeset
848 checkConsumer.ok = false;
4245
75c620f90ab9 Support stack-operands and register hints in new register allocator API
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4214
diff changeset
849
16801
067dbd8e7114 Use ValueConsumer in LinearScan where possible.
Josef Eisl <josef.eisl@jku.at>
parents: 16796
diff changeset
850 op.visitEachInput(checkConsumer);
067dbd8e7114 Use ValueConsumer in LinearScan where possible.
Josef Eisl <josef.eisl@jku.at>
parents: 16796
diff changeset
851 op.visitEachAlive(checkConsumer);
067dbd8e7114 Use ValueConsumer in LinearScan where possible.
Josef Eisl <josef.eisl@jku.at>
parents: 16796
diff changeset
852 op.visitEachTemp(checkConsumer);
067dbd8e7114 Use ValueConsumer in LinearScan where possible.
Josef Eisl <josef.eisl@jku.at>
parents: 16796
diff changeset
853 op.visitEachOutput(checkConsumer);
4245
75c620f90ab9 Support stack-operands and register hints in new register allocator API
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4214
diff changeset
854
16801
067dbd8e7114 Use ValueConsumer in LinearScan where possible.
Josef Eisl <josef.eisl@jku.at>
parents: 16796
diff changeset
855 assert checkConsumer.ok : "fixed intervals should never be live across an oopmap point";
13467
7c694e3e97e5 remove remaining old style TTY debug logging in LinearScan and remove TraceLinearScan option
Erik Eckstein <erik.eckstein@oracle.com>
parents: 13377
diff changeset
856 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
857 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
858 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
859 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
860 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
861 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
862 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
863 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
864
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
865 }