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

Side by Side Diff: test/cctest/compiler/compiler/instruction-selector-tester.h

Issue 426233002: Land the Fan (disabled) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review feedback, rebase and "git cl format" Created 6 years, 4 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
(Empty)
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_CCTEST_COMPILER_INSTRUCTION_SELECTOR_TEST_H_
6 #define V8_CCTEST_COMPILER_INSTRUCTION_SELECTOR_TEST_H_
7
8 #include <deque>
9 #include <set>
10
11 #include "src/compiler/instruction-selector.h"
12 #include "src/compiler/raw-machine-assembler.h"
13 #include "src/ostreams.h"
14 #include "test/cctest/cctest.h"
15
16 namespace v8 {
17 namespace internal {
18 namespace compiler {
19
20 typedef std::set<int> VirtualRegisterSet;
21
22 enum InstructionSelectorTesterMode { kTargetMode, kInternalMode };
23
24 class InstructionSelectorTester : public HandleAndZoneScope,
25 public RawMachineAssembler {
26 public:
27 enum Mode { kTargetMode, kInternalMode };
28
29 static const int kParameterCount = 3;
30 static MachineRepresentation* BuildParameterArray(Zone* zone) {
31 MachineRepresentation* array =
32 zone->NewArray<MachineRepresentation>(kParameterCount);
33 for (int i = 0; i < kParameterCount; ++i) {
34 array[i] = kMachineWord32;
35 }
36 return array;
37 }
38
39 explicit InstructionSelectorTester(Mode mode = kTargetMode)
40 : RawMachineAssembler(
41 new (main_zone()) Graph(main_zone()), new (main_zone())
42 MachineCallDescriptorBuilder(kMachineWord32, kParameterCount,
43 BuildParameterArray(main_zone())),
44 MachineOperatorBuilder::pointer_rep()),
45 mode_(mode) {}
46
47 void SelectInstructions() {
48 OFStream out(stdout);
49 Schedule* schedule = Export();
50 CHECK_NE(0, graph()->NodeCount());
51 CompilationInfo info(main_isolate(), main_zone());
52 Linkage linkage(&info, call_descriptor());
53 InstructionSequence sequence(&linkage, graph(), schedule);
54 SourcePositionTable source_positions(graph());
55 InstructionSelector selector(&sequence, &source_positions);
56 selector.SelectInstructions();
57 out << "--- Code sequence after instruction selection --- " << endl
58 << sequence;
59 for (InstructionSequence::const_iterator i = sequence.begin();
60 i != sequence.end(); ++i) {
61 Instruction* instr = *i;
62 if (instr->opcode() < 0) continue;
63 if (mode_ == kTargetMode) {
64 switch (ArchOpcodeField::decode(instr->opcode())) {
65 #define CASE(Name) \
66 case k##Name: \
67 break;
68 TARGET_ARCH_OPCODE_LIST(CASE)
69 #undef CASE
70 default:
71 continue;
72 }
73 }
74 code.push_back(instr);
75 }
76 for (int vreg = 0; vreg < sequence.VirtualRegisterCount(); ++vreg) {
77 if (sequence.IsDouble(vreg)) {
78 CHECK(!sequence.IsReference(vreg));
79 doubles.insert(vreg);
80 }
81 if (sequence.IsReference(vreg)) {
82 CHECK(!sequence.IsDouble(vreg));
83 references.insert(vreg);
84 }
85 }
86 immediates.assign(sequence.immediates().begin(),
87 sequence.immediates().end());
88 }
89
90 int32_t ToInt32(const InstructionOperand* operand) const {
91 size_t i = operand->index();
92 CHECK(i < immediates.size());
93 CHECK_EQ(InstructionOperand::IMMEDIATE, operand->kind());
94 return immediates[i].ToInt32();
95 }
96
97 std::deque<Instruction*> code;
98 VirtualRegisterSet doubles;
99 VirtualRegisterSet references;
100 std::deque<Constant> immediates;
101
102 private:
103 Mode mode_;
104 };
105
106
107 static inline void CheckSameVreg(InstructionOperand* exp,
108 InstructionOperand* val) {
109 CHECK_EQ(InstructionOperand::UNALLOCATED, exp->kind());
110 CHECK_EQ(InstructionOperand::UNALLOCATED, val->kind());
111 CHECK_EQ(UnallocatedOperand::cast(exp)->virtual_register(),
112 UnallocatedOperand::cast(val)->virtual_register());
113 }
114
115 } // namespace compiler
116 } // namespace internal
117 } // namespace v8
118
119 #endif // V8_CCTEST_COMPILER_INSTRUCTION_SELECTOR_TEST_H_
OLDNEW
« no previous file with comments | « test/cctest/compiler/compiler/graph-tester.h ('k') | test/cctest/compiler/compiler/simplified-graph-builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698