Mercurial > hg > truffle
annotate graal/com.oracle.graal.lir/src/com/oracle/graal/lir/stackslotalloc/LSStackSlotAllocator.java @ 21554:b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 26 May 2015 23:21:15 +0200 |
parents | 0e1e8879b655 |
children | 48c1ebd24120 |
rev | line source |
---|---|
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
1 /* |
19037
cc2b817de0b5
StackSlotAllocation: fix style/formating issues.
Josef Eisl <josef.eisl@jku.at>
parents:
19035
diff
changeset
|
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
4 * |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
8 * |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
14 * |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
18 * |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
21 * questions. |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
22 */ |
19031
beb7c10b7747
Move StackSlotAllocators into a package.
Josef Eisl <josef.eisl@jku.at>
parents:
19028
diff
changeset
|
23 package com.oracle.graal.lir.stackslotalloc; |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
24 |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
25 import static com.oracle.graal.api.code.ValueUtil.*; |
19686
fa75218e3942
Fix nested Timer and MemUse tracking logic
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19651
diff
changeset
|
26 import static com.oracle.graal.lir.phases.LIRPhase.Options.*; |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
27 |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
28 import java.util.*; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
29 import java.util.function.*; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
30 |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
31 import com.oracle.graal.api.code.*; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
32 import com.oracle.graal.api.meta.*; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
33 import com.oracle.graal.compiler.common.cfg.*; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
34 import com.oracle.graal.lir.*; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
35 import com.oracle.graal.lir.LIRInstruction.OperandFlag; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
36 import com.oracle.graal.lir.LIRInstruction.OperandMode; |
19031
beb7c10b7747
Move StackSlotAllocators into a package.
Josef Eisl <josef.eisl@jku.at>
parents:
19028
diff
changeset
|
37 import com.oracle.graal.lir.framemap.*; |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
38 import com.oracle.graal.lir.gen.*; |
19549
1cf73c50e3dc
Move SpillMoveFactory from LIR to LIRGeneratorTool.
Josef Eisl <josef.eisl@jku.at>
parents:
19465
diff
changeset
|
39 import com.oracle.graal.lir.gen.LIRGeneratorTool.SpillMoveFactory; |
19216
baa9fb17fd91
Make LSStackSlotAllocator and SimpleStackSlotAllocator a LowLevelMidTierPhase.
Josef Eisl <josef.eisl@jku.at>
parents:
19127
diff
changeset
|
40 import com.oracle.graal.lir.phases.*; |
21554
b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21004
diff
changeset
|
41 import com.oracle.jvmci.debug.*; |
b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21004
diff
changeset
|
42 import com.oracle.jvmci.debug.Debug.Scope; |
b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21004
diff
changeset
|
43 import com.oracle.jvmci.options.*; |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
44 |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
45 /** |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
46 * Linear Scan {@link StackSlotAllocator}. |
19034
94ca6ce786ee
StackSlotAllocation: improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19032
diff
changeset
|
47 * <p> |
94ca6ce786ee
StackSlotAllocation: improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19032
diff
changeset
|
48 * <b>Remark:</b> The analysis works under the assumption that a stack slot is no longer live after |
94ca6ce786ee
StackSlotAllocation: improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19032
diff
changeset
|
49 * its last usage. If an {@link LIRInstruction instruction} transfers the raw address of the stack |
94ca6ce786ee
StackSlotAllocation: improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19032
diff
changeset
|
50 * slot to another location, e.g. a registers, and this location is referenced later on, the |
94ca6ce786ee
StackSlotAllocation: improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19032
diff
changeset
|
51 * {@link com.oracle.graal.lir.LIRInstruction.Use usage} of the stack slot must be marked with the |
94ca6ce786ee
StackSlotAllocation: improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19032
diff
changeset
|
52 * {@link OperandFlag#UNINITIALIZED}. Otherwise the stack slot might be reused and its content |
94ca6ce786ee
StackSlotAllocation: improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19032
diff
changeset
|
53 * destroyed. |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
54 */ |
19465
ab8decaddb11
Rename LIRMidTier to AllocationStage.
Josef Eisl <josef.eisl@jku.at>
parents:
19275
diff
changeset
|
55 public final class LSStackSlotAllocator extends AllocationPhase implements StackSlotAllocator { |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
56 |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
57 public static class Options { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
58 // @formatter:off |
19076
76dd59e530b2
Rename EnableLSStackSlotAllocation command line flag to LSStackSlotAllocation.
Josef Eisl <josef.eisl@jku.at>
parents:
19037
diff
changeset
|
59 @Option(help = "Use linear scan stack slot allocation.", type = OptionType.Debug) |
19651
a0284c1724e6
Introduce LIROptimization option to disable all LIR optimization.
Josef Eisl <josef.eisl@jku.at>
parents:
19563
diff
changeset
|
60 public static final NestedBooleanOptionValue LIROptLSStackSlotAllocator = new NestedBooleanOptionValue(LIROptimization, true); |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
61 // @formatter:on |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
62 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
63 |
19120
638da18b3186
LSStackSlotAllocator: add debug timers.
Josef Eisl <josef.eisl@jku.at>
parents:
19091
diff
changeset
|
64 private static final DebugTimer MainTimer = Debug.timer("LSStackSlotAllocator"); |
638da18b3186
LSStackSlotAllocator: add debug timers.
Josef Eisl <josef.eisl@jku.at>
parents:
19091
diff
changeset
|
65 private static final DebugTimer NumInstTimer = Debug.timer("LSStackSlotAllocator[NumberInstruction]"); |
638da18b3186
LSStackSlotAllocator: add debug timers.
Josef Eisl <josef.eisl@jku.at>
parents:
19091
diff
changeset
|
66 private static final DebugTimer BuildIntervalsTimer = Debug.timer("LSStackSlotAllocator[BuildIntervals]"); |
638da18b3186
LSStackSlotAllocator: add debug timers.
Josef Eisl <josef.eisl@jku.at>
parents:
19091
diff
changeset
|
67 private static final DebugTimer VerifyIntervalsTimer = Debug.timer("LSStackSlotAllocator[VerifyIntervals]"); |
638da18b3186
LSStackSlotAllocator: add debug timers.
Josef Eisl <josef.eisl@jku.at>
parents:
19091
diff
changeset
|
68 private static final DebugTimer AllocateSlotsTimer = Debug.timer("LSStackSlotAllocator[AllocateSlots]"); |
638da18b3186
LSStackSlotAllocator: add debug timers.
Josef Eisl <josef.eisl@jku.at>
parents:
19091
diff
changeset
|
69 private static final DebugTimer AssignSlotsTimer = Debug.timer("LSStackSlotAllocator[AssignSlots]"); |
638da18b3186
LSStackSlotAllocator: add debug timers.
Josef Eisl <josef.eisl@jku.at>
parents:
19091
diff
changeset
|
70 |
19216
baa9fb17fd91
Make LSStackSlotAllocator and SimpleStackSlotAllocator a LowLevelMidTierPhase.
Josef Eisl <josef.eisl@jku.at>
parents:
19127
diff
changeset
|
71 @Override |
19563 | 72 protected <B extends AbstractBlockBase<B>> void run(TargetDescription target, LIRGenerationResult lirGenRes, List<B> codeEmittingOrder, List<B> linearScanOrder, SpillMoveFactory spillMoveFactory) { |
19216
baa9fb17fd91
Make LSStackSlotAllocator and SimpleStackSlotAllocator a LowLevelMidTierPhase.
Josef Eisl <josef.eisl@jku.at>
parents:
19127
diff
changeset
|
73 lirGenRes.buildFrameMap(this); |
baa9fb17fd91
Make LSStackSlotAllocator and SimpleStackSlotAllocator a LowLevelMidTierPhase.
Josef Eisl <josef.eisl@jku.at>
parents:
19127
diff
changeset
|
74 } |
baa9fb17fd91
Make LSStackSlotAllocator and SimpleStackSlotAllocator a LowLevelMidTierPhase.
Josef Eisl <josef.eisl@jku.at>
parents:
19127
diff
changeset
|
75 |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
76 public void allocateStackSlots(FrameMapBuilderTool builder, LIRGenerationResult res) { |
19686
fa75218e3942
Fix nested Timer and MemUse tracking logic
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19651
diff
changeset
|
77 try (DebugCloseable t = MainTimer.start()) { |
19120
638da18b3186
LSStackSlotAllocator: add debug timers.
Josef Eisl <josef.eisl@jku.at>
parents:
19091
diff
changeset
|
78 new Allocator(res.getLIR(), builder).allocate(); |
638da18b3186
LSStackSlotAllocator: add debug timers.
Josef Eisl <josef.eisl@jku.at>
parents:
19091
diff
changeset
|
79 } |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
80 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
81 |
19126
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
82 private static final class Allocator { |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
83 private final LIR lir; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
84 private final FrameMapBuilderTool frameMapBuilder; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
85 private final StackInterval[] stackSlotMap; |
19088
fb4344ad6cd2
LSStackSlotAllocator: make unhandled, active and sortedBlocks final.
Josef Eisl <josef.eisl@jku.at>
parents:
19087
diff
changeset
|
86 private final PriorityQueue<StackInterval> unhandled; |
fb4344ad6cd2
LSStackSlotAllocator: make unhandled, active and sortedBlocks final.
Josef Eisl <josef.eisl@jku.at>
parents:
19087
diff
changeset
|
87 private final PriorityQueue<StackInterval> active; |
19560
4d70d150944f
Remove AbstractBlock interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19465
diff
changeset
|
88 private final List<? extends AbstractBlockBase<?>> sortedBlocks; |
19126
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
89 private final int maxOpId; |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
90 |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
91 private Allocator(LIR lir, FrameMapBuilderTool frameMapBuilder) { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
92 this.lir = lir; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
93 this.frameMapBuilder = frameMapBuilder; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
94 this.stackSlotMap = new StackInterval[frameMapBuilder.getNumberOfStackSlots()]; |
19088
fb4344ad6cd2
LSStackSlotAllocator: make unhandled, active and sortedBlocks final.
Josef Eisl <josef.eisl@jku.at>
parents:
19087
diff
changeset
|
95 this.sortedBlocks = lir.getControlFlowGraph().getBlocks(); |
fb4344ad6cd2
LSStackSlotAllocator: make unhandled, active and sortedBlocks final.
Josef Eisl <josef.eisl@jku.at>
parents:
19087
diff
changeset
|
96 |
fb4344ad6cd2
LSStackSlotAllocator: make unhandled, active and sortedBlocks final.
Josef Eisl <josef.eisl@jku.at>
parents:
19087
diff
changeset
|
97 // insert by from |
fb4344ad6cd2
LSStackSlotAllocator: make unhandled, active and sortedBlocks final.
Josef Eisl <josef.eisl@jku.at>
parents:
19087
diff
changeset
|
98 this.unhandled = new PriorityQueue<>((a, b) -> a.from() - b.from()); |
fb4344ad6cd2
LSStackSlotAllocator: make unhandled, active and sortedBlocks final.
Josef Eisl <josef.eisl@jku.at>
parents:
19087
diff
changeset
|
99 // insert by to |
fb4344ad6cd2
LSStackSlotAllocator: make unhandled, active and sortedBlocks final.
Josef Eisl <josef.eisl@jku.at>
parents:
19087
diff
changeset
|
100 this.active = new PriorityQueue<>((a, b) -> a.to() - b.to()); |
19089
5b61f60e458f
LSStackSlotAllocator: remove InstructionNumberer.
Josef Eisl <josef.eisl@jku.at>
parents:
19088
diff
changeset
|
101 |
19686
fa75218e3942
Fix nested Timer and MemUse tracking logic
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19651
diff
changeset
|
102 try (DebugCloseable t = NumInstTimer.start()) { |
19120
638da18b3186
LSStackSlotAllocator: add debug timers.
Josef Eisl <josef.eisl@jku.at>
parents:
19091
diff
changeset
|
103 // step 1: number instructions |
19126
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
104 this.maxOpId = numberInstructions(lir, sortedBlocks); |
19120
638da18b3186
LSStackSlotAllocator: add debug timers.
Josef Eisl <josef.eisl@jku.at>
parents:
19091
diff
changeset
|
105 } |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
106 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
107 |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
108 private void allocate() { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
109 Debug.dump(lir, "After StackSlot numbering"); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
110 |
21004
0e1e8879b655
{LS,Simple}StackSlotAllocator: use DebugMetric.isEnabled().
Josef Eisl <josef.eisl@jku.at>
parents:
20975
diff
changeset
|
111 long currentFrameSize = StackSlotAllocator.allocatedFramesize.isEnabled() ? frameMapBuilder.getFrameMap().currentFrameSize() : 0; |
19127
e0b4d14d1731
FixPointIntervalBuilder: do not record instruction ids but instructions.
Josef Eisl <josef.eisl@jku.at>
parents:
19126
diff
changeset
|
112 Set<LIRInstruction> usePos; |
19090
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
113 // step 2: build intervals |
19686
fa75218e3942
Fix nested Timer and MemUse tracking logic
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19651
diff
changeset
|
114 try (Scope s = Debug.scope("StackSlotAllocationBuildIntervals"); Indent indent = Debug.logAndIndent("BuildIntervals"); DebugCloseable t = BuildIntervalsTimer.start()) { |
19123
0f3c0639dc3f
LSStackSlotAllocator: record use positions globally.
Josef Eisl <josef.eisl@jku.at>
parents:
19121
diff
changeset
|
115 usePos = buildIntervals(); |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
116 } |
19090
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
117 // step 3: verify intervals |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
118 if (Debug.isEnabled()) { |
19686
fa75218e3942
Fix nested Timer and MemUse tracking logic
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19651
diff
changeset
|
119 try (DebugCloseable t = VerifyIntervalsTimer.start()) { |
19120
638da18b3186
LSStackSlotAllocator: add debug timers.
Josef Eisl <josef.eisl@jku.at>
parents:
19091
diff
changeset
|
120 verifyIntervals(); |
638da18b3186
LSStackSlotAllocator: add debug timers.
Josef Eisl <josef.eisl@jku.at>
parents:
19091
diff
changeset
|
121 } |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
122 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
123 if (Debug.isDumpEnabled()) { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
124 dumpIntervals("Before stack slot allocation"); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
125 } |
19090
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
126 // step 4: allocate stack slots |
19686
fa75218e3942
Fix nested Timer and MemUse tracking logic
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19651
diff
changeset
|
127 try (DebugCloseable t = AllocateSlotsTimer.start()) { |
19120
638da18b3186
LSStackSlotAllocator: add debug timers.
Josef Eisl <josef.eisl@jku.at>
parents:
19091
diff
changeset
|
128 allocateStackSlots(); |
638da18b3186
LSStackSlotAllocator: add debug timers.
Josef Eisl <josef.eisl@jku.at>
parents:
19091
diff
changeset
|
129 } |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
130 if (Debug.isDumpEnabled()) { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
131 dumpIntervals("After stack slot allocation"); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
132 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
133 |
19090
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
134 // step 5: assign stack slots |
19686
fa75218e3942
Fix nested Timer and MemUse tracking logic
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19651
diff
changeset
|
135 try (DebugCloseable t = AssignSlotsTimer.start()) { |
19123
0f3c0639dc3f
LSStackSlotAllocator: record use positions globally.
Josef Eisl <josef.eisl@jku.at>
parents:
19121
diff
changeset
|
136 assignStackSlots(usePos); |
19120
638da18b3186
LSStackSlotAllocator: add debug timers.
Josef Eisl <josef.eisl@jku.at>
parents:
19091
diff
changeset
|
137 } |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
138 Debug.dump(lir, "After StackSlot assignment"); |
21004
0e1e8879b655
{LS,Simple}StackSlotAllocator: use DebugMetric.isEnabled().
Josef Eisl <josef.eisl@jku.at>
parents:
20975
diff
changeset
|
139 if (StackSlotAllocator.allocatedFramesize.isEnabled()) { |
19089
5b61f60e458f
LSStackSlotAllocator: remove InstructionNumberer.
Josef Eisl <josef.eisl@jku.at>
parents:
19088
diff
changeset
|
140 StackSlotAllocator.allocatedFramesize.add(frameMapBuilder.getFrameMap().currentFrameSize() - currentFrameSize); |
5b61f60e458f
LSStackSlotAllocator: remove InstructionNumberer.
Josef Eisl <josef.eisl@jku.at>
parents:
19088
diff
changeset
|
141 } |
5b61f60e458f
LSStackSlotAllocator: remove InstructionNumberer.
Josef Eisl <josef.eisl@jku.at>
parents:
19088
diff
changeset
|
142 } |
5b61f60e458f
LSStackSlotAllocator: remove InstructionNumberer.
Josef Eisl <josef.eisl@jku.at>
parents:
19088
diff
changeset
|
143 |
19090
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
144 // ==================== |
19126
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
145 // step 1: number instructions |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
146 // ==================== |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
147 |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
148 /** |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
149 * Numbers all instructions in all blocks. |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
150 * |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
151 * @return The id of the last operation. |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
152 */ |
19560
4d70d150944f
Remove AbstractBlock interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19465
diff
changeset
|
153 private static int numberInstructions(LIR lir, List<? extends AbstractBlockBase<?>> sortedBlocks) { |
19126
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
154 int opId = 0; |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
155 int index = 0; |
19560
4d70d150944f
Remove AbstractBlock interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19465
diff
changeset
|
156 for (AbstractBlockBase<?> block : sortedBlocks) { |
19126
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
157 |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
158 List<LIRInstruction> instructions = lir.getLIRforBlock(block); |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
159 |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
160 int numInst = instructions.size(); |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
161 for (int j = 0; j < numInst; j++) { |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
162 LIRInstruction op = instructions.get(j); |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
163 op.setId(opId); |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
164 |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
165 index++; |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
166 opId += 2; // numbering of lirOps by two |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
167 } |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
168 } |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
169 assert (index << 1) == opId : "must match: " + (index << 1); |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
170 return opId - 2; |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
171 } |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
172 |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
173 // ==================== |
19090
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
174 // step 2: build intervals |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
175 // ==================== |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
176 |
19127
e0b4d14d1731
FixPointIntervalBuilder: do not record instruction ids but instructions.
Josef Eisl <josef.eisl@jku.at>
parents:
19126
diff
changeset
|
177 private Set<LIRInstruction> buildIntervals() { |
19123
0f3c0639dc3f
LSStackSlotAllocator: record use positions globally.
Josef Eisl <josef.eisl@jku.at>
parents:
19121
diff
changeset
|
178 return new FixPointIntervalBuilder(lir, stackSlotMap, maxOpId()).build(); |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
179 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
180 |
19090
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
181 // ==================== |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
182 // step 3: verify intervals |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
183 // ==================== |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
184 |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
185 private void verifyIntervals() { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
186 forEachInterval(interval -> { |
19083
09292c24d555
LSStackSlotAllocator: hide inner class.
Josef Eisl <josef.eisl@jku.at>
parents:
19082
diff
changeset
|
187 assert interval.verify(maxOpId()); |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
188 }); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
189 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
190 |
19090
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
191 // ==================== |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
192 // step 4: allocate stack slots |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
193 // ==================== |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
194 |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
195 private void allocateStackSlots() { |
19090
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
196 // create unhandled lists |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
197 forEachInterval(unhandled::add); |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
198 |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
199 for (StackInterval current = activateNext(); current != null; current = activateNext()) { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
200 try (Indent indent = Debug.logAndIndent("allocate %s", current)) { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
201 allocateSlot(current); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
202 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
203 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
204 |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
205 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
206 |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
207 private void allocateSlot(StackInterval current) { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
208 VirtualStackSlot virtualSlot = current.getOperand(); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
209 final StackSlot location; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
210 if (virtualSlot instanceof VirtualStackSlotRange) { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
211 // No reuse of ranges (yet). |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
212 VirtualStackSlotRange slotRange = (VirtualStackSlotRange) virtualSlot; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
213 location = frameMapBuilder.getFrameMap().allocateStackSlots(slotRange.getSlots(), slotRange.getObjects()); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
214 StackSlotAllocator.virtualFramesize.add(frameMapBuilder.getFrameMap().spillSlotRangeSize(slotRange.getSlots())); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
215 StackSlotAllocator.allocatedSlots.increment(); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
216 } else { |
19077
3dd21f7125e9
LSStackSlotAllocator: fix typos.
Josef Eisl <josef.eisl@jku.at>
parents:
19076
diff
changeset
|
217 assert virtualSlot instanceof SimpleVirtualStackSlot : "Unexpected VirtualStackSlot type: " + virtualSlot; |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
218 StackSlot slot = findFreeSlot((SimpleVirtualStackSlot) virtualSlot); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
219 if (slot != null) { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
220 /* |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
221 * Free stack slot available. Note that we create a new one because the kind |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
222 * might not match. |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
223 */ |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
224 location = StackSlot.get(current.kind(), slot.getRawOffset(), slot.getRawAddFrameSize()); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
225 StackSlotAllocator.reusedSlots.increment(); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
226 Debug.log(1, "Reuse stack slot %s (reallocated from %s) for virtual stack slot %s", location, slot, virtualSlot); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
227 } else { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
228 // Allocate new stack slot. |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
229 location = frameMapBuilder.getFrameMap().allocateSpillSlot(virtualSlot.getLIRKind()); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
230 StackSlotAllocator.virtualFramesize.add(frameMapBuilder.getFrameMap().spillSlotSize(virtualSlot.getLIRKind())); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
231 StackSlotAllocator.allocatedSlots.increment(); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
232 Debug.log(1, "New stack slot %s for virtual stack slot %s", location, virtualSlot); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
233 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
234 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
235 Debug.log("Allocate location %s for interval %s", location, current); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
236 current.setLocation(location); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
237 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
238 |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
239 private static enum SlotSize { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
240 Size1, |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
241 Size2, |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
242 Size4, |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
243 Size8, |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
244 Illegal; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
245 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
246 |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
247 private SlotSize forKind(LIRKind kind) { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
248 switch (frameMapBuilder.getFrameMap().spillSlotSize(kind)) { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
249 case 1: |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
250 return SlotSize.Size1; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
251 case 2: |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
252 return SlotSize.Size2; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
253 case 4: |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
254 return SlotSize.Size4; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
255 case 8: |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
256 return SlotSize.Size8; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
257 default: |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
258 return SlotSize.Illegal; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
259 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
260 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
261 |
19091
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
262 private EnumMap<SlotSize, Deque<StackSlot>> freeSlots; |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
263 |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
264 /** |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
265 * @return The list of free stack slots for {@code size} or {@code null} if there is none. |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
266 */ |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
267 private Deque<StackSlot> getOrNullFreeSlots(SlotSize size) { |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
268 if (freeSlots == null) { |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
269 return null; |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
270 } |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
271 return freeSlots.get(size); |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
272 } |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
273 |
19091
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
274 /** |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
275 * @return the list of free stack slots for {@code size}. If there is none a list is |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
276 * created. |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
277 */ |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
278 private Deque<StackSlot> getOrInitFreeSlots(SlotSize size) { |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
279 assert size != SlotSize.Illegal; |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
280 Deque<StackSlot> freeList; |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
281 if (freeSlots != null) { |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
282 freeList = freeSlots.get(size); |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
283 } else { |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
284 freeSlots = new EnumMap<>(SlotSize.class); |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
285 freeList = null; |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
286 } |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
287 if (freeList == null) { |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
288 freeList = new ArrayDeque<>(); |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
289 freeSlots.put(size, freeList); |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
290 } |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
291 assert freeList != null; |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
292 return freeList; |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
293 } |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
294 |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
295 /** |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
296 * Gets a free stack slot for {@code slot} or {@code null} if there is none. |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
297 */ |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
298 private StackSlot findFreeSlot(SimpleVirtualStackSlot slot) { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
299 assert slot != null; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
300 SlotSize size = forKind(slot.getLIRKind()); |
19091
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
301 if (size == SlotSize.Illegal) { |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
302 return null; |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
303 } |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
304 Deque<StackSlot> freeList = getOrNullFreeSlots(size); |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
305 if (freeList == null) { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
306 return null; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
307 } |
19091
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
308 return freeList.pollLast(); |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
309 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
310 |
19091
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
311 /** |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
312 * Adds a stack slot to the list of free slots. |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
313 */ |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
314 private void freeSlot(StackSlot slot) { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
315 SlotSize size = forKind(slot.getLIRKind()); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
316 if (size == SlotSize.Illegal) { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
317 return; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
318 } |
19091
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
319 getOrInitFreeSlots(size).addLast(slot); |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
320 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
321 |
19091
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
322 /** |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
323 * Gets the next unhandled interval and finishes handled intervals. |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
324 */ |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
325 private StackInterval activateNext() { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
326 if (unhandled.isEmpty()) { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
327 return null; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
328 } |
19082
a4c9a0fe4bd5
LSStackSlotAllocator: use priority queue.
Josef Eisl <josef.eisl@jku.at>
parents:
19081
diff
changeset
|
329 StackInterval next = unhandled.poll(); |
19091
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
330 // finish handled intervals |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
331 for (int id = next.from(); activePeekId() < id;) { |
19082
a4c9a0fe4bd5
LSStackSlotAllocator: use priority queue.
Josef Eisl <josef.eisl@jku.at>
parents:
19081
diff
changeset
|
332 finished(active.poll()); |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
333 } |
19077
3dd21f7125e9
LSStackSlotAllocator: fix typos.
Josef Eisl <josef.eisl@jku.at>
parents:
19076
diff
changeset
|
334 Debug.log("active %s", next); |
19082
a4c9a0fe4bd5
LSStackSlotAllocator: use priority queue.
Josef Eisl <josef.eisl@jku.at>
parents:
19081
diff
changeset
|
335 active.add(next); |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
336 return next; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
337 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
338 |
19091
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
339 /** |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
340 * Gets the lowest {@link StackInterval#to() end position} of all active intervals. If there |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
341 * is none {@link Integer#MAX_VALUE} is returned. |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
342 */ |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
343 private int activePeekId() { |
19082
a4c9a0fe4bd5
LSStackSlotAllocator: use priority queue.
Josef Eisl <josef.eisl@jku.at>
parents:
19081
diff
changeset
|
344 StackInterval first = active.peek(); |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
345 if (first == null) { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
346 return Integer.MAX_VALUE; |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
347 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
348 return first.to(); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
349 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
350 |
19091
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
351 /** |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
352 * Finishes {@code interval} by adding its location to the list of free stack slots. |
684612ee6abb
LSStackSlotAllocator: lazy initialize freeSlot and improve javadoc.
Josef Eisl <josef.eisl@jku.at>
parents:
19090
diff
changeset
|
353 */ |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
354 private void finished(StackInterval interval) { |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
355 StackSlot location = interval.location(); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
356 Debug.log("finished %s (freeing %s)", interval, location); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
357 freeSlot(location); |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
358 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
359 |
19090
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
360 // ==================== |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
361 // step 5: assign stack slots |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
362 // ==================== |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
363 |
19127
e0b4d14d1731
FixPointIntervalBuilder: do not record instruction ids but instructions.
Josef Eisl <josef.eisl@jku.at>
parents:
19126
diff
changeset
|
364 private void assignStackSlots(Set<LIRInstruction> usePos) { |
e0b4d14d1731
FixPointIntervalBuilder: do not record instruction ids but instructions.
Josef Eisl <josef.eisl@jku.at>
parents:
19126
diff
changeset
|
365 for (LIRInstruction op : usePos) { |
20975
3ffe4efcc399
Allocate visiting lambdas earlier
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19686
diff
changeset
|
366 op.forEachInput(assignSlot); |
3ffe4efcc399
Allocate visiting lambdas earlier
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19686
diff
changeset
|
367 op.forEachAlive(assignSlot); |
3ffe4efcc399
Allocate visiting lambdas earlier
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19686
diff
changeset
|
368 op.forEachState(assignSlot); |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
369 |
20975
3ffe4efcc399
Allocate visiting lambdas earlier
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19686
diff
changeset
|
370 op.forEachTemp(assignSlot); |
3ffe4efcc399
Allocate visiting lambdas earlier
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19686
diff
changeset
|
371 op.forEachOutput(assignSlot); |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
372 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
373 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
374 |
20975
3ffe4efcc399
Allocate visiting lambdas earlier
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19686
diff
changeset
|
375 ValueProcedure assignSlot = new ValueProcedure() { |
3ffe4efcc399
Allocate visiting lambdas earlier
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19686
diff
changeset
|
376 public Value doValue(Value value, OperandMode mode, EnumSet<OperandFlag> flags) { |
3ffe4efcc399
Allocate visiting lambdas earlier
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19686
diff
changeset
|
377 if (isVirtualStackSlot(value)) { |
3ffe4efcc399
Allocate visiting lambdas earlier
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19686
diff
changeset
|
378 VirtualStackSlot slot = asVirtualStackSlot(value); |
3ffe4efcc399
Allocate visiting lambdas earlier
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19686
diff
changeset
|
379 StackInterval interval = get(slot); |
3ffe4efcc399
Allocate visiting lambdas earlier
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19686
diff
changeset
|
380 assert interval != null; |
3ffe4efcc399
Allocate visiting lambdas earlier
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19686
diff
changeset
|
381 return interval.location(); |
3ffe4efcc399
Allocate visiting lambdas earlier
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19686
diff
changeset
|
382 } |
3ffe4efcc399
Allocate visiting lambdas earlier
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19686
diff
changeset
|
383 return value; |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
384 } |
20975
3ffe4efcc399
Allocate visiting lambdas earlier
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19686
diff
changeset
|
385 }; |
19090
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
386 |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
387 // ==================== |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
388 // |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
389 // ==================== |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
390 |
19126
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
391 /** |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
392 * Gets the highest instruction id. |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
393 */ |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
394 private int maxOpId() { |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
395 return maxOpId; |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
396 } |
53c3e0c470b0
Remove InstructionNumberer once again (Backed out changeset: 1fca9212fb61).
Josef Eisl <josef.eisl@jku.at>
parents:
19123
diff
changeset
|
397 |
19090
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
398 private StackInterval get(VirtualStackSlot stackSlot) { |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
399 return stackSlotMap[stackSlot.getId()]; |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
400 } |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
401 |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
402 private void forEachInterval(Consumer<StackInterval> proc) { |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
403 for (StackInterval interval : stackSlotMap) { |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
404 if (interval != null) { |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
405 proc.accept(interval); |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
406 } |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
407 } |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
408 } |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
409 |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
410 private void dumpIntervals(String label) { |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
411 Debug.dump(stackSlotMap, label); |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
412 } |
d367ad9138f8
LSStackSlotAllocator: clean up comments and sort methods.
Josef Eisl <josef.eisl@jku.at>
parents:
19089
diff
changeset
|
413 |
19028
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
414 } |
f59fc4850df5
StackSlotAllocator: add linear scan stack slot allocator.
Josef Eisl <josef.eisl@jku.at>
parents:
diff
changeset
|
415 } |