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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 Key key = {is_constant, kind, index}; | 82 Key key = {is_constant, kind, index}; |
83 return key; | 83 return key; |
84 } | 84 } |
85 | 85 |
86 static Value ValueFor(const InstructionOperand& op) { return KeyFor(op); } | 86 static Value ValueFor(const InstructionOperand& op) { return KeyFor(op); } |
87 | 87 |
88 static InstructionOperand FromKey(Key key) { | 88 static InstructionOperand FromKey(Key key) { |
89 if (key.is_constant) { | 89 if (key.is_constant) { |
90 return ConstantOperand(key.index); | 90 return ConstantOperand(key.index); |
91 } | 91 } |
92 return AllocatedOperand( | 92 return AllocatedOperand(key.kind, key.index); |
93 key.kind, InstructionSequence::DefaultRepresentation(), key.index); | |
94 } | 93 } |
95 | 94 |
96 friend std::ostream& operator<<(std::ostream& os, | 95 friend std::ostream& operator<<(std::ostream& os, |
97 const InterpreterState& is) { | 96 const InterpreterState& is) { |
98 for (OperandMap::const_iterator it = is.values_.begin(); | 97 for (OperandMap::const_iterator it = is.values_.begin(); |
99 it != is.values_.end(); ++it) { | 98 it != is.values_.end(); ++it) { |
100 if (it != is.values_.begin()) os << " "; | 99 if (it != is.values_.begin()) os << " "; |
101 InstructionOperand source = FromKey(it->first); | 100 InstructionOperand source = FromKey(it->first); |
102 InstructionOperand destination = FromKey(it->second); | 101 InstructionOperand destination = FromKey(it->second); |
103 MoveOperands mo(source, destination); | 102 MoveOperands mo(source, destination); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 InterpreterState state_; | 141 InterpreterState state_; |
143 }; | 142 }; |
144 | 143 |
145 | 144 |
146 class ParallelMoveCreator : public HandleAndZoneScope { | 145 class ParallelMoveCreator : public HandleAndZoneScope { |
147 public: | 146 public: |
148 ParallelMoveCreator() : rng_(CcTest::random_number_generator()) {} | 147 ParallelMoveCreator() : rng_(CcTest::random_number_generator()) {} |
149 | 148 |
150 ParallelMove* Create(int size) { | 149 ParallelMove* Create(int size) { |
151 ParallelMove* parallel_move = new (main_zone()) ParallelMove(main_zone()); | 150 ParallelMove* parallel_move = new (main_zone()) ParallelMove(main_zone()); |
152 std::set<InstructionOperand, CompareOperandModuloType> seen; | 151 std::set<InstructionOperand> seen; |
153 for (int i = 0; i < size; ++i) { | 152 for (int i = 0; i < size; ++i) { |
154 MoveOperands mo(CreateRandomOperand(true), CreateRandomOperand(false)); | 153 MoveOperands mo(CreateRandomOperand(true), CreateRandomOperand(false)); |
155 if (!mo.IsRedundant() && seen.find(mo.destination()) == seen.end()) { | 154 if (!mo.IsRedundant() && seen.find(mo.destination()) == seen.end()) { |
156 parallel_move->AddMove(mo.source(), mo.destination()); | 155 parallel_move->AddMove(mo.source(), mo.destination()); |
157 seen.insert(mo.destination()); | 156 seen.insert(mo.destination()); |
158 } | 157 } |
159 } | 158 } |
160 return parallel_move; | 159 return parallel_move; |
161 } | 160 } |
162 | 161 |
163 private: | 162 private: |
164 MachineType RandomType() { | |
165 int index = rng_->NextInt(3); | |
166 switch (index) { | |
167 case 0: | |
168 return kRepWord32; | |
169 case 1: | |
170 return kRepWord64; | |
171 case 2: | |
172 return kRepTagged; | |
173 } | |
174 UNREACHABLE(); | |
175 return kMachNone; | |
176 } | |
177 | |
178 MachineType RandomDoubleType() { | |
179 int index = rng_->NextInt(2); | |
180 if (index == 0) return kRepFloat64; | |
181 return kRepFloat32; | |
182 } | |
183 | |
184 InstructionOperand CreateRandomOperand(bool is_source) { | 163 InstructionOperand CreateRandomOperand(bool is_source) { |
185 int index = rng_->NextInt(6); | 164 int index = rng_->NextInt(6); |
186 // destination can't be Constant. | 165 // destination can't be Constant. |
187 switch (rng_->NextInt(is_source ? 5 : 4)) { | 166 switch (rng_->NextInt(is_source ? 5 : 4)) { |
188 case 0: | 167 case 0: |
189 return StackSlotOperand(RandomType(), index); | 168 return StackSlotOperand(index); |
190 case 1: | 169 case 1: |
191 return DoubleStackSlotOperand(RandomDoubleType(), index); | 170 return DoubleStackSlotOperand(index); |
192 case 2: | 171 case 2: |
193 return RegisterOperand(RandomType(), index); | 172 return RegisterOperand(index); |
194 case 3: | 173 case 3: |
195 return DoubleRegisterOperand(RandomDoubleType(), index); | 174 return DoubleRegisterOperand(index); |
196 case 4: | 175 case 4: |
197 return ConstantOperand(index); | 176 return ConstantOperand(index); |
198 } | 177 } |
199 UNREACHABLE(); | 178 UNREACHABLE(); |
200 return InstructionOperand(); | 179 return InstructionOperand(); |
201 } | 180 } |
202 | 181 |
203 private: | 182 private: |
204 v8::base::RandomNumberGenerator* rng_; | 183 v8::base::RandomNumberGenerator* rng_; |
205 }; | 184 }; |
(...skipping 10 matching lines...) Expand all Loading... |
216 mi1.AssembleParallelMove(pm); | 195 mi1.AssembleParallelMove(pm); |
217 | 196 |
218 MoveInterpreter mi2(pmc.main_zone()); | 197 MoveInterpreter mi2(pmc.main_zone()); |
219 GapResolver resolver(&mi2); | 198 GapResolver resolver(&mi2); |
220 resolver.Resolve(pm); | 199 resolver.Resolve(pm); |
221 | 200 |
222 CHECK(mi1.state() == mi2.state()); | 201 CHECK(mi1.state() == mi2.state()); |
223 } | 202 } |
224 } | 203 } |
225 } | 204 } |
OLD | NEW |