1 /* |
|
2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. |
|
3 * Copyright 2008, 2009 Red Hat, Inc. |
|
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
5 * |
|
6 * This code is free software; you can redistribute it and/or modify it |
|
7 * under the terms of the GNU General Public License version 2 only, as |
|
8 * published by the Free Software Foundation. |
|
9 * |
|
10 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 * version 2 for more details (a copy is included in the LICENSE file that |
|
14 * accompanied this code). |
|
15 * |
|
16 * You should have received a copy of the GNU General Public License version |
|
17 * 2 along with this work; if not, write to the Free Software Foundation, |
|
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 * |
|
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 * or visit www.oracle.com if you need additional information or have any |
|
22 * questions. |
|
23 * |
|
24 */ |
|
25 |
|
26 #include "precompiled.hpp" |
|
27 #include "ci/ciType.hpp" |
|
28 #include "shark/llvmHeaders.hpp" |
|
29 #include "shark/llvmValue.hpp" |
|
30 #include "shark/sharkBuilder.hpp" |
|
31 #include "shark/sharkValue.hpp" |
|
32 |
|
33 using namespace llvm; |
|
34 |
|
35 // Cloning |
|
36 |
|
37 SharkValue* SharkNormalValue::clone() const { |
|
38 return SharkValue::create_generic(type(), generic_value(), zero_checked()); |
|
39 } |
|
40 SharkValue* SharkPHIValue::clone() const { |
|
41 return SharkValue::create_phi(type(), (PHINode *) generic_value(), this); |
|
42 } |
|
43 SharkValue* SharkAddressValue::clone() const { |
|
44 return SharkValue::address_constant(address_value()); |
|
45 } |
|
46 |
|
47 // Casting |
|
48 |
|
49 bool SharkValue::is_phi() const { |
|
50 return false; |
|
51 } |
|
52 bool SharkPHIValue::is_phi() const { |
|
53 return true; |
|
54 } |
|
55 SharkPHIValue* SharkValue::as_phi() { |
|
56 ShouldNotCallThis(); |
|
57 } |
|
58 SharkPHIValue* SharkPHIValue::as_phi() { |
|
59 return this; |
|
60 } |
|
61 |
|
62 // Comparison |
|
63 |
|
64 bool SharkNormalValue::equal_to(SharkValue *other) const { |
|
65 return (this->type() == other->type() && |
|
66 this->generic_value() == other->generic_value() && |
|
67 this->zero_checked() == other->zero_checked()); |
|
68 } |
|
69 bool SharkAddressValue::equal_to(SharkValue *other) const { |
|
70 return (this->address_value() == other->address_value()); |
|
71 } |
|
72 |
|
73 // Type access |
|
74 |
|
75 ciType* SharkValue::type() const { |
|
76 ShouldNotCallThis(); |
|
77 } |
|
78 ciType* SharkNormalValue::type() const { |
|
79 return _type; |
|
80 } |
|
81 |
|
82 BasicType SharkNormalValue::basic_type() const { |
|
83 return type()->basic_type(); |
|
84 } |
|
85 BasicType SharkAddressValue::basic_type() const { |
|
86 return T_ADDRESS; |
|
87 } |
|
88 |
|
89 int SharkNormalValue::size() const { |
|
90 return type()->size(); |
|
91 } |
|
92 int SharkAddressValue::size() const { |
|
93 return 1; |
|
94 } |
|
95 |
|
96 bool SharkValue::is_jint() const { |
|
97 return false; |
|
98 } |
|
99 bool SharkValue::is_jlong() const { |
|
100 return false; |
|
101 } |
|
102 bool SharkValue::is_jfloat() const { |
|
103 return false; |
|
104 } |
|
105 bool SharkValue::is_jdouble() const { |
|
106 return false; |
|
107 } |
|
108 bool SharkValue::is_jobject() const { |
|
109 return false; |
|
110 } |
|
111 bool SharkValue::is_jarray() const { |
|
112 return false; |
|
113 } |
|
114 bool SharkValue::is_address() const { |
|
115 return false; |
|
116 } |
|
117 |
|
118 bool SharkNormalValue::is_jint() const { |
|
119 return llvm_value()->getType() == SharkType::jint_type(); |
|
120 } |
|
121 bool SharkNormalValue::is_jlong() const { |
|
122 return llvm_value()->getType() == SharkType::jlong_type(); |
|
123 } |
|
124 bool SharkNormalValue::is_jfloat() const { |
|
125 return llvm_value()->getType() == SharkType::jfloat_type(); |
|
126 } |
|
127 bool SharkNormalValue::is_jdouble() const { |
|
128 return llvm_value()->getType() == SharkType::jdouble_type(); |
|
129 } |
|
130 bool SharkNormalValue::is_jobject() const { |
|
131 return llvm_value()->getType() == SharkType::oop_type(); |
|
132 } |
|
133 bool SharkNormalValue::is_jarray() const { |
|
134 return basic_type() == T_ARRAY; |
|
135 } |
|
136 bool SharkAddressValue::is_address() const { |
|
137 return true; |
|
138 } |
|
139 |
|
140 // Typed conversions from SharkValues |
|
141 |
|
142 Value* SharkValue::jint_value() const { |
|
143 ShouldNotCallThis(); |
|
144 } |
|
145 Value* SharkValue::jlong_value() const { |
|
146 ShouldNotCallThis(); |
|
147 } |
|
148 Value* SharkValue::jfloat_value() const { |
|
149 ShouldNotCallThis(); |
|
150 } |
|
151 Value* SharkValue::jdouble_value() const { |
|
152 ShouldNotCallThis(); |
|
153 } |
|
154 Value* SharkValue::jobject_value() const { |
|
155 ShouldNotCallThis(); |
|
156 } |
|
157 Value* SharkValue::jarray_value() const { |
|
158 ShouldNotCallThis(); |
|
159 } |
|
160 int SharkValue::address_value() const { |
|
161 ShouldNotCallThis(); |
|
162 } |
|
163 |
|
164 Value* SharkNormalValue::jint_value() const { |
|
165 assert(is_jint(), "should be"); |
|
166 return llvm_value(); |
|
167 } |
|
168 Value* SharkNormalValue::jlong_value() const { |
|
169 assert(is_jlong(), "should be"); |
|
170 return llvm_value(); |
|
171 } |
|
172 Value* SharkNormalValue::jfloat_value() const { |
|
173 assert(is_jfloat(), "should be"); |
|
174 return llvm_value(); |
|
175 } |
|
176 Value* SharkNormalValue::jdouble_value() const { |
|
177 assert(is_jdouble(), "should be"); |
|
178 return llvm_value(); |
|
179 } |
|
180 Value* SharkNormalValue::jobject_value() const { |
|
181 assert(is_jobject(), "should be"); |
|
182 return llvm_value(); |
|
183 } |
|
184 Value* SharkNormalValue::jarray_value() const { |
|
185 // XXX assert(is_jarray(), "should be"); |
|
186 // XXX http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=324 |
|
187 assert(is_jobject(), "should be"); |
|
188 return llvm_value(); |
|
189 } |
|
190 int SharkAddressValue::address_value() const { |
|
191 return _bci; |
|
192 } |
|
193 |
|
194 // Type-losing conversions -- use with care! |
|
195 |
|
196 Value* SharkNormalValue::generic_value() const { |
|
197 return llvm_value(); |
|
198 } |
|
199 Value* SharkAddressValue::generic_value() const { |
|
200 return LLVMValue::intptr_constant(address_value()); |
|
201 } |
|
202 |
|
203 Value* SharkValue::intptr_value(SharkBuilder* builder) const { |
|
204 ShouldNotCallThis(); |
|
205 } |
|
206 Value* SharkNormalValue::intptr_value(SharkBuilder* builder) const { |
|
207 return builder->CreatePtrToInt(jobject_value(), SharkType::intptr_type()); |
|
208 } |
|
209 |
|
210 // Phi-style stuff for SharkPHIState::add_incoming |
|
211 |
|
212 void SharkValue::addIncoming(SharkValue *value, BasicBlock* block) { |
|
213 ShouldNotCallThis(); |
|
214 } |
|
215 void SharkPHIValue::addIncoming(SharkValue *value, BasicBlock* block) { |
|
216 assert(!is_clone(), "shouldn't be"); |
|
217 ((llvm::PHINode *) generic_value())->addIncoming( |
|
218 value->generic_value(), block); |
|
219 if (!value->zero_checked()) |
|
220 _all_incomers_zero_checked = false; |
|
221 } |
|
222 void SharkAddressValue::addIncoming(SharkValue *value, BasicBlock* block) { |
|
223 assert(this->equal_to(value), "should be"); |
|
224 } |
|
225 |
|
226 // Phi-style stuff for SharkState::merge |
|
227 |
|
228 SharkValue* SharkNormalValue::merge(SharkBuilder* builder, |
|
229 SharkValue* other, |
|
230 BasicBlock* other_block, |
|
231 BasicBlock* this_block, |
|
232 const char* name) { |
|
233 assert(type() == other->type(), "should be"); |
|
234 assert(zero_checked() == other->zero_checked(), "should be"); |
|
235 |
|
236 PHINode *phi = builder->CreatePHI(SharkType::to_stackType(type()), 0, name); |
|
237 phi->addIncoming(this->generic_value(), this_block); |
|
238 phi->addIncoming(other->generic_value(), other_block); |
|
239 return SharkValue::create_generic(type(), phi, zero_checked()); |
|
240 } |
|
241 SharkValue* SharkAddressValue::merge(SharkBuilder* builder, |
|
242 SharkValue* other, |
|
243 BasicBlock* other_block, |
|
244 BasicBlock* this_block, |
|
245 const char* name) { |
|
246 assert(this->equal_to(other), "should be"); |
|
247 return this; |
|
248 } |
|
249 |
|
250 // Repeated null and divide-by-zero check removal |
|
251 |
|
252 bool SharkValue::zero_checked() const { |
|
253 ShouldNotCallThis(); |
|
254 } |
|
255 void SharkValue::set_zero_checked(bool zero_checked) { |
|
256 ShouldNotCallThis(); |
|
257 } |
|
258 |
|
259 bool SharkNormalValue::zero_checked() const { |
|
260 return _zero_checked; |
|
261 } |
|
262 void SharkNormalValue::set_zero_checked(bool zero_checked) { |
|
263 _zero_checked = zero_checked; |
|
264 } |
|