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_IA32. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. |
6 #if defined(TARGET_ARCH_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
7 | 7 |
8 #include "vm/flow_graph_compiler.h" | 8 #include "vm/flow_graph_compiler.h" |
9 | 9 |
10 #include "lib/error.h" | 10 #include "lib/error.h" |
11 #include "vm/ast_printer.h" | 11 #include "vm/ast_printer.h" |
12 #include "vm/dart_entry.h" | 12 #include "vm/dart_entry.h" |
| 13 #include "vm/deopt_instructions.h" |
13 #include "vm/il_printer.h" | 14 #include "vm/il_printer.h" |
14 #include "vm/locations.h" | 15 #include "vm/locations.h" |
15 #include "vm/object_store.h" | 16 #include "vm/object_store.h" |
16 #include "vm/parser.h" | 17 #include "vm/parser.h" |
17 #include "vm/stack_frame.h" | 18 #include "vm/stack_frame.h" |
18 #include "vm/stub_code.h" | 19 #include "vm/stub_code.h" |
19 #include "vm/symbols.h" | 20 #include "vm/symbols.h" |
20 | 21 |
21 namespace dart { | 22 namespace dart { |
22 | 23 |
(...skipping 15 matching lines...) Expand all Loading... |
38 } | 39 } |
39 } | 40 } |
40 | 41 |
41 | 42 |
42 bool FlowGraphCompiler::SupportsUnboxedMints() { | 43 bool FlowGraphCompiler::SupportsUnboxedMints() { |
43 // Support unboxed mints when SSE 4.1 is available. | 44 // Support unboxed mints when SSE 4.1 is available. |
44 return FLAG_unbox_mints && CPUFeatures::sse4_1_supported(); | 45 return FLAG_unbox_mints && CPUFeatures::sse4_1_supported(); |
45 } | 46 } |
46 | 47 |
47 | 48 |
| 49 RawDeoptInfo* CompilerDeoptInfo::CreateDeoptInfo(FlowGraphCompiler* compiler, |
| 50 DeoptInfoBuilder* builder) { |
| 51 if (deoptimization_env_ == NULL) return DeoptInfo::null(); |
| 52 |
| 53 intptr_t stack_height = compiler->StackSize(); |
| 54 AllocateIncomingParametersRecursive(deoptimization_env_, &stack_height); |
| 55 |
| 56 intptr_t slot_ix = 0; |
| 57 Environment* current = deoptimization_env_; |
| 58 |
| 59 // Emit all kMaterializeObject instructions describing objects to be |
| 60 // materialized on the deoptimization as a prefix to the deoptimization info. |
| 61 EmitMaterializations(deoptimization_env_, builder); |
| 62 |
| 63 // The real frame starts here. |
| 64 builder->MarkFrameStart(); |
| 65 |
| 66 // Callee's PC marker is not used anymore. Pass Function::null() to set to 0. |
| 67 builder->AddPcMarker(Function::Handle(), slot_ix++); |
| 68 |
| 69 // Current FP and PC. |
| 70 builder->AddCallerFp(slot_ix++); |
| 71 builder->AddReturnAddress(current->function(), |
| 72 deopt_id(), |
| 73 slot_ix++); |
| 74 |
| 75 // Emit all values that are needed for materialization as a part of the |
| 76 // expression stack for the bottom-most frame. This guarantees that GC |
| 77 // will be able to find them during materialization. |
| 78 slot_ix = builder->EmitMaterializationArguments(slot_ix); |
| 79 |
| 80 // For the innermost environment, set outgoing arguments and the locals. |
| 81 for (intptr_t i = current->Length() - 1; |
| 82 i >= current->fixed_parameter_count(); |
| 83 i--) { |
| 84 builder->AddCopy(current->ValueAt(i), current->LocationAt(i), slot_ix++); |
| 85 } |
| 86 |
| 87 // Current PC marker and caller FP. |
| 88 builder->AddPcMarker(current->function(), slot_ix++); |
| 89 builder->AddCallerFp(slot_ix++); |
| 90 |
| 91 Environment* previous = current; |
| 92 current = current->outer(); |
| 93 while (current != NULL) { |
| 94 // For any outer environment the deopt id is that of the call instruction |
| 95 // which is recorded in the outer environment. |
| 96 builder->AddReturnAddress(current->function(), |
| 97 Isolate::ToDeoptAfter(current->deopt_id()), |
| 98 slot_ix++); |
| 99 |
| 100 // The values of outgoing arguments can be changed from the inlined call so |
| 101 // we must read them from the previous environment. |
| 102 for (intptr_t i = previous->fixed_parameter_count() - 1; i >= 0; i--) { |
| 103 builder->AddCopy(previous->ValueAt(i), |
| 104 previous->LocationAt(i), |
| 105 slot_ix++); |
| 106 } |
| 107 |
| 108 // Set the locals, note that outgoing arguments are not in the environment. |
| 109 for (intptr_t i = current->Length() - 1; |
| 110 i >= current->fixed_parameter_count(); |
| 111 i--) { |
| 112 builder->AddCopy(current->ValueAt(i), |
| 113 current->LocationAt(i), |
| 114 slot_ix++); |
| 115 } |
| 116 |
| 117 // PC marker and caller FP. |
| 118 builder->AddPcMarker(current->function(), slot_ix++); |
| 119 builder->AddCallerFp(slot_ix++); |
| 120 |
| 121 // Iterate on the outer environment. |
| 122 previous = current; |
| 123 current = current->outer(); |
| 124 } |
| 125 // The previous pointer is now the outermost environment. |
| 126 ASSERT(previous != NULL); |
| 127 |
| 128 // For the outermost environment, set caller PC. |
| 129 builder->AddCallerPc(slot_ix++); |
| 130 |
| 131 // For the outermost environment, set the incoming arguments. |
| 132 for (intptr_t i = previous->fixed_parameter_count() - 1; i >= 0; i--) { |
| 133 builder->AddCopy(previous->ValueAt(i), previous->LocationAt(i), slot_ix++); |
| 134 } |
| 135 |
| 136 const DeoptInfo& deopt_info = DeoptInfo::Handle(builder->CreateDeoptInfo()); |
| 137 return deopt_info.raw(); |
| 138 } |
| 139 |
| 140 |
48 void CompilerDeoptInfoWithStub::GenerateCode(FlowGraphCompiler* compiler, | 141 void CompilerDeoptInfoWithStub::GenerateCode(FlowGraphCompiler* compiler, |
49 intptr_t stub_ix) { | 142 intptr_t stub_ix) { |
50 // Calls do not need stubs, they share a deoptimization trampoline. | 143 // Calls do not need stubs, they share a deoptimization trampoline. |
51 ASSERT(reason() != kDeoptAtCall); | 144 ASSERT(reason() != kDeoptAtCall); |
52 Assembler* assem = compiler->assembler(); | 145 Assembler* assem = compiler->assembler(); |
53 #define __ assem-> | 146 #define __ assem-> |
54 __ Comment("Deopt stub for id %"Pd"", deopt_id()); | 147 __ Comment("Deopt stub for id %"Pd"", deopt_id()); |
55 __ Bind(entry_label()); | 148 __ Bind(entry_label()); |
56 if (FLAG_trap_on_deoptimization) __ int3(); | 149 if (FLAG_trap_on_deoptimization) __ int3(); |
57 | 150 |
58 ASSERT(deoptimization_env() != NULL); | 151 ASSERT(deoptimization_env() != NULL); |
59 | 152 |
60 __ call(&StubCode::DeoptimizeLabel()); | 153 __ call(&StubCode::DeoptimizeLabel()); |
61 set_pc_offset(assem->CodeSize()); | 154 set_pc_offset(assem->CodeSize()); |
| 155 __ int3(); |
62 #undef __ | 156 #undef __ |
63 } | 157 } |
64 | 158 |
65 | 159 |
66 #define __ assembler()-> | 160 #define __ assembler()-> |
67 | 161 |
68 | 162 |
69 // Fall through if bool_register contains null. | 163 // Fall through if bool_register contains null. |
70 void FlowGraphCompiler::GenerateBoolToJump(Register bool_register, | 164 void FlowGraphCompiler::GenerateBoolToJump(Register bool_register, |
71 Label* is_true, | 165 Label* is_true, |
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 if (FLAG_print_scopes) { | 1232 if (FLAG_print_scopes) { |
1139 // Print the function scope (again) after generating the prologue in order | 1233 // Print the function scope (again) after generating the prologue in order |
1140 // to see annotations such as allocation indices of locals. | 1234 // to see annotations such as allocation indices of locals. |
1141 if (FLAG_print_ast) { | 1235 if (FLAG_print_ast) { |
1142 // Second printing. | 1236 // Second printing. |
1143 OS::Print("Annotated "); | 1237 OS::Print("Annotated "); |
1144 } | 1238 } |
1145 AstPrinter::PrintFunctionScope(parsed_function()); | 1239 AstPrinter::PrintFunctionScope(parsed_function()); |
1146 } | 1240 } |
1147 | 1241 |
| 1242 ASSERT(!block_order().is_empty()); |
1148 VisitBlocks(); | 1243 VisitBlocks(); |
1149 | 1244 |
1150 __ int3(); | 1245 __ int3(); |
1151 GenerateDeferredCode(); | 1246 GenerateDeferredCode(); |
1152 // Emit function patching code. This will be swapped with the first 5 bytes | 1247 // Emit function patching code. This will be swapped with the first 5 bytes |
1153 // at entry point. | 1248 // at entry point. |
1154 AddCurrentDescriptor(PcDescriptors::kPatchCode, | 1249 AddCurrentDescriptor(PcDescriptors::kPatchCode, |
1155 Isolate::kNoDeoptId, | 1250 Isolate::kNoDeoptId, |
1156 0); // No token position. | 1251 0); // No token position. |
1157 __ jmp(&StubCode::FixCallersTargetLabel()); | 1252 __ jmp(&StubCode::FixCallersTargetLabel()); |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1857 __ movups(reg, Address(ESP, 0)); | 1952 __ movups(reg, Address(ESP, 0)); |
1858 __ addl(ESP, Immediate(kFpuRegisterSize)); | 1953 __ addl(ESP, Immediate(kFpuRegisterSize)); |
1859 } | 1954 } |
1860 | 1955 |
1861 | 1956 |
1862 #undef __ | 1957 #undef __ |
1863 | 1958 |
1864 } // namespace dart | 1959 } // namespace dart |
1865 | 1960 |
1866 #endif // defined TARGET_ARCH_IA32 | 1961 #endif // defined TARGET_ARCH_IA32 |
OLD | NEW |