annotate graal/com.oracle.graal.asm/src/com/oracle/graal/asm/AbstractAssembler.java @ 13227:1a66453f73db

renamed TargetMethodAssembler to CompilationResultBuilder
author Doug Simon <doug.simon@oracle.com>
date Tue, 03 Dec 2013 10:51:16 +0100
parents f8fe0f7ee22a
children 390c4b742890
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 */
6531
4afe23aa0a00 renamed packages: com.oracle.max.asm... -> com.oracle.graal.asm...
Doug Simon <doug.simon@oracle.com>
parents: 6497
diff changeset
23 package com.oracle.graal.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
5510
426c605c9d3c Move cri.ci to api.code.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5233
diff changeset
28 import com.oracle.graal.api.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 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33 public abstract class AbstractAssembler {
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;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36 public final Buffer codeBuffer;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5510
diff changeset
38 public AbstractAssembler(TargetDescription target) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39 this.target = target;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40
7700
627c284671b7 Use java.nio.ByteOrder instead of our own ByteOrder enumeration
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7530
diff changeset
41 if (target.arch.getByteOrder() == ByteOrder.BIG_ENDIAN) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42 this.codeBuffer = new Buffer.BigEndian();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 this.codeBuffer = new Buffer.LittleEndian();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47
7804
447f9ba1962b Experimental PTX backend. Contribution by Christian Thalinger.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7700
diff changeset
48 public void bind(Label l) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 assert !l.isBound() : "can bind label only once";
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50 l.bind(codeBuffer.position());
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51 l.patchInstructions(this);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53
4522
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
54 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
55
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
56 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
57
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
58 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
59
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
60 private Map<Label, String> nameMap;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
61
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
62 /**
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
63 * Creates a name for a label.
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
64 *
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
65 * @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
66 * @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
67 * @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
68 */
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
69 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
70 return "L" + id;
10662
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
71 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
72
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
73 /**
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
74 * 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
75 * 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
76 */
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
77 public String nameOf(Label l) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
78 if (nameMap == null) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
79 nameMap = new HashMap<>();
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
80 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
81 String name = nameMap.get(l);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
82 if (name == null) {
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
83 name = createLabelName(l, nameMap.size());
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
84 nameMap.put(l, name);
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
85 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
86 return name;
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
87 }
4ef92b67aeae added HSAIL backend and tests
Doug Simon <doug.simon@oracle.com>
parents: 8170
diff changeset
88
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
89 protected final void emitByte(int x) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
90 codeBuffer.emitByte(x);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
91 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
92
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
93 protected final void emitShort(int x) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
94 codeBuffer.emitShort(x);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
95 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
96
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
97 protected final void emitInt(int x) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
98 codeBuffer.emitInt(x);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
99 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
100
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
101 protected final void emitLong(long x) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
102 codeBuffer.emitLong(x);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
103 }
7804
447f9ba1962b Experimental PTX backend. Contribution by Christian Thalinger.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7700
diff changeset
104
447f9ba1962b Experimental PTX backend. Contribution by Christian Thalinger.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7700
diff changeset
105 /**
447f9ba1962b Experimental PTX backend. Contribution by Christian Thalinger.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7700
diff changeset
106 * Some GPU architectures have a text based encoding.
447f9ba1962b Experimental PTX backend. Contribution by Christian Thalinger.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7700
diff changeset
107 */
447f9ba1962b Experimental PTX backend. Contribution by Christian Thalinger.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7700
diff changeset
108 protected final void emitString(String x) {
447f9ba1962b Experimental PTX backend. Contribution by Christian Thalinger.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7700
diff changeset
109 codeBuffer.emitString(x);
447f9ba1962b Experimental PTX backend. Contribution by Christian Thalinger.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7700
diff changeset
110 }
7805
0e58445d54df Integration fixes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7804
diff changeset
111
7804
447f9ba1962b Experimental PTX backend. Contribution by Christian Thalinger.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7700
diff changeset
112 // XXX for pretty-printing
447f9ba1962b Experimental PTX backend. Contribution by Christian Thalinger.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7700
diff changeset
113 protected final void emitString0(String x) {
447f9ba1962b Experimental PTX backend. Contribution by Christian Thalinger.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7700
diff changeset
114 codeBuffer.emitString0(x);
447f9ba1962b Experimental PTX backend. Contribution by Christian Thalinger.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7700
diff changeset
115 }
7839
838293a77af7 Make Address class platform specific.
Roland Schatz <roland.schatz@oracle.com>
parents: 7808
diff changeset
116
838293a77af7 Make Address class platform specific.
Roland Schatz <roland.schatz@oracle.com>
parents: 7808
diff changeset
117 /**
13227
1a66453f73db renamed TargetMethodAssembler to CompilationResultBuilder
Doug Simon <doug.simon@oracle.com>
parents: 10820
diff changeset
118 * 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
119 * {@link AbstractAddress}.
7839
838293a77af7 Make Address class platform specific.
Roland Schatz <roland.schatz@oracle.com>
parents: 7808
diff changeset
120 */
8170
537f03d2bdf7 Removed unused parameter from AbstractAssembler.makeAddress().
Roland Schatz <roland.schatz@oracle.com>
parents: 8167
diff changeset
121 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
122
838293a77af7 Make Address class platform specific.
Roland Schatz <roland.schatz@oracle.com>
parents: 7808
diff changeset
123 /**
838293a77af7 Make Address class platform specific.
Roland Schatz <roland.schatz@oracle.com>
parents: 7808
diff changeset
124 * 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
125 */
8167
7f57c30575c8 Make AMD64Address a low-level representation for use by the assembler only.
Roland Schatz <roland.schatz@oracle.com>
parents: 7839
diff changeset
126 public abstract AbstractAddress getPlaceholder();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
127 }