V8 Project
instruction-selector-unittest.h
Go to the documentation of this file.
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
3 // found in the LICENSE file.
4 
5 #ifndef V8_COMPILER_INSTRUCTION_SELECTOR_UNITTEST_H_
6 #define V8_COMPILER_INSTRUCTION_SELECTOR_UNITTEST_H_
7 
8 #include <deque>
9 #include <set>
10 
14 #include "src/test/test-utils.h"
15 
16 namespace v8 {
17 namespace internal {
18 namespace compiler {
19 
21  public:
23  virtual ~InstructionSelectorTest();
24 
25  base::RandomNumberGenerator* rng() { return &rng_; }
26 
27  class Stream;
28 
33  };
34 
35  class StreamBuilder FINAL : public RawMachineAssembler {
36  public:
38  : RawMachineAssembler(new (test->zone()) Graph(test->zone()),
39  MakeMachineSignature(test->zone(), return_type)),
40  test_(test) {}
42  MachineType parameter0_type)
44  new (test->zone()) Graph(test->zone()),
45  MakeMachineSignature(test->zone(), return_type, parameter0_type)),
46  test_(test) {}
48  MachineType parameter0_type, MachineType parameter1_type)
50  new (test->zone()) Graph(test->zone()),
51  MakeMachineSignature(test->zone(), return_type, parameter0_type,
52  parameter1_type)),
53  test_(test) {}
55  MachineType parameter0_type, MachineType parameter1_type,
56  MachineType parameter2_type)
58  new (test->zone()) Graph(test->zone()),
59  MakeMachineSignature(test->zone(), return_type, parameter0_type,
60  parameter1_type, parameter2_type)),
61  test_(test) {}
62 
63  Stream Build(CpuFeature feature) {
64  return Build(InstructionSelector::Features(feature));
65  }
66  Stream Build(CpuFeature feature1, CpuFeature feature2) {
67  return Build(InstructionSelector::Features(feature1, feature2));
68  }
70  return Build(InstructionSelector::Features(), mode);
71  }
72  Stream Build(InstructionSelector::Features features,
74 
75  private:
77  MachineType return_type) {
78  MachineSignature::Builder builder(zone, 1, 0);
79  builder.AddReturn(return_type);
80  return builder.Build();
81  }
82 
84  MachineType parameter0_type) {
85  MachineSignature::Builder builder(zone, 1, 1);
86  builder.AddReturn(return_type);
87  builder.AddParam(parameter0_type);
88  return builder.Build();
89  }
90 
92  MachineType parameter0_type,
93  MachineType parameter1_type) {
94  MachineSignature::Builder builder(zone, 1, 2);
95  builder.AddReturn(return_type);
96  builder.AddParam(parameter0_type);
97  builder.AddParam(parameter1_type);
98  return builder.Build();
99  }
100 
102  MachineType parameter0_type,
103  MachineType parameter1_type,
104  MachineType parameter2_type) {
105  MachineSignature::Builder builder(zone, 1, 3);
106  builder.AddReturn(return_type);
107  builder.AddParam(parameter0_type);
108  builder.AddParam(parameter1_type);
109  builder.AddParam(parameter2_type);
110  return builder.Build();
111  }
112 
113  private:
115  };
116 
117  class Stream FINAL {
118  public:
119  size_t size() const { return instructions_.size(); }
120  const Instruction* operator[](size_t index) const {
121  EXPECT_LT(index, size());
122  return instructions_[index];
123  }
124 
125  bool IsDouble(const InstructionOperand* operand) const {
126  return IsDouble(ToVreg(operand));
127  }
128  bool IsDouble(int virtual_register) const {
129  return doubles_.find(virtual_register) != doubles_.end();
130  }
131 
132  bool IsInteger(const InstructionOperand* operand) const {
133  return IsInteger(ToVreg(operand));
134  }
135  bool IsInteger(int virtual_register) const {
136  return !IsDouble(virtual_register) && !IsReference(virtual_register);
137  }
138 
139  bool IsReference(const InstructionOperand* operand) const {
140  return IsReference(ToVreg(operand));
141  }
142  bool IsReference(int virtual_register) const {
143  return references_.find(virtual_register) != references_.end();
144  }
145 
146  float ToFloat32(const InstructionOperand* operand) const {
147  return ToConstant(operand).ToFloat32();
148  }
149 
150  int32_t ToInt32(const InstructionOperand* operand) const {
151  return ToConstant(operand).ToInt32();
152  }
153 
154  int64_t ToInt64(const InstructionOperand* operand) const {
155  return ToConstant(operand).ToInt64();
156  }
157 
158  int ToVreg(const InstructionOperand* operand) const {
159  if (operand->IsConstant()) return operand->index();
160  EXPECT_EQ(InstructionOperand::UNALLOCATED, operand->kind());
161  return UnallocatedOperand::cast(operand)->virtual_register();
162  }
163 
165  EXPECT_LT(deoptimization_id, GetFrameStateDescriptorCount());
166  return deoptimization_entries_[deoptimization_id];
167  }
168 
170  return static_cast<int>(deoptimization_entries_.size());
171  }
172 
173  private:
174  Constant ToConstant(const InstructionOperand* operand) const {
175  ConstantMap::const_iterator i;
176  if (operand->IsConstant()) {
177  i = constants_.find(operand->index());
178  EXPECT_FALSE(constants_.end() == i);
179  } else {
180  EXPECT_EQ(InstructionOperand::IMMEDIATE, operand->kind());
181  i = immediates_.find(operand->index());
182  EXPECT_FALSE(immediates_.end() == i);
183  }
184  EXPECT_EQ(operand->index(), i->first);
185  return i->second;
186  }
187 
188  friend class StreamBuilder;
189 
190  typedef std::map<int, Constant> ConstantMap;
191 
194  std::deque<Instruction*> instructions_;
195  std::set<int> doubles_;
196  std::set<int> references_;
197  std::deque<FrameStateDescriptor*> deoptimization_entries_;
198  };
199 
200  base::RandomNumberGenerator rng_;
201 };
202 
203 
204 template <typename T>
206  : public InstructionSelectorTest,
207  public ::testing::WithParamInterface<T> {};
208 
209 } // namespace compiler
210 } // namespace internal
211 } // namespace v8
212 
213 #endif // V8_COMPILER_INSTRUCTION_SELECTOR_UNITTEST_H_
Stream Build(StreamBuilderMode mode=kTargetInstructions)
StreamBuilder(InstructionSelectorTest *test, MachineType return_type, MachineType parameter0_type, MachineType parameter1_type, MachineType parameter2_type)
MachineSignature * MakeMachineSignature(Zone *zone, MachineType return_type, MachineType parameter0_type)
int32_t ToInt32(const InstructionOperand *operand) const
MachineSignature * MakeMachineSignature(Zone *zone, MachineType return_type, MachineType parameter0_type, MachineType parameter1_type, MachineType parameter2_type)
MachineSignature * MakeMachineSignature(Zone *zone, MachineType return_type, MachineType parameter0_type, MachineType parameter1_type)
FrameStateDescriptor * GetFrameStateDescriptor(int deoptimization_id)
int64_t ToInt64(const InstructionOperand *operand) const
float ToFloat32(const InstructionOperand *operand) const
MachineSignature * MakeMachineSignature(Zone *zone, MachineType return_type)
StreamBuilder(InstructionSelectorTest *test, MachineType return_type, MachineType parameter0_type, MachineType parameter1_type)
StreamBuilder(InstructionSelectorTest *test, MachineType return_type, MachineType parameter0_type)
Stream Build(InstructionSelector::Features features, StreamBuilderMode mode=kTargetInstructions)
StreamBuilder(InstructionSelectorTest *test, MachineType return_type)
Stream Build(CpuFeature feature1, CpuFeature feature2)
bool IsReference(const InstructionOperand *operand) const
bool IsDouble(const InstructionOperand *operand) const
Constant ToConstant(const InstructionOperand *operand) const
bool IsInteger(const InstructionOperand *operand) const
static const UnallocatedOperand * cast(const InstructionOperand *op)
Definition: instruction.h:160
enable harmony numeric enable harmony object literal extensions Optimize object size
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long mode(MIPS only)") DEFINE_BOOL(enable_always_align_csp
int int32_t
Definition: unicode.cc:24
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20