OLD | NEW |
(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 #include "test/unittests/compiler/test-instruction-selector.h" |
| 6 #include "test/unittests/unittests.h" |
| 7 |
| 8 namespace v8 { |
| 9 namespace internal { |
| 10 namespace compiler { |
| 11 |
| 12 InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build( |
| 13 InstructionSelectorTest::StreamBuilderMode mode) { |
| 14 Schedule* schedule = Export(); |
| 15 EXPECT_NE(0, graph()->NodeCount()); |
| 16 CompilationInfo info(test_->isolate(), test_->zone()); |
| 17 Linkage linkage(&info, call_descriptor()); |
| 18 InstructionSequence sequence(&linkage, graph(), schedule); |
| 19 SourcePositionTable source_position_table(graph()); |
| 20 InstructionSelector selector(&sequence, &source_position_table); |
| 21 selector.SelectInstructions(); |
| 22 OFStream out(stdout); |
| 23 out << "--- Code sequence after instruction selection ---" << endl |
| 24 << sequence; |
| 25 Stream s; |
| 26 for (InstructionSequence::const_iterator i = sequence.begin(); |
| 27 i != sequence.end(); ++i) { |
| 28 Instruction* instr = *i; |
| 29 if (instr->opcode() < 0) continue; |
| 30 if (mode == kTargetInstructions) { |
| 31 switch (instr->arch_opcode()) { |
| 32 #define CASE(Name) \ |
| 33 case k##Name: \ |
| 34 break; |
| 35 TARGET_ARCH_OPCODE_LIST(CASE) |
| 36 #undef CASE |
| 37 default: |
| 38 continue; |
| 39 } |
| 40 } |
| 41 for (size_t i = 0; i < instr->OutputCount(); ++i) { |
| 42 InstructionOperand* output = instr->OutputAt(i); |
| 43 EXPECT_NE(InstructionOperand::IMMEDIATE, output->kind()); |
| 44 if (output->IsConstant()) { |
| 45 s.constants_.insert(std::make_pair( |
| 46 output->index(), sequence.GetConstant(output->index()))); |
| 47 } |
| 48 } |
| 49 for (size_t i = 0; i < instr->InputCount(); ++i) { |
| 50 InstructionOperand* input = instr->InputAt(i); |
| 51 EXPECT_NE(InstructionOperand::CONSTANT, input->kind()); |
| 52 if (input->IsImmediate()) { |
| 53 s.immediates_.insert(std::make_pair( |
| 54 input->index(), sequence.GetImmediate(input->index()))); |
| 55 } |
| 56 } |
| 57 s.instructions_.push_back(instr); |
| 58 } |
| 59 return s; |
| 60 } |
| 61 |
| 62 |
| 63 COMPILER_TEST_F(InstructionSelectorTest, ReturnZero) { |
| 64 StreamBuilder m(this, kMachineWord32); |
| 65 m.Return(m.Int32Constant(0)); |
| 66 Stream s = m.Build(kAllInstructions); |
| 67 ASSERT_EQ(2U, s.size()); |
| 68 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); |
| 69 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 70 EXPECT_EQ(InstructionOperand::CONSTANT, s[0]->OutputAt(0)->kind()); |
| 71 EXPECT_EQ(0, s.ToInt32(s[0]->OutputAt(0))); |
| 72 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); |
| 73 EXPECT_EQ(1U, s[1]->InputCount()); |
| 74 } |
| 75 |
| 76 } // namespace compiler |
| 77 } // namespace internal |
| 78 } // namespace v8 |
OLD | NEW |