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.
7 #include "graph-tester.h"
8 #include "src/compiler/common-operator.h"
9 #include "src/compiler/node-cache.h"
11 using namespace v8::internal;
12 using namespace v8::internal::compiler;
14 TEST(Int32Constant_back_to_back) {
18 for (int i = -2000000000; i < 2000000000; i += 3315177) {
19 Node** pos = cache.Find(graph.zone(), i);
21 for (int j = 0; j < 3; j++) {
22 Node** npos = cache.Find(graph.zone(), i);
29 TEST(Int32Constant_five) {
32 CommonOperatorBuilder common(graph.zone());
34 int32_t constants[] = {static_cast<int32_t>(0x80000000), -77, 0, 1, -1};
36 Node* nodes[ARRAY_SIZE(constants)];
38 for (size_t i = 0; i < ARRAY_SIZE(constants); i++) {
39 int32_t k = constants[i];
40 Node* node = graph.NewNode(common.Int32Constant(k));
41 *cache.Find(graph.zone(), k) = nodes[i] = node;
44 for (size_t i = 0; i < ARRAY_SIZE(constants); i++) {
45 int32_t k = constants[i];
46 CHECK_EQ(nodes[i], *cache.Find(graph.zone(), k));
51 TEST(Int32Constant_hits) {
54 const int32_t kSize = 1500;
55 Node** nodes = graph.zone()->NewArray<Node*>(kSize);
56 CommonOperatorBuilder common(graph.zone());
58 for (int i = 0; i < kSize; i++) {
60 nodes[i] = graph.NewNode(common.Int32Constant(v));
61 *cache.Find(graph.zone(), v) = nodes[i];
65 for (int i = 0; i < kSize; i++) {
67 Node** pos = cache.Find(graph.zone(), v);
69 CHECK_EQ(nodes[i], *pos);
77 TEST(Int64Constant_back_to_back) {
81 for (int64_t i = -2000000000; i < 2000000000; i += 3315177) {
82 Node** pos = cache.Find(graph.zone(), i);
84 for (int j = 0; j < 3; j++) {
85 Node** npos = cache.Find(graph.zone(), i);
92 TEST(Int64Constant_hits) {
95 const int32_t kSize = 1500;
96 Node** nodes = graph.zone()->NewArray<Node*>(kSize);
97 CommonOperatorBuilder common(graph.zone());
99 for (int i = 0; i < kSize; i++) {
100 int64_t v = static_cast<int64_t>(i) * static_cast<int64_t>(5003001);
101 nodes[i] = graph.NewNode(common.Int32Constant(i));
102 *cache.Find(graph.zone(), v) = nodes[i];
106 for (int i = 0; i < kSize; i++) {
107 int64_t v = static_cast<int64_t>(i) * static_cast<int64_t>(5003001);
108 Node** pos = cache.Find(graph.zone(), v);
110 CHECK_EQ(nodes[i], *pos);
118 TEST(PtrConstant_back_to_back) {
123 for (int32_t* p = buffer;
124 (p - buffer) < static_cast<ptrdiff_t>(ARRAY_SIZE(buffer)); p++) {
125 Node** pos = cache.Find(graph.zone(), p);
127 for (int j = 0; j < 3; j++) {
128 Node** npos = cache.Find(graph.zone(), p);
135 TEST(PtrConstant_hits) {
138 const int32_t kSize = 50;
139 int32_t buffer[kSize];
141 CommonOperatorBuilder common(graph.zone());
143 for (size_t i = 0; i < ARRAY_SIZE(buffer); i++) {
144 int k = static_cast<int>(i);
145 int32_t* p = &buffer[i];
146 nodes[i] = graph.NewNode(common.Int32Constant(k));
147 *cache.Find(graph.zone(), p) = nodes[i];
151 for (size_t i = 0; i < ARRAY_SIZE(buffer); i++) {
152 int32_t* p = &buffer[i];
153 Node** pos = cache.Find(graph.zone(), p);
155 CHECK_EQ(nodes[i], *pos);