Mercurial > hg > truffle
annotate graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RegisterSaveLayout.java @ 16532:2dd966b157e8
Merge
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Tue, 15 Jul 2014 21:26:34 -0700 |
parents | 0e0c24424d14 |
children | d60dd21329f2 |
rev | line source |
---|---|
9336
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
15454
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
9336
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.api.code; |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
25 import java.util.*; |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
26 |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
27 /** |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 * A map from registers to frame slots. This can be used to describe where callee saved registers |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
29 * are saved in a callee's frame. |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
30 */ |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
31 public class RegisterSaveLayout { |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
33 /** |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
34 * Keys. |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 */ |
15454
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
36 private final Register[] registers; |
9336
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
37 |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
38 /** |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 * Slot indexes relative to stack pointer. |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
40 */ |
15454
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
41 private final int[] slots; |
9336
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
42 |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
43 /** |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
44 * Creates a map from registers to frame slots. |
15454
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
45 * |
9336
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
46 * @param registers the keys in the map |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 * @param slots frame slot index for each register in {@code registers} |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 */ |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
49 public RegisterSaveLayout(Register[] registers, int[] slots) { |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
50 assert registers.length == slots.length; |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
51 this.registers = registers; |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
52 this.slots = slots; |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
53 assert registersToSlots(false).size() == registers.length : "non-unique registers"; |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
54 assert new HashSet<>(registersToSlots(false).values()).size() == slots.length : "non-unqiue slots"; |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 } |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
56 |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
57 /** |
15454
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
58 * Gets the frame slot index for a given register. |
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
59 * |
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
60 * @param register register to get the frame slot index for |
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
61 * @return frame slot index |
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
62 */ |
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
63 public int registerToSlot(Register register) { |
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
64 for (int i = 0; i < registers.length; i++) { |
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
65 if (register.equals(registers[i])) { |
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
66 return slots[i]; |
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
67 } |
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
68 } |
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
69 throw new IllegalArgumentException(register + " not saved by this layout: " + this); |
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
70 } |
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
71 |
0e0c24424d14
added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register)
twisti
parents:
9336
diff
changeset
|
72 /** |
9336
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
73 * Gets this layout information as a {@link Map} from registers to slots. |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
74 */ |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
75 public Map<Register, Integer> registersToSlots(boolean sorted) { |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
76 Map<Register, Integer> result; |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
77 if (sorted) { |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
78 result = new TreeMap<>(); |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
79 } else { |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
80 result = new HashMap<>(); |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
81 } |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
82 for (int i = 0; i < registers.length; i++) { |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
83 result.put(registers[i], slots[i]); |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
84 } |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
85 return result; |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
86 } |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
87 |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
88 /** |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
89 * Gets this layout information as a {@link Map} from slots to registers. |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
90 */ |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
91 public Map<Integer, Register> slotsToRegisters(boolean sorted) { |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
92 Map<Integer, Register> result; |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
93 if (sorted) { |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
94 result = new TreeMap<>(); |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
95 } else { |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
96 result = new HashMap<>(); |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
97 } |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
98 for (int i = 0; i < registers.length; i++) { |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
99 result.put(slots[i], registers[i]); |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
100 } |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
101 return result; |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
102 } |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
103 |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
104 @Override |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
105 public String toString() { |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
106 return registersToSlots(true).toString(); |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
107 } |
47e7933283f1
added support for adding callee save information to a DebugInfo (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
108 } |