OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/ast.h" | 5 #include "src/ast.h" |
6 | 6 |
7 #include <cmath> // For isfinite. | 7 #include <cmath> // For isfinite. |
8 #include "src/builtins.h" | 8 #include "src/builtins.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/contexts.h" | 10 #include "src/contexts.h" |
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 } | 1021 } |
1022 #define REGULAR_NODE_WITH_FEEDBACK_SLOTS(NodeType) \ | 1022 #define REGULAR_NODE_WITH_FEEDBACK_SLOTS(NodeType) \ |
1023 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ | 1023 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
1024 increase_node_count(); \ | 1024 increase_node_count(); \ |
1025 add_slot_node(node); \ | 1025 add_slot_node(node); \ |
1026 } | 1026 } |
1027 #define DONT_OPTIMIZE_NODE(NodeType) \ | 1027 #define DONT_OPTIMIZE_NODE(NodeType) \ |
1028 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ | 1028 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
1029 increase_node_count(); \ | 1029 increase_node_count(); \ |
1030 set_dont_optimize_reason(k##NodeType); \ | 1030 set_dont_optimize_reason(k##NodeType); \ |
1031 add_flag(kDontInline); \ | |
1032 add_flag(kDontSelfOptimize); \ | 1031 add_flag(kDontSelfOptimize); \ |
1033 } | 1032 } |
1034 #define DONT_SELFOPTIMIZE_NODE(NodeType) \ | 1033 #define DONT_SELFOPTIMIZE_NODE(NodeType) \ |
1035 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ | 1034 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
1036 increase_node_count(); \ | 1035 increase_node_count(); \ |
1037 add_flag(kDontSelfOptimize); \ | 1036 add_flag(kDontSelfOptimize); \ |
1038 } | 1037 } |
1039 #define DONT_SELFOPTIMIZE_NODE_WITH_FEEDBACK_SLOTS(NodeType) \ | 1038 #define DONT_SELFOPTIMIZE_NODE_WITH_FEEDBACK_SLOTS(NodeType) \ |
1040 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ | 1039 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
1041 increase_node_count(); \ | 1040 increase_node_count(); \ |
1042 add_slot_node(node); \ | 1041 add_slot_node(node); \ |
1043 add_flag(kDontSelfOptimize); \ | 1042 add_flag(kDontSelfOptimize); \ |
1044 } | 1043 } |
1045 #define DONT_CACHE_NODE(NodeType) \ | 1044 #define DONT_CACHE_NODE(NodeType) \ |
1046 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ | 1045 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
1047 increase_node_count(); \ | 1046 increase_node_count(); \ |
1048 set_dont_optimize_reason(k##NodeType); \ | 1047 set_dont_optimize_reason(k##NodeType); \ |
1049 add_flag(kDontInline); \ | |
1050 add_flag(kDontSelfOptimize); \ | 1048 add_flag(kDontSelfOptimize); \ |
1051 add_flag(kDontCache); \ | 1049 add_flag(kDontCache); \ |
1052 } | 1050 } |
1053 | 1051 |
1054 REGULAR_NODE(VariableDeclaration) | 1052 REGULAR_NODE(VariableDeclaration) |
1055 REGULAR_NODE(FunctionDeclaration) | 1053 REGULAR_NODE(FunctionDeclaration) |
1056 REGULAR_NODE(Block) | 1054 REGULAR_NODE(Block) |
1057 REGULAR_NODE(ExpressionStatement) | 1055 REGULAR_NODE(ExpressionStatement) |
1058 REGULAR_NODE(EmptyStatement) | 1056 REGULAR_NODE(EmptyStatement) |
1059 REGULAR_NODE(IfStatement) | 1057 REGULAR_NODE(IfStatement) |
(...skipping 12 matching lines...) Expand all Loading... |
1072 REGULAR_NODE(Throw) | 1070 REGULAR_NODE(Throw) |
1073 REGULAR_NODE(Property) | 1071 REGULAR_NODE(Property) |
1074 REGULAR_NODE(UnaryOperation) | 1072 REGULAR_NODE(UnaryOperation) |
1075 REGULAR_NODE(CountOperation) | 1073 REGULAR_NODE(CountOperation) |
1076 REGULAR_NODE(BinaryOperation) | 1074 REGULAR_NODE(BinaryOperation) |
1077 REGULAR_NODE(CompareOperation) | 1075 REGULAR_NODE(CompareOperation) |
1078 REGULAR_NODE(ThisFunction) | 1076 REGULAR_NODE(ThisFunction) |
1079 REGULAR_NODE_WITH_FEEDBACK_SLOTS(Call) | 1077 REGULAR_NODE_WITH_FEEDBACK_SLOTS(Call) |
1080 REGULAR_NODE_WITH_FEEDBACK_SLOTS(CallNew) | 1078 REGULAR_NODE_WITH_FEEDBACK_SLOTS(CallNew) |
1081 // In theory, for VariableProxy we'd have to add: | 1079 // In theory, for VariableProxy we'd have to add: |
1082 // if (node->var()->IsLookupSlot()) add_flag(kDontInline); | 1080 // if (node->var()->IsLookupSlot()) |
| 1081 // set_dont_optimize_reason(kReferenceToAVariableWhichRequiresDynamicLookup); |
1083 // But node->var() is usually not bound yet at VariableProxy creation time, and | 1082 // But node->var() is usually not bound yet at VariableProxy creation time, and |
1084 // LOOKUP variables only result from constructs that cannot be inlined anyway. | 1083 // LOOKUP variables only result from constructs that cannot be inlined anyway. |
1085 REGULAR_NODE(VariableProxy) | 1084 REGULAR_NODE(VariableProxy) |
1086 | 1085 |
1087 // We currently do not optimize any modules. | 1086 // We currently do not optimize any modules. |
1088 DONT_OPTIMIZE_NODE(ModuleDeclaration) | 1087 DONT_OPTIMIZE_NODE(ModuleDeclaration) |
1089 DONT_OPTIMIZE_NODE(ImportDeclaration) | 1088 DONT_OPTIMIZE_NODE(ImportDeclaration) |
1090 DONT_OPTIMIZE_NODE(ExportDeclaration) | 1089 DONT_OPTIMIZE_NODE(ExportDeclaration) |
1091 DONT_OPTIMIZE_NODE(ModuleVariable) | 1090 DONT_OPTIMIZE_NODE(ModuleVariable) |
1092 DONT_OPTIMIZE_NODE(ModulePath) | 1091 DONT_OPTIMIZE_NODE(ModulePath) |
(...skipping 11 matching lines...) Expand all Loading... |
1104 DONT_SELFOPTIMIZE_NODE(ForStatement) | 1103 DONT_SELFOPTIMIZE_NODE(ForStatement) |
1105 DONT_SELFOPTIMIZE_NODE_WITH_FEEDBACK_SLOTS(ForInStatement) | 1104 DONT_SELFOPTIMIZE_NODE_WITH_FEEDBACK_SLOTS(ForInStatement) |
1106 DONT_SELFOPTIMIZE_NODE(ForOfStatement) | 1105 DONT_SELFOPTIMIZE_NODE(ForOfStatement) |
1107 | 1106 |
1108 DONT_CACHE_NODE(ModuleLiteral) | 1107 DONT_CACHE_NODE(ModuleLiteral) |
1109 | 1108 |
1110 | 1109 |
1111 void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) { | 1110 void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) { |
1112 increase_node_count(); | 1111 increase_node_count(); |
1113 if (node->is_jsruntime()) { | 1112 if (node->is_jsruntime()) { |
1114 // Don't try to inline JS runtime calls because we don't (currently) even | 1113 // Don't try to optimize JS runtime calls because we bailout on them. |
1115 // optimize them. | 1114 set_dont_optimize_reason(kCallToAJavaScriptRuntimeFunction); |
1116 add_flag(kDontInline); | |
1117 } | 1115 } |
1118 } | 1116 } |
1119 | 1117 |
1120 #undef REGULAR_NODE | 1118 #undef REGULAR_NODE |
1121 #undef DONT_OPTIMIZE_NODE | 1119 #undef DONT_OPTIMIZE_NODE |
1122 #undef DONT_SELFOPTIMIZE_NODE | 1120 #undef DONT_SELFOPTIMIZE_NODE |
1123 #undef DONT_CACHE_NODE | 1121 #undef DONT_CACHE_NODE |
1124 | 1122 |
1125 | 1123 |
1126 Handle<String> Literal::ToString() { | 1124 Handle<String> Literal::ToString() { |
1127 if (value_->IsString()) return value_->AsString()->string(); | 1125 if (value_->IsString()) return value_->AsString()->string(); |
1128 ASSERT(value_->IsNumber()); | 1126 ASSERT(value_->IsNumber()); |
1129 char arr[100]; | 1127 char arr[100]; |
1130 Vector<char> buffer(arr, ARRAY_SIZE(arr)); | 1128 Vector<char> buffer(arr, ARRAY_SIZE(arr)); |
1131 const char* str; | 1129 const char* str; |
1132 if (value()->IsSmi()) { | 1130 if (value()->IsSmi()) { |
1133 // Optimization only, the heap number case would subsume this. | 1131 // Optimization only, the heap number case would subsume this. |
1134 SNPrintF(buffer, "%d", Smi::cast(*value())->value()); | 1132 SNPrintF(buffer, "%d", Smi::cast(*value())->value()); |
1135 str = arr; | 1133 str = arr; |
1136 } else { | 1134 } else { |
1137 str = DoubleToCString(value()->Number(), buffer); | 1135 str = DoubleToCString(value()->Number(), buffer); |
1138 } | 1136 } |
1139 return isolate_->factory()->NewStringFromAsciiChecked(str); | 1137 return isolate_->factory()->NewStringFromAsciiChecked(str); |
1140 } | 1138 } |
1141 | 1139 |
1142 | 1140 |
1143 } } // namespace v8::internal | 1141 } } // namespace v8::internal |
OLD | NEW |