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 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 int pos) | 986 int pos) |
987 : label_(label), | 987 : label_(label), |
988 statements_(statements), | 988 statements_(statements), |
989 position_(pos), | 989 position_(pos), |
990 compare_type_(NONE), | 990 compare_type_(NONE), |
991 compare_id_(AstNode::GetNextId(isolate)), | 991 compare_id_(AstNode::GetNextId(isolate)), |
992 entry_id_(AstNode::GetNextId(isolate)) { | 992 entry_id_(AstNode::GetNextId(isolate)) { |
993 } | 993 } |
994 | 994 |
995 | 995 |
996 #define INCREASE_NODE_COUNT(NodeType) \ | 996 #define REGULAR_NODE(NodeType) \ |
997 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ | 997 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
998 increase_node_count(); \ | 998 increase_node_count(); \ |
999 } | 999 } |
| 1000 #define DONT_OPTIMIZE_NODE(NodeType) \ |
| 1001 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
| 1002 increase_node_count(); \ |
| 1003 add_flag(kDontOptimize); \ |
| 1004 add_flag(kDontInline); \ |
| 1005 add_flag(kDontSelfOptimize); \ |
| 1006 } |
| 1007 #define DONT_INLINE_NODE(NodeType) \ |
| 1008 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
| 1009 increase_node_count(); \ |
| 1010 add_flag(kDontInline); \ |
| 1011 } |
| 1012 #define DONT_SELFOPTIMIZE_NODE(NodeType) \ |
| 1013 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
| 1014 increase_node_count(); \ |
| 1015 add_flag(kDontSelfOptimize); \ |
| 1016 } |
1000 | 1017 |
1001 INCREASE_NODE_COUNT(VariableDeclaration) | 1018 REGULAR_NODE(VariableDeclaration) |
1002 INCREASE_NODE_COUNT(FunctionDeclaration) | 1019 REGULAR_NODE(FunctionDeclaration) |
1003 INCREASE_NODE_COUNT(ModuleDeclaration) | 1020 REGULAR_NODE(Block) |
1004 INCREASE_NODE_COUNT(ImportDeclaration) | 1021 REGULAR_NODE(ExpressionStatement) |
1005 INCREASE_NODE_COUNT(ExportDeclaration) | 1022 REGULAR_NODE(EmptyStatement) |
1006 INCREASE_NODE_COUNT(ModuleLiteral) | 1023 REGULAR_NODE(IfStatement) |
1007 INCREASE_NODE_COUNT(ModuleVariable) | 1024 REGULAR_NODE(ContinueStatement) |
1008 INCREASE_NODE_COUNT(ModulePath) | 1025 REGULAR_NODE(BreakStatement) |
1009 INCREASE_NODE_COUNT(ModuleUrl) | 1026 REGULAR_NODE(ReturnStatement) |
1010 INCREASE_NODE_COUNT(Block) | 1027 REGULAR_NODE(Conditional) |
1011 INCREASE_NODE_COUNT(ExpressionStatement) | 1028 REGULAR_NODE(Literal) |
1012 INCREASE_NODE_COUNT(EmptyStatement) | 1029 REGULAR_NODE(ObjectLiteral) |
1013 INCREASE_NODE_COUNT(IfStatement) | 1030 REGULAR_NODE(Assignment) |
1014 INCREASE_NODE_COUNT(ContinueStatement) | 1031 REGULAR_NODE(Throw) |
1015 INCREASE_NODE_COUNT(BreakStatement) | 1032 REGULAR_NODE(Property) |
1016 INCREASE_NODE_COUNT(ReturnStatement) | 1033 REGULAR_NODE(UnaryOperation) |
1017 INCREASE_NODE_COUNT(Conditional) | 1034 REGULAR_NODE(CountOperation) |
1018 INCREASE_NODE_COUNT(Literal) | 1035 REGULAR_NODE(BinaryOperation) |
1019 INCREASE_NODE_COUNT(ObjectLiteral) | 1036 REGULAR_NODE(CompareOperation) |
1020 INCREASE_NODE_COUNT(Assignment) | 1037 REGULAR_NODE(ThisFunction) |
1021 INCREASE_NODE_COUNT(Throw) | 1038 REGULAR_NODE(Call) |
1022 INCREASE_NODE_COUNT(Property) | 1039 REGULAR_NODE(CallNew) |
1023 INCREASE_NODE_COUNT(UnaryOperation) | 1040 // In theory, for VariableProxy we'd have to add: |
1024 INCREASE_NODE_COUNT(CountOperation) | 1041 // if (node->var()->IsLookupSlot()) add_flag(kDontInline); |
1025 INCREASE_NODE_COUNT(BinaryOperation) | 1042 // But node->var() is usually not bound yet at VariableProxy creation time, and |
1026 INCREASE_NODE_COUNT(CompareOperation) | 1043 // LOOKUP variables only result from constructs that cannot be inlined anyway. |
1027 INCREASE_NODE_COUNT(ThisFunction) | 1044 REGULAR_NODE(VariableProxy) |
1028 INCREASE_NODE_COUNT(Call) | |
1029 INCREASE_NODE_COUNT(CallNew) | |
1030 | 1045 |
1031 #undef INCREASE_NODE_COUNT | 1046 DONT_OPTIMIZE_NODE(ModuleDeclaration) |
| 1047 DONT_OPTIMIZE_NODE(ImportDeclaration) |
| 1048 DONT_OPTIMIZE_NODE(ExportDeclaration) |
| 1049 DONT_OPTIMIZE_NODE(ModuleLiteral) |
| 1050 DONT_OPTIMIZE_NODE(ModuleVariable) |
| 1051 DONT_OPTIMIZE_NODE(ModulePath) |
| 1052 DONT_OPTIMIZE_NODE(ModuleUrl) |
| 1053 DONT_OPTIMIZE_NODE(WithStatement) |
| 1054 DONT_OPTIMIZE_NODE(TryCatchStatement) |
| 1055 DONT_OPTIMIZE_NODE(TryFinallyStatement) |
| 1056 DONT_OPTIMIZE_NODE(DebuggerStatement) |
| 1057 DONT_OPTIMIZE_NODE(SharedFunctionInfoLiteral) |
1032 | 1058 |
| 1059 DONT_INLINE_NODE(SwitchStatement) |
| 1060 DONT_INLINE_NODE(FunctionLiteral) |
| 1061 DONT_INLINE_NODE(RegExpLiteral) // TODO(1322): Allow materialized literals. |
| 1062 DONT_INLINE_NODE(ArrayLiteral) // TODO(1322): Allow materialized literals. |
1033 | 1063 |
1034 void AstConstructionVisitor::VisitWithStatement(WithStatement* node) { | 1064 DONT_SELFOPTIMIZE_NODE(DoWhileStatement) |
1035 increase_node_count(); | 1065 DONT_SELFOPTIMIZE_NODE(WhileStatement) |
1036 add_flag(kDontOptimize); | 1066 DONT_SELFOPTIMIZE_NODE(ForStatement) |
1037 add_flag(kDontInline); | 1067 DONT_SELFOPTIMIZE_NODE(ForInStatement) |
1038 } | |
1039 | |
1040 | |
1041 void AstConstructionVisitor::VisitSwitchStatement(SwitchStatement* node) { | |
1042 increase_node_count(); | |
1043 add_flag(kDontInline); | |
1044 } | |
1045 | |
1046 | |
1047 void AstConstructionVisitor::VisitDoWhileStatement(DoWhileStatement* node) { | |
1048 increase_node_count(); | |
1049 add_flag(kDontSelfOptimize); | |
1050 } | |
1051 | |
1052 | |
1053 void AstConstructionVisitor::VisitWhileStatement(WhileStatement* node) { | |
1054 increase_node_count(); | |
1055 add_flag(kDontSelfOptimize); | |
1056 } | |
1057 | |
1058 | |
1059 void AstConstructionVisitor::VisitForStatement(ForStatement* node) { | |
1060 increase_node_count(); | |
1061 add_flag(kDontSelfOptimize); | |
1062 } | |
1063 | |
1064 | |
1065 void AstConstructionVisitor::VisitForInStatement(ForInStatement* node) { | |
1066 increase_node_count(); | |
1067 add_flag(kDontSelfOptimize); | |
1068 } | |
1069 | |
1070 | |
1071 void AstConstructionVisitor::VisitTryCatchStatement(TryCatchStatement* node) { | |
1072 increase_node_count(); | |
1073 add_flag(kDontOptimize); | |
1074 add_flag(kDontInline); | |
1075 } | |
1076 | |
1077 | |
1078 void AstConstructionVisitor::VisitTryFinallyStatement( | |
1079 TryFinallyStatement* node) { | |
1080 increase_node_count(); | |
1081 add_flag(kDontOptimize); | |
1082 add_flag(kDontInline); | |
1083 } | |
1084 | |
1085 | |
1086 void AstConstructionVisitor::VisitDebuggerStatement(DebuggerStatement* node) { | |
1087 increase_node_count(); | |
1088 add_flag(kDontOptimize); | |
1089 add_flag(kDontInline); | |
1090 } | |
1091 | |
1092 | |
1093 void AstConstructionVisitor::VisitFunctionLiteral(FunctionLiteral* node) { | |
1094 increase_node_count(); | |
1095 add_flag(kDontInline); | |
1096 } | |
1097 | |
1098 | |
1099 void AstConstructionVisitor::VisitSharedFunctionInfoLiteral( | |
1100 SharedFunctionInfoLiteral* node) { | |
1101 increase_node_count(); | |
1102 add_flag(kDontOptimize); | |
1103 add_flag(kDontInline); | |
1104 } | |
1105 | |
1106 | |
1107 void AstConstructionVisitor::VisitVariableProxy(VariableProxy* node) { | |
1108 increase_node_count(); | |
1109 // In theory, we'd have to add: | |
1110 // if(node->var()->IsLookupSlot()) { add_flag(kDontInline); } | |
1111 // However, node->var() is usually not bound yet at VariableProxy creation | |
1112 // time, and LOOKUP variables only result from constructs that cannot | |
1113 // be inlined anyway. | |
1114 } | |
1115 | |
1116 | |
1117 void AstConstructionVisitor::VisitRegExpLiteral(RegExpLiteral* node) { | |
1118 increase_node_count(); | |
1119 add_flag(kDontInline); // TODO(1322): Allow materialized literals. | |
1120 } | |
1121 | |
1122 | |
1123 void AstConstructionVisitor::VisitArrayLiteral(ArrayLiteral* node) { | |
1124 increase_node_count(); | |
1125 add_flag(kDontInline); // TODO(1322): Allow materialized literals. | |
1126 } | |
1127 | |
1128 | 1068 |
1129 void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) { | 1069 void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) { |
1130 increase_node_count(); | 1070 increase_node_count(); |
1131 if (node->is_jsruntime()) { | 1071 if (node->is_jsruntime()) { |
1132 // Don't try to inline JS runtime calls because we don't (currently) even | 1072 // Don't try to inline JS runtime calls because we don't (currently) even |
1133 // optimize them. | 1073 // optimize them. |
1134 add_flag(kDontInline); | 1074 add_flag(kDontInline); |
1135 } else if (node->function()->intrinsic_type == Runtime::INLINE && | 1075 } else if (node->function()->intrinsic_type == Runtime::INLINE && |
1136 (node->name()->IsEqualTo(CStrVector("_ArgumentsLength")) || | 1076 (node->name()->IsEqualTo(CStrVector("_ArgumentsLength")) || |
1137 node->name()->IsEqualTo(CStrVector("_Arguments")))) { | 1077 node->name()->IsEqualTo(CStrVector("_Arguments")))) { |
1138 // Don't inline the %_ArgumentsLength or %_Arguments because their | 1078 // Don't inline the %_ArgumentsLength or %_Arguments because their |
1139 // implementation will not work. There is no stack frame to get them | 1079 // implementation will not work. There is no stack frame to get them |
1140 // from. | 1080 // from. |
1141 add_flag(kDontInline); | 1081 add_flag(kDontInline); |
1142 } | 1082 } |
1143 } | 1083 } |
1144 | 1084 |
| 1085 #undef REGULAR_NODE |
| 1086 #undef DONT_OPTIMIZE_NODE |
| 1087 #undef DONT_INLINE_NODE |
| 1088 #undef DONT_SELFOPTIMIZE_NODE |
| 1089 |
1145 | 1090 |
1146 Handle<String> Literal::ToString() { | 1091 Handle<String> Literal::ToString() { |
1147 if (handle_->IsString()) return Handle<String>::cast(handle_); | 1092 if (handle_->IsString()) return Handle<String>::cast(handle_); |
1148 ASSERT(handle_->IsNumber()); | 1093 ASSERT(handle_->IsNumber()); |
1149 char arr[100]; | 1094 char arr[100]; |
1150 Vector<char> buffer(arr, ARRAY_SIZE(arr)); | 1095 Vector<char> buffer(arr, ARRAY_SIZE(arr)); |
1151 const char* str; | 1096 const char* str; |
1152 if (handle_->IsSmi()) { | 1097 if (handle_->IsSmi()) { |
1153 // Optimization only, the heap number case would subsume this. | 1098 // Optimization only, the heap number case would subsume this. |
1154 OS::SNPrintF(buffer, "%d", Smi::cast(*handle_)->value()); | 1099 OS::SNPrintF(buffer, "%d", Smi::cast(*handle_)->value()); |
1155 str = arr; | 1100 str = arr; |
1156 } else { | 1101 } else { |
1157 str = DoubleToCString(handle_->Number(), buffer); | 1102 str = DoubleToCString(handle_->Number(), buffer); |
1158 } | 1103 } |
1159 return FACTORY->NewStringFromAscii(CStrVector(str)); | 1104 return FACTORY->NewStringFromAscii(CStrVector(str)); |
1160 } | 1105 } |
1161 | 1106 |
1162 | 1107 |
1163 } } // namespace v8::internal | 1108 } } // namespace v8::internal |
OLD | NEW |