| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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/method_recognizer.h" | 5 #include "vm/method_recognizer.h" |
| 6 | 6 |
| 7 #include "vm/object.h" | 7 #include "vm/object.h" |
| 8 #include "vm/symbols.h" | 8 #include "vm/symbols.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| 11 | 11 |
| 12 MethodRecognizer::Kind MethodRecognizer::RecognizeKind( | 12 MethodRecognizer::Kind MethodRecognizer::RecognizeKind( |
| 13 const Function& function) { | 13 const Function& function) { |
| 14 return function.recognized_kind(); | 14 return function.recognized_kind(); |
| 15 } | 15 } |
| 16 | 16 |
| 17 | 17 |
| 18 bool MethodRecognizer::AlwaysInline(const Function& function) { | 18 bool MethodRecognizer::AlwaysInline(const Function& function) { |
| 19 return function.always_inline(); | 19 return function.always_inline(); |
| 20 } | 20 } |
| 21 | 21 |
| 22 | 22 |
| 23 bool MethodRecognizer::PolymorphicTarget(const Function& function) { | 23 bool MethodRecognizer::PolymorphicTarget(const Function& function) { |
| 24 return function.is_polymorphic_target(); | 24 return function.is_polymorphic_target(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 | 27 |
| 28 #define KIND_TO_STRING(class_name, function_name, enum_name, fp) \ | 28 intptr_t MethodRecognizer::ResultCid(const Function& function) { |
| 29 switch (function.recognized_kind()) { |
| 30 #define DEFINE_CASE(cname, fname, ename, result_type, fingerprint) \ |
| 31 case k##ename: return k##result_type##Cid; |
| 32 RECOGNIZED_LIST(DEFINE_CASE) |
| 33 #undef DEFINE_CASE |
| 34 default: |
| 35 return kDynamicCid; |
| 36 } |
| 37 } |
| 38 |
| 39 |
| 40 #define KIND_TO_STRING(class_name, function_name, enum_name, type, fp) \ |
| 29 #enum_name, | 41 #enum_name, |
| 30 static const char* recognized_list_method_name[] = { | 42 static const char* recognized_list_method_name[] = { |
| 31 "Unknown", | 43 "Unknown", |
| 32 RECOGNIZED_LIST(KIND_TO_STRING) | 44 RECOGNIZED_LIST(KIND_TO_STRING) |
| 33 }; | 45 }; |
| 34 #undef KIND_TO_STRING | 46 #undef KIND_TO_STRING |
| 35 | 47 |
| 36 const char* MethodRecognizer::KindToCString(Kind kind) { | 48 const char* MethodRecognizer::KindToCString(Kind kind) { |
| 37 if (kind > kUnknown && kind < kNumRecognizedMethods) | 49 if (kind > kUnknown && kind < kNumRecognizedMethods) |
| 38 return recognized_list_method_name[kind]; | 50 return recognized_list_method_name[kind]; |
| 39 return "?"; | 51 return "?"; |
| 40 } | 52 } |
| 41 | 53 |
| 42 | 54 |
| 43 #if defined(DART_NO_SNAPSHOT) | 55 #if defined(DART_NO_SNAPSHOT) |
| 44 void MethodRecognizer::InitializeState() { | 56 void MethodRecognizer::InitializeState() { |
| 45 GrowableArray<Library*> libs(3); | 57 GrowableArray<Library*> libs(3); |
| 46 libs.Add(&Library::ZoneHandle(Library::CoreLibrary())); | 58 libs.Add(&Library::ZoneHandle(Library::CoreLibrary())); |
| 47 libs.Add(&Library::ZoneHandle(Library::CollectionLibrary())); | 59 libs.Add(&Library::ZoneHandle(Library::CollectionLibrary())); |
| 48 libs.Add(&Library::ZoneHandle(Library::MathLibrary())); | 60 libs.Add(&Library::ZoneHandle(Library::MathLibrary())); |
| 49 libs.Add(&Library::ZoneHandle(Library::TypedDataLibrary())); | 61 libs.Add(&Library::ZoneHandle(Library::TypedDataLibrary())); |
| 50 libs.Add(&Library::ZoneHandle(Library::InternalLibrary())); | 62 libs.Add(&Library::ZoneHandle(Library::InternalLibrary())); |
| 51 libs.Add(&Library::ZoneHandle(Library::DeveloperLibrary())); | 63 libs.Add(&Library::ZoneHandle(Library::DeveloperLibrary())); |
| 52 Function& func = Function::Handle(); | 64 Function& func = Function::Handle(); |
| 53 | 65 |
| 54 #define SET_RECOGNIZED_KIND(class_name, function_name, enum_name, fp) \ | 66 #define SET_RECOGNIZED_KIND(class_name, function_name, enum_name, type, fp) \ |
| 55 func = Library::GetFunction(libs, #class_name, #function_name); \ | 67 func = Library::GetFunction(libs, #class_name, #function_name); \ |
| 56 if (func.IsNull()) { \ | 68 if (func.IsNull()) { \ |
| 57 OS::PrintErr("Missing %s::%s\n", #class_name, #function_name); \ | 69 OS::PrintErr("Missing %s::%s\n", #class_name, #function_name); \ |
| 58 UNREACHABLE(); \ | 70 UNREACHABLE(); \ |
| 59 } \ | 71 } \ |
| 60 CHECK_FINGERPRINT3(func, class_name, function_name, enum_name, fp); \ | 72 CHECK_FINGERPRINT3(func, class_name, function_name, enum_name, fp); \ |
| 61 func.set_recognized_kind(k##enum_name); | 73 func.set_recognized_kind(k##enum_name); |
| 62 | 74 |
| 63 RECOGNIZED_LIST(SET_RECOGNIZED_KIND); | 75 RECOGNIZED_LIST(SET_RECOGNIZED_KIND); |
| 64 | 76 |
| 65 #define SET_FUNCTION_BIT(class_name, function_name, dest, fp, setter, value) \ | 77 #define SET_FUNCTION_BIT(class_name, function_name, dest, fp, setter, value) \ |
| 66 func = Library::GetFunction(libs, #class_name, #function_name); \ | 78 func = Library::GetFunction(libs, #class_name, #function_name); \ |
| 67 if (func.IsNull()) { \ | 79 if (func.IsNull()) { \ |
| 68 OS::PrintErr("Missing %s::%s\n", #class_name, #function_name); \ | 80 OS::PrintErr("Missing %s::%s\n", #class_name, #function_name); \ |
| 69 UNREACHABLE(); \ | 81 UNREACHABLE(); \ |
| 70 } \ | 82 } \ |
| 71 CHECK_FINGERPRINT3(func, class_name, function_name, dest, fp); \ | 83 CHECK_FINGERPRINT3(func, class_name, function_name, dest, fp); \ |
| 72 func.setter(value); | 84 func.setter(value); |
| 73 | 85 |
| 74 #define SET_IS_ALWAYS_INLINE(class_name, function_name, dest, fp) \ | 86 #define SET_IS_ALWAYS_INLINE(class_name, function_name, dest, fp) \ |
| 75 SET_FUNCTION_BIT(class_name, function_name, dest, fp, set_always_inline, true) | 87 SET_FUNCTION_BIT(class_name, function_name, dest, fp, set_always_inline, true) |
| 76 | 88 |
| 77 #define SET_IS_NEVER_INLINE(class_name, function_name, dest, fp) \ | 89 #define SET_IS_NEVER_INLINE(class_name, function_name, dest, fp) \ |
| 78 SET_FUNCTION_BIT(class_name, function_name, dest, fp, set_is_inlinable, false) | 90 SET_FUNCTION_BIT(class_name, function_name, dest, fp, set_is_inlinable, false) |
| 79 | 91 |
| 80 #define SET_IS_POLYMORPHIC_TARGET(class_name, function_name, dest, fp) \ | 92 #define SET_IS_POLYMORPHIC_TARGET(class_name, function_name, dest, fp) \ |
| 81 SET_FUNCTION_BIT(class_name, function_name, dest, fp, \ | 93 SET_FUNCTION_BIT(class_name, function_name, dest, fp, \ |
| 82 set_is_polymorphic_target, true) | 94 set_is_polymorphic_target, true) |
| 83 | 95 |
| 84 INLINE_WHITE_LIST(SET_IS_ALWAYS_INLINE); | 96 INLINE_WHITE_LIST(SET_IS_ALWAYS_INLINE); |
| 85 INLINE_BLACK_LIST(SET_IS_NEVER_INLINE); | 97 INLINE_BLACK_LIST(SET_IS_NEVER_INLINE); |
| 86 POLYMORPHIC_TARGET_LIST(SET_IS_POLYMORPHIC_TARGET); | 98 POLYMORPHIC_TARGET_LIST(SET_IS_POLYMORPHIC_TARGET); |
| 87 | 99 |
| 88 #undef SET_RECOGNIZED_KIND | 100 #undef SET_RECOGNIZED_KIND |
| 89 #undef SET_IS_ALWAYS_INLINE | 101 #undef SET_IS_ALWAYS_INLINE |
| 90 #undef SET_IS_POLYMORPHIC_TARGET | 102 #undef SET_IS_POLYMORPHIC_TARGET |
| 91 #undef SET_FUNCTION_BIT | 103 #undef SET_FUNCTION_BIT |
| 92 } | 104 } |
| 93 #endif // defined(DART_NO_SNAPSHOT). | 105 #endif // defined(DART_NO_SNAPSHOT). |
| 94 | 106 |
| 95 } // namespace dart | 107 } // namespace dart |
| OLD | NEW |