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

Side by Side Diff: src/hydrogen.cc

Issue 14793014: Use AssumeRepresentation when the representation is known and will not change. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 7 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 | « no previous file | no next file » | 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 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 716
717 HInstruction* HGraphBuilder::IfBuilder::IfCompare( 717 HInstruction* HGraphBuilder::IfBuilder::IfCompare(
718 HValue* left, 718 HValue* left,
719 HValue* right, 719 HValue* right,
720 Token::Value token, 720 Token::Value token,
721 Representation input_representation) { 721 Representation input_representation) {
722 HCompareIDAndBranch* compare = 722 HCompareIDAndBranch* compare =
723 new(zone()) HCompareIDAndBranch(left, right, token); 723 new(zone()) HCompareIDAndBranch(left, right, token);
724 compare->set_observed_input_representation(input_representation, 724 compare->set_observed_input_representation(input_representation,
725 input_representation); 725 input_representation);
726 compare->ChangeRepresentation(input_representation); 726 compare->AssumeRepresentation(input_representation);
727 AddCompare(compare); 727 AddCompare(compare);
728 return compare; 728 return compare;
729 } 729 }
730 730
731 731
732 HInstruction* HGraphBuilder::IfBuilder::IfCompareMap(HValue* left, 732 HInstruction* HGraphBuilder::IfBuilder::IfCompareMap(HValue* left,
733 Handle<Map> map) { 733 Handle<Map> map) {
734 HCompareMap* compare = 734 HCompareMap* compare =
735 new(zone()) HCompareMap(left, map, 735 new(zone()) HCompareMap(left, map,
736 first_true_block_, first_false_block_); 736 first_true_block_, first_false_block_);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 898
899 HValue* HGraphBuilder::LoopBuilder::BeginBody( 899 HValue* HGraphBuilder::LoopBuilder::BeginBody(
900 HValue* initial, 900 HValue* initial,
901 HValue* terminating, 901 HValue* terminating,
902 Token::Value token, 902 Token::Value token,
903 Representation input_representation) { 903 Representation input_representation) {
904 HEnvironment* env = builder_->environment(); 904 HEnvironment* env = builder_->environment();
905 phi_ = new(zone()) HPhi(env->values()->length(), zone()); 905 phi_ = new(zone()) HPhi(env->values()->length(), zone());
906 header_block_->AddPhi(phi_); 906 header_block_->AddPhi(phi_);
907 phi_->AddInput(initial); 907 phi_->AddInput(initial);
908 phi_->ChangeRepresentation(Representation::Integer32()); 908 phi_->AssumeRepresentation(Representation::Integer32());
909 env->Push(initial); 909 env->Push(initial);
910 builder_->current_block()->GotoNoSimulate(header_block_); 910 builder_->current_block()->GotoNoSimulate(header_block_);
911 911
912 HEnvironment* body_env = env->Copy(); 912 HEnvironment* body_env = env->Copy();
913 HEnvironment* exit_env = env->Copy(); 913 HEnvironment* exit_env = env->Copy();
914 body_block_ = builder_->CreateBasicBlock(body_env); 914 body_block_ = builder_->CreateBasicBlock(body_env);
915 exit_block_ = builder_->CreateBasicBlock(exit_env); 915 exit_block_ = builder_->CreateBasicBlock(exit_env);
916 // Remove the phi from the expression stack 916 // Remove the phi from the expression stack
917 body_env->Pop(); 917 body_env->Pop();
918 918
919 builder_->set_current_block(header_block_); 919 builder_->set_current_block(header_block_);
920 HCompareIDAndBranch* compare = 920 HCompareIDAndBranch* compare =
921 new(zone()) HCompareIDAndBranch(phi_, terminating, token); 921 new(zone()) HCompareIDAndBranch(phi_, terminating, token);
922 compare->set_observed_input_representation(input_representation, 922 compare->set_observed_input_representation(input_representation,
923 input_representation); 923 input_representation);
924 compare->ChangeRepresentation(input_representation); 924 compare->AssumeRepresentation(input_representation);
925 compare->SetSuccessorAt(0, body_block_); 925 compare->SetSuccessorAt(0, body_block_);
926 compare->SetSuccessorAt(1, exit_block_); 926 compare->SetSuccessorAt(1, exit_block_);
927 builder_->current_block()->Finish(compare); 927 builder_->current_block()->Finish(compare);
928 928
929 builder_->set_current_block(body_block_); 929 builder_->set_current_block(body_block_);
930 if (direction_ == kPreIncrement || direction_ == kPreDecrement) { 930 if (direction_ == kPreIncrement || direction_ == kPreDecrement) {
931 HValue* one = builder_->graph()->GetConstant1(); 931 HValue* one = builder_->graph()->GetConstant1();
932 if (direction_ == kPreIncrement) { 932 if (direction_ == kPreIncrement) {
933 increment_ = HAdd::New(zone(), context_, phi_, one); 933 increment_ = HAdd::New(zone(), context_, phi_, one);
934 } else { 934 } else {
935 increment_ = HSub::New(zone(), context_, phi_, one); 935 increment_ = HSub::New(zone(), context_, phi_, one);
936 } 936 }
937 increment_->ClearFlag(HValue::kCanOverflow); 937 increment_->ClearFlag(HValue::kCanOverflow);
938 increment_->ChangeRepresentation(Representation::Integer32()); 938 increment_->AssumeRepresentation(Representation::Integer32());
939 builder_->AddInstruction(increment_); 939 builder_->AddInstruction(increment_);
940 return increment_; 940 return increment_;
941 } else { 941 } else {
942 return phi_; 942 return phi_;
943 } 943 }
944 } 944 }
945 945
946 946
947 void HGraphBuilder::LoopBuilder::EndBody() { 947 void HGraphBuilder::LoopBuilder::EndBody() {
948 ASSERT(!finished_); 948 ASSERT(!finished_);
949 949
950 if (direction_ == kPostIncrement || direction_ == kPostDecrement) { 950 if (direction_ == kPostIncrement || direction_ == kPostDecrement) {
951 HValue* one = builder_->graph()->GetConstant1(); 951 HValue* one = builder_->graph()->GetConstant1();
952 if (direction_ == kPostIncrement) { 952 if (direction_ == kPostIncrement) {
953 increment_ = HAdd::New(zone(), context_, phi_, one); 953 increment_ = HAdd::New(zone(), context_, phi_, one);
954 } else { 954 } else {
955 increment_ = HSub::New(zone(), context_, phi_, one); 955 increment_ = HSub::New(zone(), context_, phi_, one);
956 } 956 }
957 increment_->ClearFlag(HValue::kCanOverflow); 957 increment_->ClearFlag(HValue::kCanOverflow);
958 increment_->ChangeRepresentation(Representation::Integer32()); 958 increment_->AssumeRepresentation(Representation::Integer32());
959 builder_->AddInstruction(increment_); 959 builder_->AddInstruction(increment_);
960 } 960 }
961 961
962 // Push the new increment value on the expression stack to merge into the phi. 962 // Push the new increment value on the expression stack to merge into the phi.
963 builder_->environment()->Push(increment_); 963 builder_->environment()->Push(increment_);
964 builder_->current_block()->GotoNoSimulate(header_block_); 964 builder_->current_block()->GotoNoSimulate(header_block_);
965 header_block_->loop_information()->RegisterBackEdge(body_block_); 965 header_block_->loop_information()->RegisterBackEdge(body_block_);
966 966
967 builder_->set_current_block(exit_block_); 967 builder_->set_current_block(exit_block_);
968 // Pop the phi from the expression stack 968 // Pop the phi from the expression stack
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 1181
1182 environment()->Push(new_elements); 1182 environment()->Push(new_elements);
1183 capacity_checker.Else(); 1183 capacity_checker.Else();
1184 1184
1185 environment()->Push(elements); 1185 environment()->Push(elements);
1186 capacity_checker.End(); 1186 capacity_checker.End();
1187 1187
1188 if (is_js_array) { 1188 if (is_js_array) {
1189 HValue* new_length = AddInstruction( 1189 HValue* new_length = AddInstruction(
1190 HAdd::New(zone, context, length, graph_->GetConstant1())); 1190 HAdd::New(zone, context, length, graph_->GetConstant1()));
1191 new_length->ChangeRepresentation(Representation::Integer32()); 1191 new_length->AssumeRepresentation(Representation::Integer32());
1192 new_length->ClearFlag(HValue::kCanOverflow); 1192 new_length->ClearFlag(HValue::kCanOverflow);
1193 1193
1194 Factory* factory = isolate()->factory(); 1194 Factory* factory = isolate()->factory();
1195 Representation representation = IsFastElementsKind(kind) 1195 Representation representation = IsFastElementsKind(kind)
1196 ? Representation::Smi() : Representation::Tagged(); 1196 ? Representation::Smi() : Representation::Tagged();
1197 HInstruction* length_store = AddInstruction(new(zone) HStoreNamedField( 1197 HInstruction* length_store = AddInstruction(new(zone) HStoreNamedField(
1198 object, 1198 object,
1199 factory->length_field_string(), 1199 factory->length_field_string(),
1200 new_length, true, 1200 new_length, true,
1201 representation, 1201 representation,
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 HValue* capacity) { 1367 HValue* capacity) {
1368 Zone* zone = this->zone(); 1368 Zone* zone = this->zone();
1369 1369
1370 int elements_size = IsFastDoubleElementsKind(kind) 1370 int elements_size = IsFastDoubleElementsKind(kind)
1371 ? kDoubleSize : kPointerSize; 1371 ? kDoubleSize : kPointerSize;
1372 HConstant* elements_size_value = 1372 HConstant* elements_size_value =
1373 new(zone) HConstant(elements_size, Representation::Integer32()); 1373 new(zone) HConstant(elements_size, Representation::Integer32());
1374 AddInstruction(elements_size_value); 1374 AddInstruction(elements_size_value);
1375 HValue* mul = AddInstruction( 1375 HValue* mul = AddInstruction(
1376 HMul::New(zone, context, capacity, elements_size_value)); 1376 HMul::New(zone, context, capacity, elements_size_value));
1377 mul->ChangeRepresentation(Representation::Integer32()); 1377 mul->AssumeRepresentation(Representation::Integer32());
1378 mul->ClearFlag(HValue::kCanOverflow); 1378 mul->ClearFlag(HValue::kCanOverflow);
1379 1379
1380 HConstant* header_size = 1380 HConstant* header_size =
1381 new(zone) HConstant(FixedArray::kHeaderSize, Representation::Integer32()); 1381 new(zone) HConstant(FixedArray::kHeaderSize, Representation::Integer32());
1382 AddInstruction(header_size); 1382 AddInstruction(header_size);
1383 HValue* total_size = AddInstruction( 1383 HValue* total_size = AddInstruction(
1384 HAdd::New(zone, context, mul, header_size)); 1384 HAdd::New(zone, context, mul, header_size));
1385 total_size->ChangeRepresentation(Representation::Integer32()); 1385 total_size->AssumeRepresentation(Representation::Integer32());
1386 total_size->ClearFlag(HValue::kCanOverflow); 1386 total_size->ClearFlag(HValue::kCanOverflow);
1387 1387
1388 HAllocate::Flags flags = HAllocate::DefaultFlags(kind); 1388 HAllocate::Flags flags = HAllocate::DefaultFlags(kind);
1389 if (FLAG_pretenure_literals) { 1389 if (FLAG_pretenure_literals) {
1390 // TODO(hpayer): When pretenuring can be internalized, flags can become 1390 // TODO(hpayer): When pretenuring can be internalized, flags can become
1391 // private to HAllocate. 1391 // private to HAllocate.
1392 if (IsFastDoubleElementsKind(kind)) { 1392 if (IsFastDoubleElementsKind(kind)) {
1393 flags = static_cast<HAllocate::Flags>( 1393 flags = static_cast<HAllocate::Flags>(
1394 flags | HAllocate::CAN_ALLOCATE_IN_OLD_DATA_SPACE); 1394 flags | HAllocate::CAN_ALLOCATE_IN_OLD_DATA_SPACE);
1395 } else { 1395 } else {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 return instr; 1531 return instr;
1532 } 1532 }
1533 1533
1534 1534
1535 HValue* HGraphBuilder::BuildNewElementsCapacity(HValue* context, 1535 HValue* HGraphBuilder::BuildNewElementsCapacity(HValue* context,
1536 HValue* old_capacity) { 1536 HValue* old_capacity) {
1537 Zone* zone = this->zone(); 1537 Zone* zone = this->zone();
1538 HValue* half_old_capacity = 1538 HValue* half_old_capacity =
1539 AddInstruction(HShr::New(zone, context, old_capacity, 1539 AddInstruction(HShr::New(zone, context, old_capacity,
1540 graph_->GetConstant1())); 1540 graph_->GetConstant1()));
1541 half_old_capacity->ChangeRepresentation(Representation::Integer32()); 1541 half_old_capacity->AssumeRepresentation(Representation::Integer32());
1542 half_old_capacity->ClearFlag(HValue::kCanOverflow); 1542 half_old_capacity->ClearFlag(HValue::kCanOverflow);
1543 1543
1544 HValue* new_capacity = AddInstruction( 1544 HValue* new_capacity = AddInstruction(
1545 HAdd::New(zone, context, half_old_capacity, old_capacity)); 1545 HAdd::New(zone, context, half_old_capacity, old_capacity));
1546 new_capacity->ChangeRepresentation(Representation::Integer32()); 1546 new_capacity->AssumeRepresentation(Representation::Integer32());
1547 new_capacity->ClearFlag(HValue::kCanOverflow); 1547 new_capacity->ClearFlag(HValue::kCanOverflow);
1548 1548
1549 HValue* min_growth = 1549 HValue* min_growth =
1550 AddInstruction(new(zone) HConstant(16, Representation::Integer32())); 1550 AddInstruction(new(zone) HConstant(16, Representation::Integer32()));
1551 1551
1552 new_capacity = AddInstruction( 1552 new_capacity = AddInstruction(
1553 HAdd::New(zone, context, new_capacity, min_growth)); 1553 HAdd::New(zone, context, new_capacity, min_growth));
1554 new_capacity->ChangeRepresentation(Representation::Integer32()); 1554 new_capacity->AssumeRepresentation(Representation::Integer32());
1555 new_capacity->ClearFlag(HValue::kCanOverflow); 1555 new_capacity->ClearFlag(HValue::kCanOverflow);
1556 1556
1557 return new_capacity; 1557 return new_capacity;
1558 } 1558 }
1559 1559
1560 1560
1561 void HGraphBuilder::BuildNewSpaceArrayCheck(HValue* length, ElementsKind kind) { 1561 void HGraphBuilder::BuildNewSpaceArrayCheck(HValue* length, ElementsKind kind) {
1562 Zone* zone = this->zone(); 1562 Zone* zone = this->zone();
1563 Heap* heap = isolate()->heap(); 1563 Heap* heap = isolate()->heap();
1564 int element_size = IsFastDoubleElementsKind(kind) ? kDoubleSize 1564 int element_size = IsFastDoubleElementsKind(kind) ? kDoubleSize
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 base_size += FixedDoubleArray::kHeaderSize; 1924 base_size += FixedDoubleArray::kHeaderSize;
1925 } else { 1925 } else {
1926 base_size += FixedArray::kHeaderSize; 1926 base_size += FixedArray::kHeaderSize;
1927 } 1927 }
1928 1928
1929 HInstruction* elements_size_value = new(zone()) 1929 HInstruction* elements_size_value = new(zone())
1930 HConstant(elements_size(), Representation::Integer32()); 1930 HConstant(elements_size(), Representation::Integer32());
1931 AddInstruction(elements_size_value); 1931 AddInstruction(elements_size_value);
1932 HInstruction* mul = HMul::New(zone(), context, length_node, 1932 HInstruction* mul = HMul::New(zone(), context, length_node,
1933 elements_size_value); 1933 elements_size_value);
1934 mul->ChangeRepresentation(Representation::Integer32()); 1934 mul->AssumeRepresentation(Representation::Integer32());
1935 mul->ClearFlag(HValue::kCanOverflow); 1935 mul->ClearFlag(HValue::kCanOverflow);
1936 AddInstruction(mul); 1936 AddInstruction(mul);
1937 1937
1938 HInstruction* base = new(zone()) HConstant(base_size, 1938 HInstruction* base = new(zone()) HConstant(base_size,
1939 Representation::Integer32()); 1939 Representation::Integer32());
1940 AddInstruction(base); 1940 AddInstruction(base);
1941 HInstruction* total_size = HAdd::New(zone(), context, base, mul); 1941 HInstruction* total_size = HAdd::New(zone(), context, base, mul);
1942 total_size->ChangeRepresentation(Representation::Integer32()); 1942 total_size->AssumeRepresentation(Representation::Integer32());
1943 total_size->ClearFlag(HValue::kCanOverflow); 1943 total_size->ClearFlag(HValue::kCanOverflow);
1944 AddInstruction(total_size); 1944 AddInstruction(total_size);
1945 return total_size; 1945 return total_size;
1946 } 1946 }
1947 1947
1948 1948
1949 HValue* HGraphBuilder::JSArrayBuilder::EstablishEmptyArrayAllocationSize() { 1949 HValue* HGraphBuilder::JSArrayBuilder::EstablishEmptyArrayAllocationSize() {
1950 int base_size = JSArray::kSize; 1950 int base_size = JSArray::kSize;
1951 if (mode_ == TRACK_ALLOCATION_SITE) { 1951 if (mode_ == TRACK_ALLOCATION_SITE) {
1952 base_size += AllocationSiteInfo::kSize; 1952 base_size += AllocationSiteInfo::kSize;
(...skipping 10351 matching lines...) Expand 10 before | Expand all | Expand 10 after
12304 } 12304 }
12305 } 12305 }
12306 12306
12307 #ifdef DEBUG 12307 #ifdef DEBUG
12308 if (graph_ != NULL) graph_->Verify(false); // No full verify. 12308 if (graph_ != NULL) graph_->Verify(false); // No full verify.
12309 if (allocator_ != NULL) allocator_->Verify(); 12309 if (allocator_ != NULL) allocator_->Verify();
12310 #endif 12310 #endif
12311 } 12311 }
12312 12312
12313 } } // namespace v8::internal 12313 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698