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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 Register reg = | 179 Register reg = |
180 Register::FromAllocationIndex(RegisterOperand::cast(operand).index()); | 180 Register::FromAllocationIndex(RegisterOperand::cast(operand).index()); |
181 safepoint.DefinePointerRegister(reg, zone()); | 181 safepoint.DefinePointerRegister(reg, zone()); |
182 } | 182 } |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 | 186 |
187 void CodeGenerator::AssembleInstruction(Instruction* instr) { | 187 void CodeGenerator::AssembleInstruction(Instruction* instr) { |
188 AssembleGaps(instr); | 188 AssembleGaps(instr); |
189 if (instr->IsSourcePosition()) { | 189 AssembleSourcePosition(instr); |
190 AssembleSourcePosition(SourcePositionInstruction::cast(instr)); | 190 // Assemble architecture-specific code for the instruction. |
191 } else { | 191 AssembleArchInstruction(instr); |
192 // Assemble architecture-specific code for the instruction. | |
193 AssembleArchInstruction(instr); | |
194 | 192 |
195 FlagsMode mode = FlagsModeField::decode(instr->opcode()); | 193 FlagsMode mode = FlagsModeField::decode(instr->opcode()); |
196 FlagsCondition condition = FlagsConditionField::decode(instr->opcode()); | 194 FlagsCondition condition = FlagsConditionField::decode(instr->opcode()); |
197 if (mode == kFlags_branch) { | 195 if (mode == kFlags_branch) { |
198 // Assemble a branch after this instruction. | 196 // Assemble a branch after this instruction. |
199 InstructionOperandConverter i(this, instr); | 197 InstructionOperandConverter i(this, instr); |
200 RpoNumber true_rpo = i.InputRpo(instr->InputCount() - 2); | 198 RpoNumber true_rpo = i.InputRpo(instr->InputCount() - 2); |
201 RpoNumber false_rpo = i.InputRpo(instr->InputCount() - 1); | 199 RpoNumber false_rpo = i.InputRpo(instr->InputCount() - 1); |
202 | 200 |
203 if (true_rpo == false_rpo) { | 201 if (true_rpo == false_rpo) { |
204 // redundant branch. | 202 // redundant branch. |
205 if (!IsNextInAssemblyOrder(true_rpo)) { | 203 if (!IsNextInAssemblyOrder(true_rpo)) { |
206 AssembleArchJump(true_rpo); | 204 AssembleArchJump(true_rpo); |
207 } | |
208 return; | |
209 } | 205 } |
210 if (IsNextInAssemblyOrder(true_rpo)) { | 206 return; |
211 // true block is next, can fall through if condition negated. | |
212 std::swap(true_rpo, false_rpo); | |
213 condition = NegateFlagsCondition(condition); | |
214 } | |
215 BranchInfo branch; | |
216 branch.condition = condition; | |
217 branch.true_label = GetLabel(true_rpo); | |
218 branch.false_label = GetLabel(false_rpo); | |
219 branch.fallthru = IsNextInAssemblyOrder(false_rpo); | |
220 // Assemble architecture-specific branch. | |
221 AssembleArchBranch(instr, &branch); | |
222 } else if (mode == kFlags_set) { | |
223 // Assemble a boolean materialization after this instruction. | |
224 AssembleArchBoolean(instr, condition); | |
225 } | 207 } |
| 208 if (IsNextInAssemblyOrder(true_rpo)) { |
| 209 // true block is next, can fall through if condition negated. |
| 210 std::swap(true_rpo, false_rpo); |
| 211 condition = NegateFlagsCondition(condition); |
| 212 } |
| 213 BranchInfo branch; |
| 214 branch.condition = condition; |
| 215 branch.true_label = GetLabel(true_rpo); |
| 216 branch.false_label = GetLabel(false_rpo); |
| 217 branch.fallthru = IsNextInAssemblyOrder(false_rpo); |
| 218 // Assemble architecture-specific branch. |
| 219 AssembleArchBranch(instr, &branch); |
| 220 } else if (mode == kFlags_set) { |
| 221 // Assemble a boolean materialization after this instruction. |
| 222 AssembleArchBoolean(instr, condition); |
226 } | 223 } |
227 } | 224 } |
228 | 225 |
229 | 226 |
230 void CodeGenerator::AssembleSourcePosition(SourcePositionInstruction* instr) { | 227 void CodeGenerator::AssembleSourcePosition(Instruction* instr) { |
231 SourcePosition source_position = instr->source_position(); | 228 SourcePosition source_position; |
| 229 if (!code()->GetSourcePosition(instr, &source_position)) return; |
232 if (source_position == current_source_position_) return; | 230 if (source_position == current_source_position_) return; |
233 DCHECK(!source_position.IsInvalid()); | 231 DCHECK(!source_position.IsInvalid()); |
234 if (!source_position.IsUnknown()) { | 232 current_source_position_ = source_position; |
235 int code_pos = source_position.raw(); | 233 if (source_position.IsUnknown()) return; |
236 masm()->positions_recorder()->RecordPosition(source_position.raw()); | 234 int code_pos = source_position.raw(); |
237 masm()->positions_recorder()->WriteRecordedPositions(); | 235 masm()->positions_recorder()->RecordPosition(source_position.raw()); |
238 if (FLAG_code_comments) { | 236 masm()->positions_recorder()->WriteRecordedPositions(); |
239 Vector<char> buffer = Vector<char>::New(256); | 237 if (FLAG_code_comments) { |
240 CompilationInfo* info = this->info(); | 238 Vector<char> buffer = Vector<char>::New(256); |
241 int ln = Script::GetLineNumber(info->script(), code_pos); | 239 CompilationInfo* info = this->info(); |
242 int cn = Script::GetColumnNumber(info->script(), code_pos); | 240 int ln = Script::GetLineNumber(info->script(), code_pos); |
243 if (info->script()->name()->IsString()) { | 241 int cn = Script::GetColumnNumber(info->script(), code_pos); |
244 Handle<String> file(String::cast(info->script()->name())); | 242 if (info->script()->name()->IsString()) { |
245 base::OS::SNPrintF(buffer.start(), buffer.length(), "-- %s:%d:%d --", | 243 Handle<String> file(String::cast(info->script()->name())); |
246 file->ToCString().get(), ln, cn); | 244 base::OS::SNPrintF(buffer.start(), buffer.length(), "-- %s:%d:%d --", |
247 } else { | 245 file->ToCString().get(), ln, cn); |
248 base::OS::SNPrintF(buffer.start(), buffer.length(), | 246 } else { |
249 "-- <unknown>:%d:%d --", ln, cn); | 247 base::OS::SNPrintF(buffer.start(), buffer.length(), |
250 } | 248 "-- <unknown>:%d:%d --", ln, cn); |
251 masm()->RecordComment(buffer.start()); | |
252 } | 249 } |
| 250 masm()->RecordComment(buffer.start()); |
253 } | 251 } |
254 current_source_position_ = source_position; | |
255 } | 252 } |
256 | 253 |
257 | 254 |
258 void CodeGenerator::AssembleGaps(Instruction* instr) { | 255 void CodeGenerator::AssembleGaps(Instruction* instr) { |
259 for (int i = Instruction::FIRST_GAP_POSITION; | 256 for (int i = Instruction::FIRST_GAP_POSITION; |
260 i <= Instruction::LAST_GAP_POSITION; i++) { | 257 i <= Instruction::LAST_GAP_POSITION; i++) { |
261 Instruction::GapPosition inner_pos = | 258 Instruction::GapPosition inner_pos = |
262 static_cast<Instruction::GapPosition>(i); | 259 static_cast<Instruction::GapPosition>(i); |
263 ParallelMove* move = instr->GetParallelMove(inner_pos); | 260 ParallelMove* move = instr->GetParallelMove(inner_pos); |
264 if (move != nullptr) resolver()->Resolve(move); | 261 if (move != nullptr) resolver()->Resolve(move); |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 : masm_(gen->masm()), next_(gen->ools_) { | 636 : masm_(gen->masm()), next_(gen->ools_) { |
640 gen->ools_ = this; | 637 gen->ools_ = this; |
641 } | 638 } |
642 | 639 |
643 | 640 |
644 OutOfLineCode::~OutOfLineCode() {} | 641 OutOfLineCode::~OutOfLineCode() {} |
645 | 642 |
646 } // namespace compiler | 643 } // namespace compiler |
647 } // namespace internal | 644 } // namespace internal |
648 } // namespace v8 | 645 } // namespace v8 |
OLD | NEW |