Mercurial > hg > graal-jvmci-8
comparison graal/Compiler/src/com/sun/c1x/ir/Intrinsic.java @ 2507:9ec15d6914ca
Pull over of compiler from maxine repository.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 27 Apr 2011 11:43:22 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2506:4a3bf8a5bf41 | 2507:9ec15d6914ca |
---|---|
1 /* | |
2 * Copyright (c) 2009, 2011, 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 com.sun.c1x.ir; | |
24 | |
25 import com.sun.c1x.*; | |
26 import com.sun.c1x.debug.*; | |
27 import com.sun.c1x.value.*; | |
28 import com.sun.cri.ci.*; | |
29 import com.sun.cri.ri.*; | |
30 | |
31 /** | |
32 * The {@code Intrinsic} instruction represents a call to a JDK method | |
33 * that has been made {@linkplain C1XIntrinsic intrinsic}. | |
34 * | |
35 * @author Ben L. Titzer | |
36 * @see C1XIntrinsic | |
37 */ | |
38 public final class Intrinsic extends StateSplit { | |
39 | |
40 final C1XIntrinsic intrinsic; | |
41 final RiMethod target; | |
42 final Value[] arguments; | |
43 final boolean canTrap; | |
44 | |
45 /** | |
46 * Creates a new Intrinsic instruction. | |
47 * @param kind the result type of the instruction | |
48 * @param intrinsic the actual intrinsic | |
49 * @param target the method for this intrinsic | |
50 * @param args the arguments to the call (including the receiver object) | |
51 * @param isStatic {@code true} if this method is static | |
52 * @param stateBefore the lock stack | |
53 * @param preservesState {@code true} if the implementation of this intrinsic preserves register state | |
54 * @param canTrap {@code true} if this intrinsic can cause a trap | |
55 */ | |
56 public Intrinsic(CiKind kind, C1XIntrinsic intrinsic, RiMethod target, Value[] args, boolean isStatic, | |
57 FrameState stateBefore, boolean preservesState, boolean canTrap) { | |
58 super(kind, stateBefore); | |
59 this.intrinsic = intrinsic; | |
60 int nonNullArgs = 0; | |
61 for (int i = 0; i < args.length; ++i) { | |
62 if (args[i] != null) { | |
63 nonNullArgs++; | |
64 } | |
65 } | |
66 this.arguments = new Value[nonNullArgs]; | |
67 int z = 0; | |
68 for (int i = 0; i < args.length; ++i) { | |
69 if (args[i] != null) { | |
70 arguments[z++] = args[i]; | |
71 } | |
72 } | |
73 this.target = target; | |
74 initFlag(Flag.IsStatic, isStatic); | |
75 // Preserves state means that the intrinsic preserves register state across all cases, | |
76 // including slow cases--even if it causes a trap. If so, it can still be a candidate | |
77 // for load elimination and common subexpression elimination | |
78 initFlag(Flag.PreservesState, preservesState); | |
79 this.canTrap = canTrap; | |
80 if (!isStatic && args[0].isNonNull()) { | |
81 eliminateNullCheck(); | |
82 } | |
83 } | |
84 | |
85 /** | |
86 * Gets the intrinsic represented by this instruction. | |
87 * @return the intrinsic | |
88 */ | |
89 public C1XIntrinsic intrinsic() { | |
90 return intrinsic; | |
91 } | |
92 | |
93 /** | |
94 * Gets the target method for this invocation instruction. | |
95 * @return the target method | |
96 */ | |
97 public RiMethod target() { | |
98 return target; | |
99 } | |
100 | |
101 /** | |
102 * Gets the list of instructions that produce input for this instruction. | |
103 * @return the list of instructions that produce input | |
104 */ | |
105 public Value[] arguments() { | |
106 return arguments; | |
107 } | |
108 | |
109 public boolean isStatic() { | |
110 return checkFlag(Flag.IsStatic); | |
111 } | |
112 | |
113 /** | |
114 * Checks whether this intrinsic has a receiver object. | |
115 * @return {@code true} if this intrinsic has a receiver object | |
116 */ | |
117 public boolean hasReceiver() { | |
118 return !isStatic(); | |
119 } | |
120 | |
121 /** | |
122 * Gets the instruction which produces the receiver object for this intrinsic. | |
123 * @return the instruction producing the receiver object | |
124 */ | |
125 public Value receiver() { | |
126 assert !isStatic(); | |
127 return arguments[0]; | |
128 } | |
129 | |
130 /** | |
131 * Checks whether this intrinsic preserves the state of registers across all cases. | |
132 * @return {@code true} if this intrinsic always preserves register state | |
133 */ | |
134 public boolean preservesState() { | |
135 return checkFlag(Flag.PreservesState); | |
136 } | |
137 | |
138 /** | |
139 * Checks whether this intrinsic can cause a trap. | |
140 * @return {@code true} if this intrinsic can cause a trap | |
141 */ | |
142 @Override | |
143 public boolean canTrap() { | |
144 return canTrap; | |
145 } | |
146 | |
147 @Override | |
148 public void inputValuesDo(ValueClosure closure) { | |
149 for (int i = 0; i < arguments.length; i++) { | |
150 arguments[i] = closure.apply(arguments[i]); | |
151 } | |
152 } | |
153 | |
154 @Override | |
155 public void accept(ValueVisitor v) { | |
156 v.visitIntrinsic(this); | |
157 } | |
158 | |
159 public Value argumentAt(int i) { | |
160 return arguments[i]; | |
161 } | |
162 | |
163 public int numberOfArguments() { | |
164 return arguments.length; | |
165 } | |
166 | |
167 @Override | |
168 public void print(LogStream out) { | |
169 out.print(intrinsic().className).print('.').print(intrinsic().name()).print('('); | |
170 for (int i = 0; i < arguments().length; i++) { | |
171 if (i > 0) { | |
172 out.print(", "); | |
173 } | |
174 out.print(arguments()[i]); | |
175 } | |
176 out.print(')'); | |
177 } | |
178 } |