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

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

Issue 505133002: Unit test of instruction selection for calls with deoptimization. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments. Created 6 years, 3 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_COMPILER_UNITTESTS_INSTRUCTION_SELECTOR_UNITTEST_H_ 5 #ifndef V8_COMPILER_UNITTESTS_INSTRUCTION_SELECTOR_UNITTEST_H_
6 #define V8_COMPILER_UNITTESTS_INSTRUCTION_SELECTOR_UNITTEST_H_ 6 #define V8_COMPILER_UNITTESTS_INSTRUCTION_SELECTOR_UNITTEST_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <set> 9 #include <set>
10 10
11 #include "src/base/utils/random-number-generator.h" 11 #include "src/base/utils/random-number-generator.h"
12 #include "src/compiler/instruction-selector.h" 12 #include "src/compiler/instruction-selector.h"
13 #include "src/compiler/raw-machine-assembler.h" 13 #include "src/compiler/raw-machine-assembler.h"
14 #include "test/compiler-unittests/compiler-unittests.h" 14 #include "test/compiler-unittests/compiler-unittests.h"
15 15
16 namespace v8 { 16 namespace v8 {
17 namespace internal { 17 namespace internal {
18 namespace compiler { 18 namespace compiler {
19 19
20 class InstructionSelectorTest : public CompilerTest { 20 class InstructionSelectorTest : public CompilerTest {
21 public: 21 public:
22 InstructionSelectorTest(); 22 InstructionSelectorTest();
23 virtual ~InstructionSelectorTest() {} 23 virtual ~InstructionSelectorTest() {}
24 24
25 base::RandomNumberGenerator* rng() { return &rng_; } 25 base::RandomNumberGenerator* rng() { return &rng_; }
26 26
27 class Stream; 27 class Stream;
28 28
29 enum StreamBuilderMode { kAllInstructions, kTargetInstructions }; 29 enum StreamBuilderMode {
30 kAllInstructions,
31 kTargetInstructions,
32 kAllExceptNopInstructions
33 };
30 34
31 class StreamBuilder V8_FINAL : public RawMachineAssembler { 35 class StreamBuilder V8_FINAL : public RawMachineAssembler {
32 public: 36 public:
33 StreamBuilder(InstructionSelectorTest* test, MachineType return_type) 37 StreamBuilder(InstructionSelectorTest* test, MachineType return_type)
34 : RawMachineAssembler(new (test->zone()) Graph(test->zone()), 38 : RawMachineAssembler(new (test->zone()) Graph(test->zone()),
35 CallDescriptorBuilder(test->zone(), return_type)), 39 CallDescriptorBuilder(test->zone(), return_type)),
36 test_(test) {} 40 test_(test) {}
37 StreamBuilder(InstructionSelectorTest* test, MachineType return_type, 41 StreamBuilder(InstructionSelectorTest* test, MachineType return_type,
38 MachineType parameter0_type) 42 MachineType parameter0_type)
39 : RawMachineAssembler(new (test->zone()) Graph(test->zone()), 43 : RawMachineAssembler(new (test->zone()) Graph(test->zone()),
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 int32_t ToInt32(const InstructionOperand* operand) const { 143 int32_t ToInt32(const InstructionOperand* operand) const {
140 return ToConstant(operand).ToInt32(); 144 return ToConstant(operand).ToInt32();
141 } 145 }
142 146
143 int ToVreg(const InstructionOperand* operand) const { 147 int ToVreg(const InstructionOperand* operand) const {
144 if (operand->IsConstant()) return operand->index(); 148 if (operand->IsConstant()) return operand->index();
145 EXPECT_EQ(InstructionOperand::UNALLOCATED, operand->kind()); 149 EXPECT_EQ(InstructionOperand::UNALLOCATED, operand->kind());
146 return UnallocatedOperand::cast(operand)->virtual_register(); 150 return UnallocatedOperand::cast(operand)->virtual_register();
147 } 151 }
148 152
153 FrameStateDescriptor* GetDeoptimizationEntry(int deoptimization_id) {
154 EXPECT_LT(deoptimization_id, GetDeoptimizationEntryCount());
155 return deoptimization_entries_[deoptimization_id];
156 }
157
158 int GetDeoptimizationEntryCount() {
159 return static_cast<int>(deoptimization_entries_.size());
160 }
161
149 private: 162 private:
150 Constant ToConstant(const InstructionOperand* operand) const { 163 Constant ToConstant(const InstructionOperand* operand) const {
151 ConstantMap::const_iterator i; 164 ConstantMap::const_iterator i;
152 if (operand->IsConstant()) { 165 if (operand->IsConstant()) {
153 i = constants_.find(operand->index()); 166 i = constants_.find(operand->index());
154 EXPECT_FALSE(constants_.end() == i); 167 EXPECT_FALSE(constants_.end() == i);
155 } else { 168 } else {
156 EXPECT_EQ(InstructionOperand::IMMEDIATE, operand->kind()); 169 EXPECT_EQ(InstructionOperand::IMMEDIATE, operand->kind());
157 i = immediates_.find(operand->index()); 170 i = immediates_.find(operand->index());
158 EXPECT_FALSE(immediates_.end() == i); 171 EXPECT_FALSE(immediates_.end() == i);
159 } 172 }
160 EXPECT_EQ(operand->index(), i->first); 173 EXPECT_EQ(operand->index(), i->first);
161 return i->second; 174 return i->second;
162 } 175 }
163 176
164 friend class StreamBuilder; 177 friend class StreamBuilder;
165 178
166 typedef std::map<int, Constant> ConstantMap; 179 typedef std::map<int, Constant> ConstantMap;
167 180
168 ConstantMap constants_; 181 ConstantMap constants_;
169 ConstantMap immediates_; 182 ConstantMap immediates_;
170 std::deque<Instruction*> instructions_; 183 std::deque<Instruction*> instructions_;
171 std::set<int> doubles_; 184 std::set<int> doubles_;
172 std::set<int> references_; 185 std::set<int> references_;
186 std::deque<FrameStateDescriptor*> deoptimization_entries_;
173 }; 187 };
174 188
175 base::RandomNumberGenerator rng_; 189 base::RandomNumberGenerator rng_;
176 }; 190 };
177 191
178 192
179 template <typename T> 193 template <typename T>
180 class InstructionSelectorTestWithParam 194 class InstructionSelectorTestWithParam
181 : public InstructionSelectorTest, 195 : public InstructionSelectorTest,
182 public ::testing::WithParamInterface<T> {}; 196 public ::testing::WithParamInterface<T> {};
183 197
184 } // namespace compiler 198 } // namespace compiler
185 } // namespace internal 199 } // namespace internal
186 } // namespace v8 200 } // namespace v8
187 201
188 #endif // V8_COMPILER_UNITTESTS_INSTRUCTION_SELECTOR_UNITTEST_H_ 202 #endif // V8_COMPILER_UNITTESTS_INSTRUCTION_SELECTOR_UNITTEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698