Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: src/hydrogen-instructions.cc

Issue 24704005: Merged r16393 into 3.20 branch. (Closed) Base URL: https://v8.googlecode.com/svn/branches/3.20
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/json-stringifier.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2348 matching lines...) Expand 10 before | Expand all | Expand 10 after
2359 is_internalized_string_(is_internalize_string), 2359 is_internalized_string_(is_internalize_string),
2360 is_not_in_new_space_(is_not_in_new_space), 2360 is_not_in_new_space_(is_not_in_new_space),
2361 is_cell_(is_cell), 2361 is_cell_(is_cell),
2362 boolean_value_(boolean_value) { 2362 boolean_value_(boolean_value) {
2363 ASSERT(!handle.is_null()); 2363 ASSERT(!handle.is_null());
2364 ASSERT(!type.IsTaggedNumber()); 2364 ASSERT(!type.IsTaggedNumber());
2365 Initialize(r); 2365 Initialize(r);
2366 } 2366 }
2367 2367
2368 2368
2369 HConstant::HConstant(Handle<Map> handle,
2370 UniqueValueId unique_id)
2371 : HTemplateInstruction<0>(HType::Tagged()),
2372 handle_(handle),
2373 unique_id_(unique_id),
2374 has_smi_value_(false),
2375 has_int32_value_(false),
2376 has_double_value_(false),
2377 has_external_reference_value_(false),
2378 is_internalized_string_(false),
2379 is_not_in_new_space_(true),
2380 is_cell_(false),
2381 boolean_value_(false) {
2382 ASSERT(!handle.is_null());
2383 Initialize(Representation::Tagged());
2384 }
2385
2386
2369 HConstant::HConstant(int32_t integer_value, 2387 HConstant::HConstant(int32_t integer_value,
2370 Representation r, 2388 Representation r,
2371 bool is_not_in_new_space, 2389 bool is_not_in_new_space,
2372 Handle<Object> optional_handle) 2390 Handle<Object> optional_handle)
2373 : handle_(optional_handle), 2391 : handle_(optional_handle),
2374 unique_id_(), 2392 unique_id_(),
2375 has_smi_value_(Smi::IsValid(integer_value)), 2393 has_smi_value_(Smi::IsValid(integer_value)),
2376 has_int32_value_(true), 2394 has_int32_value_(true),
2377 has_double_value_(true), 2395 has_double_value_(true),
2378 has_external_reference_value_(false), 2396 has_external_reference_value_(false),
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
3176 if (!input_rep.IsTagged()) { 3194 if (!input_rep.IsTagged()) {
3177 rep = rep.generalize(input_rep); 3195 rep = rep.generalize(input_rep);
3178 } 3196 }
3179 return rep; 3197 return rep;
3180 } 3198 }
3181 3199
3182 3200
3183 void HAllocate::HandleSideEffectDominator(GVNFlag side_effect, 3201 void HAllocate::HandleSideEffectDominator(GVNFlag side_effect,
3184 HValue* dominator) { 3202 HValue* dominator) {
3185 ASSERT(side_effect == kChangesNewSpacePromotion); 3203 ASSERT(side_effect == kChangesNewSpacePromotion);
3204 Zone* zone = block()->zone();
3186 if (!FLAG_use_allocation_folding) return; 3205 if (!FLAG_use_allocation_folding) return;
3187 3206
3188 // Try to fold allocations together with their dominating allocations. 3207 // Try to fold allocations together with their dominating allocations.
3189 if (!dominator->IsAllocate()) { 3208 if (!dominator->IsAllocate()) {
3190 if (FLAG_trace_allocation_folding) { 3209 if (FLAG_trace_allocation_folding) {
3191 PrintF("#%d (%s) cannot fold into #%d (%s)\n", 3210 PrintF("#%d (%s) cannot fold into #%d (%s)\n",
3192 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); 3211 id(), Mnemonic(), dominator->id(), dominator->Mnemonic());
3193 } 3212 }
3194 return; 3213 return;
3195 } 3214 }
3196 3215
3197 HAllocate* dominator_allocate_instr = HAllocate::cast(dominator); 3216 HAllocate* dominator_allocate = HAllocate::cast(dominator);
3198 HValue* dominator_size = dominator_allocate_instr->size(); 3217 HValue* dominator_size = dominator_allocate->size();
3199 HValue* current_size = size(); 3218 HValue* current_size = size();
3200 // We can just fold allocations that are guaranteed in new space. 3219
3201 // TODO(hpayer): Add support for non-constant allocation in dominator. 3220 // TODO(hpayer): Add support for non-constant allocation in dominator.
3202 if (!IsNewSpaceAllocation() || !current_size->IsInteger32Constant() || 3221 if (!current_size->IsInteger32Constant() ||
3203 !dominator_allocate_instr->IsNewSpaceAllocation() ||
3204 !dominator_size->IsInteger32Constant()) { 3222 !dominator_size->IsInteger32Constant()) {
3205 if (FLAG_trace_allocation_folding) { 3223 if (FLAG_trace_allocation_folding) {
3206 PrintF("#%d (%s) cannot fold into #%d (%s)\n", 3224 PrintF("#%d (%s) cannot fold into #%d (%s), dynamic allocation size\n",
3207 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); 3225 id(), Mnemonic(), dominator->id(), dominator->Mnemonic());
3208 } 3226 }
3209 return; 3227 return;
3210 } 3228 }
3211 3229
3230 dominator_allocate = GetFoldableDominator(dominator_allocate);
3231 if (dominator_allocate == NULL) {
3232 return;
3233 }
3234
3235 ASSERT((IsNewSpaceAllocation() &&
3236 dominator_allocate->IsNewSpaceAllocation()) ||
3237 (IsOldDataSpaceAllocation() &&
3238 dominator_allocate->IsOldDataSpaceAllocation()) ||
3239 (IsOldPointerSpaceAllocation() &&
3240 dominator_allocate->IsOldPointerSpaceAllocation()));
3241
3212 // First update the size of the dominator allocate instruction. 3242 // First update the size of the dominator allocate instruction.
3213 int32_t dominator_size_constant = 3243 dominator_size = dominator_allocate->size();
3244 int32_t original_object_size =
3214 HConstant::cast(dominator_size)->GetInteger32Constant(); 3245 HConstant::cast(dominator_size)->GetInteger32Constant();
3246 int32_t dominator_size_constant = original_object_size;
3215 int32_t current_size_constant = 3247 int32_t current_size_constant =
3216 HConstant::cast(current_size)->GetInteger32Constant(); 3248 HConstant::cast(current_size)->GetInteger32Constant();
3217 int32_t new_dominator_size = dominator_size_constant + current_size_constant; 3249 int32_t new_dominator_size = dominator_size_constant + current_size_constant;
3218 3250
3219 if (MustAllocateDoubleAligned()) { 3251 if (MustAllocateDoubleAligned()) {
3220 if (!dominator_allocate_instr->MustAllocateDoubleAligned()) { 3252 if (!dominator_allocate->MustAllocateDoubleAligned()) {
3221 dominator_allocate_instr->MakeDoubleAligned(); 3253 dominator_allocate->MakeDoubleAligned();
3222 } 3254 }
3223 if ((dominator_size_constant & kDoubleAlignmentMask) != 0) { 3255 if ((dominator_size_constant & kDoubleAlignmentMask) != 0) {
3224 dominator_size_constant += kDoubleSize / 2; 3256 dominator_size_constant += kDoubleSize / 2;
3225 new_dominator_size += kDoubleSize / 2; 3257 new_dominator_size += kDoubleSize / 2;
3226 } 3258 }
3227 } 3259 }
3228 3260
3229 if (new_dominator_size > Page::kMaxNonCodeHeapObjectSize) { 3261 if (new_dominator_size > Page::kMaxNonCodeHeapObjectSize) {
3230 if (FLAG_trace_allocation_folding) { 3262 if (FLAG_trace_allocation_folding) {
3231 PrintF("#%d (%s) cannot fold into #%d (%s) due to size: %d\n", 3263 PrintF("#%d (%s) cannot fold into #%d (%s) due to size: %d\n",
3232 id(), Mnemonic(), dominator->id(), dominator->Mnemonic(), 3264 id(), Mnemonic(), dominator_allocate->id(),
3233 new_dominator_size); 3265 dominator_allocate->Mnemonic(), new_dominator_size);
3234 } 3266 }
3235 return; 3267 return;
3236 } 3268 }
3237 HBasicBlock* block = dominator->block(); 3269
3238 Zone* zone = block->zone(); 3270 HInstruction* new_dominator_size_constant = HConstant::CreateAndInsertBefore(
3239 HInstruction* new_dominator_size_constant = 3271 zone, context(), new_dominator_size, dominator_allocate);
3240 HConstant::New(zone, context(), new_dominator_size); 3272 dominator_allocate->UpdateSize(new_dominator_size_constant);
3241 new_dominator_size_constant->InsertBefore(dominator_allocate_instr);
3242 dominator_allocate_instr->UpdateSize(new_dominator_size_constant);
3243 3273
3244 #ifdef VERIFY_HEAP 3274 #ifdef VERIFY_HEAP
3245 if (FLAG_verify_heap) { 3275 if (FLAG_verify_heap && dominator_allocate->IsNewSpaceAllocation()) {
3246 dominator_allocate_instr->MakePrefillWithFiller(); 3276 dominator_allocate->MakePrefillWithFiller();
3277 } else {
3278 // TODO(hpayer): This is a short-term hack to make allocation mementos
3279 // work again in new space.
3280 dominator_allocate->ClearNextMapWord(original_object_size);
3247 } 3281 }
3282 #else
3283 // TODO(hpayer): This is a short-term hack to make allocation mementos
3284 // work again in new space.
3285 dominator_allocate->ClearNextMapWord(original_object_size);
3248 #endif 3286 #endif
3249 3287
3288 dominator_allocate->clear_next_map_word_ = clear_next_map_word_;
3289
3250 // After that replace the dominated allocate instruction. 3290 // After that replace the dominated allocate instruction.
3251 HInstruction* dominated_allocate_instr = 3291 HInstruction* dominated_allocate_instr =
3252 HInnerAllocatedObject::New(zone, 3292 HInnerAllocatedObject::New(zone,
3253 context(), 3293 context(),
3254 dominator_allocate_instr, 3294 dominator_allocate,
3255 dominator_size_constant, 3295 dominator_size_constant,
3256 type()); 3296 type());
3257 dominated_allocate_instr->InsertBefore(this); 3297 dominated_allocate_instr->InsertBefore(this);
3258 DeleteAndReplaceWith(dominated_allocate_instr); 3298 DeleteAndReplaceWith(dominated_allocate_instr);
3259 if (FLAG_trace_allocation_folding) { 3299 if (FLAG_trace_allocation_folding) {
3260 PrintF("#%d (%s) folded into #%d (%s)\n", 3300 PrintF("#%d (%s) folded into #%d (%s)\n",
3261 id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); 3301 id(), Mnemonic(), dominator_allocate->id(),
3302 dominator_allocate->Mnemonic());
3262 } 3303 }
3263 } 3304 }
3264 3305
3306
3307 HAllocate* HAllocate::GetFoldableDominator(HAllocate* dominator) {
3308 if (!IsFoldable(dominator)) {
3309 // We cannot hoist old space allocations over new space allocations.
3310 if (IsNewSpaceAllocation() || dominator->IsNewSpaceAllocation()) {
3311 if (FLAG_trace_allocation_folding) {
3312 PrintF("#%d (%s) cannot fold into #%d (%s), new space hoisting\n",
3313 id(), Mnemonic(), dominator->id(), dominator->Mnemonic());
3314 }
3315 return NULL;
3316 }
3317
3318 HAllocate* dominator_dominator = dominator->dominating_allocate_;
3319
3320 // We can hoist old data space allocations over an old pointer space
3321 // allocation and vice versa. For that we have to check the dominator
3322 // of the dominator allocate instruction.
3323 if (dominator_dominator == NULL) {
3324 dominating_allocate_ = dominator;
3325 if (FLAG_trace_allocation_folding) {
3326 PrintF("#%d (%s) cannot fold into #%d (%s), different spaces\n",
3327 id(), Mnemonic(), dominator->id(), dominator->Mnemonic());
3328 }
3329 return NULL;
3330 }
3331
3332 // We can just fold old space allocations that are in the same basic block,
3333 // since it is not guaranteed that we fill up the whole allocated old
3334 // space memory.
3335 // TODO(hpayer): Remove this limitation and add filler maps for each each
3336 // allocation as soon as we have store elimination.
3337 if (block()->block_id() != dominator_dominator->block()->block_id()) {
3338 if (FLAG_trace_allocation_folding) {
3339 PrintF("#%d (%s) cannot fold into #%d (%s), different basic blocks\n",
3340 id(), Mnemonic(), dominator_dominator->id(),
3341 dominator_dominator->Mnemonic());
3342 }
3343 return NULL;
3344 }
3345
3346 ASSERT((IsOldDataSpaceAllocation() &&
3347 dominator_dominator->IsOldDataSpaceAllocation()) ||
3348 (IsOldPointerSpaceAllocation() &&
3349 dominator_dominator->IsOldPointerSpaceAllocation()));
3350
3351 int32_t current_size = HConstant::cast(size())->GetInteger32Constant();
3352 HStoreNamedField* dominator_free_space_size =
3353 dominator->filler_free_space_size_;
3354 if (dominator_free_space_size != NULL) {
3355 // We already hoisted one old space allocation, i.e., we already installed
3356 // a filler map. Hence, we just have to update the free space size.
3357 dominator->UpdateFreeSpaceFiller(current_size);
3358 } else {
3359 // This is the first old space allocation that gets hoisted. We have to
3360 // install a filler map since the follwing allocation may cause a GC.
3361 dominator->CreateFreeSpaceFiller(current_size);
3362 }
3363
3364 // We can hoist the old space allocation over the actual dominator.
3365 return dominator_dominator;
3366 }
3367 return dominator;
3368 }
3369
3370
3371 void HAllocate::UpdateFreeSpaceFiller(int32_t free_space_size) {
3372 ASSERT(filler_free_space_size_ != NULL);
3373 Zone* zone = block()->zone();
3374 HConstant* new_free_space_size = HConstant::CreateAndInsertBefore(
3375 zone,
3376 context(),
3377 filler_free_space_size_->value()->GetInteger32Constant() +
3378 free_space_size,
3379 filler_free_space_size_);
3380 filler_free_space_size_->UpdateValue(new_free_space_size);
3381 }
3382
3383
3384 void HAllocate::CreateFreeSpaceFiller(int32_t free_space_size) {
3385 ASSERT(filler_free_space_size_ == NULL);
3386 Zone* zone = block()->zone();
3387 int32_t dominator_size =
3388 HConstant::cast(dominating_allocate_->size())->GetInteger32Constant();
3389 HInstruction* free_space_instr =
3390 HInnerAllocatedObject::New(zone, context(), dominating_allocate_,
3391 dominator_size, type());
3392 free_space_instr->InsertBefore(this);
3393 HConstant* filler_map = HConstant::New(
3394 zone,
3395 context(),
3396 isolate()->factory()->free_space_map(),
3397 UniqueValueId(isolate()->heap()->free_space_map()));
3398 filler_map->InsertAfter(free_space_instr);
3399 HInstruction* store_map = HStoreNamedField::New(zone, context(),
3400 free_space_instr, HObjectAccess::ForMap(), filler_map);
3401 store_map->SetFlag(HValue::kHasNoObservableSideEffects);
3402 store_map->InsertAfter(filler_map);
3403
3404 HConstant* filler_size = HConstant::CreateAndInsertAfter(
3405 zone, context(), free_space_size, store_map);
3406 HObjectAccess access =
3407 HObjectAccess::ForJSObjectOffset(FreeSpace::kSizeOffset);
3408 HStoreNamedField* store_size = HStoreNamedField::New(zone, context(),
3409 free_space_instr, access, filler_size);
3410 store_size->SetFlag(HValue::kHasNoObservableSideEffects);
3411 store_size->InsertAfter(filler_size);
3412 filler_free_space_size_ = store_size;
3413 }
3414
3415
3416 void HAllocate::ClearNextMapWord(int offset) {
3417 if (clear_next_map_word_) {
3418 Zone* zone = block()->zone();
3419 HObjectAccess access = HObjectAccess::ForJSObjectOffset(offset);
3420 HStoreNamedField* clear_next_map =
3421 HStoreNamedField::New(zone, context(), this, access,
3422 block()->graph()->GetConstantNull());
3423 clear_next_map->ClearAllSideEffects();
3424 clear_next_map->InsertAfter(this);
3425 }
3426 }
3427
3265 3428
3266 void HAllocate::PrintDataTo(StringStream* stream) { 3429 void HAllocate::PrintDataTo(StringStream* stream) {
3267 size()->PrintNameTo(stream); 3430 size()->PrintNameTo(stream);
3268 stream->Add(" ("); 3431 stream->Add(" (");
3269 if (IsNewSpaceAllocation()) stream->Add("N"); 3432 if (IsNewSpaceAllocation()) stream->Add("N");
3270 if (IsOldPointerSpaceAllocation()) stream->Add("P"); 3433 if (IsOldPointerSpaceAllocation()) stream->Add("P");
3271 if (IsOldDataSpaceAllocation()) stream->Add("D"); 3434 if (IsOldDataSpaceAllocation()) stream->Add("D");
3272 if (MustAllocateDoubleAligned()) stream->Add("A"); 3435 if (MustAllocateDoubleAligned()) stream->Add("A");
3273 if (MustPrefillWithFiller()) stream->Add("F"); 3436 if (MustPrefillWithFiller()) stream->Add("F");
3274 stream->Add(")"); 3437 stream->Add(")");
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
3997 break; 4160 break;
3998 case kExternalMemory: 4161 case kExternalMemory:
3999 stream->Add("[external-memory]"); 4162 stream->Add("[external-memory]");
4000 break; 4163 break;
4001 } 4164 }
4002 4165
4003 stream->Add("@%d", offset()); 4166 stream->Add("@%d", offset());
4004 } 4167 }
4005 4168
4006 } } // namespace v8::internal 4169 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/json-stringifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698