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 | 25 |
26 bool operator==(const InterpreterState& other) const { | 26 bool operator==(const InterpreterState& other) const { |
27 return values_ == other.values_; | 27 return values_ == other.values_; |
28 } | 28 } |
29 | 29 |
30 bool operator!=(const InterpreterState& other) const { | 30 bool operator!=(const InterpreterState& other) const { |
31 return values_ != other.values_; | 31 return values_ != other.values_; |
32 } | 32 } |
33 | 33 |
34 private: | 34 private: |
| 35 struct Key { |
| 36 bool is_constant; |
| 37 AllocatedOperand::AllocatedKind kind; |
| 38 int index; |
| 39 |
| 40 bool operator<(const Key& other) const { |
| 41 if (this->is_constant != other.is_constant) { |
| 42 return this->is_constant; |
| 43 } |
| 44 if (this->kind != other.kind) { |
| 45 return this->kind < other.kind; |
| 46 } |
| 47 return this->index < other.index; |
| 48 } |
| 49 |
| 50 bool operator==(const Key& other) const { |
| 51 return this->is_constant == other.is_constant && |
| 52 this->kind == other.kind && this->index == other.index; |
| 53 } |
| 54 }; |
| 55 |
35 // Internally, the state is a normalized permutation of (kind,index) pairs. | 56 // Internally, the state is a normalized permutation of (kind,index) pairs. |
36 typedef std::pair<InstructionOperand::Kind, int> Key; | |
37 typedef Key Value; | 57 typedef Key Value; |
38 typedef std::map<Key, Value> OperandMap; | 58 typedef std::map<Key, Value> OperandMap; |
39 | 59 |
40 Value read(const InstructionOperand* op) const { | 60 Value read(const InstructionOperand* op) const { |
41 OperandMap::const_iterator it = values_.find(KeyFor(op)); | 61 OperandMap::const_iterator it = values_.find(KeyFor(op)); |
42 return (it == values_.end()) ? ValueFor(op) : it->second; | 62 return (it == values_.end()) ? ValueFor(op) : it->second; |
43 } | 63 } |
44 | 64 |
45 void write(const InstructionOperand* op, Value v) { | 65 void write(const InstructionOperand* op, Value v) { |
46 if (v == ValueFor(op)) { | 66 if (v == ValueFor(op)) { |
47 values_.erase(KeyFor(op)); | 67 values_.erase(KeyFor(op)); |
48 } else { | 68 } else { |
49 values_[KeyFor(op)] = v; | 69 values_[KeyFor(op)] = v; |
50 } | 70 } |
51 } | 71 } |
52 | 72 |
53 static Key KeyFor(const InstructionOperand* op) { | 73 static Key KeyFor(const InstructionOperand* op) { |
54 int v = op->IsConstant() ? ConstantOperand::cast(op)->virtual_register() | 74 bool is_constant = op->IsConstant(); |
55 : AllocatedOperand::cast(op)->index(); | 75 AllocatedOperand::AllocatedKind kind; |
56 return Key(op->kind(), v); | 76 int index; |
| 77 if (!is_constant) { |
| 78 index = AllocatedOperand::cast(op)->index(); |
| 79 kind = AllocatedOperand::cast(op)->allocated_kind(); |
| 80 } else { |
| 81 index = ConstantOperand::cast(op)->virtual_register(); |
| 82 kind = AllocatedOperand::REGISTER; |
| 83 } |
| 84 Key key = {is_constant, kind, index}; |
| 85 return key; |
57 } | 86 } |
58 | 87 |
59 static Value ValueFor(const InstructionOperand* op) { | 88 static Value ValueFor(const InstructionOperand* op) { return KeyFor(op); } |
60 int v = op->IsConstant() ? ConstantOperand::cast(op)->virtual_register() | |
61 : AllocatedOperand::cast(op)->index(); | |
62 return Value(op->kind(), v); | |
63 } | |
64 | 89 |
65 static InstructionOperand FromKey(Key key) { | 90 static InstructionOperand FromKey(Key key) { |
66 if (key.first == InstructionOperand::CONSTANT) { | 91 if (key.is_constant) { |
67 return ConstantOperand(key.second); | 92 return ConstantOperand(key.index); |
68 } | 93 } |
69 return AllocatedOperand(key.first, key.second); | 94 return AllocatedOperand(key.kind, key.index); |
70 } | 95 } |
71 | 96 |
72 friend std::ostream& operator<<(std::ostream& os, | 97 friend std::ostream& operator<<(std::ostream& os, |
73 const InterpreterState& is) { | 98 const InterpreterState& is) { |
74 for (OperandMap::const_iterator it = is.values_.begin(); | 99 for (OperandMap::const_iterator it = is.values_.begin(); |
75 it != is.values_.end(); ++it) { | 100 it != is.values_.end(); ++it) { |
76 if (it != is.values_.begin()) os << " "; | 101 if (it != is.values_.begin()) os << " "; |
77 InstructionOperand source = FromKey(it->first); | 102 InstructionOperand source = FromKey(it->first); |
78 InstructionOperand destination = FromKey(it->second); | 103 InstructionOperand destination = FromKey(it->second); |
79 MoveOperands mo(&source, &destination); | 104 MoveOperands mo(&source, &destination); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 mi1.AssembleParallelMove(pm); | 203 mi1.AssembleParallelMove(pm); |
179 | 204 |
180 MoveInterpreter mi2; | 205 MoveInterpreter mi2; |
181 GapResolver resolver(&mi2); | 206 GapResolver resolver(&mi2); |
182 resolver.Resolve(pm); | 207 resolver.Resolve(pm); |
183 | 208 |
184 CHECK(mi1.state() == mi2.state()); | 209 CHECK(mi1.state() == mi2.state()); |
185 } | 210 } |
186 } | 211 } |
187 } | 212 } |
OLD | NEW |