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

Side by Side Diff: test/unittests/compiler/js-typed-lowering-unittest.cc

Issue 631093003: [turbofan] Fix lowering of typed loads/stores. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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 | « test/unittests/compiler/js-builtin-reducer-unittest.cc ('k') | test/unittests/test-utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/compiler/access-builder.h"
6 #include "src/compiler/js-graph.h"
7 #include "src/compiler/js-operator.h"
8 #include "src/compiler/js-typed-lowering.h"
9 #include "src/compiler/machine-operator.h"
10 #include "src/compiler/node-properties-inl.h"
11 #include "src/compiler/typer.h"
12 #include "test/unittests/compiler/compiler-test-utils.h"
13 #include "test/unittests/compiler/graph-unittest.h"
14 #include "testing/gmock-support.h"
15
16 using testing::_;
17 using testing::AllOf;
18 using testing::Capture;
19 using testing::CaptureEq;
20
21 namespace v8 {
22 namespace internal {
23 namespace compiler {
24
25 namespace {
26
27 const ExternalArrayType kExternalArrayTypes[] = {
28 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) kExternal##Type##Array,
29 TYPED_ARRAYS(TYPED_ARRAY_CASE)
30 #undef TYPED_ARRAY_CASE
31 };
32
33
34 const StrictMode kStrictModes[] = {SLOPPY, STRICT};
35
36 } // namespace
37
38
39 class JSTypedLoweringTest : public GraphTest {
40 public:
41 JSTypedLoweringTest() : GraphTest(3), javascript_(zone()) {}
42 virtual ~JSTypedLoweringTest() {}
43
44 protected:
45 Reduction Reduce(Node* node) {
46 Typer typer(zone());
47 MachineOperatorBuilder machine;
48 JSGraph jsgraph(graph(), common(), javascript(), &typer, &machine);
49 JSTypedLowering reducer(&jsgraph);
50 return reducer.Reduce(node);
51 }
52
53 Node* Parameter(Type* type, int index = 0) {
54 Node* node = graph()->NewNode(common()->Parameter(index), graph()->start());
55 NodeProperties::SetBounds(node, Bounds(Type::None(), type));
56 return node;
57 }
58
59 Handle<JSArrayBuffer> NewArrayBuffer(void* bytes, size_t byte_length) {
60 Handle<JSArrayBuffer> buffer = factory()->NewJSArrayBuffer();
61 Runtime::SetupArrayBuffer(isolate(), buffer, true, bytes, byte_length);
62 return buffer;
63 }
64
65 JSOperatorBuilder* javascript() { return &javascript_; }
66
67 private:
68 JSOperatorBuilder javascript_;
69 };
70
71
72 // -----------------------------------------------------------------------------
73 // JSLoadProperty
74
75
76 TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArray) {
77 const size_t kLength = 17;
78 uint8_t backing_store[kLength * 8];
79 Handle<JSArrayBuffer> buffer =
80 NewArrayBuffer(backing_store, arraysize(backing_store));
81 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) {
82 Handle<JSTypedArray> array =
83 factory()->NewJSTypedArray(type, buffer, kLength);
84
85 Node* key = Parameter(Type::Integral32());
86 Node* base = HeapConstant(array);
87 Node* context = UndefinedConstant();
88 Node* effect = graph()->start();
89 Node* control = graph()->start();
90 Node* node =
91 graph()->NewNode(javascript()->LoadProperty(), base, key, context);
92 if (FLAG_turbo_deoptimization) {
93 node->AppendInput(zone(), UndefinedConstant());
94 }
95 node->AppendInput(zone(), effect);
96 node->AppendInput(zone(), control);
97 Reduction r = Reduce(node);
98
99 Capture<Node*> elements;
100 ASSERT_TRUE(r.Changed());
101 EXPECT_THAT(
102 r.replacement(),
103 IsLoadElement(
104 AccessBuilder::ForTypedArrayElement(type, true),
105 IsLoadField(AccessBuilder::ForExternalArrayPointer(),
106 AllOf(CaptureEq(&elements),
107 IsLoadField(AccessBuilder::ForJSObjectElements(),
108 base, _)),
109 CaptureEq(&elements)),
110 key, IsInt32Constant(static_cast<int>(kLength)), effect, control));
111 }
112 }
113
114
115 // -----------------------------------------------------------------------------
116 // JSStoreProperty
117
118
119 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArray) {
120 const size_t kLength = 17;
121 uint8_t backing_store[kLength * 8];
122 Handle<JSArrayBuffer> buffer =
123 NewArrayBuffer(backing_store, arraysize(backing_store));
124 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) {
125 TRACED_FOREACH(StrictMode, strict_mode, kStrictModes) {
126 Handle<JSTypedArray> array =
127 factory()->NewJSTypedArray(type, buffer, kLength);
128
129 Node* key = Parameter(Type::Integral32());
130 Node* base = HeapConstant(array);
131 Node* value = Parameter(Type::Any());
132 Node* context = UndefinedConstant();
133 Node* effect = graph()->start();
134 Node* control = graph()->start();
135 Node* node = graph()->NewNode(javascript()->StoreProperty(strict_mode),
136 base, key, value, context);
137 if (FLAG_turbo_deoptimization) {
138 node->AppendInput(zone(), UndefinedConstant());
139 }
140 node->AppendInput(zone(), effect);
141 node->AppendInput(zone(), control);
142 Reduction r = Reduce(node);
143
144 Capture<Node*> elements;
145 ASSERT_TRUE(r.Changed());
146 EXPECT_THAT(
147 r.replacement(),
148 IsStoreElement(
149 AccessBuilder::ForTypedArrayElement(type, true),
150 IsLoadField(
151 AccessBuilder::ForExternalArrayPointer(),
152 AllOf(CaptureEq(&elements),
153 IsLoadField(AccessBuilder::ForJSObjectElements(), base,
154 _)),
155 CaptureEq(&elements)),
156 key, IsInt32Constant(static_cast<int>(kLength)), value, effect,
157 control));
158 }
159 }
160 }
161
162 } // namespace compiler
163 } // namespace internal
164 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/compiler/js-builtin-reducer-unittest.cc ('k') | test/unittests/test-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698