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