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

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: CR feedback 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 7974 matching lines...) Expand 10 before | Expand all | Expand 10 after
8045 &HOptimizedGraphBuilder::Generate##Name, 8046 &HOptimizedGraphBuilder::Generate##Name,
8046 8047
8047 const HOptimizedGraphBuilder::InlineFunctionGenerator 8048 const HOptimizedGraphBuilder::InlineFunctionGenerator
8048 HOptimizedGraphBuilder::kInlineFunctionGenerators[] = { 8049 HOptimizedGraphBuilder::kInlineFunctionGenerators[] = {
8049 INLINE_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS) 8050 INLINE_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
8050 INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS) 8051 INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
8051 }; 8052 };
8052 #undef INLINE_FUNCTION_GENERATOR_ADDRESS 8053 #undef INLINE_FUNCTION_GENERATOR_ADDRESS
8053 8054
8054 8055
8056 void HOptimizedGraphBuilder::VisitTypedArrayInitialize(
8057 CallRuntime* expr) {
8058 ZoneList<Expression*>* arguments = expr->arguments();
8059
8060 NoObservableSideEffectsScope scope(this);
8061
8062 static const int kObjectArg = 0;
8063 static const int kArrayIdArg = 1;
8064 static const int kBufferArg = 2;
8065 static const int kByteOffsetArg = 3;
8066 static const int kByteLengthArg = 4;
8067 static const int kArgsLength = 5;
8068 ASSERT(arguments->length() == kArgsLength);
8069
8070
8071 CHECK_ALIVE(VisitForValue(arguments->at(kObjectArg)));
8072 HValue* obj = Pop();
8073
8074 ASSERT(arguments->at(kArrayIdArg)->node_type() == AstNode::kLiteral);
8075 Handle<Object> value =
8076 static_cast<Literal*>(arguments->at(kArrayIdArg))->value();
8077 ASSERT(value->IsSmi());
8078 int array_id = Smi::cast(*value)->value();
8079
8080 CHECK_ALIVE(VisitForValue(arguments->at(kBufferArg)));
8081 HValue* buffer = Pop();
8082
8083 HValue* byte_offset;
8084 bool is_zero_byte_offset;
8085
8086 if (arguments->at(kByteOffsetArg)->node_type() == AstNode::kLiteral
8087 && Smi::FromInt(0) ==
8088 *static_cast<Literal*>(arguments->at(kByteOffsetArg))->value()) {
8089 byte_offset = Add<HConstant>(static_cast<int32_t>(0));
8090 is_zero_byte_offset = true;
8091 } else {
8092 CHECK_ALIVE(VisitForValue(arguments->at(kByteOffsetArg)));
8093 byte_offset = Pop();
8094 is_zero_byte_offset = false;
8095 }
8096
8097 CHECK_ALIVE(VisitForValue(arguments->at(kByteLengthArg)));
8098 HValue* byte_length = Pop();
8099
8100 IfBuilder byte_offset_smi(this);
8101
8102 if (!is_zero_byte_offset) {
8103 byte_offset_smi.If<HIsSmiAndBranch>(byte_offset);
8104 byte_offset_smi.Then();
8105 }
8106
8107 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization.
8108 size_t element_size = 1; // Bogus initialization.
8109 Runtime::ArrayIdToTypeAndSize(array_id, &array_type, &element_size);
8110
8111 for (int offset = JSTypedArray::kSize;
8112 offset < JSTypedArray::kSizeWithInternalFields;
8113 offset += kPointerSize) {
8114 Add<HStoreNamedField>(obj,
8115 HObjectAccess::ForJSObjectOffset(offset),
8116 Add<HConstant>(static_cast<int32_t>(0)));
8117 }
8118
8119 Add<HStoreNamedField>(obj,
8120 HObjectAccess::ForJSObjectOffset(JSTypedArray::kBufferOffset), buffer);
8121 Add<HStoreNamedField>(obj,
8122 HObjectAccess::ForJSObjectOffset(JSTypedArray::kByteOffsetOffset),
8123 byte_offset);
8124 Add<HStoreNamedField>(obj,
8125 HObjectAccess::ForJSObjectOffset(JSTypedArray::kByteLengthOffset),
8126 byte_length);
8127
8128 HInstruction* length = Add<HDiv>(byte_length,
8129 Add<HConstant>(static_cast<int32_t>(element_size)));
8130
8131 Add<HStoreNamedField>(obj,
8132 HObjectAccess::ForJSObjectOffset(JSTypedArray::kLengthOffset),
8133 length);
8134
8135 Add<HStoreNamedField>(obj,
8136 HObjectAccess::ForJSObjectOffset(JSTypedArray::kWeakNextOffset),
8137 Add<HLoadNamedField>(buffer,
8138 HObjectAccess::ForJSObjectOffset(
8139 JSArrayBuffer::kWeakFirstViewOffset)));
8140 Add<HStoreNamedField>(buffer,
8141 HObjectAccess::ForJSObjectOffset(JSArrayBuffer::kWeakFirstViewOffset),
8142 obj);
8143
8144 HValue* elements =
8145 Add<HAllocate>(
8146 Add<HConstant>(ExternalArray::kAlignedSize),
8147 HType::JSArray(),
8148 NOT_TENURED,
8149 static_cast<InstanceType>(FIRST_EXTERNAL_ARRAY_TYPE + array_type));
8150
8151 Handle<Map> external_array_map(
8152 isolate()->heap()->MapForExternalArrayType(array_type));
8153
8154 Add<HStoreNamedField>(elements,
8155 HObjectAccess::ForMap(),
8156 Add<HConstant>(external_array_map));
8157 HValue* backing_store =
8158 Add<HLoadNamedField>(buffer,
8159 HObjectAccess::ForJSObjectOffset(
8160 JSArrayBuffer::kBackingStoreOffset, Representation::External()));
8161
8162 HValue* typed_array_start;
8163 if (is_zero_byte_offset) {
8164 typed_array_start = backing_store;
8165 } else {
8166 HAdd* external_pointer =
8167 HAdd::NewExternalPointerOffset(
8168 zone(), graph()->GetInvalidContext(), backing_store, byte_offset);
8169 // Arguments are checked prior to call to TypedArrayInitialize,
8170 // including byte_offset.
8171 external_pointer->ClearFlag(HValue::kCanOverflow);
8172 typed_array_start = AddInstruction(external_pointer);
8173 }
8174
8175 Add<HStoreNamedField>(elements,
8176 HObjectAccess::ForJSObjectOffset(
8177 ExternalArray::kExternalPointerOffset, Representation::External()),
8178 typed_array_start);
8179 Add<HStoreNamedField>(elements,
8180 HObjectAccess::ForJSObjectOffset(ExternalArray::kLengthOffset),
8181 length);
8182 Add<HStoreNamedField>(
8183 obj, HObjectAccess::ForElementsPointer(), elements);
8184
8185 if (!is_zero_byte_offset) {
8186 byte_offset_smi.Else();
8187 Push(Add<HPushArgument>(obj));
8188 VisitArgument(arguments->at(kArrayIdArg));
8189 Push(Add<HPushArgument>(buffer));
8190 Push(Add<HPushArgument>(byte_offset));
8191 Push(Add<HPushArgument>(byte_length));
8192 Add<HCallRuntime>(expr->name(), expr->function(), kArgsLength);
8193 Drop(kArgsLength);
8194 byte_offset_smi.End();
8195 }
8196 }
8197
8198
8055 void HOptimizedGraphBuilder::VisitCallRuntime(CallRuntime* expr) { 8199 void HOptimizedGraphBuilder::VisitCallRuntime(CallRuntime* expr) {
8056 ASSERT(!HasStackOverflow()); 8200 ASSERT(!HasStackOverflow());
8057 ASSERT(current_block() != NULL); 8201 ASSERT(current_block() != NULL);
8058 ASSERT(current_block()->HasPredecessor()); 8202 ASSERT(current_block()->HasPredecessor());
8059 if (expr->is_jsruntime()) { 8203 if (expr->is_jsruntime()) {
8060 return Bailout(kCallToAJavaScriptRuntimeFunction); 8204 return Bailout(kCallToAJavaScriptRuntimeFunction);
8061 } 8205 }
8062 8206
8063 const Runtime::Function* function = expr->function(); 8207 const Runtime::Function* function = expr->function();
8064 ASSERT(function != NULL); 8208 ASSERT(function != NULL);
8209
8210 if (function->function_id == Runtime::kTypedArrayInitialize) {
8211 return VisitTypedArrayInitialize(expr);
8212 }
8213
8214 if (function->function_id == Runtime::kMaxSmi) {
8215 ASSERT(expr->arguments()->length() == 0);
8216 HConstant* max_smi = New<HConstant>(static_cast<int32_t>(Smi::kMaxValue));
8217 return ast_context()->ReturnInstruction(max_smi, expr->id());
8218 }
8219
8065 if (function->intrinsic_type == Runtime::INLINE) { 8220 if (function->intrinsic_type == Runtime::INLINE) {
8066 ASSERT(expr->name()->length() > 0); 8221 ASSERT(expr->name()->length() > 0);
8067 ASSERT(expr->name()->Get(0) == '_'); 8222 ASSERT(expr->name()->Get(0) == '_');
8068 // Call to an inline function. 8223 // Call to an inline function.
8069 int lookup_index = static_cast<int>(function->function_id) - 8224 int lookup_index = static_cast<int>(function->function_id) -
8070 static_cast<int>(Runtime::kFirstInlineFunction); 8225 static_cast<int>(Runtime::kFirstInlineFunction);
8071 ASSERT(lookup_index >= 0); 8226 ASSERT(lookup_index >= 0);
8072 ASSERT(static_cast<size_t>(lookup_index) < 8227 ASSERT(static_cast<size_t>(lookup_index) <
8073 ARRAY_SIZE(kInlineFunctionGenerators)); 8228 ARRAY_SIZE(kInlineFunctionGenerators));
8074 InlineFunctionGenerator generator = kInlineFunctionGenerators[lookup_index]; 8229 InlineFunctionGenerator generator = kInlineFunctionGenerators[lookup_index];
(...skipping 2475 matching lines...) Expand 10 before | Expand all | Expand 10 after
10550 if (ShouldProduceTraceOutput()) { 10705 if (ShouldProduceTraceOutput()) {
10551 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 10706 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
10552 } 10707 }
10553 10708
10554 #ifdef DEBUG 10709 #ifdef DEBUG
10555 graph_->Verify(false); // No full verify. 10710 graph_->Verify(false); // No full verify.
10556 #endif 10711 #endif
10557 } 10712 }
10558 10713
10559 } } // namespace v8::internal 10714 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | src/property-details.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698