OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 6944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6955 target, static_cast<HValue*>(NULL), | 6955 target, static_cast<HValue*>(NULL), |
6956 HObjectAccess::ForFunctionContextPointer()); | 6956 HObjectAccess::ForFunctionContextPointer()); |
6957 return NewArgumentAdaptorCall(target, context, | 6957 return NewArgumentAdaptorCall(target, context, |
6958 argument_count, param_count_value); | 6958 argument_count, param_count_value); |
6959 } | 6959 } |
6960 UNREACHABLE(); | 6960 UNREACHABLE(); |
6961 return NULL; | 6961 return NULL; |
6962 } | 6962 } |
6963 | 6963 |
6964 | 6964 |
| 6965 class FunctionSorter { |
| 6966 public: |
| 6967 FunctionSorter(int index = 0, int ticks = 0, int size = 0) |
| 6968 : index_(index), ticks_(ticks), size_(size) { } |
| 6969 |
| 6970 int index() const { return index_; } |
| 6971 int ticks() const { return ticks_; } |
| 6972 int size() const { return size_; } |
| 6973 |
| 6974 private: |
| 6975 int index_; |
| 6976 int ticks_; |
| 6977 int size_; |
| 6978 }; |
| 6979 |
| 6980 |
| 6981 inline bool operator<(const FunctionSorter& lhs, const FunctionSorter& rhs) { |
| 6982 int diff = lhs.ticks() - rhs.ticks(); |
| 6983 if (diff != 0) return diff > 0; |
| 6984 return lhs.size() < rhs.size(); |
| 6985 } |
| 6986 |
| 6987 |
6965 void HOptimizedGraphBuilder::HandlePolymorphicCallNamed( | 6988 void HOptimizedGraphBuilder::HandlePolymorphicCallNamed( |
6966 Call* expr, | 6989 Call* expr, |
6967 HValue* receiver, | 6990 HValue* receiver, |
6968 SmallMapList* types, | 6991 SmallMapList* types, |
6969 Handle<String> name) { | 6992 Handle<String> name) { |
6970 int argument_count = expr->arguments()->length() + 1; // Includes receiver. | 6993 int argument_count = expr->arguments()->length() + 1; // Includes receiver. |
6971 int order[kMaxCallPolymorphism]; | 6994 FunctionSorter order[kMaxCallPolymorphism]; |
6972 | 6995 |
6973 bool handle_smi = false; | 6996 bool handle_smi = false; |
6974 bool handled_string = false; | 6997 bool handled_string = false; |
6975 int ordered_functions = 0; | 6998 int ordered_functions = 0; |
6976 | 6999 |
6977 for (int i = 0; | 7000 for (int i = 0; |
6978 i < types->length() && ordered_functions < kMaxCallPolymorphism; | 7001 i < types->length() && ordered_functions < kMaxCallPolymorphism; |
6979 ++i) { | 7002 ++i) { |
6980 PropertyAccessInfo info(this, LOAD, ToType(types->at(i)), name); | 7003 PropertyAccessInfo info(this, LOAD, ToType(types->at(i)), name); |
6981 if (info.CanAccessMonomorphic() && | 7004 if (info.CanAccessMonomorphic() && |
6982 info.lookup()->IsConstant() && | 7005 info.lookup()->IsConstant() && |
6983 info.constant()->IsJSFunction()) { | 7006 info.constant()->IsJSFunction()) { |
6984 if (info.type()->Is(Type::String())) { | 7007 if (info.type()->Is(Type::String())) { |
6985 if (handled_string) continue; | 7008 if (handled_string) continue; |
6986 handled_string = true; | 7009 handled_string = true; |
6987 } | 7010 } |
6988 Handle<JSFunction> target = Handle<JSFunction>::cast(info.constant()); | 7011 Handle<JSFunction> target = Handle<JSFunction>::cast(info.constant()); |
6989 if (info.type()->Is(Type::Number())) { | 7012 if (info.type()->Is(Type::Number())) { |
6990 handle_smi = true; | 7013 handle_smi = true; |
6991 } | 7014 } |
6992 expr->set_target(target); | 7015 expr->set_target(target); |
6993 order[ordered_functions++] = i; | 7016 order[ordered_functions++] = FunctionSorter( |
| 7017 i, target->shared()->profiler_ticks(), InliningAstSize(target)); |
6994 } | 7018 } |
6995 } | 7019 } |
6996 | 7020 |
| 7021 std::sort(order, order + ordered_functions); |
| 7022 |
6997 HBasicBlock* number_block = NULL; | 7023 HBasicBlock* number_block = NULL; |
6998 HBasicBlock* join = NULL; | 7024 HBasicBlock* join = NULL; |
6999 handled_string = false; | 7025 handled_string = false; |
7000 int count = 0; | 7026 int count = 0; |
7001 | 7027 |
7002 for (int fn = 0; fn < ordered_functions; ++fn) { | 7028 for (int fn = 0; fn < ordered_functions; ++fn) { |
7003 int i = order[fn]; | 7029 int i = order[fn].index(); |
7004 PropertyAccessInfo info(this, LOAD, ToType(types->at(i)), name); | 7030 PropertyAccessInfo info(this, LOAD, ToType(types->at(i)), name); |
7005 if (info.type()->Is(Type::String())) { | 7031 if (info.type()->Is(Type::String())) { |
7006 if (handled_string) continue; | 7032 if (handled_string) continue; |
7007 handled_string = true; | 7033 handled_string = true; |
7008 } | 7034 } |
7009 // Reloads the target. | 7035 // Reloads the target. |
7010 info.CanAccessMonomorphic(); | 7036 info.CanAccessMonomorphic(); |
7011 Handle<JSFunction> target = Handle<JSFunction>::cast(info.constant()); | 7037 Handle<JSFunction> target = Handle<JSFunction>::cast(info.constant()); |
7012 | 7038 |
7013 expr->set_target(target); | 7039 expr->set_target(target); |
(...skipping 4632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11646 if (ShouldProduceTraceOutput()) { | 11672 if (ShouldProduceTraceOutput()) { |
11647 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 11673 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
11648 } | 11674 } |
11649 | 11675 |
11650 #ifdef DEBUG | 11676 #ifdef DEBUG |
11651 graph_->Verify(false); // No full verify. | 11677 graph_->Verify(false); // No full verify. |
11652 #endif | 11678 #endif |
11653 } | 11679 } |
11654 | 11680 |
11655 } } // namespace v8::internal | 11681 } } // namespace v8::internal |
OLD | NEW |