| 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/compiler-unittests/instruction-selector-unittest.h" | |
| 6 | |
| 7 namespace v8 { | |
| 8 namespace internal { | |
| 9 namespace compiler { | |
| 10 | |
| 11 InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build( | |
| 12 InstructionSelector::Features features, | |
| 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, features); | |
| 21 selector.SelectInstructions(); | |
| 22 if (FLAG_trace_turbo) { | |
| 23 OFStream out(stdout); | |
| 24 out << "--- Code sequence after instruction selection ---" << endl | |
| 25 << sequence; | |
| 26 } | |
| 27 Stream s; | |
| 28 for (InstructionSequence::const_iterator i = sequence.begin(); | |
| 29 i != sequence.end(); ++i) { | |
| 30 Instruction* instr = *i; | |
| 31 if (instr->opcode() < 0) continue; | |
| 32 if (mode == kTargetInstructions) { | |
| 33 switch (instr->arch_opcode()) { | |
| 34 #define CASE(Name) \ | |
| 35 case k##Name: \ | |
| 36 break; | |
| 37 TARGET_ARCH_OPCODE_LIST(CASE) | |
| 38 #undef CASE | |
| 39 default: | |
| 40 continue; | |
| 41 } | |
| 42 } | |
| 43 for (size_t i = 0; i < instr->OutputCount(); ++i) { | |
| 44 InstructionOperand* output = instr->OutputAt(i); | |
| 45 EXPECT_NE(InstructionOperand::IMMEDIATE, output->kind()); | |
| 46 if (output->IsConstant()) { | |
| 47 s.constants_.insert(std::make_pair( | |
| 48 output->index(), sequence.GetConstant(output->index()))); | |
| 49 } | |
| 50 } | |
| 51 for (size_t i = 0; i < instr->InputCount(); ++i) { | |
| 52 InstructionOperand* input = instr->InputAt(i); | |
| 53 EXPECT_NE(InstructionOperand::CONSTANT, input->kind()); | |
| 54 if (input->IsImmediate()) { | |
| 55 s.immediates_.insert(std::make_pair( | |
| 56 input->index(), sequence.GetImmediate(input->index()))); | |
| 57 } | |
| 58 } | |
| 59 s.instructions_.push_back(instr); | |
| 60 } | |
| 61 return s; | |
| 62 } | |
| 63 | |
| 64 | |
| 65 COMPILER_TEST_F(InstructionSelectorTest, ReturnP) { | |
| 66 StreamBuilder m(this, kMachineWord32, kMachineWord32); | |
| 67 m.Return(m.Parameter(0)); | |
| 68 Stream s = m.Build(kAllInstructions); | |
| 69 ASSERT_EQ(2U, s.size()); | |
| 70 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); | |
| 71 ASSERT_EQ(1U, s[0]->OutputCount()); | |
| 72 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); | |
| 73 EXPECT_EQ(1U, s[1]->InputCount()); | |
| 74 } | |
| 75 | |
| 76 | |
| 77 COMPILER_TEST_F(InstructionSelectorTest, ReturnImm) { | |
| 78 StreamBuilder m(this, kMachineWord32); | |
| 79 m.Return(m.Int32Constant(0)); | |
| 80 Stream s = m.Build(kAllInstructions); | |
| 81 ASSERT_EQ(2U, s.size()); | |
| 82 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); | |
| 83 ASSERT_EQ(1U, s[0]->OutputCount()); | |
| 84 EXPECT_EQ(InstructionOperand::CONSTANT, s[0]->OutputAt(0)->kind()); | |
| 85 EXPECT_EQ(0, s.ToInt32(s[0]->OutputAt(0))); | |
| 86 EXPECT_EQ(kArchRet, s[1]->arch_opcode()); | |
| 87 EXPECT_EQ(1U, s[1]->InputCount()); | |
| 88 } | |
| 89 | |
| 90 } // namespace compiler | |
| 91 } // namespace internal | |
| 92 } // namespace v8 | |
| OLD | NEW |