Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: test/cctest/compiler/test-gap-resolver.cc

Issue 1111323003: Reland: [turbofan] add MachineType to AllocatedOperand (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/register-allocator-verifier.cc ('k') | test/cctest/compiler/test-instruction.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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(key.kind, key.index); 92 return AllocatedOperand(
93 key.kind, InstructionSequence::DefaultRepresentation(), key.index);
93 } 94 }
94 95
95 friend std::ostream& operator<<(std::ostream& os, 96 friend std::ostream& operator<<(std::ostream& os,
96 const InterpreterState& is) { 97 const InterpreterState& is) {
97 for (OperandMap::const_iterator it = is.values_.begin(); 98 for (OperandMap::const_iterator it = is.values_.begin();
98 it != is.values_.end(); ++it) { 99 it != is.values_.end(); ++it) {
99 if (it != is.values_.begin()) os << " "; 100 if (it != is.values_.begin()) os << " ";
100 InstructionOperand source = FromKey(it->first); 101 InstructionOperand source = FromKey(it->first);
101 InstructionOperand destination = FromKey(it->second); 102 InstructionOperand destination = FromKey(it->second);
102 MoveOperands mo(source, destination); 103 MoveOperands mo(source, destination);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 InterpreterState state_; 142 InterpreterState state_;
142 }; 143 };
143 144
144 145
145 class ParallelMoveCreator : public HandleAndZoneScope { 146 class ParallelMoveCreator : public HandleAndZoneScope {
146 public: 147 public:
147 ParallelMoveCreator() : rng_(CcTest::random_number_generator()) {} 148 ParallelMoveCreator() : rng_(CcTest::random_number_generator()) {}
148 149
149 ParallelMove* Create(int size) { 150 ParallelMove* Create(int size) {
150 ParallelMove* parallel_move = new (main_zone()) ParallelMove(main_zone()); 151 ParallelMove* parallel_move = new (main_zone()) ParallelMove(main_zone());
151 std::set<InstructionOperand> seen; 152 std::set<InstructionOperand, CompareOperandModuloType> seen;
152 for (int i = 0; i < size; ++i) { 153 for (int i = 0; i < size; ++i) {
153 MoveOperands mo(CreateRandomOperand(true), CreateRandomOperand(false)); 154 MoveOperands mo(CreateRandomOperand(true), CreateRandomOperand(false));
154 if (!mo.IsRedundant() && seen.find(mo.destination()) == seen.end()) { 155 if (!mo.IsRedundant() && seen.find(mo.destination()) == seen.end()) {
155 parallel_move->AddMove(mo.source(), mo.destination()); 156 parallel_move->AddMove(mo.source(), mo.destination());
156 seen.insert(mo.destination()); 157 seen.insert(mo.destination());
157 } 158 }
158 } 159 }
159 return parallel_move; 160 return parallel_move;
160 } 161 }
161 162
162 private: 163 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
163 InstructionOperand CreateRandomOperand(bool is_source) { 184 InstructionOperand CreateRandomOperand(bool is_source) {
164 int index = rng_->NextInt(6); 185 int index = rng_->NextInt(6);
165 // destination can't be Constant. 186 // destination can't be Constant.
166 switch (rng_->NextInt(is_source ? 5 : 4)) { 187 switch (rng_->NextInt(is_source ? 5 : 4)) {
167 case 0: 188 case 0:
168 return StackSlotOperand(index); 189 return StackSlotOperand(RandomType(), index);
169 case 1: 190 case 1:
170 return DoubleStackSlotOperand(index); 191 return DoubleStackSlotOperand(RandomDoubleType(), index);
171 case 2: 192 case 2:
172 return RegisterOperand(index); 193 return RegisterOperand(RandomType(), index);
173 case 3: 194 case 3:
174 return DoubleRegisterOperand(index); 195 return DoubleRegisterOperand(RandomDoubleType(), index);
175 case 4: 196 case 4:
176 return ConstantOperand(index); 197 return ConstantOperand(index);
177 } 198 }
178 UNREACHABLE(); 199 UNREACHABLE();
179 return InstructionOperand(); 200 return InstructionOperand();
180 } 201 }
181 202
182 private: 203 private:
183 v8::base::RandomNumberGenerator* rng_; 204 v8::base::RandomNumberGenerator* rng_;
184 }; 205 };
(...skipping 10 matching lines...) Expand all
195 mi1.AssembleParallelMove(pm); 216 mi1.AssembleParallelMove(pm);
196 217
197 MoveInterpreter mi2(pmc.main_zone()); 218 MoveInterpreter mi2(pmc.main_zone());
198 GapResolver resolver(&mi2); 219 GapResolver resolver(&mi2);
199 resolver.Resolve(pm); 220 resolver.Resolve(pm);
200 221
201 CHECK(mi1.state() == mi2.state()); 222 CHECK(mi1.state() == mi2.state());
202 } 223 }
203 } 224 }
204 } 225 }
OLDNEW
« no previous file with comments | « src/compiler/register-allocator-verifier.cc ('k') | test/cctest/compiler/test-instruction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698