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

Side by Side Diff: test/unittests/compiler/instruction-selector-unittest.h

Issue 636543002: [turbofan] fix vreg mapping for instruction selector tests (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 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 | Annotate | Revision Log
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 #ifndef V8_UNITTESTS_COMPILER_INSTRUCTION_SELECTOR_UNITTEST_H_ 5 #ifndef V8_UNITTESTS_COMPILER_INSTRUCTION_SELECTOR_UNITTEST_H_
6 #define V8_UNITTESTS_COMPILER_INSTRUCTION_SELECTOR_UNITTEST_H_ 6 #define V8_UNITTESTS_COMPILER_INSTRUCTION_SELECTOR_UNITTEST_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <set> 9 #include <set>
10 10
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 public: 118 public:
119 size_t size() const { return instructions_.size(); } 119 size_t size() const { return instructions_.size(); }
120 const Instruction* operator[](size_t index) const { 120 const Instruction* operator[](size_t index) const {
121 EXPECT_LT(index, size()); 121 EXPECT_LT(index, size());
122 return instructions_[index]; 122 return instructions_[index];
123 } 123 }
124 124
125 bool IsDouble(const InstructionOperand* operand) const { 125 bool IsDouble(const InstructionOperand* operand) const {
126 return IsDouble(ToVreg(operand)); 126 return IsDouble(ToVreg(operand));
127 } 127 }
128 bool IsDouble(int virtual_register) const { 128
129 return doubles_.find(virtual_register) != doubles_.end(); 129 bool IsDouble(const Node* node) const { return IsDouble(ToVreg(node)); }
130 }
131 130
132 bool IsInteger(const InstructionOperand* operand) const { 131 bool IsInteger(const InstructionOperand* operand) const {
133 return IsInteger(ToVreg(operand)); 132 return IsInteger(ToVreg(operand));
134 } 133 }
135 bool IsInteger(int virtual_register) const { 134
136 return !IsDouble(virtual_register) && !IsReference(virtual_register); 135 bool IsInteger(const Node* node) const { return IsInteger(ToVreg(node)); }
137 }
138 136
139 bool IsReference(const InstructionOperand* operand) const { 137 bool IsReference(const InstructionOperand* operand) const {
140 return IsReference(ToVreg(operand)); 138 return IsReference(ToVreg(operand));
141 } 139 }
142 bool IsReference(int virtual_register) const { 140
143 return references_.find(virtual_register) != references_.end(); 141 bool IsReference(const Node* node) const {
142 return IsReference(ToVreg(node));
144 } 143 }
145 144
146 float ToFloat32(const InstructionOperand* operand) const { 145 float ToFloat32(const InstructionOperand* operand) const {
147 return ToConstant(operand).ToFloat32(); 146 return ToConstant(operand).ToFloat32();
148 } 147 }
149 148
150 int32_t ToInt32(const InstructionOperand* operand) const { 149 int32_t ToInt32(const InstructionOperand* operand) const {
151 return ToConstant(operand).ToInt32(); 150 return ToConstant(operand).ToInt32();
152 } 151 }
153 152
154 int64_t ToInt64(const InstructionOperand* operand) const { 153 int64_t ToInt64(const InstructionOperand* operand) const {
155 return ToConstant(operand).ToInt64(); 154 return ToConstant(operand).ToInt64();
156 } 155 }
157 156
158 int ToVreg(const InstructionOperand* operand) const { 157 int ToVreg(const InstructionOperand* operand) const {
159 if (operand->IsConstant()) return operand->index(); 158 if (operand->IsConstant()) return operand->index();
160 EXPECT_EQ(InstructionOperand::UNALLOCATED, operand->kind()); 159 EXPECT_EQ(InstructionOperand::UNALLOCATED, operand->kind());
161 return UnallocatedOperand::cast(operand)->virtual_register(); 160 return UnallocatedOperand::cast(operand)->virtual_register();
162 } 161 }
163 162
163 int ToVreg(const Node* node) const;
164
164 FrameStateDescriptor* GetFrameStateDescriptor(int deoptimization_id) { 165 FrameStateDescriptor* GetFrameStateDescriptor(int deoptimization_id) {
165 EXPECT_LT(deoptimization_id, GetFrameStateDescriptorCount()); 166 EXPECT_LT(deoptimization_id, GetFrameStateDescriptorCount());
166 return deoptimization_entries_[deoptimization_id]; 167 return deoptimization_entries_[deoptimization_id];
167 } 168 }
168 169
169 int GetFrameStateDescriptorCount() { 170 int GetFrameStateDescriptorCount() {
170 return static_cast<int>(deoptimization_entries_.size()); 171 return static_cast<int>(deoptimization_entries_.size());
171 } 172 }
172 173
173 private: 174 private:
175 bool IsDouble(int virtual_register) const {
176 return doubles_.find(virtual_register) != doubles_.end();
177 }
178
179 bool IsInteger(int virtual_register) const {
180 return !IsDouble(virtual_register) && !IsReference(virtual_register);
181 }
182
183 bool IsReference(int virtual_register) const {
184 return references_.find(virtual_register) != references_.end();
185 }
186
174 Constant ToConstant(const InstructionOperand* operand) const { 187 Constant ToConstant(const InstructionOperand* operand) const {
175 ConstantMap::const_iterator i; 188 ConstantMap::const_iterator i;
176 if (operand->IsConstant()) { 189 if (operand->IsConstant()) {
177 i = constants_.find(operand->index()); 190 i = constants_.find(operand->index());
178 EXPECT_FALSE(constants_.end() == i); 191 EXPECT_FALSE(constants_.end() == i);
179 } else { 192 } else {
180 EXPECT_EQ(InstructionOperand::IMMEDIATE, operand->kind()); 193 EXPECT_EQ(InstructionOperand::IMMEDIATE, operand->kind());
181 i = immediates_.find(operand->index()); 194 i = immediates_.find(operand->index());
182 EXPECT_FALSE(immediates_.end() == i); 195 EXPECT_FALSE(immediates_.end() == i);
183 } 196 }
184 EXPECT_EQ(operand->index(), i->first); 197 EXPECT_EQ(operand->index(), i->first);
185 return i->second; 198 return i->second;
186 } 199 }
187 200
188 friend class StreamBuilder; 201 friend class StreamBuilder;
189 202
190 typedef std::map<int, Constant> ConstantMap; 203 typedef std::map<int, Constant> ConstantMap;
204 typedef std::map<NodeId, int> VirtualRegisters;
191 205
192 ConstantMap constants_; 206 ConstantMap constants_;
193 ConstantMap immediates_; 207 ConstantMap immediates_;
194 std::deque<Instruction*> instructions_; 208 std::deque<Instruction*> instructions_;
195 std::set<int> doubles_; 209 std::set<int> doubles_;
196 std::set<int> references_; 210 std::set<int> references_;
211 VirtualRegisters virtual_registers_;
197 std::deque<FrameStateDescriptor*> deoptimization_entries_; 212 std::deque<FrameStateDescriptor*> deoptimization_entries_;
198 }; 213 };
199 214
200 base::RandomNumberGenerator rng_; 215 base::RandomNumberGenerator rng_;
201 }; 216 };
202 217
203 218
204 template <typename T> 219 template <typename T>
205 class InstructionSelectorTestWithParam 220 class InstructionSelectorTestWithParam
206 : public InstructionSelectorTest, 221 : public InstructionSelectorTest,
207 public ::testing::WithParamInterface<T> {}; 222 public ::testing::WithParamInterface<T> {};
208 223
209 } // namespace compiler 224 } // namespace compiler
210 } // namespace internal 225 } // namespace internal
211 } // namespace v8 226 } // namespace v8
212 227
213 #endif // V8_UNITTESTS_COMPILER_INSTRUCTION_SELECTOR_UNITTEST_H_ 228 #endif // V8_UNITTESTS_COMPILER_INSTRUCTION_SELECTOR_UNITTEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698