annotate graal/com.oracle.jvmci.asm/src/com/oracle/jvmci/asm/Assembler.java @ 21712:a59a0c85650a

removed redundant definition of JVM opcodes
author Doug Simon <doug.simon@oracle.com>
date Wed, 03 Jun 2015 21:53:28 +0200
parents 6df25b1418be
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
21708
6df25b1418be moved com.oracle.asm.** to jvmci-util.jar (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21556
diff changeset
23 package com.oracle.jvmci.asm;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
7700
627c284671b7 Use java.nio.ByteOrder instead of our own ByteOrder enumeration
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7530
diff changeset
25 import java.nio.*;
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
26 import java.util.*;
7700
627c284671b7 Use java.nio.ByteOrder instead of our own ByteOrder enumeration
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7530
diff changeset
27
21556
48c1ebd24120 renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 20003
diff changeset
28 import com.oracle.jvmci.code.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31 * The platform-independent base class for the assembler.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32 */
14032
d1c1f103d42c renamed com.oracle.graal.asm.AbstractAssembler to com.oracle.graal.asm.Assembler
twisti
parents: 14031
diff changeset
33 public abstract class Assembler {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7369
diff changeset
34
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5510
diff changeset
35 public final TargetDescription target;
17213
959d3e75534a LabelHints are now collected in ArrayLists instead of HashSet
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 17207
diff changeset
36 private List<LabelHint> jumpDisplacementHints;
14031
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
37
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
38 /**
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
39 * Backing code buffer.
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
40 */
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
41 private final Buffer codeBuffer;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42
14032
d1c1f103d42c renamed com.oracle.graal.asm.AbstractAssembler to com.oracle.graal.asm.Assembler
twisti
parents: 14031
diff changeset
43 public Assembler(TargetDescription target) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 this.target = target;
7700
627c284671b7 Use java.nio.ByteOrder instead of our own ByteOrder enumeration
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7530
diff changeset
45 if (target.arch.getByteOrder() == ByteOrder.BIG_ENDIAN) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46 this.codeBuffer = new Buffer.BigEndian();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 this.codeBuffer = new Buffer.LittleEndian();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51
14031
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
52 /**
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
53 * Returns the current position of the underlying code buffer.
17207
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
54 *
14031
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
55 * @return current position in code buffer
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
56 */
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
57 public int position() {
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
58 return codeBuffer.position();
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
59 }
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
60
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
61 public final void emitByte(int x) {
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
62 codeBuffer.emitByte(x);
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
63 }
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
64
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
65 public final void emitShort(int x) {
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
66 codeBuffer.emitShort(x);
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
67 }
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
68
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
69 public final void emitInt(int x) {
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
70 codeBuffer.emitInt(x);
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
71 }
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
72
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
73 public final void emitLong(long x) {
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
74 codeBuffer.emitLong(x);
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
75 }
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
76
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
77 public final void emitByte(int b, int pos) {
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
78 codeBuffer.emitByte(b, pos);
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
79 }
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
80
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
81 public final void emitShort(int b, int pos) {
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
82 codeBuffer.emitShort(b, pos);
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
83 }
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
84
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
85 public final void emitInt(int b, int pos) {
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
86 codeBuffer.emitInt(b, pos);
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
87 }
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
88
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
89 public final void emitLong(long b, int pos) {
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
90 codeBuffer.emitLong(b, pos);
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
91 }
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
92
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
93 public final int getByte(int pos) {
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
94 return codeBuffer.getByte(pos);
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
95 }
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
96
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
97 public final int getShort(int pos) {
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
98 return codeBuffer.getShort(pos);
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
99 }
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
100
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
101 public final int getInt(int pos) {
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
102 return codeBuffer.getInt(pos);
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
103 }
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
104
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
105 private static final String NEWLINE = System.getProperty("line.separator");
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
106
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
107 /**
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
108 * Some GPU architectures have a text based encoding.
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
109 */
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
110 public final void emitString(String x) {
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
111 emitString0("\t"); // XXX REMOVE ME pretty-printing
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
112 emitString0(x);
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
113 emitString0(NEWLINE);
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
114 }
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
115
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
116 // XXX for pretty-printing
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
117 public final void emitString0(String x) {
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
118 codeBuffer.emitBytes(x.getBytes(), 0, x.length());
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
119 }
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
120
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
121 public void emitString(String s, int pos) {
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
122 codeBuffer.emitBytes(s.getBytes(), pos);
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
123 }
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
124
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
125 /**
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
126 * Closes this assembler. No extra data can be written to this assembler after this call.
17207
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
127 *
14031
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
128 * @param trimmedCopy if {@code true}, then a copy of the underlying byte array up to (but not
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
129 * including) {@code position()} is returned
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
130 * @return the data in this buffer or a trimmed copy if {@code trimmedCopy} is {@code true}
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
131 */
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
132 public byte[] close(boolean trimmedCopy) {
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
133 return codeBuffer.close(trimmedCopy);
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
134 }
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
135
7804
447f9ba1962b Experimental PTX backend. Contribution by Christian Thalinger.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7700
diff changeset
136 public void bind(Label l) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
137 assert !l.isBound() : "can bind label only once";
14031
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13227
diff changeset
138 l.bind(position());
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
139 l.patchInstructions(this);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
140 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
141
4522
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
142 public abstract void align(int modulus);
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
143
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
144 public abstract void jmp(Label l);
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
145
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
146 protected abstract void patchJumpTarget(int branch, int jumpTarget);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
147
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
148 private Map<Label, String> nameMap;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
149
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
150 /**
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
151 * Creates a name for a label.
17207
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
152 *
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
153 * @param l the label for which a name is being created
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
154 * @param id a label identifier that is unique with the scope of this assembler
10820
f8fe0f7ee22a added createLabelName override in AbstractHSAILAssembler; create a common label name in AbstractAssembler
twisti
parents: 10662
diff changeset
155 * @return a label name in the form of "L123"
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
156 */
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
157 protected String createLabelName(Label l, int id) {
10820
f8fe0f7ee22a added createLabelName override in AbstractHSAILAssembler; create a common label name in AbstractAssembler
twisti
parents: 10662
diff changeset
158 return "L" + id;
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
159 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
160
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
161 /**
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
162 * Gets a name for a label, creating it if it does not yet exist. By default, the returned name
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
163 * is only unique with the scope of this assembler.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
164 */
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
165 public String nameOf(Label l) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
166 if (nameMap == null) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
167 nameMap = new HashMap<>();
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
168 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
169 String name = nameMap.get(l);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
170 if (name == null) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
171 name = createLabelName(l, nameMap.size());
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
172 nameMap.put(l, name);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
173 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
174 return name;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
175 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
176
7839
838293a77af7 Make Address class platform specific.
Roland Schatz <roland.schatz@oracle.com>
parents: 7808
diff changeset
177 /**
13227
1a66453f73db renamed TargetMethodAssembler to CompilationResultBuilder
Doug Simon <doug.simon@oracle.com>
parents: 10820
diff changeset
178 * This is used by the CompilationResultBuilder to convert a {@link StackSlot} to an
8167
7f57c30575c8 Make AMD64Address a low-level representation for use by the assembler only.
Roland Schatz <roland.schatz@oracle.com>
parents: 7839
diff changeset
179 * {@link AbstractAddress}.
7839
838293a77af7 Make Address class platform specific.
Roland Schatz <roland.schatz@oracle.com>
parents: 7808
diff changeset
180 */
8170
537f03d2bdf7 Removed unused parameter from AbstractAssembler.makeAddress().
Roland Schatz <roland.schatz@oracle.com>
parents: 8167
diff changeset
181 public abstract AbstractAddress makeAddress(Register base, int displacement);
7839
838293a77af7 Make Address class platform specific.
Roland Schatz <roland.schatz@oracle.com>
parents: 7808
diff changeset
182
838293a77af7 Make Address class platform specific.
Roland Schatz <roland.schatz@oracle.com>
parents: 7808
diff changeset
183 /**
838293a77af7 Make Address class platform specific.
Roland Schatz <roland.schatz@oracle.com>
parents: 7808
diff changeset
184 * Returns a target specific placeholder address that can be used for code patching.
838293a77af7 Make Address class platform specific.
Roland Schatz <roland.schatz@oracle.com>
parents: 7808
diff changeset
185 */
8167
7f57c30575c8 Make AMD64Address a low-level representation for use by the assembler only.
Roland Schatz <roland.schatz@oracle.com>
parents: 7839
diff changeset
186 public abstract AbstractAddress getPlaceholder();
14754
164903a50a9a make ensureUniquePC an abstract method of the base Assembler class
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14032
diff changeset
187
164903a50a9a make ensureUniquePC an abstract method of the base Assembler class
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14032
diff changeset
188 /**
164903a50a9a make ensureUniquePC an abstract method of the base Assembler class
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14032
diff changeset
189 * Emits a NOP instruction to advance the current PC.
164903a50a9a make ensureUniquePC an abstract method of the base Assembler class
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14032
diff changeset
190 */
164903a50a9a make ensureUniquePC an abstract method of the base Assembler class
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14032
diff changeset
191 public abstract void ensureUniquePC();
17207
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
192
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
193 public void reset() {
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
194 codeBuffer.reset();
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
195 captureLabelPositions();
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
196 }
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
197
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
198 private void captureLabelPositions() {
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
199 if (jumpDisplacementHints == null) {
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
200 return;
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
201 }
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
202 for (LabelHint request : this.jumpDisplacementHints) {
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
203 request.capture();
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
204 }
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
205 }
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
206
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
207 public LabelHint requestLabelHint(Label label) {
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
208 if (jumpDisplacementHints == null) {
17213
959d3e75534a LabelHints are now collected in ArrayLists instead of HashSet
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 17207
diff changeset
209 jumpDisplacementHints = new ArrayList<>();
17207
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
210 }
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
211 LabelHint hint = new LabelHint(label, position());
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
212 this.jumpDisplacementHints.add(hint);
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
213 return hint;
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
214 }
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
215
20003
422e60a2f4b9 Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 17215
diff changeset
216 public InstructionCounter getInstructionCounter() {
422e60a2f4b9 Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 17215
diff changeset
217 throw new UnsupportedOperationException("Instruction counter is not implemented for " + this);
422e60a2f4b9 Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 17215
diff changeset
218 }
422e60a2f4b9 Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 17215
diff changeset
219
17207
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
220 public static class LabelHint {
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
221 private Label label;
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
222 private int forPosition;
17215
7a99826863d9 Eliminate valid bit in LabelHint as the validity can be encoded into the capturedTarget
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 17213
diff changeset
223 private int capturedTarget = -1;
17207
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
224
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
225 protected LabelHint(Label label, int lastPosition) {
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
226 super();
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
227 this.label = label;
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
228 this.forPosition = lastPosition;
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
229 }
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
230
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
231 protected void capture() {
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
232 this.capturedTarget = label.position();
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
233 }
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
234
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
235 public int getTarget() {
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
236 assert isValid();
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
237 return capturedTarget;
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
238 }
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
239
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
240 public int getPosition() {
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
241 assert isValid();
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
242 return forPosition;
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
243 }
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
244
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
245 public boolean isValid() {
17215
7a99826863d9 Eliminate valid bit in LabelHint as the validity can be encoded into the capturedTarget
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 17213
diff changeset
246 return capturedTarget >= 0;
17207
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
247 }
5a7b82c1514e [SPARC] Add functionality to be able to do assembly in two passes (knowing offsets of forward branches)
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 14754
diff changeset
248 }
20003
422e60a2f4b9 Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 17215
diff changeset
249
422e60a2f4b9 Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 17215
diff changeset
250 /**
422e60a2f4b9 Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 17215
diff changeset
251 * Instruction counter class which gives the user of the assembler to count different kinds of
422e60a2f4b9 Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 17215
diff changeset
252 * instructions in the generated assembler code.
422e60a2f4b9 Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 17215
diff changeset
253 */
422e60a2f4b9 Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 17215
diff changeset
254 public interface InstructionCounter {
422e60a2f4b9 Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 17215
diff changeset
255 String[] getSupportedInstructionTypes();
422e60a2f4b9 Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 17215
diff changeset
256
422e60a2f4b9 Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 17215
diff changeset
257 int[] countInstructions(String[] instructionTypes, int beginPc, int endPc);
422e60a2f4b9 Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 17215
diff changeset
258 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
259 }