OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/gap-resolver.h" | 5 #include "src/compiler/gap-resolver.h" |
6 | 6 |
7 #include "src/base/utils/random-number-generator.h" | 7 #include "src/base/utils/random-number-generator.h" |
8 #include "test/cctest/cctest.h" | 8 #include "test/cctest/cctest.h" |
9 | 9 |
10 using namespace v8::internal; | 10 using namespace v8::internal; |
(...skipping 14 matching lines...) Expand all Loading... |
25 return values_ == other.values_; | 25 return values_ == other.values_; |
26 } | 26 } |
27 | 27 |
28 bool operator!=(const InterpreterState& other) const { | 28 bool operator!=(const InterpreterState& other) const { |
29 return values_ != other.values_; | 29 return values_ != other.values_; |
30 } | 30 } |
31 | 31 |
32 private: | 32 private: |
33 struct Key { | 33 struct Key { |
34 bool is_constant; | 34 bool is_constant; |
35 AllocatedOperand::AllocatedKind kind; | 35 bool is_float; |
| 36 LocationOperand::LocationKind kind; |
36 int index; | 37 int index; |
37 | 38 |
38 bool operator<(const Key& other) const { | 39 bool operator<(const Key& other) const { |
39 if (this->is_constant != other.is_constant) { | 40 if (this->is_constant != other.is_constant) { |
40 return this->is_constant; | 41 return this->is_constant; |
41 } | 42 } |
| 43 if (this->is_float != other.is_float) { |
| 44 return this->is_float; |
| 45 } |
42 if (this->kind != other.kind) { | 46 if (this->kind != other.kind) { |
43 return this->kind < other.kind; | 47 return this->kind < other.kind; |
44 } | 48 } |
45 return this->index < other.index; | 49 return this->index < other.index; |
46 } | 50 } |
47 | 51 |
48 bool operator==(const Key& other) const { | 52 bool operator==(const Key& other) const { |
49 return this->is_constant == other.is_constant && | 53 return this->is_constant == other.is_constant && |
50 this->kind == other.kind && this->index == other.index; | 54 this->kind == other.kind && this->index == other.index; |
51 } | 55 } |
(...skipping 11 matching lines...) Expand all Loading... |
63 void write(const InstructionOperand& op, Value v) { | 67 void write(const InstructionOperand& op, Value v) { |
64 if (v == ValueFor(op)) { | 68 if (v == ValueFor(op)) { |
65 values_.erase(KeyFor(op)); | 69 values_.erase(KeyFor(op)); |
66 } else { | 70 } else { |
67 values_[KeyFor(op)] = v; | 71 values_[KeyFor(op)] = v; |
68 } | 72 } |
69 } | 73 } |
70 | 74 |
71 static Key KeyFor(const InstructionOperand& op) { | 75 static Key KeyFor(const InstructionOperand& op) { |
72 bool is_constant = op.IsConstant(); | 76 bool is_constant = op.IsConstant(); |
73 AllocatedOperand::AllocatedKind kind; | 77 bool is_float = false; |
| 78 LocationOperand::LocationKind kind; |
74 int index; | 79 int index; |
75 if (!is_constant) { | 80 if (!is_constant) { |
76 if (op.IsRegister()) { | 81 if (op.IsRegister()) { |
77 index = AllocatedOperand::cast(op).GetRegister().code(); | 82 index = LocationOperand::cast(op).GetRegister().code(); |
78 } else if (op.IsDoubleRegister()) { | 83 } else if (op.IsDoubleRegister()) { |
79 index = AllocatedOperand::cast(op).GetDoubleRegister().code(); | 84 index = LocationOperand::cast(op).GetDoubleRegister().code(); |
80 } else { | 85 } else { |
81 index = AllocatedOperand::cast(op).index(); | 86 index = LocationOperand::cast(op).index(); |
82 } | 87 } |
83 kind = AllocatedOperand::cast(op).allocated_kind(); | 88 is_float = IsFloatingPoint(LocationOperand::cast(op).machine_type()); |
| 89 kind = LocationOperand::cast(op).location_kind(); |
84 } else { | 90 } else { |
85 index = ConstantOperand::cast(op).virtual_register(); | 91 index = ConstantOperand::cast(op).virtual_register(); |
86 kind = AllocatedOperand::REGISTER; | 92 kind = LocationOperand::REGISTER; |
87 } | 93 } |
88 Key key = {is_constant, kind, index}; | 94 Key key = {is_constant, is_float, kind, index}; |
89 return key; | 95 return key; |
90 } | 96 } |
91 | 97 |
92 static Value ValueFor(const InstructionOperand& op) { return KeyFor(op); } | 98 static Value ValueFor(const InstructionOperand& op) { return KeyFor(op); } |
93 | 99 |
94 static InstructionOperand FromKey(Key key) { | 100 static InstructionOperand FromKey(Key key) { |
95 if (key.is_constant) { | 101 if (key.is_constant) { |
96 return ConstantOperand(key.index); | 102 return ConstantOperand(key.index); |
97 } | 103 } |
98 return AllocatedOperand( | 104 return AllocatedOperand( |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 return kMachNone; | 191 return kMachNone; |
186 } | 192 } |
187 | 193 |
188 MachineType RandomDoubleType() { | 194 MachineType RandomDoubleType() { |
189 int index = rng_->NextInt(2); | 195 int index = rng_->NextInt(2); |
190 if (index == 0) return kRepFloat64; | 196 if (index == 0) return kRepFloat64; |
191 return kRepFloat32; | 197 return kRepFloat32; |
192 } | 198 } |
193 | 199 |
194 InstructionOperand CreateRandomOperand(bool is_source) { | 200 InstructionOperand CreateRandomOperand(bool is_source) { |
195 int index = rng_->NextInt(6); | 201 int index = rng_->NextInt(7); |
196 // destination can't be Constant. | 202 // destination can't be Constant. |
197 switch (rng_->NextInt(is_source ? 5 : 4)) { | 203 switch (rng_->NextInt(is_source ? 7 : 6)) { |
198 case 0: | 204 case 0: |
199 return StackSlotOperand(RandomType(), index); | 205 return AllocatedOperand(LocationOperand::STACK_SLOT, RandomType(), |
| 206 index); |
200 case 1: | 207 case 1: |
201 return DoubleStackSlotOperand(RandomDoubleType(), index); | 208 return AllocatedOperand(LocationOperand::STACK_SLOT, RandomDoubleType(), |
| 209 index); |
202 case 2: | 210 case 2: |
203 return RegisterOperand(RandomType(), index); | 211 return AllocatedOperand(LocationOperand::REGISTER, RandomType(), index); |
204 case 3: | 212 case 3: |
205 return DoubleRegisterOperand(RandomDoubleType(), index); | 213 return AllocatedOperand(LocationOperand::REGISTER, RandomDoubleType(), |
| 214 index); |
206 case 4: | 215 case 4: |
| 216 return ExplicitOperand(LocationOperand::REGISTER, RandomType(), 1); |
| 217 case 5: |
| 218 return ExplicitOperand(LocationOperand::STACK_SLOT, RandomType(), |
| 219 index); |
| 220 case 6: |
207 return ConstantOperand(index); | 221 return ConstantOperand(index); |
208 } | 222 } |
209 UNREACHABLE(); | 223 UNREACHABLE(); |
210 return InstructionOperand(); | 224 return InstructionOperand(); |
211 } | 225 } |
212 | 226 |
213 private: | 227 private: |
214 v8::base::RandomNumberGenerator* rng_; | 228 v8::base::RandomNumberGenerator* rng_; |
215 }; | 229 }; |
216 | 230 |
217 | 231 |
218 TEST(FuzzResolver) { | 232 TEST(FuzzResolver) { |
219 ParallelMoveCreator pmc; | 233 ParallelMoveCreator pmc; |
220 for (int size = 0; size < 20; ++size) { | 234 for (int size = 0; size < 20; ++size) { |
221 for (int repeat = 0; repeat < 50; ++repeat) { | 235 for (int repeat = 0; repeat < 50; ++repeat) { |
222 ParallelMove* pm = pmc.Create(size); | 236 ParallelMove* pm = pmc.Create(size); |
223 | 237 |
224 // Note: The gap resolver modifies the ParallelMove, so interpret first. | 238 // Note: The gap resolver modifies the ParallelMove, so interpret first. |
225 MoveInterpreter mi1(pmc.main_zone()); | 239 MoveInterpreter mi1(pmc.main_zone()); |
226 mi1.AssembleParallelMove(pm); | 240 mi1.AssembleParallelMove(pm); |
227 | 241 |
228 MoveInterpreter mi2(pmc.main_zone()); | 242 MoveInterpreter mi2(pmc.main_zone()); |
229 GapResolver resolver(&mi2); | 243 GapResolver resolver(&mi2); |
230 resolver.Resolve(pm); | 244 resolver.Resolve(pm); |
231 | 245 |
232 CHECK(mi1.state() == mi2.state()); | 246 CHECK(mi1.state() == mi2.state()); |
233 } | 247 } |
234 } | 248 } |
235 } | 249 } |
OLD | NEW |