| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Class for intrinsifying functions. | 4 // Class for intrinsifying functions. |
| 5 | 5 |
| 6 #include "vm/assembler.h" | 6 #include "vm/assembler.h" |
| 7 #include "vm/intrinsifier.h" | 7 #include "vm/intrinsifier.h" |
| 8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
| 9 #include "vm/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/symbols.h" | 10 #include "vm/symbols.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 bool Intrinsifier::CanIntrinsify(const Function& function) { | 28 bool Intrinsifier::CanIntrinsify(const Function& function) { |
| 29 if (!FLAG_intrinsify) return false; | 29 if (!FLAG_intrinsify) return false; |
| 30 if (function.IsClosureFunction()) return false; | 30 if (function.IsClosureFunction()) return false; |
| 31 // Can occur because of compile-all flag. | 31 // Can occur because of compile-all flag. |
| 32 if (function.is_external()) return false; | 32 if (function.is_external()) return false; |
| 33 return function.is_intrinsic(); | 33 return function.is_intrinsic(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 | 36 |
| 37 #if defined(DART_NO_SNAPSHOT) |
| 37 void Intrinsifier::InitializeState() { | 38 void Intrinsifier::InitializeState() { |
| 38 Isolate* isolate = Isolate::Current(); | 39 Isolate* isolate = Isolate::Current(); |
| 39 Library& lib = Library::Handle(isolate); | 40 Library& lib = Library::Handle(isolate); |
| 40 Class& cls = Class::Handle(isolate); | 41 Class& cls = Class::Handle(isolate); |
| 41 Function& func = Function::Handle(isolate); | 42 Function& func = Function::Handle(isolate); |
| 42 String& str = String::Handle(isolate); | 43 String& str = String::Handle(isolate); |
| 43 Error& error = Error::Handle(isolate); | 44 Error& error = Error::Handle(isolate); |
| 44 | 45 |
| 45 #define SETUP_FUNCTION(class_name, function_name, destination, fp) \ | 46 #define SETUP_FUNCTION(class_name, function_name, destination, fp) \ |
| 46 if (strcmp(#class_name, "::") == 0) { \ | 47 if (strcmp(#class_name, "::") == 0) { \ |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 TYPED_DATA_LIB_INTRINSIC_LIST(SETUP_FUNCTION); | 84 TYPED_DATA_LIB_INTRINSIC_LIST(SETUP_FUNCTION); |
| 84 GRAPH_TYPED_DATA_INTRINSICS_LIST(SETUP_FUNCTION); | 85 GRAPH_TYPED_DATA_INTRINSICS_LIST(SETUP_FUNCTION); |
| 85 | 86 |
| 86 // Setup all dart:profiler lib functions that can be intrinsified. | 87 // Setup all dart:profiler lib functions that can be intrinsified. |
| 87 lib = Library::ProfilerLibrary(); | 88 lib = Library::ProfilerLibrary(); |
| 88 ASSERT(!lib.IsNull()); | 89 ASSERT(!lib.IsNull()); |
| 89 PROFILER_LIB_INTRINSIC_LIST(SETUP_FUNCTION); | 90 PROFILER_LIB_INTRINSIC_LIST(SETUP_FUNCTION); |
| 90 | 91 |
| 91 #undef SETUP_FUNCTION | 92 #undef SETUP_FUNCTION |
| 92 } | 93 } |
| 94 #endif // defined(DART_NO_SNAPSHOT). |
| 93 | 95 |
| 94 | 96 |
| 95 static void EmitCodeFor(FlowGraphCompiler* compiler, | 97 static void EmitCodeFor(FlowGraphCompiler* compiler, |
| 96 FlowGraph* graph) { | 98 FlowGraph* graph) { |
| 97 // The FlowGraph here is constructed by the intrinsics builder methods, and | 99 // The FlowGraph here is constructed by the intrinsics builder methods, and |
| 98 // is different from compiler->flow_graph(), the original method's flow graph. | 100 // is different from compiler->flow_graph(), the original method's flow graph. |
| 99 compiler->assembler()->Comment("Graph intrinsic"); | 101 compiler->assembler()->Comment("Graph intrinsic"); |
| 100 for (intptr_t i = 0; i < graph->reverse_postorder().length(); i++) { | 102 for (intptr_t i = 0; i < graph->reverse_postorder().length(); i++) { |
| 101 BlockEntryInstr* block = graph->reverse_postorder()[i]; | 103 BlockEntryInstr* block = graph->reverse_postorder()[i]; |
| 102 if (block->IsGraphEntry()) continue; // No code for graph entry needed. | 104 if (block->IsGraphEntry()) continue; // No code for graph entry needed. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 TargetEntryInstr* normal_entry = | 138 TargetEntryInstr* normal_entry = |
| 137 new TargetEntryInstr(block_id, | 139 new TargetEntryInstr(block_id, |
| 138 CatchClauseNode::kInvalidTryIndex); | 140 CatchClauseNode::kInvalidTryIndex); |
| 139 GraphEntryInstr* graph_entry = new GraphEntryInstr( | 141 GraphEntryInstr* graph_entry = new GraphEntryInstr( |
| 140 parsed_function, normal_entry, Isolate::kNoDeoptId); // No OSR id. | 142 parsed_function, normal_entry, Isolate::kNoDeoptId); // No OSR id. |
| 141 FlowGraph* graph = new FlowGraph(parsed_function, graph_entry, block_id); | 143 FlowGraph* graph = new FlowGraph(parsed_function, graph_entry, block_id); |
| 142 const Function& function = parsed_function.function(); | 144 const Function& function = parsed_function.function(); |
| 143 switch (function.recognized_kind()) { | 145 switch (function.recognized_kind()) { |
| 144 #define EMIT_CASE(class_name, function_name, enum_name, fp) \ | 146 #define EMIT_CASE(class_name, function_name, enum_name, fp) \ |
| 145 case MethodRecognizer::k##enum_name: \ | 147 case MethodRecognizer::k##enum_name: \ |
| 146 CHECK_FINGERPRINT3(function, class_name, function_name, enum_name, fp); \ | |
| 147 if (!Build_##enum_name(graph)) return false; \ | 148 if (!Build_##enum_name(graph)) return false; \ |
| 148 break; | 149 break; |
| 149 | 150 |
| 150 GRAPH_INTRINSICS_LIST(EMIT_CASE); | 151 GRAPH_INTRINSICS_LIST(EMIT_CASE); |
| 151 default: | 152 default: |
| 152 return false; | 153 return false; |
| 153 #undef EMIT_CASE | 154 #undef EMIT_CASE |
| 154 } | 155 } |
| 155 | 156 |
| 156 if (FLAG_print_flow_graph && FlowGraphPrinter::ShouldPrint(function)) { | 157 if (FLAG_print_flow_graph && FlowGraphPrinter::ShouldPrint(function)) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 180 return; | 181 return; |
| 181 } | 182 } |
| 182 | 183 |
| 183 ASSERT(!compiler->flow_graph().IsCompiledForOsr()); | 184 ASSERT(!compiler->flow_graph().IsCompiledForOsr()); |
| 184 if (GraphIntrinsify(parsed_function, compiler)) { | 185 if (GraphIntrinsify(parsed_function, compiler)) { |
| 185 return; | 186 return; |
| 186 } | 187 } |
| 187 | 188 |
| 188 #define EMIT_CASE(class_name, function_name, enum_name, fp) \ | 189 #define EMIT_CASE(class_name, function_name, enum_name, fp) \ |
| 189 case MethodRecognizer::k##enum_name: \ | 190 case MethodRecognizer::k##enum_name: \ |
| 190 CHECK_FINGERPRINT3(function, class_name, function_name, enum_name, fp); \ | |
| 191 compiler->assembler()->Comment("Intrinsic"); \ | 191 compiler->assembler()->Comment("Intrinsic"); \ |
| 192 enum_name(compiler->assembler()); \ | 192 enum_name(compiler->assembler()); \ |
| 193 break; | 193 break; |
| 194 | 194 |
| 195 if (FLAG_throw_on_javascript_int_overflow && (Smi::kBits >= 32)) { | 195 switch (function.recognized_kind()) { |
| 196 // Integer intrinsics are in the core library, but we don't want to | 196 ALL_INTRINSICS_NO_INTEGER_LIB_LIST(EMIT_CASE); |
| 197 // intrinsify when Smi > 32 bits if we are looking for javascript integer | 197 default: |
| 198 // overflow. | 198 break; |
| 199 } |
| 200 // Integer intrinsics are in the core library, but we don't want to |
| 201 // intrinsify when Smi > 32 bits if we are looking for javascript integer |
| 202 // overflow. |
| 203 if (!(FLAG_throw_on_javascript_int_overflow && (Smi::kBits >= 32))) { |
| 199 switch (function.recognized_kind()) { | 204 switch (function.recognized_kind()) { |
| 200 ALL_INTRINSICS_NO_INTEGER_LIB_LIST(EMIT_CASE); | 205 CORE_INTEGER_LIB_INTRINSIC_LIST(EMIT_CASE) |
| 201 default: | |
| 202 break; | |
| 203 } | |
| 204 } else { | |
| 205 switch (function.recognized_kind()) { | |
| 206 ALL_INTRINSICS_LIST(EMIT_CASE); | |
| 207 default: | 206 default: |
| 208 break; | 207 break; |
| 209 } | 208 } |
| 210 } | 209 } |
| 211 #undef EMIT_INTRINSIC | 210 #undef EMIT_INTRINSIC |
| 212 } | 211 } |
| 213 | 212 |
| 214 | 213 |
| 215 class BlockBuilder : public ValueObject { | 214 class BlockBuilder : public ValueObject { |
| 216 public: | 215 public: |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 new Value(growable_array), | 682 new Value(growable_array), |
| 684 new Value(length), | 683 new Value(length), |
| 685 kNoStoreBarrier, | 684 kNoStoreBarrier, |
| 686 builder.TokenPos())); | 685 builder.TokenPos())); |
| 687 Definition* null_def = builder.AddNullDefinition(); | 686 Definition* null_def = builder.AddNullDefinition(); |
| 688 builder.AddIntrinsicReturn(new Value(null_def)); | 687 builder.AddIntrinsicReturn(new Value(null_def)); |
| 689 return true; | 688 return true; |
| 690 } | 689 } |
| 691 | 690 |
| 692 } // namespace dart | 691 } // namespace dart |
| OLD | NEW |