OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 #include "src/compiler/code-generator.h" | 5 #include "src/compiler/code-generator.h" |
6 | 6 |
7 #include "src/compiler/code-generator-impl.h" | 7 #include "src/compiler/code-generator-impl.h" |
8 #include "src/compiler/linkage.h" | 8 #include "src/compiler/linkage.h" |
9 #include "src/compiler/pipeline.h" | 9 #include "src/compiler/pipeline.h" |
10 | 10 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 void CodeGenerator::AssembleInstruction(Instruction* instr) { | 132 void CodeGenerator::AssembleInstruction(Instruction* instr) { |
133 if (instr->IsGapMoves()) { | 133 if (instr->IsGapMoves()) { |
134 // Handle parallel moves associated with the gap instruction. | 134 // Handle parallel moves associated with the gap instruction. |
135 AssembleGap(GapInstruction::cast(instr)); | 135 AssembleGap(GapInstruction::cast(instr)); |
136 } else if (instr->IsSourcePosition()) { | 136 } else if (instr->IsSourcePosition()) { |
137 AssembleSourcePosition(SourcePositionInstruction::cast(instr)); | 137 AssembleSourcePosition(SourcePositionInstruction::cast(instr)); |
138 } else { | 138 } else { |
139 // Assemble architecture-specific code for the instruction. | 139 // Assemble architecture-specific code for the instruction. |
140 AssembleArchInstruction(instr); | 140 AssembleArchInstruction(instr); |
141 | 141 |
142 // Assemble branches or boolean materializations after this instruction. | |
143 FlagsMode mode = FlagsModeField::decode(instr->opcode()); | 142 FlagsMode mode = FlagsModeField::decode(instr->opcode()); |
144 FlagsCondition condition = FlagsConditionField::decode(instr->opcode()); | 143 FlagsCondition condition = FlagsConditionField::decode(instr->opcode()); |
145 switch (mode) { | 144 if (mode == kFlags_branch) { |
146 case kFlags_none: | 145 // Assemble a branch after this instruction. |
| 146 InstructionOperandConverter i(this, instr); |
| 147 BasicBlock::RpoNumber true_rpo = |
| 148 i.InputRpo(static_cast<int>(instr->InputCount()) - 2); |
| 149 BasicBlock::RpoNumber false_rpo = |
| 150 i.InputRpo(static_cast<int>(instr->InputCount()) - 1); |
| 151 |
| 152 if (true_rpo == false_rpo) { |
| 153 // redundant branch. |
| 154 if (!IsNextInAssemblyOrder(true_rpo)) { |
| 155 AssembleArchJump(true_rpo); |
| 156 } |
147 return; | 157 return; |
148 case kFlags_set: | 158 } |
149 return AssembleArchBoolean(instr, condition); | 159 if (IsNextInAssemblyOrder(true_rpo)) { |
150 case kFlags_branch: | 160 // true block is next, can fall through if condition negated. |
151 return AssembleArchBranch(instr, condition); | 161 std::swap(true_rpo, false_rpo); |
| 162 condition = NegateFlagsCondition(condition); |
| 163 } |
| 164 BranchInfo branch; |
| 165 branch.condition = condition; |
| 166 branch.true_label = GetLabel(true_rpo); |
| 167 branch.false_label = GetLabel(false_rpo); |
| 168 branch.fallthru = IsNextInAssemblyOrder(false_rpo); |
| 169 // Assemble architecture-specific branch. |
| 170 AssembleArchBranch(instr, &branch); |
| 171 } else if (mode == kFlags_set) { |
| 172 // Assemble a boolean materialization after this instruction. |
| 173 AssembleArchBoolean(instr, condition); |
152 } | 174 } |
153 UNREACHABLE(); | |
154 } | 175 } |
155 } | 176 } |
156 | 177 |
157 | 178 |
158 void CodeGenerator::AssembleSourcePosition(SourcePositionInstruction* instr) { | 179 void CodeGenerator::AssembleSourcePosition(SourcePositionInstruction* instr) { |
159 SourcePosition source_position = instr->source_position(); | 180 SourcePosition source_position = instr->source_position(); |
160 if (source_position == current_source_position_) return; | 181 if (source_position == current_source_position_) return; |
161 DCHECK(!source_position.IsInvalid()); | 182 DCHECK(!source_position.IsInvalid()); |
162 if (!source_position.IsUnknown()) { | 183 if (!source_position.IsUnknown()) { |
163 int code_pos = source_position.raw(); | 184 int code_pos = source_position.raw(); |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 } | 546 } |
526 | 547 |
527 | 548 |
528 void CodeGenerator::AddNopForSmiCodeInlining() { UNIMPLEMENTED(); } | 549 void CodeGenerator::AddNopForSmiCodeInlining() { UNIMPLEMENTED(); } |
529 | 550 |
530 #endif // !V8_TURBOFAN_BACKEND | 551 #endif // !V8_TURBOFAN_BACKEND |
531 | 552 |
532 } // namespace compiler | 553 } // namespace compiler |
533 } // namespace internal | 554 } // namespace internal |
534 } // namespace v8 | 555 } // namespace v8 |
OLD | NEW |