| 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/intrinsifier.h" | 6 #include "vm/intrinsifier.h" |
| 7 #include "vm/flags.h" | 7 #include "vm/flags.h" |
| 8 #include "vm/object.h" | 8 #include "vm/object.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 static bool TestFunction(const Function& function, | 43 static bool TestFunction(const Function& function, |
| 44 const char* function_class_name, | 44 const char* function_class_name, |
| 45 const char* function_name, | 45 const char* function_name, |
| 46 const char* test_class_name, | 46 const char* test_class_name, |
| 47 const char* test_function_name) { | 47 const char* test_function_name) { |
| 48 return CompareNames(test_class_name, function_class_name) && | 48 return CompareNames(test_class_name, function_class_name) && |
| 49 CompareNames(test_function_name, function_name); | 49 CompareNames(test_function_name, function_name); |
| 50 } | 50 } |
| 51 | 51 |
| 52 | 52 |
| 53 bool Intrinsifier::Intrinsify(const Function& function, Assembler* assembler) { | 53 bool Intrinsifier::CanIntrinsify(const Function& function) { |
| 54 if (!FLAG_intrinsify) return false; | 54 if (!FLAG_intrinsify) return false; |
| 55 // Closure functions may have different arguments. | 55 // Closure functions may have different arguments. |
| 56 if (function.IsClosureFunction()) return false; | 56 if (function.IsClosureFunction()) return false; |
| 57 const char* function_name = String::Handle(function.name()).ToCString(); | 57 const char* function_name = String::Handle(function.name()).ToCString(); |
| 58 const Class& function_class = Class::Handle(function.Owner()); | 58 const Class& function_class = Class::Handle(function.Owner()); |
| 59 const char* class_name = String::Handle(function_class.Name()).ToCString(); | 59 const char* class_name = String::Handle(function_class.Name()).ToCString(); |
| 60 // Only core and math library methods can be intrinsified. | 60 // Only core and math library methods can be intrinsified. |
| 61 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | 61 const Library& core_lib = Library::Handle(Library::CoreLibrary()); |
| 62 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); | 62 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); |
| 63 const Library& math_lib = Library::Handle(Library::MathLibrary()); | 63 const Library& math_lib = Library::Handle(Library::MathLibrary()); |
| 64 if ((function_class.library() != core_lib.raw()) && | 64 if ((function_class.library() != core_lib.raw()) && |
| 65 (function_class.library() != core_impl_lib.raw()) && | 65 (function_class.library() != core_impl_lib.raw()) && |
| 66 (function_class.library() != math_lib.raw())) { | 66 (function_class.library() != math_lib.raw())) { |
| 67 return false; | 67 return false; |
| 68 } | 68 } |
| 69 #define FIND_INTRINSICS(test_class_name, test_function_name, destination) \ | 69 #define FIND_INTRINSICS(test_class_name, test_function_name, destination) \ |
| 70 if (TestFunction(function, \ | 70 if (TestFunction(function, \ |
| 71 class_name, function_name, \ | 71 class_name, function_name, \ |
| 72 #test_class_name, #test_function_name)) { \ | 72 #test_class_name, #test_function_name)) { \ |
| 73 return true; \ |
| 74 } \ |
| 75 |
| 76 INTRINSIC_LIST(FIND_INTRINSICS); |
| 77 #undef FIND_INTRINSICS |
| 78 return false; |
| 79 } |
| 80 |
| 81 bool Intrinsifier::Intrinsify(const Function& function, Assembler* assembler) { |
| 82 if (!CanIntrinsify(function)) return false; |
| 83 const char* function_name = String::Handle(function.name()).ToCString(); |
| 84 const Class& function_class = Class::Handle(function.Owner()); |
| 85 const char* class_name = String::Handle(function_class.Name()).ToCString(); |
| 86 #define FIND_INTRINSICS(test_class_name, test_function_name, destination) \ |
| 87 if (TestFunction(function, \ |
| 88 class_name, function_name, \ |
| 89 #test_class_name, #test_function_name)) { \ |
| 73 return destination(assembler); \ | 90 return destination(assembler); \ |
| 74 } \ | 91 } \ |
| 75 | 92 |
| 76 INTRINSIC_LIST(FIND_INTRINSICS); | 93 INTRINSIC_LIST(FIND_INTRINSICS); |
| 77 #undef FIND_INTRINSICS | 94 #undef FIND_INTRINSICS |
| 78 return false; | 95 return false; |
| 79 } | 96 } |
| 80 | 97 |
| 81 } // namespace dart | 98 } // namespace dart |
| OLD | NEW |