| OLD | NEW |
| (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/v8.h" | |
| 6 | |
| 7 #include "graph-tester.h" | |
| 8 #include "src/compiler/common-operator.h" | |
| 9 #include "src/compiler/node-cache.h" | |
| 10 | |
| 11 using namespace v8::internal; | |
| 12 using namespace v8::internal::compiler; | |
| 13 | |
| 14 TEST(Int32Constant_back_to_back) { | |
| 15 GraphTester graph; | |
| 16 Int32NodeCache cache; | |
| 17 | |
| 18 for (int i = -2000000000; i < 2000000000; i += 3315177) { | |
| 19 Node** pos = cache.Find(graph.zone(), i); | |
| 20 CHECK(pos); | |
| 21 for (int j = 0; j < 3; j++) { | |
| 22 Node** npos = cache.Find(graph.zone(), i); | |
| 23 CHECK_EQ(pos, npos); | |
| 24 } | |
| 25 } | |
| 26 } | |
| 27 | |
| 28 | |
| 29 TEST(Int32Constant_five) { | |
| 30 GraphTester graph; | |
| 31 Int32NodeCache cache; | |
| 32 CommonOperatorBuilder common(graph.zone()); | |
| 33 | |
| 34 int32_t constants[] = {static_cast<int32_t>(0x80000000), -77, 0, 1, -1}; | |
| 35 | |
| 36 Node* nodes[arraysize(constants)]; | |
| 37 | |
| 38 for (size_t i = 0; i < arraysize(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; | |
| 42 } | |
| 43 | |
| 44 for (size_t i = 0; i < arraysize(constants); i++) { | |
| 45 int32_t k = constants[i]; | |
| 46 CHECK_EQ(nodes[i], *cache.Find(graph.zone(), k)); | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 | |
| 51 TEST(Int32Constant_hits) { | |
| 52 GraphTester graph; | |
| 53 Int32NodeCache cache; | |
| 54 const int32_t kSize = 1500; | |
| 55 Node** nodes = graph.zone()->NewArray<Node*>(kSize); | |
| 56 CommonOperatorBuilder common(graph.zone()); | |
| 57 | |
| 58 for (int i = 0; i < kSize; i++) { | |
| 59 int32_t v = i * -55; | |
| 60 nodes[i] = graph.NewNode(common.Int32Constant(v)); | |
| 61 *cache.Find(graph.zone(), v) = nodes[i]; | |
| 62 } | |
| 63 | |
| 64 int hits = 0; | |
| 65 for (int i = 0; i < kSize; i++) { | |
| 66 int32_t v = i * -55; | |
| 67 Node** pos = cache.Find(graph.zone(), v); | |
| 68 if (*pos != NULL) { | |
| 69 CHECK_EQ(nodes[i], *pos); | |
| 70 hits++; | |
| 71 } | |
| 72 } | |
| 73 CHECK_LT(4, hits); | |
| 74 } | |
| 75 | |
| 76 | |
| 77 TEST(Int64Constant_back_to_back) { | |
| 78 GraphTester graph; | |
| 79 Int64NodeCache cache; | |
| 80 | |
| 81 for (int64_t i = -2000000000; i < 2000000000; i += 3315177) { | |
| 82 Node** pos = cache.Find(graph.zone(), i); | |
| 83 CHECK(pos); | |
| 84 for (int j = 0; j < 3; j++) { | |
| 85 Node** npos = cache.Find(graph.zone(), i); | |
| 86 CHECK_EQ(pos, npos); | |
| 87 } | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 | |
| 92 TEST(Int64Constant_hits) { | |
| 93 GraphTester graph; | |
| 94 Int64NodeCache cache; | |
| 95 const int32_t kSize = 1500; | |
| 96 Node** nodes = graph.zone()->NewArray<Node*>(kSize); | |
| 97 CommonOperatorBuilder common(graph.zone()); | |
| 98 | |
| 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]; | |
| 103 } | |
| 104 | |
| 105 int hits = 0; | |
| 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); | |
| 109 if (*pos != NULL) { | |
| 110 CHECK_EQ(nodes[i], *pos); | |
| 111 hits++; | |
| 112 } | |
| 113 } | |
| 114 CHECK_LT(4, hits); | |
| 115 } | |
| 116 | |
| 117 | |
| 118 static bool Contains(ZoneVector<Node*>* nodes, Node* n) { | |
| 119 for (size_t i = 0; i < nodes->size(); i++) { | |
| 120 if (nodes->at(i) == n) return true; | |
| 121 } | |
| 122 return false; | |
| 123 } | |
| 124 | |
| 125 | |
| 126 TEST(NodeCache_GetCachedNodes_int32) { | |
| 127 GraphTester graph; | |
| 128 Int32NodeCache cache; | |
| 129 CommonOperatorBuilder common(graph.zone()); | |
| 130 | |
| 131 int32_t constants[] = {0, 311, 12, 13, 14, 555, -555, -44, -33, -22, -11, | |
| 132 0, 311, 311, 412, 412, 11, 11, -33, -33, -22, -11}; | |
| 133 | |
| 134 for (size_t i = 0; i < arraysize(constants); i++) { | |
| 135 int32_t k = constants[i]; | |
| 136 Node** pos = cache.Find(graph.zone(), k); | |
| 137 if (*pos != NULL) { | |
| 138 ZoneVector<Node*> nodes(graph.zone()); | |
| 139 cache.GetCachedNodes(&nodes); | |
| 140 CHECK(Contains(&nodes, *pos)); | |
| 141 } else { | |
| 142 ZoneVector<Node*> nodes(graph.zone()); | |
| 143 Node* n = graph.NewNode(common.Int32Constant(k)); | |
| 144 *pos = n; | |
| 145 cache.GetCachedNodes(&nodes); | |
| 146 CHECK(Contains(&nodes, n)); | |
| 147 } | |
| 148 } | |
| 149 } | |
| 150 | |
| 151 | |
| 152 TEST(NodeCache_GetCachedNodes_int64) { | |
| 153 GraphTester graph; | |
| 154 Int64NodeCache cache; | |
| 155 CommonOperatorBuilder common(graph.zone()); | |
| 156 | |
| 157 int64_t constants[] = {0, 311, 12, 13, 14, 555, -555, -44, -33, -22, -11, | |
| 158 0, 311, 311, 412, 412, 11, 11, -33, -33, -22, -11}; | |
| 159 | |
| 160 for (size_t i = 0; i < arraysize(constants); i++) { | |
| 161 int64_t k = constants[i]; | |
| 162 Node** pos = cache.Find(graph.zone(), k); | |
| 163 if (*pos != NULL) { | |
| 164 ZoneVector<Node*> nodes(graph.zone()); | |
| 165 cache.GetCachedNodes(&nodes); | |
| 166 CHECK(Contains(&nodes, *pos)); | |
| 167 } else { | |
| 168 ZoneVector<Node*> nodes(graph.zone()); | |
| 169 Node* n = graph.NewNode(common.Int64Constant(k)); | |
| 170 *pos = n; | |
| 171 cache.GetCachedNodes(&nodes); | |
| 172 CHECK(Contains(&nodes, n)); | |
| 173 } | |
| 174 } | |
| 175 } | |
| OLD | NEW |