43972
|
1 |
/*
|
59095
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
43972
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.hotspot.amd64;
|
|
26 |
|
|
27 |
import static jdk.vm.ci.amd64.AMD64.r10;
|
|
28 |
import static jdk.vm.ci.amd64.AMD64.r11;
|
|
29 |
import static jdk.vm.ci.amd64.AMD64.r12;
|
|
30 |
import static jdk.vm.ci.amd64.AMD64.r13;
|
|
31 |
import static jdk.vm.ci.amd64.AMD64.r14;
|
|
32 |
import static jdk.vm.ci.amd64.AMD64.r8;
|
|
33 |
import static jdk.vm.ci.amd64.AMD64.r9;
|
|
34 |
import static jdk.vm.ci.amd64.AMD64.rax;
|
|
35 |
import static jdk.vm.ci.amd64.AMD64.rbp;
|
|
36 |
import static jdk.vm.ci.amd64.AMD64.rbx;
|
|
37 |
import static jdk.vm.ci.amd64.AMD64.rcx;
|
|
38 |
import static jdk.vm.ci.amd64.AMD64.rdi;
|
|
39 |
import static jdk.vm.ci.amd64.AMD64.rdx;
|
|
40 |
import static jdk.vm.ci.amd64.AMD64.rsi;
|
|
41 |
import static jdk.vm.ci.amd64.AMD64.xmm0;
|
|
42 |
import static jdk.vm.ci.amd64.AMD64.xmm1;
|
|
43 |
import static jdk.vm.ci.amd64.AMD64.xmm10;
|
|
44 |
import static jdk.vm.ci.amd64.AMD64.xmm11;
|
|
45 |
import static jdk.vm.ci.amd64.AMD64.xmm12;
|
|
46 |
import static jdk.vm.ci.amd64.AMD64.xmm13;
|
|
47 |
import static jdk.vm.ci.amd64.AMD64.xmm14;
|
|
48 |
import static jdk.vm.ci.amd64.AMD64.xmm15;
|
|
49 |
import static jdk.vm.ci.amd64.AMD64.xmm2;
|
|
50 |
import static jdk.vm.ci.amd64.AMD64.xmm3;
|
|
51 |
import static jdk.vm.ci.amd64.AMD64.xmm4;
|
|
52 |
import static jdk.vm.ci.amd64.AMD64.xmm5;
|
|
53 |
import static jdk.vm.ci.amd64.AMD64.xmm6;
|
|
54 |
import static jdk.vm.ci.amd64.AMD64.xmm7;
|
|
55 |
import static jdk.vm.ci.amd64.AMD64.xmm8;
|
|
56 |
import static jdk.vm.ci.amd64.AMD64.xmm9;
|
|
57 |
|
|
58 |
import java.util.ArrayList;
|
|
59 |
import java.util.BitSet;
|
|
60 |
|
|
61 |
import org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig;
|
|
62 |
|
|
63 |
import jdk.vm.ci.code.Register;
|
|
64 |
import jdk.vm.ci.code.RegisterArray;
|
|
65 |
import jdk.vm.ci.code.RegisterConfig;
|
|
66 |
|
|
67 |
class AMD64HotSpotRegisterAllocationConfig extends RegisterAllocationConfig {
|
|
68 |
/**
|
|
69 |
* Specify priority of register selection within phases of register allocation. Highest priority
|
|
70 |
* is first. A useful heuristic is to give registers a low priority when they are required by
|
|
71 |
* machine instructions, like EAX and EDX on I486, and choose no-save registers before
|
|
72 |
* save-on-call, & save-on-call before save-on-entry. Registers which participate in fixed
|
|
73 |
* calling sequences should come last. Registers which are used as pairs must fall on an even
|
|
74 |
* boundary.
|
|
75 |
*
|
|
76 |
* Adopted from x86_64.ad.
|
|
77 |
*/
|
|
78 |
// @formatter:off
|
|
79 |
static final Register[] registerAllocationOrder = {
|
|
80 |
r10, r11, r8, r9, r12, rcx, rbx, rdi, rdx, rsi, rax, rbp, r13, r14, /*r15,*/ /*rsp,*/
|
|
81 |
xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7,
|
|
82 |
xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15
|
|
83 |
};
|
|
84 |
// @formatter:on
|
|
85 |
|
59095
|
86 |
private final boolean useStandardFrameProlog;
|
|
87 |
|
|
88 |
AMD64HotSpotRegisterAllocationConfig(RegisterConfig registerConfig, String[] allocationRestrictedTo, boolean useStandardFrameProlog) {
|
46344
|
89 |
super(registerConfig, allocationRestrictedTo);
|
59095
|
90 |
this.useStandardFrameProlog = useStandardFrameProlog;
|
43972
|
91 |
}
|
|
92 |
|
|
93 |
@Override
|
|
94 |
protected RegisterArray initAllocatable(RegisterArray registers) {
|
|
95 |
BitSet regMap = new BitSet(registerConfig.getAllocatableRegisters().size());
|
|
96 |
for (Register reg : registers) {
|
|
97 |
regMap.set(reg.number);
|
|
98 |
}
|
59095
|
99 |
if (useStandardFrameProlog) {
|
|
100 |
regMap.clear(rbp.number);
|
|
101 |
}
|
43972
|
102 |
|
|
103 |
ArrayList<Register> allocatableRegisters = new ArrayList<>(registers.size());
|
|
104 |
for (Register reg : registerAllocationOrder) {
|
|
105 |
if (regMap.get(reg.number)) {
|
|
106 |
allocatableRegisters.add(reg);
|
|
107 |
}
|
|
108 |
}
|
|
109 |
|
|
110 |
return super.initAllocatable(new RegisterArray(allocatableRegisters));
|
|
111 |
}
|
|
112 |
}
|