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

Unified Diff: src/hydrogen.cc

Issue 1109353003: Unify internal and external typed arrays a bit (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index f6a6d8d147d356129bd17f80d6a200695b9899e4..bef57aa8431f34efd2ca1bf220e859340960fb7b 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -3167,29 +3167,21 @@ HValue* HGraphBuilder::BuildArrayBufferViewFieldAccessor(HValue* object,
object, checked_object, HObjectAccess::ForJSArrayBufferViewBuffer());
HInstruction* field = Add<HLoadNamedField>(object, checked_object, access);
- IfBuilder if_has_buffer(this);
- HValue* has_buffer = if_has_buffer.IfNot<HIsSmiAndBranch>(buffer);
- if_has_buffer.Then();
- {
- HInstruction* flags = Add<HLoadNamedField>(
- buffer, has_buffer, HObjectAccess::ForJSArrayBufferBitField());
- HValue* was_neutered_mask =
- Add<HConstant>(1 << JSArrayBuffer::WasNeutered::kShift);
- HValue* was_neutered_test =
- AddUncasted<HBitwise>(Token::BIT_AND, flags, was_neutered_mask);
-
- IfBuilder if_was_neutered(this);
- if_was_neutered.If<HCompareNumericAndBranch>(
- was_neutered_test, graph()->GetConstant0(), Token::NE);
- if_was_neutered.Then();
- Push(graph()->GetConstant0());
- if_was_neutered.Else();
- Push(field);
- if_was_neutered.End();
- }
- if_has_buffer.Else();
+ HInstruction* flags = Add<HLoadNamedField>(
+ buffer, nullptr, HObjectAccess::ForJSArrayBufferBitField());
+ HValue* was_neutered_mask =
+ Add<HConstant>(1 << JSArrayBuffer::WasNeutered::kShift);
+ HValue* was_neutered_test =
+ AddUncasted<HBitwise>(Token::BIT_AND, flags, was_neutered_mask);
+
+ IfBuilder if_was_neutered(this);
+ if_was_neutered.If<HCompareNumericAndBranch>(
+ was_neutered_test, graph()->GetConstant0(), Token::NE);
+ if_was_neutered.Then();
+ Push(graph()->GetConstant0());
+ if_was_neutered.Else();
Push(field);
- if_has_buffer.End();
+ if_was_neutered.End();
return Pop();
}
@@ -9702,6 +9694,45 @@ void HOptimizedGraphBuilder::VisitCallNew(CallNew* expr) {
}
+HValue* HGraphBuilder::BuildAllocateEmptyArrayBuffer(HValue* byte_length) {
+ HAllocate* result =
+ BuildAllocate(Add<HConstant>(JSArrayBuffer::kSizeWithInternalFields),
+ HType::JSObject(), JS_ARRAY_BUFFER_TYPE, HAllocationMode());
+
+ HValue* global_object = Add<HLoadNamedField>(
+ context(), nullptr,
+ HObjectAccess::ForContextSlot(Context::GLOBAL_OBJECT_INDEX));
+ HValue* native_context = Add<HLoadNamedField>(
+ global_object, nullptr, HObjectAccess::ForGlobalObjectNativeContext());
+ Add<HStoreNamedField>(
+ result, HObjectAccess::ForMap(),
+ Add<HLoadNamedField>(
+ native_context, nullptr,
+ HObjectAccess::ForContextSlot(Context::ARRAY_BUFFER_MAP_INDEX)));
+
+ Add<HStoreNamedField>(result, HObjectAccess::ForJSArrayBufferBackingStore(),
+ Add<HConstant>(ExternalReference()));
+ Add<HStoreNamedField>(result, HObjectAccess::ForJSArrayBufferByteLength(),
+ byte_length);
+ Add<HStoreNamedField>(result, HObjectAccess::ForJSArrayBufferBitFieldSlot(),
+ graph()->GetConstant0());
+ Add<HStoreNamedField>(
+ result, HObjectAccess::ForJSArrayBufferBitField(),
+ Add<HConstant>((1 << JSArrayBuffer::IsExternal::kShift) |
+ (1 << JSArrayBuffer::IsNeuterable::kShift)));
+
+ for (int field = 0; field < v8::ArrayBuffer::kInternalFieldCount; ++field) {
+ Add<HStoreNamedField>(
+ result,
+ HObjectAccess::ForObservableJSObjectOffset(
+ JSArrayBuffer::kSize + field * kPointerSize, Representation::Smi()),
+ graph()->GetConstant0());
+ }
+
+ return result;
+}
+
+
template <class ViewClass>
void HGraphBuilder::BuildArrayBufferViewInitialization(
HValue* obj,
@@ -9725,17 +9756,8 @@ void HGraphBuilder::BuildArrayBufferViewInitialization(
obj,
HObjectAccess::ForJSArrayBufferViewByteLength(),
byte_length);
-
- if (buffer != NULL) {
- Add<HStoreNamedField>(
- obj,
- HObjectAccess::ForJSArrayBufferViewBuffer(), buffer);
- } else {
- Add<HStoreNamedField>(
- obj,
- HObjectAccess::ForJSArrayBufferViewBuffer(),
- Add<HConstant>(static_cast<int32_t>(0)));
- }
+ Add<HStoreNamedField>(obj, HObjectAccess::ForJSArrayBufferViewBuffer(),
+ buffer);
}
@@ -9957,8 +9979,12 @@ void HOptimizedGraphBuilder::GenerateTypedArrayInitialize(
{ // byte_offset is Smi.
- BuildArrayBufferViewInitialization<JSTypedArray>(
- obj, buffer, byte_offset, byte_length);
+ HValue* allocated_buffer = buffer;
+ if (buffer == NULL) {
+ allocated_buffer = BuildAllocateEmptyArrayBuffer(byte_length);
+ }
+ BuildArrayBufferViewInitialization<JSTypedArray>(obj, allocated_buffer,
+ byte_offset, byte_length);
HInstruction* length = AddUncasted<HDiv>(byte_length,
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698