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_MIPS. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_MIPS. |
6 #if defined(TARGET_ARCH_MIPS) | 6 #if defined(TARGET_ARCH_MIPS) |
7 | 7 |
8 #include "vm/flow_graph_compiler.h" | 8 #include "vm/flow_graph_compiler.h" |
9 | 9 |
10 #include "vm/ast_printer.h" | 10 #include "vm/ast_printer.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 // Emit all kMaterializeObject instructions describing objects to be | 90 // Emit all kMaterializeObject instructions describing objects to be |
91 // materialized on the deoptimization as a prefix to the deoptimization info. | 91 // materialized on the deoptimization as a prefix to the deoptimization info. |
92 EmitMaterializations(deopt_env_, builder); | 92 EmitMaterializations(deopt_env_, builder); |
93 | 93 |
94 // The real frame starts here. | 94 // The real frame starts here. |
95 builder->MarkFrameStart(); | 95 builder->MarkFrameStart(); |
96 | 96 |
97 Zone* zone = compiler->zone(); | 97 Zone* zone = compiler->zone(); |
98 | 98 |
99 // Current PP, FP, and PC. | |
100 builder->AddPp(current->function(), slot_ix++); | 99 builder->AddPp(current->function(), slot_ix++); |
| 100 builder->AddPcMarker(Function::Handle(zone), slot_ix++); |
101 builder->AddCallerFp(slot_ix++); | 101 builder->AddCallerFp(slot_ix++); |
102 builder->AddReturnAddress(current->function(), deopt_id(), slot_ix++); | 102 builder->AddReturnAddress(current->function(), deopt_id(), slot_ix++); |
103 | 103 |
104 // Callee's PC marker is not used anymore. Pass Code::null() to set to 0. | |
105 builder->AddPcMarker(Function::Handle(zone), slot_ix++); | |
106 | 104 |
107 // Emit all values that are needed for materialization as a part of the | 105 // Emit all values that are needed for materialization as a part of the |
108 // expression stack for the bottom-most frame. This guarantees that GC | 106 // expression stack for the bottom-most frame. This guarantees that GC |
109 // will be able to find them during materialization. | 107 // will be able to find them during materialization. |
110 slot_ix = builder->EmitMaterializationArguments(slot_ix); | 108 slot_ix = builder->EmitMaterializationArguments(slot_ix); |
111 | 109 |
112 // For the innermost environment, set outgoing arguments and the locals. | 110 // For the innermost environment, set outgoing arguments and the locals. |
113 for (intptr_t i = current->Length() - 1; | 111 for (intptr_t i = current->Length() - 1; |
114 i >= current->fixed_parameter_count(); | 112 i >= current->fixed_parameter_count(); |
115 i--) { | 113 i--) { |
116 builder->AddCopy(current->ValueAt(i), current->LocationAt(i), slot_ix++); | 114 builder->AddCopy(current->ValueAt(i), current->LocationAt(i), slot_ix++); |
117 } | 115 } |
118 | 116 |
119 Environment* previous = current; | 117 Environment* previous = current; |
120 current = current->outer(); | 118 current = current->outer(); |
121 while (current != NULL) { | 119 while (current != NULL) { |
122 // PP, FP, and PC. | |
123 builder->AddPp(current->function(), slot_ix++); | 120 builder->AddPp(current->function(), slot_ix++); |
| 121 builder->AddPcMarker(previous->function(), slot_ix++); |
124 builder->AddCallerFp(slot_ix++); | 122 builder->AddCallerFp(slot_ix++); |
125 | 123 |
126 // For any outer environment the deopt id is that of the call instruction | 124 // For any outer environment the deopt id is that of the call instruction |
127 // which is recorded in the outer environment. | 125 // which is recorded in the outer environment. |
128 builder->AddReturnAddress( | 126 builder->AddReturnAddress( |
129 current->function(), | 127 current->function(), |
130 Isolate::ToDeoptAfter(current->deopt_id()), | 128 Isolate::ToDeoptAfter(current->deopt_id()), |
131 slot_ix++); | 129 slot_ix++); |
132 | 130 |
133 // PC marker. | |
134 builder->AddPcMarker(previous->function(), slot_ix++); | |
135 | |
136 // The values of outgoing arguments can be changed from the inlined call so | 131 // The values of outgoing arguments can be changed from the inlined call so |
137 // we must read them from the previous environment. | 132 // we must read them from the previous environment. |
138 for (intptr_t i = previous->fixed_parameter_count() - 1; i >= 0; i--) { | 133 for (intptr_t i = previous->fixed_parameter_count() - 1; i >= 0; i--) { |
139 builder->AddCopy(previous->ValueAt(i), | 134 builder->AddCopy(previous->ValueAt(i), |
140 previous->LocationAt(i), | 135 previous->LocationAt(i), |
141 slot_ix++); | 136 slot_ix++); |
142 } | 137 } |
143 | 138 |
144 // Set the locals, note that outgoing arguments are not in the environment. | 139 // Set the locals, note that outgoing arguments are not in the environment. |
145 for (intptr_t i = current->Length() - 1; | 140 for (intptr_t i = current->Length() - 1; |
146 i >= current->fixed_parameter_count(); | 141 i >= current->fixed_parameter_count(); |
147 i--) { | 142 i--) { |
148 builder->AddCopy(current->ValueAt(i), | 143 builder->AddCopy(current->ValueAt(i), |
149 current->LocationAt(i), | 144 current->LocationAt(i), |
150 slot_ix++); | 145 slot_ix++); |
151 } | 146 } |
152 | 147 |
153 // Iterate on the outer environment. | 148 // Iterate on the outer environment. |
154 previous = current; | 149 previous = current; |
155 current = current->outer(); | 150 current = current->outer(); |
156 } | 151 } |
157 // The previous pointer is now the outermost environment. | 152 // The previous pointer is now the outermost environment. |
158 ASSERT(previous != NULL); | 153 ASSERT(previous != NULL); |
159 | 154 |
160 // For the outermost environment, set caller PC, caller PP, and caller FP. | 155 // Set slots for the outermost environment. |
161 builder->AddCallerPp(slot_ix++); | 156 builder->AddCallerPp(slot_ix++); |
| 157 builder->AddPcMarker(previous->function(), slot_ix++); |
162 builder->AddCallerFp(slot_ix++); | 158 builder->AddCallerFp(slot_ix++); |
163 builder->AddCallerPc(slot_ix++); | 159 builder->AddCallerPc(slot_ix++); |
164 | 160 |
165 // PC marker. | |
166 builder->AddPcMarker(previous->function(), slot_ix++); | |
167 | |
168 // For the outermost environment, set the incoming arguments. | 161 // For the outermost environment, set the incoming arguments. |
169 for (intptr_t i = previous->fixed_parameter_count() - 1; i >= 0; i--) { | 162 for (intptr_t i = previous->fixed_parameter_count() - 1; i >= 0; i--) { |
170 builder->AddCopy(previous->ValueAt(i), previous->LocationAt(i), slot_ix++); | 163 builder->AddCopy(previous->ValueAt(i), previous->LocationAt(i), slot_ix++); |
171 } | 164 } |
172 | 165 |
173 return builder->CreateDeoptInfo(deopt_table); | 166 return builder->CreateDeoptInfo(deopt_table); |
174 } | 167 } |
175 | 168 |
176 | 169 |
177 void CompilerDeoptInfoWithStub::GenerateCode(FlowGraphCompiler* compiler, | 170 void CompilerDeoptInfoWithStub::GenerateCode(FlowGraphCompiler* compiler, |
178 intptr_t stub_ix) { | 171 intptr_t stub_ix) { |
179 // Calls do not need stubs, they share a deoptimization trampoline. | 172 // Calls do not need stubs, they share a deoptimization trampoline. |
180 ASSERT(reason() != ICData::kDeoptAtCall); | 173 ASSERT(reason() != ICData::kDeoptAtCall); |
181 Assembler* assem = compiler->assembler(); | 174 Assembler* assem = compiler->assembler(); |
182 #define __ assem-> | 175 #define __ assem-> |
183 __ Comment("%s", Name()); | 176 __ Comment("%s", Name()); |
184 __ Bind(entry_label()); | 177 __ Bind(entry_label()); |
185 if (FLAG_trap_on_deoptimization) { | 178 if (FLAG_trap_on_deoptimization) { |
186 __ break_(0); | 179 __ break_(0); |
187 } | 180 } |
188 | 181 |
189 ASSERT(deopt_env() != NULL); | 182 ASSERT(deopt_env() != NULL); |
190 | 183 __ Push(CODE_REG); |
191 __ BranchLink(*StubCode::Deoptimize_entry()); | 184 __ BranchLink(*StubCode::Deoptimize_entry()); |
192 set_pc_offset(assem->CodeSize()); | 185 set_pc_offset(assem->CodeSize()); |
193 #undef __ | 186 #undef __ |
194 } | 187 } |
195 | 188 |
196 | 189 |
197 #define __ assembler()-> | 190 #define __ assembler()-> |
198 | 191 |
199 | 192 |
200 // Fall through if bool_register contains null. | 193 // Fall through if bool_register contains null. |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 if (check_correct_named_args) { | 914 if (check_correct_named_args) { |
922 __ lw(T1, FieldAddress(S4, ArgumentsDescriptor::count_offset())); | 915 __ lw(T1, FieldAddress(S4, ArgumentsDescriptor::count_offset())); |
923 __ SmiUntag(T1); | 916 __ SmiUntag(T1); |
924 // Check that T2 equals T1, i.e. no named arguments passed. | 917 // Check that T2 equals T1, i.e. no named arguments passed. |
925 __ beq(T2, T1, &all_arguments_processed); | 918 __ beq(T2, T1, &all_arguments_processed); |
926 } | 919 } |
927 } | 920 } |
928 | 921 |
929 __ Bind(&wrong_num_arguments); | 922 __ Bind(&wrong_num_arguments); |
930 if (function.IsClosureFunction()) { | 923 if (function.IsClosureFunction()) { |
931 __ LeaveDartFrame(); // The arguments are still on the stack. | 924 __ LeaveDartFrame(kKeepCalleePP); // Arguments are still on the stack. |
932 __ Branch(*StubCode::CallClosureNoSuchMethod_entry()); | 925 __ Branch(*StubCode::CallClosureNoSuchMethod_entry()); |
933 // The noSuchMethod call may return to the caller, but not here. | 926 // The noSuchMethod call may return to the caller, but not here. |
934 } else if (check_correct_named_args) { | 927 } else if (check_correct_named_args) { |
935 __ Stop("Wrong arguments"); | 928 __ Stop("Wrong arguments"); |
936 } | 929 } |
937 | 930 |
938 __ Bind(&all_arguments_processed); | 931 __ Bind(&all_arguments_processed); |
939 // Nullify originally passed arguments only after they have been copied and | 932 // Nullify originally passed arguments only after they have been copied and |
940 // checked, otherwise noSuchMethod would not see their original values. | 933 // checked, otherwise noSuchMethod would not see their original values. |
941 // This step can be skipped in case we decide that formal parameters are | 934 // This step can be skipped in case we decide that formal parameters are |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 // Sequence node has one store node and one return NULL node. | 972 // Sequence node has one store node and one return NULL node. |
980 __ Comment("Inlined Setter"); | 973 __ Comment("Inlined Setter"); |
981 __ lw(T0, Address(SP, 1 * kWordSize)); // Receiver. | 974 __ lw(T0, Address(SP, 1 * kWordSize)); // Receiver. |
982 __ lw(T1, Address(SP, 0 * kWordSize)); // Value. | 975 __ lw(T1, Address(SP, 0 * kWordSize)); // Value. |
983 __ StoreIntoObjectOffset(T0, offset, T1); | 976 __ StoreIntoObjectOffset(T0, offset, T1); |
984 __ LoadObject(V0, Object::null_object()); | 977 __ LoadObject(V0, Object::null_object()); |
985 __ Ret(); | 978 __ Ret(); |
986 } | 979 } |
987 | 980 |
988 | 981 |
| 982 static const Register new_pp = T7; |
| 983 |
| 984 |
989 void FlowGraphCompiler::EmitFrameEntry() { | 985 void FlowGraphCompiler::EmitFrameEntry() { |
990 const Function& function = parsed_function().function(); | 986 const Function& function = parsed_function().function(); |
991 if (CanOptimizeFunction() && | 987 if (CanOptimizeFunction() && |
992 function.IsOptimizable() && | 988 function.IsOptimizable() && |
993 (!is_optimizing() || may_reoptimize())) { | 989 (!is_optimizing() || may_reoptimize())) { |
994 const Register function_reg = T0; | 990 const Register function_reg = T0; |
995 | 991 |
996 __ GetNextPC(T2, TMP); | |
997 | |
998 // Calculate offset of pool pointer from the PC. | |
999 const intptr_t object_pool_pc_dist = | |
1000 Instructions::HeaderSize() - Instructions::object_pool_offset() + | |
1001 assembler()->CodeSize() - 1 * Instr::kInstrSize; | |
1002 | |
1003 // Preserve PP of caller. | |
1004 __ mov(T1, PP); | |
1005 // Temporarily setup pool pointer for this dart function. | 992 // Temporarily setup pool pointer for this dart function. |
1006 __ lw(PP, Address(T2, -object_pool_pc_dist)); | 993 __ LoadPoolPointer(new_pp); |
1007 // Load function object from object pool. | 994 // Load function object from object pool. |
1008 __ LoadObject(function_reg, function); // Uses PP. | 995 __ LoadFunctionFromCalleePool(function_reg, function, new_pp); |
1009 // Restore PP of caller. | |
1010 __ mov(PP, T1); | |
1011 | |
1012 // Patch point is after the eventually inlined function object. | |
1013 entry_patch_pc_offset_ = assembler()->CodeSize(); | |
1014 | 996 |
1015 __ lw(T1, FieldAddress(function_reg, Function::usage_counter_offset())); | 997 __ lw(T1, FieldAddress(function_reg, Function::usage_counter_offset())); |
1016 // Reoptimization of an optimized function is triggered by counting in | 998 // Reoptimization of an optimized function is triggered by counting in |
1017 // IC stubs, but not at the entry of the function. | 999 // IC stubs, but not at the entry of the function. |
1018 if (!is_optimizing()) { | 1000 if (!is_optimizing()) { |
1019 __ addiu(T1, T1, Immediate(1)); | 1001 __ addiu(T1, T1, Immediate(1)); |
1020 __ sw(T1, FieldAddress(function_reg, Function::usage_counter_offset())); | 1002 __ sw(T1, FieldAddress(function_reg, Function::usage_counter_offset())); |
1021 } | 1003 } |
1022 | 1004 |
1023 // Skip Branch if T1 is less than the threshold. | 1005 // Skip Branch if T1 is less than the threshold. |
1024 Label dont_branch; | 1006 Label dont_branch; |
1025 __ BranchSignedLess( | 1007 __ BranchSignedLess( |
1026 T1, Immediate(GetOptimizationThreshold()), &dont_branch); | 1008 T1, Immediate(GetOptimizationThreshold()), &dont_branch); |
1027 | 1009 |
1028 ASSERT(function_reg == T0); | 1010 ASSERT(function_reg == T0); |
1029 __ Branch(*StubCode::OptimizeFunction_entry()); | 1011 __ Branch(*StubCode::OptimizeFunction_entry(), new_pp); |
1030 | 1012 |
1031 __ Bind(&dont_branch); | 1013 __ Bind(&dont_branch); |
1032 | |
1033 } else if (!flow_graph().IsCompiledForOsr()) { | |
1034 entry_patch_pc_offset_ = assembler()->CodeSize(); | |
1035 } | 1014 } |
1036 __ Comment("Enter frame"); | 1015 __ Comment("Enter frame"); |
1037 if (flow_graph().IsCompiledForOsr()) { | 1016 if (flow_graph().IsCompiledForOsr()) { |
1038 intptr_t extra_slots = StackSize() | 1017 intptr_t extra_slots = StackSize() |
1039 - flow_graph().num_stack_locals() | 1018 - flow_graph().num_stack_locals() |
1040 - flow_graph().num_copied_params(); | 1019 - flow_graph().num_copied_params(); |
1041 ASSERT(extra_slots >= 0); | 1020 ASSERT(extra_slots >= 0); |
1042 __ EnterOsrFrame(extra_slots * kWordSize); | 1021 __ EnterOsrFrame(extra_slots * kWordSize); |
1043 } else { | 1022 } else { |
1044 ASSERT(StackSize() >= 0); | 1023 ASSERT(StackSize() >= 0); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 Label correct_num_arguments, wrong_num_arguments; | 1064 Label correct_num_arguments, wrong_num_arguments; |
1086 __ lw(T0, FieldAddress(S4, ArgumentsDescriptor::count_offset())); | 1065 __ lw(T0, FieldAddress(S4, ArgumentsDescriptor::count_offset())); |
1087 __ BranchNotEqual(T0, Immediate(Smi::RawValue(num_fixed_params)), | 1066 __ BranchNotEqual(T0, Immediate(Smi::RawValue(num_fixed_params)), |
1088 &wrong_num_arguments); | 1067 &wrong_num_arguments); |
1089 | 1068 |
1090 __ lw(T1, FieldAddress(S4, | 1069 __ lw(T1, FieldAddress(S4, |
1091 ArgumentsDescriptor::positional_count_offset())); | 1070 ArgumentsDescriptor::positional_count_offset())); |
1092 __ beq(T0, T1, &correct_num_arguments); | 1071 __ beq(T0, T1, &correct_num_arguments); |
1093 __ Bind(&wrong_num_arguments); | 1072 __ Bind(&wrong_num_arguments); |
1094 if (function.IsClosureFunction()) { | 1073 if (function.IsClosureFunction()) { |
1095 __ LeaveDartFrame(); // The arguments are still on the stack. | 1074 __ LeaveDartFrame(kKeepCalleePP); // Arguments are still on the stack. |
1096 __ Branch(*StubCode::CallClosureNoSuchMethod_entry()); | 1075 __ Branch(*StubCode::CallClosureNoSuchMethod_entry()); |
1097 // The noSuchMethod call may return to the caller, but not here. | 1076 // The noSuchMethod call may return to the caller, but not here. |
1098 } else { | 1077 } else { |
1099 __ Stop("Wrong number of arguments"); | 1078 __ Stop("Wrong number of arguments"); |
1100 } | 1079 } |
1101 __ Bind(&correct_num_arguments); | 1080 __ Bind(&correct_num_arguments); |
1102 } | 1081 } |
1103 } else if (!flow_graph().IsCompiledForOsr()) { | 1082 } else if (!flow_graph().IsCompiledForOsr()) { |
1104 CopyParameters(); | 1083 CopyParameters(); |
1105 } | 1084 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 ASSERT(num_locals > 1); | 1117 ASSERT(num_locals > 1); |
1139 __ sw(V0, Address(FP, (slot_base - i) * kWordSize)); | 1118 __ sw(V0, Address(FP, (slot_base - i) * kWordSize)); |
1140 } | 1119 } |
1141 } | 1120 } |
1142 } | 1121 } |
1143 | 1122 |
1144 VisitBlocks(); | 1123 VisitBlocks(); |
1145 | 1124 |
1146 __ break_(0); | 1125 __ break_(0); |
1147 GenerateDeferredCode(); | 1126 GenerateDeferredCode(); |
1148 // Emit function patching code. This will be swapped with the first 5 bytes | |
1149 // at entry point. | |
1150 patch_code_pc_offset_ = assembler()->CodeSize(); | |
1151 __ BranchPatchable(*StubCode::FixCallersTarget_entry()); | |
1152 | 1127 |
1153 if (is_optimizing()) { | 1128 if (is_optimizing()) { |
1154 lazy_deopt_pc_offset_ = assembler()->CodeSize(); | 1129 lazy_deopt_pc_offset_ = assembler()->CodeSize(); |
1155 __ Branch(*StubCode::DeoptimizeLazy_entry()); | 1130 __ Branch(*StubCode::DeoptimizeLazy_entry()); |
1156 } | 1131 } |
1157 } | 1132 } |
1158 | 1133 |
1159 | 1134 |
1160 void FlowGraphCompiler::GenerateCall(intptr_t token_pos, | 1135 void FlowGraphCompiler::GenerateCall(intptr_t token_pos, |
1161 const StubEntry& stub_entry, | 1136 const StubEntry& stub_entry, |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1858 __ AddImmediate(SP, kDoubleSize); | 1833 __ AddImmediate(SP, kDoubleSize); |
1859 } | 1834 } |
1860 | 1835 |
1861 | 1836 |
1862 #undef __ | 1837 #undef __ |
1863 | 1838 |
1864 | 1839 |
1865 } // namespace dart | 1840 } // namespace dart |
1866 | 1841 |
1867 #endif // defined TARGET_ARCH_MIPS | 1842 #endif // defined TARGET_ARCH_MIPS |
OLD | NEW |