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