114 }
115 else {
116 if (other_value == NULL)
117 return false;
118
119 if (!value->equal_to(other_value))
120 return false;
121 }
122 }
123
124 return true;
125 }
126
127 void SharkState::merge(SharkState* other,
128 BasicBlock* other_block,
129 BasicBlock* this_block) {
130 // Method
131 Value *this_method = this->method();
132 Value *other_method = other->method();
133 if (this_method != other_method) {
134 PHINode *phi = builder()->CreatePHI(SharkType::Method*_type(), "method");
135 phi->addIncoming(this_method, this_block);
136 phi->addIncoming(other_method, other_block);
137 set_method(phi);
138 }
139
140 // Temporary oop slot
141 Value *this_oop_tmp = this->oop_tmp();
142 Value *other_oop_tmp = other->oop_tmp();
143 if (this_oop_tmp != other_oop_tmp) {
144 assert(this_oop_tmp && other_oop_tmp, "can't merge NULL with non-NULL");
145 PHINode *phi = builder()->CreatePHI(SharkType::oop_type(), "oop_tmp");
146 phi->addIncoming(this_oop_tmp, this_block);
147 phi->addIncoming(other_oop_tmp, other_block);
148 set_oop_tmp(phi);
149 }
150
151 // Monitors
152 assert(this->num_monitors() == other->num_monitors(), "should be");
153
154 // Local variables
155 assert(this->max_locals() == other->max_locals(), "should be");
156 for (int i = 0; i < max_locals(); i++) {
157 SharkValue *this_value = this->local(i);
158 SharkValue *other_value = other->local(i);
159 assert((this_value == NULL) == (other_value == NULL), "should be");
160 if (this_value != NULL) {
161 char name[18];
162 snprintf(name, sizeof(name), "local_%d_", i);
163 set_local(i, this_value->merge(
164 builder(), other_value, other_block, this_block, name));
165 }
226
227 case ciTypeFlow::StateVector::T_BOTTOM:
228 break;
229
230 case ciTypeFlow::StateVector::T_LONG2:
231 case ciTypeFlow::StateVector::T_DOUBLE2:
232 break;
233
234 default:
235 ShouldNotReachHere();
236 }
237 set_local(i, value);
238 }
239 SharkNormalEntryCacher(block->function(), method).scan(this);
240 }
241
242 SharkOSREntryState::SharkOSREntryState(SharkTopLevelBlock* block,
243 Value* method,
244 Value* osr_buf)
245 : SharkState(block) {
246 assert(!block->stack_depth_at_entry(), "entry block shouldn't have stack");
247 set_num_monitors(block->ciblock()->monitor_count());
248
249 // Local variables
250 for (int i = 0; i < max_locals(); i++) {
251 ciType *type = block->local_type_at_entry(i);
252
253 SharkValue *value = NULL;
254 switch (type->basic_type()) {
255 case T_INT:
256 case T_LONG:
257 case T_FLOAT:
258 case T_DOUBLE:
259 case T_OBJECT:
260 case T_ARRAY:
261 value = SharkValue::create_generic(type, NULL, false);
262 break;
263
264 case ciTypeFlow::StateVector::T_NULL:
265 value = SharkValue::null();
266 break;
270
271 case ciTypeFlow::StateVector::T_LONG2:
272 case ciTypeFlow::StateVector::T_DOUBLE2:
273 break;
274
275 default:
276 ShouldNotReachHere();
277 }
278 set_local(i, value);
279 }
280 SharkOSREntryCacher(block->function(), method, osr_buf).scan(this);
281 }
282
283 SharkPHIState::SharkPHIState(SharkTopLevelBlock* block)
284 : SharkState(block), _block(block) {
285 BasicBlock *saved_insert_point = builder()->GetInsertBlock();
286 builder()->SetInsertPoint(block->entry_block());
287 char name[18];
288
289 // Method
290 set_method(builder()->CreatePHI(SharkType::Method*_type(), "method"));
291
292 // Local variables
293 for (int i = 0; i < max_locals(); i++) {
294 ciType *type = block->local_type_at_entry(i);
295 if (type->basic_type() == (BasicType) ciTypeFlow::StateVector::T_NULL) {
296 // XXX we could do all kinds of clever stuff here
297 type = ciType::make(T_OBJECT); // XXX what about T_ARRAY?
298 }
299
300 SharkValue *value = NULL;
301 switch (type->basic_type()) {
302 case T_INT:
303 case T_LONG:
304 case T_FLOAT:
305 case T_DOUBLE:
306 case T_OBJECT:
307 case T_ARRAY:
308 snprintf(name, sizeof(name), "local_%d_", i);
309 value = SharkValue::create_phi(
310 type, builder()->CreatePHI(SharkType::to_stackType(type), name));
311 break;
312
313 case T_ADDRESS:
314 value = SharkValue::address_constant(type->as_return_address()->bci());
315 break;
316
317 case ciTypeFlow::StateVector::T_BOTTOM:
318 break;
319
320 case ciTypeFlow::StateVector::T_LONG2:
321 case ciTypeFlow::StateVector::T_DOUBLE2:
322 break;
323
324 default:
325 ShouldNotReachHere();
326 }
327 set_local(i, value);
328 }
329
330 // Expression stack
331 for (int i = 0; i < block->stack_depth_at_entry(); i++) {
332 ciType *type = block->stack_type_at_entry(i);
333 if (type->basic_type() == (BasicType) ciTypeFlow::StateVector::T_NULL) {
334 // XXX we could do all kinds of clever stuff here
335 type = ciType::make(T_OBJECT); // XXX what about T_ARRAY?
336 }
337
338 SharkValue *value = NULL;
339 switch (type->basic_type()) {
340 case T_INT:
341 case T_LONG:
342 case T_FLOAT:
343 case T_DOUBLE:
344 case T_OBJECT:
345 case T_ARRAY:
346 snprintf(name, sizeof(name), "stack_%d_", i);
347 value = SharkValue::create_phi(
348 type, builder()->CreatePHI(SharkType::to_stackType(type), name));
349 break;
350
351 case T_ADDRESS:
352 value = SharkValue::address_constant(type->as_return_address()->bci());
353 break;
354
355 case ciTypeFlow::StateVector::T_LONG2:
356 case ciTypeFlow::StateVector::T_DOUBLE2:
357 break;
358
359 default:
360 ShouldNotReachHere();
361 }
362 push(value);
363 }
364
365 // Monitors
366 set_num_monitors(block->ciblock()->monitor_count());
367
368 builder()->SetInsertPoint(saved_insert_point);
|
114 }
115 else {
116 if (other_value == NULL)
117 return false;
118
119 if (!value->equal_to(other_value))
120 return false;
121 }
122 }
123
124 return true;
125 }
126
127 void SharkState::merge(SharkState* other,
128 BasicBlock* other_block,
129 BasicBlock* this_block) {
130 // Method
131 Value *this_method = this->method();
132 Value *other_method = other->method();
133 if (this_method != other_method) {
134 PHINode *phi = builder()->CreatePHI(SharkType::Method_type(), 0, "method");
135 phi->addIncoming(this_method, this_block);
136 phi->addIncoming(other_method, other_block);
137 set_method(phi);
138 }
139
140 // Temporary oop slot
141 Value *this_oop_tmp = this->oop_tmp();
142 Value *other_oop_tmp = other->oop_tmp();
143 if (this_oop_tmp != other_oop_tmp) {
144 assert(this_oop_tmp && other_oop_tmp, "can't merge NULL with non-NULL");
145 PHINode *phi = builder()->CreatePHI(SharkType::oop_type(), 0, "oop_tmp");
146 phi->addIncoming(this_oop_tmp, this_block);
147 phi->addIncoming(other_oop_tmp, other_block);
148 set_oop_tmp(phi);
149 }
150
151 // Monitors
152 assert(this->num_monitors() == other->num_monitors(), "should be");
153
154 // Local variables
155 assert(this->max_locals() == other->max_locals(), "should be");
156 for (int i = 0; i < max_locals(); i++) {
157 SharkValue *this_value = this->local(i);
158 SharkValue *other_value = other->local(i);
159 assert((this_value == NULL) == (other_value == NULL), "should be");
160 if (this_value != NULL) {
161 char name[18];
162 snprintf(name, sizeof(name), "local_%d_", i);
163 set_local(i, this_value->merge(
164 builder(), other_value, other_block, this_block, name));
165 }
226
227 case ciTypeFlow::StateVector::T_BOTTOM:
228 break;
229
230 case ciTypeFlow::StateVector::T_LONG2:
231 case ciTypeFlow::StateVector::T_DOUBLE2:
232 break;
233
234 default:
235 ShouldNotReachHere();
236 }
237 set_local(i, value);
238 }
239 SharkNormalEntryCacher(block->function(), method).scan(this);
240 }
241
242 SharkOSREntryState::SharkOSREntryState(SharkTopLevelBlock* block,
243 Value* method,
244 Value* osr_buf)
245 : SharkState(block) {
246 assert(block->stack_depth_at_entry() == 0, "entry block shouldn't have stack");
247 set_num_monitors(block->ciblock()->monitor_count());
248
249 // Local variables
250 for (int i = 0; i < max_locals(); i++) {
251 ciType *type = block->local_type_at_entry(i);
252
253 SharkValue *value = NULL;
254 switch (type->basic_type()) {
255 case T_INT:
256 case T_LONG:
257 case T_FLOAT:
258 case T_DOUBLE:
259 case T_OBJECT:
260 case T_ARRAY:
261 value = SharkValue::create_generic(type, NULL, false);
262 break;
263
264 case ciTypeFlow::StateVector::T_NULL:
265 value = SharkValue::null();
266 break;
270
271 case ciTypeFlow::StateVector::T_LONG2:
272 case ciTypeFlow::StateVector::T_DOUBLE2:
273 break;
274
275 default:
276 ShouldNotReachHere();
277 }
278 set_local(i, value);
279 }
280 SharkOSREntryCacher(block->function(), method, osr_buf).scan(this);
281 }
282
283 SharkPHIState::SharkPHIState(SharkTopLevelBlock* block)
284 : SharkState(block), _block(block) {
285 BasicBlock *saved_insert_point = builder()->GetInsertBlock();
286 builder()->SetInsertPoint(block->entry_block());
287 char name[18];
288
289 // Method
290 set_method(builder()->CreatePHI(SharkType::Method_type(), 0, "method"));
291
292 // Local variables
293 for (int i = 0; i < max_locals(); i++) {
294 ciType *type = block->local_type_at_entry(i);
295 if (type->basic_type() == (BasicType) ciTypeFlow::StateVector::T_NULL) {
296 // XXX we could do all kinds of clever stuff here
297 type = ciType::make(T_OBJECT); // XXX what about T_ARRAY?
298 }
299
300 SharkValue *value = NULL;
301 switch (type->basic_type()) {
302 case T_INT:
303 case T_LONG:
304 case T_FLOAT:
305 case T_DOUBLE:
306 case T_OBJECT:
307 case T_ARRAY:
308 snprintf(name, sizeof(name), "local_%d_", i);
309 value = SharkValue::create_phi(
310 type, builder()->CreatePHI(SharkType::to_stackType(type), 0, name));
311 break;
312
313 case T_ADDRESS:
314 value = SharkValue::address_constant(type->as_return_address()->bci());
315 break;
316
317 case ciTypeFlow::StateVector::T_BOTTOM:
318 break;
319
320 case ciTypeFlow::StateVector::T_LONG2:
321 case ciTypeFlow::StateVector::T_DOUBLE2:
322 break;
323
324 default:
325 ShouldNotReachHere();
326 }
327 set_local(i, value);
328 }
329
330 // Expression stack
331 for (int i = 0; i < block->stack_depth_at_entry(); i++) {
332 ciType *type = block->stack_type_at_entry(i);
333 if (type->basic_type() == (BasicType) ciTypeFlow::StateVector::T_NULL) {
334 // XXX we could do all kinds of clever stuff here
335 type = ciType::make(T_OBJECT); // XXX what about T_ARRAY?
336 }
337
338 SharkValue *value = NULL;
339 switch (type->basic_type()) {
340 case T_INT:
341 case T_LONG:
342 case T_FLOAT:
343 case T_DOUBLE:
344 case T_OBJECT:
345 case T_ARRAY:
346 snprintf(name, sizeof(name), "stack_%d_", i);
347 value = SharkValue::create_phi(
348 type, builder()->CreatePHI(SharkType::to_stackType(type), 0, name));
349 break;
350
351 case T_ADDRESS:
352 value = SharkValue::address_constant(type->as_return_address()->bci());
353 break;
354
355 case ciTypeFlow::StateVector::T_LONG2:
356 case ciTypeFlow::StateVector::T_DOUBLE2:
357 break;
358
359 default:
360 ShouldNotReachHere();
361 }
362 push(value);
363 }
364
365 // Monitors
366 set_num_monitors(block->ciblock()->monitor_count());
367
368 builder()->SetInsertPoint(saved_insert_point);
|