| 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 AllocatedOperand::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 AllocatedOperand::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(AllocatedOperand::cast(op).machine_type()); |
| 89 kind = AllocatedOperand::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 = AllocatedOperand::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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 int index = rng_->NextInt(2); | 193 int index = rng_->NextInt(2); |
| 188 if (index == 0) return kRepFloat64; | 194 if (index == 0) return kRepFloat64; |
| 189 return kRepFloat32; | 195 return kRepFloat32; |
| 190 } | 196 } |
| 191 | 197 |
| 192 InstructionOperand CreateRandomOperand(bool is_source) { | 198 InstructionOperand CreateRandomOperand(bool is_source) { |
| 193 int index = rng_->NextInt(6); | 199 int index = rng_->NextInt(6); |
| 194 // destination can't be Constant. | 200 // destination can't be Constant. |
| 195 switch (rng_->NextInt(is_source ? 5 : 4)) { | 201 switch (rng_->NextInt(is_source ? 5 : 4)) { |
| 196 case 0: | 202 case 0: |
| 197 return StackSlotOperand(RandomType(), index); | 203 return AllocatedOperand(LocationOperand::STACK_SLOT, RandomType(), |
| 204 index); |
| 198 case 1: | 205 case 1: |
| 199 return DoubleStackSlotOperand(RandomDoubleType(), index); | 206 return AllocatedOperand(LocationOperand::STACK_SLOT, RandomDoubleType(), |
| 207 index); |
| 200 case 2: | 208 case 2: |
| 201 return RegisterOperand(RandomType(), index); | 209 return AllocatedOperand(LocationOperand::REGISTER, RandomType(), index); |
| 202 case 3: | 210 case 3: |
| 203 return DoubleRegisterOperand(RandomDoubleType(), index); | 211 return AllocatedOperand(LocationOperand::REGISTER, RandomDoubleType(), |
| 212 index); |
| 204 case 4: | 213 case 4: |
| 205 return ConstantOperand(index); | 214 return ConstantOperand(index); |
| 206 } | 215 } |
| 207 UNREACHABLE(); | 216 UNREACHABLE(); |
| 208 return InstructionOperand(); | 217 return InstructionOperand(); |
| 209 } | 218 } |
| 210 | 219 |
| 211 private: | 220 private: |
| 212 v8::base::RandomNumberGenerator* rng_; | 221 v8::base::RandomNumberGenerator* rng_; |
| 213 }; | 222 }; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 224 mi1.AssembleParallelMove(pm); | 233 mi1.AssembleParallelMove(pm); |
| 225 | 234 |
| 226 MoveInterpreter mi2(pmc.main_zone()); | 235 MoveInterpreter mi2(pmc.main_zone()); |
| 227 GapResolver resolver(&mi2); | 236 GapResolver resolver(&mi2); |
| 228 resolver.Resolve(pm); | 237 resolver.Resolve(pm); |
| 229 | 238 |
| 230 CHECK(mi1.state() == mi2.state()); | 239 CHECK(mi1.state() == mi2.state()); |
| 231 } | 240 } |
| 232 } | 241 } |
| 233 } | 242 } |
| OLD | NEW |