OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 #define DONT_INLINE_NODE(NodeType) \ | 1026 #define DONT_INLINE_NODE(NodeType) \ |
1027 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ | 1027 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
1028 increase_node_count(); \ | 1028 increase_node_count(); \ |
1029 add_flag(kDontInline); \ | 1029 add_flag(kDontInline); \ |
1030 } | 1030 } |
1031 #define DONT_SELFOPTIMIZE_NODE(NodeType) \ | 1031 #define DONT_SELFOPTIMIZE_NODE(NodeType) \ |
1032 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ | 1032 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
1033 increase_node_count(); \ | 1033 increase_node_count(); \ |
1034 add_flag(kDontSelfOptimize); \ | 1034 add_flag(kDontSelfOptimize); \ |
1035 } | 1035 } |
| 1036 #define DONT_CACHE_NODE(NodeType) \ |
| 1037 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
| 1038 increase_node_count(); \ |
| 1039 add_flag(kDontOptimize); \ |
| 1040 add_flag(kDontInline); \ |
| 1041 add_flag(kDontSelfOptimize); \ |
| 1042 add_flag(kDontCache); \ |
| 1043 } |
1036 | 1044 |
1037 REGULAR_NODE(VariableDeclaration) | 1045 REGULAR_NODE(VariableDeclaration) |
1038 REGULAR_NODE(FunctionDeclaration) | 1046 REGULAR_NODE(FunctionDeclaration) |
1039 REGULAR_NODE(Block) | 1047 REGULAR_NODE(Block) |
1040 REGULAR_NODE(ExpressionStatement) | 1048 REGULAR_NODE(ExpressionStatement) |
1041 REGULAR_NODE(EmptyStatement) | 1049 REGULAR_NODE(EmptyStatement) |
1042 REGULAR_NODE(IfStatement) | 1050 REGULAR_NODE(IfStatement) |
1043 REGULAR_NODE(ContinueStatement) | 1051 REGULAR_NODE(ContinueStatement) |
1044 REGULAR_NODE(BreakStatement) | 1052 REGULAR_NODE(BreakStatement) |
1045 REGULAR_NODE(ReturnStatement) | 1053 REGULAR_NODE(ReturnStatement) |
(...skipping 12 matching lines...) Expand all Loading... |
1058 REGULAR_NODE(CompareOperation) | 1066 REGULAR_NODE(CompareOperation) |
1059 REGULAR_NODE(ThisFunction) | 1067 REGULAR_NODE(ThisFunction) |
1060 REGULAR_NODE(Call) | 1068 REGULAR_NODE(Call) |
1061 REGULAR_NODE(CallNew) | 1069 REGULAR_NODE(CallNew) |
1062 // In theory, for VariableProxy we'd have to add: | 1070 // In theory, for VariableProxy we'd have to add: |
1063 // if (node->var()->IsLookupSlot()) add_flag(kDontInline); | 1071 // if (node->var()->IsLookupSlot()) add_flag(kDontInline); |
1064 // But node->var() is usually not bound yet at VariableProxy creation time, and | 1072 // But node->var() is usually not bound yet at VariableProxy creation time, and |
1065 // LOOKUP variables only result from constructs that cannot be inlined anyway. | 1073 // LOOKUP variables only result from constructs that cannot be inlined anyway. |
1066 REGULAR_NODE(VariableProxy) | 1074 REGULAR_NODE(VariableProxy) |
1067 | 1075 |
| 1076 // We currently do not optimize any modules. Note in particular, that module |
| 1077 // instance objects associated with ModuleLiterals are allocated during |
| 1078 // scope resolution, and references to them are embedded into the code. |
| 1079 // That code may hence neither be cached nor re-compiled. |
1068 DONT_OPTIMIZE_NODE(ModuleDeclaration) | 1080 DONT_OPTIMIZE_NODE(ModuleDeclaration) |
1069 DONT_OPTIMIZE_NODE(ImportDeclaration) | 1081 DONT_OPTIMIZE_NODE(ImportDeclaration) |
1070 DONT_OPTIMIZE_NODE(ExportDeclaration) | 1082 DONT_OPTIMIZE_NODE(ExportDeclaration) |
1071 DONT_OPTIMIZE_NODE(ModuleLiteral) | |
1072 DONT_OPTIMIZE_NODE(ModuleVariable) | 1083 DONT_OPTIMIZE_NODE(ModuleVariable) |
1073 DONT_OPTIMIZE_NODE(ModulePath) | 1084 DONT_OPTIMIZE_NODE(ModulePath) |
1074 DONT_OPTIMIZE_NODE(ModuleUrl) | 1085 DONT_OPTIMIZE_NODE(ModuleUrl) |
1075 DONT_OPTIMIZE_NODE(WithStatement) | 1086 DONT_OPTIMIZE_NODE(WithStatement) |
1076 DONT_OPTIMIZE_NODE(TryCatchStatement) | 1087 DONT_OPTIMIZE_NODE(TryCatchStatement) |
1077 DONT_OPTIMIZE_NODE(TryFinallyStatement) | 1088 DONT_OPTIMIZE_NODE(TryFinallyStatement) |
1078 DONT_OPTIMIZE_NODE(DebuggerStatement) | 1089 DONT_OPTIMIZE_NODE(DebuggerStatement) |
1079 DONT_OPTIMIZE_NODE(SharedFunctionInfoLiteral) | 1090 DONT_OPTIMIZE_NODE(SharedFunctionInfoLiteral) |
1080 | 1091 |
1081 DONT_INLINE_NODE(FunctionLiteral) | 1092 DONT_INLINE_NODE(FunctionLiteral) |
1082 | 1093 |
1083 DONT_SELFOPTIMIZE_NODE(DoWhileStatement) | 1094 DONT_SELFOPTIMIZE_NODE(DoWhileStatement) |
1084 DONT_SELFOPTIMIZE_NODE(WhileStatement) | 1095 DONT_SELFOPTIMIZE_NODE(WhileStatement) |
1085 DONT_SELFOPTIMIZE_NODE(ForStatement) | 1096 DONT_SELFOPTIMIZE_NODE(ForStatement) |
1086 DONT_SELFOPTIMIZE_NODE(ForInStatement) | 1097 DONT_SELFOPTIMIZE_NODE(ForInStatement) |
1087 | 1098 |
| 1099 DONT_CACHE_NODE(ModuleLiteral) |
| 1100 |
1088 void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) { | 1101 void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) { |
1089 increase_node_count(); | 1102 increase_node_count(); |
1090 if (node->is_jsruntime()) { | 1103 if (node->is_jsruntime()) { |
1091 // Don't try to inline JS runtime calls because we don't (currently) even | 1104 // Don't try to inline JS runtime calls because we don't (currently) even |
1092 // optimize them. | 1105 // optimize them. |
1093 add_flag(kDontInline); | 1106 add_flag(kDontInline); |
1094 } else if (node->function()->intrinsic_type == Runtime::INLINE && | 1107 } else if (node->function()->intrinsic_type == Runtime::INLINE && |
1095 (node->name()->IsEqualTo(CStrVector("_ArgumentsLength")) || | 1108 (node->name()->IsEqualTo(CStrVector("_ArgumentsLength")) || |
1096 node->name()->IsEqualTo(CStrVector("_Arguments")))) { | 1109 node->name()->IsEqualTo(CStrVector("_Arguments")))) { |
1097 // Don't inline the %_ArgumentsLength or %_Arguments because their | 1110 // Don't inline the %_ArgumentsLength or %_Arguments because their |
1098 // implementation will not work. There is no stack frame to get them | 1111 // implementation will not work. There is no stack frame to get them |
1099 // from. | 1112 // from. |
1100 add_flag(kDontInline); | 1113 add_flag(kDontInline); |
1101 } | 1114 } |
1102 } | 1115 } |
1103 | 1116 |
1104 #undef REGULAR_NODE | 1117 #undef REGULAR_NODE |
1105 #undef DONT_OPTIMIZE_NODE | 1118 #undef DONT_OPTIMIZE_NODE |
1106 #undef DONT_INLINE_NODE | 1119 #undef DONT_INLINE_NODE |
1107 #undef DONT_SELFOPTIMIZE_NODE | 1120 #undef DONT_SELFOPTIMIZE_NODE |
| 1121 #undef DONT_CACHE_NODE |
1108 | 1122 |
1109 | 1123 |
1110 Handle<String> Literal::ToString() { | 1124 Handle<String> Literal::ToString() { |
1111 if (handle_->IsString()) return Handle<String>::cast(handle_); | 1125 if (handle_->IsString()) return Handle<String>::cast(handle_); |
1112 ASSERT(handle_->IsNumber()); | 1126 ASSERT(handle_->IsNumber()); |
1113 char arr[100]; | 1127 char arr[100]; |
1114 Vector<char> buffer(arr, ARRAY_SIZE(arr)); | 1128 Vector<char> buffer(arr, ARRAY_SIZE(arr)); |
1115 const char* str; | 1129 const char* str; |
1116 if (handle_->IsSmi()) { | 1130 if (handle_->IsSmi()) { |
1117 // Optimization only, the heap number case would subsume this. | 1131 // Optimization only, the heap number case would subsume this. |
1118 OS::SNPrintF(buffer, "%d", Smi::cast(*handle_)->value()); | 1132 OS::SNPrintF(buffer, "%d", Smi::cast(*handle_)->value()); |
1119 str = arr; | 1133 str = arr; |
1120 } else { | 1134 } else { |
1121 str = DoubleToCString(handle_->Number(), buffer); | 1135 str = DoubleToCString(handle_->Number(), buffer); |
1122 } | 1136 } |
1123 return FACTORY->NewStringFromAscii(CStrVector(str)); | 1137 return FACTORY->NewStringFromAscii(CStrVector(str)); |
1124 } | 1138 } |
1125 | 1139 |
1126 | 1140 |
1127 } } // namespace v8::internal | 1141 } } // namespace v8::internal |
OLD | NEW |