| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM. |
| 6 #if defined(TARGET_ARCH_ARM) | 6 #if defined(TARGET_ARCH_ARM) |
| 7 | 7 |
| 8 #include "vm/flow_graph_compiler.h" | 8 #include "vm/flow_graph_compiler.h" |
| 9 | 9 |
| 10 #include "vm/longjump.h" | 10 #include "lib/error.h" |
| 11 #include "vm/ast_printer.h" |
| 12 #include "vm/dart_entry.h" |
| 13 #include "vm/il_printer.h" |
| 14 #include "vm/locations.h" |
| 15 #include "vm/object_store.h" |
| 16 #include "vm/parser.h" |
| 17 #include "vm/stub_code.h" |
| 18 #include "vm/symbols.h" |
| 11 | 19 |
| 12 namespace dart { | 20 namespace dart { |
| 13 | 21 |
| 22 DECLARE_FLAG(int, optimization_counter_threshold); |
| 23 DECLARE_FLAG(bool, print_ast); |
| 24 DECLARE_FLAG(bool, print_scopes); |
| 25 DECLARE_FLAG(bool, enable_type_checks); |
| 26 |
| 27 |
| 14 FlowGraphCompiler::~FlowGraphCompiler() { | 28 FlowGraphCompiler::~FlowGraphCompiler() { |
| 15 // BlockInfos are zone-allocated, so their destructors are not called. | 29 // BlockInfos are zone-allocated, so their destructors are not called. |
| 16 // Verify the labels explicitly here. | 30 // Verify the labels explicitly here. |
| 17 for (int i = 0; i < block_info_.length(); ++i) { | 31 for (int i = 0; i < block_info_.length(); ++i) { |
| 18 ASSERT(!block_info_[i]->label.IsLinked()); | 32 ASSERT(!block_info_[i]->label.IsLinked()); |
| 19 } | 33 } |
| 20 } | 34 } |
| 21 | 35 |
| 22 | 36 |
| 23 bool FlowGraphCompiler::SupportsUnboxedMints() { | 37 bool FlowGraphCompiler::SupportsUnboxedMints() { |
| 24 return false; | 38 return false; |
| 25 } | 39 } |
| 26 | 40 |
| 27 | 41 |
| 28 void CompilerDeoptInfoWithStub::GenerateCode(FlowGraphCompiler* compiler, | 42 void CompilerDeoptInfoWithStub::GenerateCode(FlowGraphCompiler* compiler, |
| 29 intptr_t stub_ix) { | 43 intptr_t stub_ix) { |
| 30 UNIMPLEMENTED(); | 44 UNIMPLEMENTED(); |
| 31 } | 45 } |
| 32 | 46 |
| 33 | 47 |
| 48 #define __ assembler()-> |
| 49 |
| 50 |
| 34 void FlowGraphCompiler::GenerateBoolToJump(Register bool_register, | 51 void FlowGraphCompiler::GenerateBoolToJump(Register bool_register, |
| 35 Label* is_true, | 52 Label* is_true, |
| 36 Label* is_false) { | 53 Label* is_false) { |
| 37 UNIMPLEMENTED(); | 54 UNIMPLEMENTED(); |
| 38 } | 55 } |
| 39 | 56 |
| 40 | 57 |
| 41 RawSubtypeTestCache* FlowGraphCompiler::GenerateCallSubtypeTestStub( | 58 RawSubtypeTestCache* FlowGraphCompiler::GenerateCallSubtypeTestStub( |
| 42 TypeTestStubKind test_kind, | 59 TypeTestStubKind test_kind, |
| 43 Register instance_reg, | 60 Register instance_reg, |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 void FlowGraphCompiler::GenerateAssertAssignable(intptr_t token_pos, | 138 void FlowGraphCompiler::GenerateAssertAssignable(intptr_t token_pos, |
| 122 intptr_t deopt_id, | 139 intptr_t deopt_id, |
| 123 const AbstractType& dst_type, | 140 const AbstractType& dst_type, |
| 124 const String& dst_name, | 141 const String& dst_name, |
| 125 LocationSummary* locs) { | 142 LocationSummary* locs) { |
| 126 UNIMPLEMENTED(); | 143 UNIMPLEMENTED(); |
| 127 } | 144 } |
| 128 | 145 |
| 129 | 146 |
| 130 void FlowGraphCompiler::EmitInstructionPrologue(Instruction* instr) { | 147 void FlowGraphCompiler::EmitInstructionPrologue(Instruction* instr) { |
| 131 UNIMPLEMENTED(); | 148 if (!is_optimizing()) { |
| 149 if (FLAG_enable_type_checks && instr->IsAssertAssignable()) { |
| 150 AssertAssignableInstr* assert = instr->AsAssertAssignable(); |
| 151 AddCurrentDescriptor(PcDescriptors::kDeoptBefore, |
| 152 assert->deopt_id(), |
| 153 assert->token_pos()); |
| 154 } |
| 155 AllocateRegistersLocally(instr); |
| 156 } |
| 132 } | 157 } |
| 133 | 158 |
| 134 | 159 |
| 135 void FlowGraphCompiler::EmitInstructionEpilogue(Instruction* instr) { | 160 void FlowGraphCompiler::EmitInstructionEpilogue(Instruction* instr) { |
| 136 UNIMPLEMENTED(); | 161 if (is_optimizing()) return; |
| 162 Definition* defn = instr->AsDefinition(); |
| 163 if ((defn != NULL) && defn->is_used()) { |
| 164 __ Push(defn->locs()->out().reg()); |
| 165 } |
| 137 } | 166 } |
| 138 | 167 |
| 139 | 168 |
| 140 void FlowGraphCompiler::CopyParameters() { | 169 void FlowGraphCompiler::CopyParameters() { |
| 141 UNIMPLEMENTED(); | 170 UNIMPLEMENTED(); |
| 142 } | 171 } |
| 143 | 172 |
| 144 | 173 |
| 145 void FlowGraphCompiler::GenerateInlinedGetter(intptr_t offset) { | 174 void FlowGraphCompiler::GenerateInlinedGetter(intptr_t offset) { |
| 146 UNIMPLEMENTED(); | 175 UNIMPLEMENTED(); |
| 147 } | 176 } |
| 148 | 177 |
| 149 | 178 |
| 150 void FlowGraphCompiler::GenerateInlinedSetter(intptr_t offset) { | 179 void FlowGraphCompiler::GenerateInlinedSetter(intptr_t offset) { |
| 151 UNIMPLEMENTED(); | 180 UNIMPLEMENTED(); |
| 152 } | 181 } |
| 153 | 182 |
| 154 | 183 |
| 155 void FlowGraphCompiler::EmitFrameEntry() { | 184 void FlowGraphCompiler::EmitFrameEntry() { |
| 156 UNIMPLEMENTED(); | 185 const Function& function = parsed_function().function(); |
| 186 if (CanOptimizeFunction() && function.is_optimizable()) { |
| 187 const bool can_optimize = !is_optimizing() || may_reoptimize(); |
| 188 const Register function_reg = R6; |
| 189 if (can_optimize) { |
| 190 __ LoadObject(function_reg, function); |
| 191 } |
| 192 // Patch point is after the eventually inlined function object. |
| 193 AddCurrentDescriptor(PcDescriptors::kEntryPatch, |
| 194 Isolate::kNoDeoptId, |
| 195 0); // No token position. |
| 196 if (can_optimize) { |
| 197 // Reoptimization of optimized function is triggered by counting in |
| 198 // IC stubs, but not at the entry of the function. |
| 199 if (!is_optimizing()) { |
| 200 __ ldr(R7, FieldAddress(function_reg, |
| 201 Function::usage_counter_offset())); |
| 202 __ add(R7, R7, ShifterOperand(1)); |
| 203 __ str(R7, FieldAddress(function_reg, |
| 204 Function::usage_counter_offset())); |
| 205 } else { |
| 206 __ ldr(R7, FieldAddress(function_reg, |
| 207 Function::usage_counter_offset())); |
| 208 } |
| 209 __ CompareImmediate(R7, FLAG_optimization_counter_threshold); |
| 210 ASSERT(function_reg == R6); |
| 211 __ Branch(&StubCode::OptimizeFunctionLabel(), GE); |
| 212 } |
| 213 } else { |
| 214 AddCurrentDescriptor(PcDescriptors::kEntryPatch, |
| 215 Isolate::kNoDeoptId, |
| 216 0); // No token position. |
| 217 } |
| 218 __ Comment("Enter frame"); |
| 219 AssemblerMacros::EnterDartFrame(assembler(), (StackSize() * kWordSize)); |
| 157 } | 220 } |
| 158 | 221 |
| 159 | 222 |
| 160 void FlowGraphCompiler::CompileGraph() { | 223 void FlowGraphCompiler::CompileGraph() { |
| 161 UNIMPLEMENTED(); | 224 InitCompiler(); |
| 225 if (TryIntrinsify()) { |
| 226 // Although this intrinsified code will never be patched, it must satisfy |
| 227 // CodePatcher::CodeIsPatchable, which verifies that this code has a minimum |
| 228 // code size. |
| 229 __ bkpt(0); |
| 230 __ Branch(&StubCode::FixCallersTargetLabel()); |
| 231 return; |
| 232 } |
| 233 |
| 234 EmitFrameEntry(); |
| 235 |
| 236 const Function& function = parsed_function().function(); |
| 237 |
| 238 const int num_fixed_params = function.num_fixed_parameters(); |
| 239 const int num_copied_params = parsed_function().num_copied_params(); |
| 240 const int num_locals = parsed_function().num_stack_locals(); |
| 241 |
| 242 // For optimized code, keep a bitmap of the frame in order to build |
| 243 // stackmaps for GC safepoints in the prologue. |
| 244 LocationSummary* prologue_locs = NULL; |
| 245 if (is_optimizing()) { |
| 246 // Spill slots are allocated but not initialized. |
| 247 prologue_locs = new LocationSummary(0, 0, LocationSummary::kCall); |
| 248 prologue_locs->stack_bitmap()->SetLength(StackSize()); |
| 249 } |
| 250 |
| 251 // We check the number of passed arguments when we have to copy them due to |
| 252 // the presence of optional parameters. |
| 253 // No such checking code is generated if only fixed parameters are declared, |
| 254 // unless we are in debug mode or unless we are compiling a closure. |
| 255 LocalVariable* saved_args_desc_var = |
| 256 parsed_function().GetSavedArgumentsDescriptorVar(); |
| 257 if (num_copied_params == 0) { |
| 258 #ifdef DEBUG |
| 259 ASSERT(!parsed_function().function().HasOptionalParameters()); |
| 260 const bool check_arguments = true; |
| 261 #else |
| 262 const bool check_arguments = function.IsClosureFunction(); |
| 263 #endif |
| 264 if (check_arguments) { |
| 265 __ Comment("Check argument count"); |
| 266 // Check that exactly num_fixed arguments are passed in. |
| 267 Label correct_num_arguments, wrong_num_arguments; |
| 268 __ ldr(R0, FieldAddress(R4, ArgumentsDescriptor::count_offset())); |
| 269 __ CompareImmediate(R0, Smi::RawValue(num_fixed_params)); |
| 270 __ b(&wrong_num_arguments, NE); |
| 271 __ ldr(R1, FieldAddress(R4, |
| 272 ArgumentsDescriptor::positional_count_offset())); |
| 273 __ cmp(R0, ShifterOperand(R1)); |
| 274 __ b(&correct_num_arguments, EQ); |
| 275 __ Bind(&wrong_num_arguments); |
| 276 if (function.IsClosureFunction()) { |
| 277 if (StackSize() != 0) { |
| 278 // We need to unwind the space we reserved for locals and copied |
| 279 // parameters. The NoSuchMethodFunction stub does not expect to see |
| 280 // that area on the stack. |
| 281 __ AddImmediate(SP, StackSize() * kWordSize); |
| 282 } |
| 283 // The call below has an empty stackmap because we have just |
| 284 // dropped the spill slots. |
| 285 BitmapBuilder* empty_stack_bitmap = new BitmapBuilder(); |
| 286 |
| 287 // Invoke noSuchMethod function passing "call" as the function name. |
| 288 const int kNumArgsChecked = 1; |
| 289 const ICData& ic_data = ICData::ZoneHandle( |
| 290 ICData::New(function, Symbols::Call(), |
| 291 Isolate::kNoDeoptId, kNumArgsChecked)); |
| 292 __ LoadObject(R5, ic_data); |
| 293 // FP - 4 : saved PP, object pool pointer of caller. |
| 294 // FP + 0 : previous frame pointer. |
| 295 // FP + 4 : return address. |
| 296 // FP + 8 : PC marker, for easy identification of RawInstruction obj. |
| 297 // FP + 12: last argument (arg n-1). |
| 298 // SP + 0 : saved PP. |
| 299 // SP + 16 + 4*(n-1) : first argument (arg 0). |
| 300 // R5 : ic-data. |
| 301 // R4 : arguments descriptor array. |
| 302 __ BranchLink(&StubCode::CallNoSuchMethodFunctionLabel()); |
| 303 if (is_optimizing()) { |
| 304 stackmap_table_builder_->AddEntry(assembler()->CodeSize(), |
| 305 empty_stack_bitmap, |
| 306 0); // No registers. |
| 307 } |
| 308 // The noSuchMethod call may return. |
| 309 AssemblerMacros::LeaveDartFrame(assembler()); |
| 310 __ Ret(); |
| 311 } else { |
| 312 __ Stop("Wrong number of arguments"); |
| 313 } |
| 314 __ Bind(&correct_num_arguments); |
| 315 } |
| 316 // The arguments descriptor is never saved in the absence of optional |
| 317 // parameters, since any argument definition test would always yield true. |
| 318 ASSERT(saved_args_desc_var == NULL); |
| 319 } else { |
| 320 if (saved_args_desc_var != NULL) { |
| 321 __ Comment("Save arguments descriptor"); |
| 322 const Register kArgumentsDescriptorReg = R4; |
| 323 // The saved_args_desc_var is allocated one slot before the first local. |
| 324 const intptr_t slot = parsed_function().first_stack_local_index() + 1; |
| 325 // If the saved_args_desc_var is captured, it is first moved to the stack |
| 326 // and later to the context, once the context is allocated. |
| 327 ASSERT(saved_args_desc_var->is_captured() || |
| 328 (saved_args_desc_var->index() == slot)); |
| 329 __ str(kArgumentsDescriptorReg, Address(FP, slot * kWordSize)); |
| 330 } |
| 331 CopyParameters(); |
| 332 } |
| 333 |
| 334 // In unoptimized code, initialize (non-argument) stack allocated slots to |
| 335 // null. This does not cover the saved_args_desc_var slot. |
| 336 if (!is_optimizing() && (num_locals > 0)) { |
| 337 __ Comment("Initialize spill slots"); |
| 338 const intptr_t slot_base = parsed_function().first_stack_local_index(); |
| 339 __ LoadImmediate(R0, reinterpret_cast<intptr_t>(Object::null())); |
| 340 for (intptr_t i = 0; i < num_locals; ++i) { |
| 341 // Subtract index i (locals lie at lower addresses than FP). |
| 342 __ str(R0, Address(FP, (slot_base - i) * kWordSize)); |
| 343 } |
| 344 } |
| 345 |
| 346 if (FLAG_print_scopes) { |
| 347 // Print the function scope (again) after generating the prologue in order |
| 348 // to see annotations such as allocation indices of locals. |
| 349 if (FLAG_print_ast) { |
| 350 // Second printing. |
| 351 OS::Print("Annotated "); |
| 352 } |
| 353 AstPrinter::PrintFunctionScope(parsed_function()); |
| 354 } |
| 355 |
| 356 VisitBlocks(); |
| 357 |
| 358 __ bkpt(0); |
| 359 GenerateDeferredCode(); |
| 360 // Emit function patching code. This will be swapped with the first 5 bytes |
| 361 // at entry point. |
| 362 AddCurrentDescriptor(PcDescriptors::kPatchCode, |
| 363 Isolate::kNoDeoptId, |
| 364 0); // No token position. |
| 365 __ Branch(&StubCode::FixCallersTargetLabel()); |
| 366 AddCurrentDescriptor(PcDescriptors::kLazyDeoptJump, |
| 367 Isolate::kNoDeoptId, |
| 368 0); // No token position. |
| 369 __ Branch(&StubCode::DeoptimizeLazyLabel()); |
| 162 } | 370 } |
| 163 | 371 |
| 164 | 372 |
| 165 void FlowGraphCompiler::GenerateCall(intptr_t token_pos, | 373 void FlowGraphCompiler::GenerateCall(intptr_t token_pos, |
| 166 const ExternalLabel* label, | 374 const ExternalLabel* label, |
| 167 PcDescriptors::Kind kind, | 375 PcDescriptors::Kind kind, |
| 168 LocationSummary* locs) { | 376 LocationSummary* locs) { |
| 169 UNIMPLEMENTED(); | 377 UNIMPLEMENTED(); |
| 170 } | 378 } |
| 171 | 379 |
| 172 | 380 |
| 173 void FlowGraphCompiler::GenerateDartCall(intptr_t deopt_id, | 381 void FlowGraphCompiler::GenerateDartCall(intptr_t deopt_id, |
| 174 intptr_t token_pos, | 382 intptr_t token_pos, |
| 175 const ExternalLabel* label, | 383 const ExternalLabel* label, |
| 176 PcDescriptors::Kind kind, | 384 PcDescriptors::Kind kind, |
| 177 LocationSummary* locs) { | 385 LocationSummary* locs) { |
| 178 UNIMPLEMENTED(); | 386 UNIMPLEMENTED(); |
| 179 } | 387 } |
| 180 | 388 |
| 181 | 389 |
| 182 void FlowGraphCompiler::GenerateCallRuntime(intptr_t token_pos, | 390 void FlowGraphCompiler::GenerateCallRuntime(intptr_t token_pos, |
| 183 intptr_t deopt_id, | 391 intptr_t deopt_id, |
| 184 const RuntimeEntry& entry, | 392 const RuntimeEntry& entry, |
| 185 LocationSummary* locs) { | 393 LocationSummary* locs) { |
| 186 UNIMPLEMENTED(); | 394 __ Unimplemented("call runtime"); |
| 187 } | 395 } |
| 188 | 396 |
| 189 | 397 |
| 190 void FlowGraphCompiler::EmitOptimizedInstanceCall( | 398 void FlowGraphCompiler::EmitOptimizedInstanceCall( |
| 191 ExternalLabel* target_label, | 399 ExternalLabel* target_label, |
| 192 const ICData& ic_data, | 400 const ICData& ic_data, |
| 193 const Array& arguments_descriptor, | 401 const Array& arguments_descriptor, |
| 194 intptr_t argument_count, | 402 intptr_t argument_count, |
| 195 intptr_t deopt_id, | 403 intptr_t deopt_id, |
| 196 intptr_t token_pos, | 404 intptr_t token_pos, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 } | 453 } |
| 246 | 454 |
| 247 | 455 |
| 248 void FlowGraphCompiler::EmitSuperEqualityCallPrologue(Register result, | 456 void FlowGraphCompiler::EmitSuperEqualityCallPrologue(Register result, |
| 249 Label* skip_call) { | 457 Label* skip_call) { |
| 250 UNIMPLEMENTED(); | 458 UNIMPLEMENTED(); |
| 251 } | 459 } |
| 252 | 460 |
| 253 | 461 |
| 254 void FlowGraphCompiler::SaveLiveRegisters(LocationSummary* locs) { | 462 void FlowGraphCompiler::SaveLiveRegisters(LocationSummary* locs) { |
| 255 UNIMPLEMENTED(); | 463 // TODO(vegorov): consider saving only caller save (volatile) registers. |
| 464 const intptr_t fpu_registers = locs->live_registers()->fpu_registers(); |
| 465 if (fpu_registers > 0) { |
| 466 UNIMPLEMENTED(); |
| 467 } |
| 468 |
| 469 // Store general purpose registers with the lowest register number at the |
| 470 // lowest address. |
| 471 const intptr_t cpu_registers = locs->live_registers()->cpu_registers(); |
| 472 ASSERT((cpu_registers & ~kAllCpuRegistersList) == 0); |
| 473 __ PushList(cpu_registers); |
| 256 } | 474 } |
| 257 | 475 |
| 258 | 476 |
| 259 void FlowGraphCompiler::RestoreLiveRegisters(LocationSummary* locs) { | 477 void FlowGraphCompiler::RestoreLiveRegisters(LocationSummary* locs) { |
| 260 UNIMPLEMENTED(); | 478 // General purpose registers have the lowest register number at the |
| 479 // lowest address. |
| 480 const intptr_t cpu_registers = locs->live_registers()->cpu_registers(); |
| 481 ASSERT((cpu_registers & ~kAllCpuRegistersList) == 0); |
| 482 __ PopList(cpu_registers); |
| 483 |
| 484 const intptr_t fpu_registers = locs->live_registers()->fpu_registers(); |
| 485 if (fpu_registers > 0) { |
| 486 UNIMPLEMENTED(); |
| 487 } |
| 261 } | 488 } |
| 262 | 489 |
| 263 | 490 |
| 264 void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data, | 491 void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data, |
| 265 Register class_id_reg, | 492 Register class_id_reg, |
| 266 intptr_t arg_count, | 493 intptr_t arg_count, |
| 267 const Array& arg_names, | 494 const Array& arg_names, |
| 268 Label* deopt, | 495 Label* deopt, |
| 269 intptr_t deopt_id, | 496 intptr_t deopt_id, |
| 270 intptr_t token_index, | 497 intptr_t token_index, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 | 595 |
| 369 | 596 |
| 370 void ParallelMoveResolver::Exchange(const Address& mem1, const Address& mem2) { | 597 void ParallelMoveResolver::Exchange(const Address& mem1, const Address& mem2) { |
| 371 UNIMPLEMENTED(); | 598 UNIMPLEMENTED(); |
| 372 } | 599 } |
| 373 | 600 |
| 374 | 601 |
| 375 } // namespace dart | 602 } // namespace dart |
| 376 | 603 |
| 377 #endif // defined TARGET_ARCH_ARM | 604 #endif // defined TARGET_ARCH_ARM |
| OLD | NEW |