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

Side by Side Diff: src/hydrogen.cc

Issue 59023003: Generate TypedArrayInitialize builtin in hydrogen. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixes Created 7 years, 1 month 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
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "hydrogen-minus-zero.h" 51 #include "hydrogen-minus-zero.h"
52 #include "hydrogen-osr.h" 52 #include "hydrogen-osr.h"
53 #include "hydrogen-range-analysis.h" 53 #include "hydrogen-range-analysis.h"
54 #include "hydrogen-redundant-phi.h" 54 #include "hydrogen-redundant-phi.h"
55 #include "hydrogen-removable-simulates.h" 55 #include "hydrogen-removable-simulates.h"
56 #include "hydrogen-representation-changes.h" 56 #include "hydrogen-representation-changes.h"
57 #include "hydrogen-sce.h" 57 #include "hydrogen-sce.h"
58 #include "hydrogen-uint32-analysis.h" 58 #include "hydrogen-uint32-analysis.h"
59 #include "lithium-allocator.h" 59 #include "lithium-allocator.h"
60 #include "parser.h" 60 #include "parser.h"
61 #include "runtime.h"
61 #include "scopeinfo.h" 62 #include "scopeinfo.h"
62 #include "scopes.h" 63 #include "scopes.h"
63 #include "stub-cache.h" 64 #include "stub-cache.h"
64 #include "typing.h" 65 #include "typing.h"
65 66
66 #if V8_TARGET_ARCH_IA32 67 #if V8_TARGET_ARCH_IA32
67 #include "ia32/lithium-codegen-ia32.h" 68 #include "ia32/lithium-codegen-ia32.h"
68 #elif V8_TARGET_ARCH_X64 69 #elif V8_TARGET_ARCH_X64
69 #include "x64/lithium-codegen-x64.h" 70 #include "x64/lithium-codegen-x64.h"
70 #elif V8_TARGET_ARCH_ARM 71 #elif V8_TARGET_ARCH_ARM
(...skipping 7976 matching lines...) Expand 10 before | Expand all | Expand 10 after
8047 &HOptimizedGraphBuilder::Generate##Name, 8048 &HOptimizedGraphBuilder::Generate##Name,
8048 8049
8049 const HOptimizedGraphBuilder::InlineFunctionGenerator 8050 const HOptimizedGraphBuilder::InlineFunctionGenerator
8050 HOptimizedGraphBuilder::kInlineFunctionGenerators[] = { 8051 HOptimizedGraphBuilder::kInlineFunctionGenerators[] = {
8051 INLINE_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS) 8052 INLINE_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
8052 INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS) 8053 INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
8053 }; 8054 };
8054 #undef INLINE_FUNCTION_GENERATOR_ADDRESS 8055 #undef INLINE_FUNCTION_GENERATOR_ADDRESS
8055 8056
8056 8057
8058 template <class ViewClass>
8059 void BuildArrayBufferViewInitialization(
8060 HGraphBuilder* graph,
danno 2013/11/20 13:50:50 this should be called "builder". Consider moving t
Dmitry Lomov (no reviews) 2013/11/20 17:38:56 Done.
8061 HValue* obj,
8062 HValue* buffer,
8063 HValue* byte_offset,
8064 HValue* byte_length) {
8065
8066 for (int offset = ViewClass::kSize;
8067 offset < ViewClass::kSizeWithInternalFields;
danno 2013/11/20 13:50:50 nit: alignment
Dmitry Lomov (no reviews) 2013/11/20 17:38:56 Done.
8068 offset += kPointerSize) {
8069 graph->Add<HStoreNamedField>(obj,
8070 HObjectAccess::ForJSObjectOffset(offset),
8071 graph->Add<HConstant>(static_cast<int32_t>(0)));
8072 }
8073
8074 graph->Add<HStoreNamedField>(obj,
8075 HObjectAccess::ForJSObjectOffset(ViewClass::kBufferOffset), buffer);
8076 graph->Add<HStoreNamedField>(obj,
8077 HObjectAccess::ForJSObjectOffset(ViewClass::kByteOffsetOffset),
8078 byte_offset);
8079 graph->Add<HStoreNamedField>(obj,
8080 HObjectAccess::ForJSObjectOffset(ViewClass::kByteLengthOffset),
8081 byte_length);
8082
8083 graph->Add<HStoreNamedField>(obj,
8084 HObjectAccess::ForJSObjectOffset(ViewClass::kWeakNextOffset),
8085 graph->Add<HLoadNamedField>(buffer,
8086 HObjectAccess::ForJSObjectOffset(
8087 JSArrayBuffer::kWeakFirstViewOffset)));
danno 2013/11/20 13:50:50 nit: 4 char indent. Perhaps move the object access
Dmitry Lomov (no reviews) 2013/11/20 17:38:56 Done.
8088 graph->Add<HStoreNamedField>(buffer,
8089 HObjectAccess::ForJSObjectOffset(JSArrayBuffer::kWeakFirstViewOffset),
8090 obj);
8091 }
8092
8093
8057 void HOptimizedGraphBuilder::VisitDataViewInitialize( 8094 void HOptimizedGraphBuilder::VisitDataViewInitialize(
8058 CallRuntime* expr) { 8095 CallRuntime* expr) {
8059 ZoneList<Expression*>* arguments = expr->arguments(); 8096 ZoneList<Expression*>* arguments = expr->arguments();
8060 8097
8061 NoObservableSideEffectsScope scope(this); 8098 NoObservableSideEffectsScope scope(this);
8062 ASSERT(arguments->length()== 4); 8099 ASSERT(arguments->length()== 4);
8063 CHECK_ALIVE(VisitForValue(arguments->at(0))); 8100 CHECK_ALIVE(VisitForValue(arguments->at(0)));
8064 HValue* obj = Pop(); 8101 HValue* obj = Pop();
8065 8102
8066 CHECK_ALIVE(VisitForValue(arguments->at(1))); 8103 CHECK_ALIVE(VisitForValue(arguments->at(1)));
8067 HValue* buffer = Pop(); 8104 HValue* buffer = Pop();
8068 8105
8069 CHECK_ALIVE(VisitForValue(arguments->at(2))); 8106 CHECK_ALIVE(VisitForValue(arguments->at(2)));
8070 HValue* byte_offset = Pop(); 8107 HValue* byte_offset = Pop();
8071 8108
8072 CHECK_ALIVE(VisitForValue(arguments->at(3))); 8109 CHECK_ALIVE(VisitForValue(arguments->at(3)));
8073 HValue* byte_length = Pop(); 8110 HValue* byte_length = Pop();
8074 8111
8075 for (int offset = JSDataView::kSize; 8112 BuildArrayBufferViewInitialization<JSDataView>(
8076 offset < JSDataView::kSizeWithInternalFields; 8113 this, obj, buffer, byte_offset, byte_length);
8077 offset += kPointerSize) {
8078 Add<HStoreNamedField>(obj,
8079 HObjectAccess::ForJSObjectOffset(offset),
8080 Add<HConstant>(static_cast<int32_t>(0)));
8081 }
8082
8083 Add<HStoreNamedField>(obj,
8084 HObjectAccess::ForJSObjectOffset(JSDataView::kBufferOffset), buffer);
8085 Add<HStoreNamedField>(obj,
8086 HObjectAccess::ForJSObjectOffset(JSDataView::kByteOffsetOffset),
8087 byte_offset);
8088 Add<HStoreNamedField>(obj,
8089 HObjectAccess::ForJSObjectOffset(JSDataView::kByteLengthOffset),
8090 byte_length);
8091
8092 Add<HStoreNamedField>(obj,
8093 HObjectAccess::ForJSObjectOffset(JSDataView::kWeakNextOffset),
8094 Add<HLoadNamedField>(buffer,
8095 HObjectAccess::ForJSObjectOffset(
8096 JSArrayBuffer::kWeakFirstViewOffset)));
8097 Add<HStoreNamedField>(buffer,
8098 HObjectAccess::ForJSObjectOffset(JSArrayBuffer::kWeakFirstViewOffset),
8099 obj);
8100 } 8114 }
8101 8115
8102 8116
8117 void HOptimizedGraphBuilder::VisitTypedArrayInitialize(
8118 CallRuntime* expr) {
8119 ZoneList<Expression*>* arguments = expr->arguments();
8120
8121 NoObservableSideEffectsScope scope(this);
8122 static const int kObjectArg = 0;
8123 static const int kArrayIdArg = 1;
8124 static const int kBufferArg = 2;
8125 static const int kByteOffsetArg = 3;
8126 static const int kByteLengthArg = 4;
8127 static const int kArgsLength = 5;
8128 ASSERT(arguments->length() == kArgsLength);
8129
8130
8131 CHECK_ALIVE(VisitForValue(arguments->at(kObjectArg)));
8132 HValue* obj = Pop();
8133
8134 ASSERT(arguments->at(kArrayIdArg)->node_type() == AstNode::kLiteral);
8135 Handle<Object> value =
8136 static_cast<Literal*>(arguments->at(kArrayIdArg))->value();
danno 2013/11/20 13:50:50 4-char indent
Dmitry Lomov (no reviews) 2013/11/20 17:38:56 Done.
8137 ASSERT(value->IsSmi());
8138 int array_id = Smi::cast(*value)->value();
8139
8140 CHECK_ALIVE(VisitForValue(arguments->at(kBufferArg)));
8141 HValue* buffer = Pop();
8142
8143 HValue* byte_offset;
8144 bool is_zero_byte_offset;
8145
8146 if (arguments->at(kByteOffsetArg)->node_type() == AstNode::kLiteral
8147 && Smi::FromInt(0) ==
8148 *static_cast<Literal*>(arguments->at(kByteOffsetArg))->value()) {
8149 byte_offset = Add<HConstant>(static_cast<int32_t>(0));
8150 is_zero_byte_offset = true;
8151 } else {
8152 CHECK_ALIVE(VisitForValue(arguments->at(kByteOffsetArg)));
8153 byte_offset = Pop();
8154 is_zero_byte_offset = false;
8155 }
8156
8157 CHECK_ALIVE(VisitForValue(arguments->at(kByteLengthArg)));
8158 HValue* byte_length = Pop();
8159
8160 IfBuilder byte_offset_smi(this);
8161
8162 if (!is_zero_byte_offset) {
8163 byte_offset_smi.If<HIsSmiAndBranch>(byte_offset);
8164 byte_offset_smi.Then();
8165 }
8166
8167 { // byte_offset is Smi.
8168 BuildArrayBufferViewInitialization<JSTypedArray>(
8169 this, obj, buffer, byte_offset, byte_length);
8170
8171 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization.
8172 size_t element_size = 1; // Bogus initialization.
8173 Runtime::ArrayIdToTypeAndSize(array_id, &array_type, &element_size);
8174
8175 HInstruction* length = Add<HDiv>(byte_length,
8176 Add<HConstant>(static_cast<int32_t>(element_size)));
8177
8178 Add<HStoreNamedField>(obj,
8179 HObjectAccess::ForJSObjectOffset(JSTypedArray::kLengthOffset),
8180 length);
8181
8182 HValue* elements =
8183 Add<HAllocate>(
8184 Add<HConstant>(ExternalArray::kAlignedSize),
8185 HType::JSArray(),
8186 NOT_TENURED,
8187 static_cast<InstanceType>(FIRST_EXTERNAL_ARRAY_TYPE + array_type));
8188
8189 Handle<Map> external_array_map(
8190 isolate()->heap()->MapForExternalArrayType(array_type));
8191
8192 Add<HStoreNamedField>(elements,
8193 HObjectAccess::ForMap(),
8194 Add<HConstant>(external_array_map));
8195 HValue* backing_store =
8196 Add<HLoadNamedField>(buffer,
8197 HObjectAccess::ForJSObjectOffset(
danno 2013/11/20 13:50:50 nit: 4 char indent
Dmitry Lomov (no reviews) 2013/11/20 17:38:56 Done.
8198 JSArrayBuffer::kBackingStoreOffset, Representation::External()));
danno 2013/11/20 13:50:50 Same here. Maybe move the access into a local vari
Dmitry Lomov (no reviews) 2013/11/20 17:38:56 Done.
8199
8200 HValue* typed_array_start;
8201 if (is_zero_byte_offset) {
8202 typed_array_start = backing_store;
8203 } else {
8204 HInstruction* external_pointer =
8205 HAdd::New(
8206 zone(), graph()->GetInvalidContext(), backing_store, byte_offset);
danno 2013/11/20 13:50:50 You should be able to use Add<> now, shouldn't you
Dmitry Lomov (no reviews) 2013/11/20 17:38:56 Done.
8207 // Arguments are checked prior to call to TypedArrayInitialize,
8208 // including byte_offset.
8209 external_pointer->ClearFlag(HValue::kCanOverflow);
8210 typed_array_start = AddInstruction(external_pointer);
8211 }
8212
8213 Add<HStoreNamedField>(elements,
8214 HObjectAccess::ForJSObjectOffset(
8215 ExternalArray::kExternalPointerOffset, Representation::External()),
danno 2013/11/20 13:50:50 nit: 4 char indent?
Dmitry Lomov (no reviews) 2013/11/20 17:38:56 Done.
8216 typed_array_start);
8217 Add<HStoreNamedField>(elements,
8218 HObjectAccess::ForJSObjectOffset(ExternalArray::kLengthOffset),
8219 length);
8220 Add<HStoreNamedField>(
8221 obj, HObjectAccess::ForElementsPointer(), elements);
8222 }
8223
8224 if (!is_zero_byte_offset) {
8225 byte_offset_smi.Else();
8226 { // byte_offset is not Smi.
8227 Push(Add<HPushArgument>(obj));
8228 VisitArgument(arguments->at(kArrayIdArg));
8229 Push(Add<HPushArgument>(buffer));
8230 Push(Add<HPushArgument>(byte_offset));
8231 Push(Add<HPushArgument>(byte_length));
8232 Add<HCallRuntime>(expr->name(), expr->function(), kArgsLength);
8233 Drop(kArgsLength);
8234 }
8235 byte_offset_smi.End();
danno 2013/11/20 13:50:50 Shouldn't this be after the } below? It should alw
Dmitry Lomov (no reviews) 2013/11/20 17:38:56 Done.
8236 }
8237 }
8238
8239
8103 void HOptimizedGraphBuilder::VisitCallRuntime(CallRuntime* expr) { 8240 void HOptimizedGraphBuilder::VisitCallRuntime(CallRuntime* expr) {
8104 ASSERT(!HasStackOverflow()); 8241 ASSERT(!HasStackOverflow());
8105 ASSERT(current_block() != NULL); 8242 ASSERT(current_block() != NULL);
8106 ASSERT(current_block()->HasPredecessor()); 8243 ASSERT(current_block()->HasPredecessor());
8107 if (expr->is_jsruntime()) { 8244 if (expr->is_jsruntime()) {
8108 return Bailout(kCallToAJavaScriptRuntimeFunction); 8245 return Bailout(kCallToAJavaScriptRuntimeFunction);
8109 } 8246 }
8110 8247
8111 const Runtime::Function* function = expr->function(); 8248 const Runtime::Function* function = expr->function();
8112 ASSERT(function != NULL); 8249 ASSERT(function != NULL);
8113 8250
8114 if (function->function_id == Runtime::kDataViewInitialize) { 8251 if (function->function_id == Runtime::kDataViewInitialize) {
8115 return VisitDataViewInitialize(expr); 8252 return VisitDataViewInitialize(expr);
8116 } 8253 }
8117 8254
8255 if (function->function_id == Runtime::kTypedArrayInitialize) {
8256 return VisitTypedArrayInitialize(expr);
8257 }
8258
8259 if (function->function_id == Runtime::kMaxSmi) {
8260 ASSERT(expr->arguments()->length() == 0);
8261 HConstant* max_smi = New<HConstant>(static_cast<int32_t>(Smi::kMaxValue));
8262 return ast_context()->ReturnInstruction(max_smi, expr->id());
8263 }
8264
8118 if (function->intrinsic_type == Runtime::INLINE) { 8265 if (function->intrinsic_type == Runtime::INLINE) {
8119 ASSERT(expr->name()->length() > 0); 8266 ASSERT(expr->name()->length() > 0);
8120 ASSERT(expr->name()->Get(0) == '_'); 8267 ASSERT(expr->name()->Get(0) == '_');
8121 // Call to an inline function. 8268 // Call to an inline function.
8122 int lookup_index = static_cast<int>(function->function_id) - 8269 int lookup_index = static_cast<int>(function->function_id) -
8123 static_cast<int>(Runtime::kFirstInlineFunction); 8270 static_cast<int>(Runtime::kFirstInlineFunction);
8124 ASSERT(lookup_index >= 0); 8271 ASSERT(lookup_index >= 0);
8125 ASSERT(static_cast<size_t>(lookup_index) < 8272 ASSERT(static_cast<size_t>(lookup_index) <
8126 ARRAY_SIZE(kInlineFunctionGenerators)); 8273 ARRAY_SIZE(kInlineFunctionGenerators));
8127 InlineFunctionGenerator generator = kInlineFunctionGenerators[lookup_index]; 8274 InlineFunctionGenerator generator = kInlineFunctionGenerators[lookup_index];
(...skipping 2495 matching lines...) Expand 10 before | Expand all | Expand 10 after
10623 if (ShouldProduceTraceOutput()) { 10770 if (ShouldProduceTraceOutput()) {
10624 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 10771 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
10625 } 10772 }
10626 10773
10627 #ifdef DEBUG 10774 #ifdef DEBUG
10628 graph_->Verify(false); // No full verify. 10775 graph_->Verify(false); // No full verify.
10629 #endif 10776 #endif
10630 } 10777 }
10631 10778
10632 } } // namespace v8::internal 10779 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | src/hydrogen-instructions.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698