Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: src/ast.h

Issue 1530003: Rework flow graph construction. (Closed)
Patch Set: Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/ast.cc » ('j') | src/data-flow.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 287 }
288 288
289 // How many bitwise logical or shift operators are used in this expression? 289 // How many bitwise logical or shift operators are used in this expression?
290 int num_bit_ops() { return NumBitOpsField::decode(bitfields_); } 290 int num_bit_ops() { return NumBitOpsField::decode(bitfields_); }
291 void set_num_bit_ops(int num_bit_ops) { 291 void set_num_bit_ops(int num_bit_ops) {
292 bitfields_ &= ~NumBitOpsField::mask(); 292 bitfields_ &= ~NumBitOpsField::mask();
293 num_bit_ops = Min(num_bit_ops, kMaxNumBitOps); 293 num_bit_ops = Min(num_bit_ops, kMaxNumBitOps);
294 bitfields_ |= NumBitOpsField::encode(num_bit_ops); 294 bitfields_ |= NumBitOpsField::encode(num_bit_ops);
295 } 295 }
296 296
297 // Functions used for dead-code elimination. Predicate is true if the
298 // expression is not dead code.
299 int is_live() const { return LiveField::decode(bitfields_); }
300 void mark_as_live() { bitfields_ |= LiveField::encode(true); }
301
302 // Mark non-live children as live and push them on a stack for further
303 // processing.
304 virtual void ProcessNonLiveChildren(
305 List<AstNode*>* stack,
306 ZoneList<Expression*>* body_definitions,
307 int variable_count) {
308 }
309
310 private: 297 private:
311 static const int kMaxNumBitOps = (1 << 5) - 1; 298 static const int kMaxNumBitOps = (1 << 5) - 1;
312 299
313 uint32_t bitfields_; 300 uint32_t bitfields_;
314 StaticType type_; 301 StaticType type_;
315 302
316 // Using template BitField<type, start, size>. 303 // Using template BitField<type, start, size>.
317 class SideEffectFreeField : public BitField<bool, 0, 1> {}; 304 class SideEffectFreeField : public BitField<bool, 0, 1> {};
318 class NoNegativeZeroField : public BitField<bool, 1, 1> {}; 305 class NoNegativeZeroField : public BitField<bool, 1, 1> {};
319 class ToInt32Field : public BitField<bool, 2, 1> {}; 306 class ToInt32Field : public BitField<bool, 2, 1> {};
320 class NumBitOpsField : public BitField<int, 3, 5> {}; 307 class NumBitOpsField : public BitField<int, 3, 5> {};
321 class LoopConditionField: public BitField<bool, 8, 1> {}; 308 class LoopConditionField: public BitField<bool, 8, 1> {};
322 class LiveField: public BitField<bool, 9, 1> {};
323 }; 309 };
324 310
325 311
326 /** 312 /**
327 * A sentinel used during pre parsing that represents some expression 313 * A sentinel used during pre parsing that represents some expression
328 * that is a valid left hand side without having to actually build 314 * that is a valid left hand side without having to actually build
329 * the expression. 315 * the expression.
330 */ 316 */
331 class ValidLeftHandSideSentinel: public Expression { 317 class ValidLeftHandSideSentinel: public Expression {
332 public: 318 public:
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 uint32_t ignored; 886 uint32_t ignored;
901 return !String::cast(*handle_)->AsArrayIndex(&ignored); 887 return !String::cast(*handle_)->AsArrayIndex(&ignored);
902 } 888 }
903 return false; 889 return false;
904 } 890 }
905 891
906 virtual bool IsLeaf() { return true; } 892 virtual bool IsLeaf() { return true; }
907 virtual bool IsTrivial() { return true; } 893 virtual bool IsTrivial() { return true; }
908 virtual bool IsPrimitive(); 894 virtual bool IsPrimitive();
909 virtual bool IsCritical(); 895 virtual bool IsCritical();
910 virtual void ProcessNonLiveChildren(
911 List<AstNode*>* stack,
912 ZoneList<Expression*>* body_definitions,
913 int variable_count);
914 896
915 // Identity testers. 897 // Identity testers.
916 bool IsNull() const { return handle_.is_identical_to(Factory::null_value()); } 898 bool IsNull() const { return handle_.is_identical_to(Factory::null_value()); }
917 bool IsTrue() const { return handle_.is_identical_to(Factory::true_value()); } 899 bool IsTrue() const { return handle_.is_identical_to(Factory::true_value()); }
918 bool IsFalse() const { 900 bool IsFalse() const {
919 return handle_.is_identical_to(Factory::false_value()); 901 return handle_.is_identical_to(Factory::false_value());
920 } 902 }
921 903
922 Handle<Object> handle() const { return handle_; } 904 Handle<Object> handle() const { return handle_; }
923 905
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 ASSERT(var_ != NULL); // Variable must be resolved. 1093 ASSERT(var_ != NULL); // Variable must be resolved.
1112 return var()->is_global() || var()->rewrite()->IsLeaf(); 1094 return var()->is_global() || var()->rewrite()->IsLeaf();
1113 } 1095 }
1114 1096
1115 // Reading from a mutable variable is a side effect, but 'this' is 1097 // Reading from a mutable variable is a side effect, but 'this' is
1116 // immutable. 1098 // immutable.
1117 virtual bool IsTrivial() { return is_trivial_; } 1099 virtual bool IsTrivial() { return is_trivial_; }
1118 1100
1119 virtual bool IsPrimitive(); 1101 virtual bool IsPrimitive();
1120 virtual bool IsCritical(); 1102 virtual bool IsCritical();
1121 virtual void ProcessNonLiveChildren(
1122 List<AstNode*>* stack,
1123 ZoneList<Expression*>* body_definitions,
1124 int variable_count);
1125 1103
1126 void SetIsPrimitive(bool value) { is_primitive_ = value; } 1104 void SetIsPrimitive(bool value) { is_primitive_ = value; }
1127 1105
1128 bool IsVariable(Handle<String> n) { 1106 bool IsVariable(Handle<String> n) {
1129 return !is_this() && name().is_identical_to(n); 1107 return !is_this() && name().is_identical_to(n);
1130 } 1108 }
1131 1109
1132 bool IsArguments() { 1110 bool IsArguments() {
1133 Variable* variable = AsVariable(); 1111 Variable* variable = AsVariable();
1134 return (variable == NULL) ? false : variable->is_arguments(); 1112 return (variable == NULL) ? false : variable->is_arguments();
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 1231
1254 virtual void Accept(AstVisitor* v); 1232 virtual void Accept(AstVisitor* v);
1255 1233
1256 // Type testing & conversion 1234 // Type testing & conversion
1257 virtual Property* AsProperty() { return this; } 1235 virtual Property* AsProperty() { return this; }
1258 1236
1259 virtual bool IsValidLeftHandSide() { return true; } 1237 virtual bool IsValidLeftHandSide() { return true; }
1260 1238
1261 virtual bool IsPrimitive(); 1239 virtual bool IsPrimitive();
1262 virtual bool IsCritical(); 1240 virtual bool IsCritical();
1263 virtual void ProcessNonLiveChildren(
1264 List<AstNode*>* stack,
1265 ZoneList<Expression*>* body_definitions,
1266 int variable_count);
1267 1241
1268 Expression* obj() const { return obj_; } 1242 Expression* obj() const { return obj_; }
1269 Expression* key() const { return key_; } 1243 Expression* key() const { return key_; }
1270 int position() const { return pos_; } 1244 int position() const { return pos_; }
1271 bool is_synthetic() const { return type_ == SYNTHETIC; } 1245 bool is_synthetic() const { return type_ == SYNTHETIC; }
1272 1246
1273 // Returns a property singleton property access on 'this'. Used 1247 // Returns a property singleton property access on 'this'. Used
1274 // during preparsing. 1248 // during preparsing.
1275 static Property* this_property() { return &this_property_; } 1249 static Property* this_property() { return &this_property_; }
1276 1250
(...skipping 15 matching lines...) Expand all
1292 1266
1293 Call(Call* other, Expression* expression, ZoneList<Expression*>* arguments); 1267 Call(Call* other, Expression* expression, ZoneList<Expression*>* arguments);
1294 1268
1295 virtual void Accept(AstVisitor* v); 1269 virtual void Accept(AstVisitor* v);
1296 1270
1297 // Type testing and conversion. 1271 // Type testing and conversion.
1298 virtual Call* AsCall() { return this; } 1272 virtual Call* AsCall() { return this; }
1299 1273
1300 virtual bool IsPrimitive(); 1274 virtual bool IsPrimitive();
1301 virtual bool IsCritical(); 1275 virtual bool IsCritical();
1302 virtual void ProcessNonLiveChildren(
1303 List<AstNode*>* stack,
1304 ZoneList<Expression*>* body_definitions,
1305 int variable_count);
1306 1276
1307 Expression* expression() const { return expression_; } 1277 Expression* expression() const { return expression_; }
1308 ZoneList<Expression*>* arguments() const { return arguments_; } 1278 ZoneList<Expression*>* arguments() const { return arguments_; }
1309 int position() { return pos_; } 1279 int position() { return pos_; }
1310 1280
1311 static Call* sentinel() { return &sentinel_; } 1281 static Call* sentinel() { return &sentinel_; }
1312 1282
1313 private: 1283 private:
1314 Expression* expression_; 1284 Expression* expression_;
1315 ZoneList<Expression*>* arguments_; 1285 ZoneList<Expression*>* arguments_;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1375 1345
1376 UnaryOperation(UnaryOperation* other, Expression* expression); 1346 UnaryOperation(UnaryOperation* other, Expression* expression);
1377 1347
1378 virtual void Accept(AstVisitor* v); 1348 virtual void Accept(AstVisitor* v);
1379 1349
1380 // Type testing & conversion 1350 // Type testing & conversion
1381 virtual UnaryOperation* AsUnaryOperation() { return this; } 1351 virtual UnaryOperation* AsUnaryOperation() { return this; }
1382 1352
1383 virtual bool IsPrimitive(); 1353 virtual bool IsPrimitive();
1384 virtual bool IsCritical(); 1354 virtual bool IsCritical();
1385 virtual void ProcessNonLiveChildren(
1386 List<AstNode*>* stack,
1387 ZoneList<Expression*>* body_definitions,
1388 int variable_count);
1389 1355
1390 Token::Value op() const { return op_; } 1356 Token::Value op() const { return op_; }
1391 Expression* expression() const { return expression_; } 1357 Expression* expression() const { return expression_; }
1392 1358
1393 private: 1359 private:
1394 Token::Value op_; 1360 Token::Value op_;
1395 Expression* expression_; 1361 Expression* expression_;
1396 }; 1362 };
1397 1363
1398 1364
1399 class BinaryOperation: public Expression { 1365 class BinaryOperation: public Expression {
1400 public: 1366 public:
1401 BinaryOperation(Token::Value op, Expression* left, Expression* right) 1367 BinaryOperation(Token::Value op, Expression* left, Expression* right)
1402 : op_(op), left_(left), right_(right) { 1368 : op_(op), left_(left), right_(right) {
1403 ASSERT(Token::IsBinaryOp(op)); 1369 ASSERT(Token::IsBinaryOp(op));
1404 } 1370 }
1405 1371
1406 BinaryOperation(BinaryOperation* other, Expression* left, Expression* right); 1372 BinaryOperation(BinaryOperation* other, Expression* left, Expression* right);
1407 1373
1408 virtual void Accept(AstVisitor* v); 1374 virtual void Accept(AstVisitor* v);
1409 1375
1410 // Type testing & conversion 1376 // Type testing & conversion
1411 virtual BinaryOperation* AsBinaryOperation() { return this; } 1377 virtual BinaryOperation* AsBinaryOperation() { return this; }
1412 1378
1413 virtual bool IsPrimitive(); 1379 virtual bool IsPrimitive();
1414 virtual bool IsCritical(); 1380 virtual bool IsCritical();
1415 virtual void ProcessNonLiveChildren(
1416 List<AstNode*>* stack,
1417 ZoneList<Expression*>* body_definitions,
1418 int variable_count);
1419 1381
1420 // True iff the result can be safely overwritten (to avoid allocation). 1382 // True iff the result can be safely overwritten (to avoid allocation).
1421 // False for operations that can return one of their operands. 1383 // False for operations that can return one of their operands.
1422 bool ResultOverwriteAllowed() { 1384 bool ResultOverwriteAllowed() {
1423 switch (op_) { 1385 switch (op_) {
1424 case Token::COMMA: 1386 case Token::COMMA:
1425 case Token::OR: 1387 case Token::OR:
1426 case Token::AND: 1388 case Token::AND:
1427 return false; 1389 return false;
1428 case Token::BIT_OR: 1390 case Token::BIT_OR:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 virtual void Accept(AstVisitor* v); 1428 virtual void Accept(AstVisitor* v);
1467 1429
1468 virtual CountOperation* AsCountOperation() { return this; } 1430 virtual CountOperation* AsCountOperation() { return this; }
1469 1431
1470 virtual Variable* AssignedVariable() { 1432 virtual Variable* AssignedVariable() {
1471 return expression()->AsVariableProxy()->AsVariable(); 1433 return expression()->AsVariableProxy()->AsVariable();
1472 } 1434 }
1473 1435
1474 virtual bool IsPrimitive(); 1436 virtual bool IsPrimitive();
1475 virtual bool IsCritical(); 1437 virtual bool IsCritical();
1476 virtual void ProcessNonLiveChildren(
1477 List<AstNode*>* stack,
1478 ZoneList<Expression*>* body_definitions,
1479 int variable_count);
1480 1438
1481 bool is_prefix() const { return is_prefix_; } 1439 bool is_prefix() const { return is_prefix_; }
1482 bool is_postfix() const { return !is_prefix_; } 1440 bool is_postfix() const { return !is_prefix_; }
1483 Token::Value op() const { return op_; } 1441 Token::Value op() const { return op_; }
1484 Token::Value binary_op() { 1442 Token::Value binary_op() {
1485 return op_ == Token::INC ? Token::ADD : Token::SUB; 1443 return op_ == Token::INC ? Token::ADD : Token::SUB;
1486 } 1444 }
1487 Expression* expression() const { return expression_; } 1445 Expression* expression() const { return expression_; }
1488 1446
1489 virtual void MarkAsStatement() { is_prefix_ = true; } 1447 virtual void MarkAsStatement() { is_prefix_ = true; }
(...skipping 13 matching lines...) Expand all
1503 } 1461 }
1504 1462
1505 CompareOperation(CompareOperation* other, 1463 CompareOperation(CompareOperation* other,
1506 Expression* left, 1464 Expression* left,
1507 Expression* right); 1465 Expression* right);
1508 1466
1509 virtual void Accept(AstVisitor* v); 1467 virtual void Accept(AstVisitor* v);
1510 1468
1511 virtual bool IsPrimitive(); 1469 virtual bool IsPrimitive();
1512 virtual bool IsCritical(); 1470 virtual bool IsCritical();
1513 virtual void ProcessNonLiveChildren(
1514 List<AstNode*>* stack,
1515 ZoneList<Expression*>* body_definitions,
1516 int variable_count);
1517 1471
1518 Token::Value op() const { return op_; } 1472 Token::Value op() const { return op_; }
1519 Expression* left() const { return left_; } 1473 Expression* left() const { return left_; }
1520 Expression* right() const { return right_; } 1474 Expression* right() const { return right_; }
1521 1475
1522 // Type testing & conversion 1476 // Type testing & conversion
1523 virtual CompareOperation* AsCompareOperation() { return this; } 1477 virtual CompareOperation* AsCompareOperation() { return this; }
1524 1478
1525 private: 1479 private:
1526 Token::Value op_; 1480 Token::Value op_;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 ASSERT(Token::IsAssignmentOp(op)); 1515 ASSERT(Token::IsAssignmentOp(op));
1562 } 1516 }
1563 1517
1564 Assignment(Assignment* other, Expression* target, Expression* value); 1518 Assignment(Assignment* other, Expression* target, Expression* value);
1565 1519
1566 virtual void Accept(AstVisitor* v); 1520 virtual void Accept(AstVisitor* v);
1567 virtual Assignment* AsAssignment() { return this; } 1521 virtual Assignment* AsAssignment() { return this; }
1568 1522
1569 virtual bool IsPrimitive(); 1523 virtual bool IsPrimitive();
1570 virtual bool IsCritical(); 1524 virtual bool IsCritical();
1571 virtual void ProcessNonLiveChildren(
1572 List<AstNode*>* stack,
1573 ZoneList<Expression*>* body_definitions,
1574 int variable_count);
1575 1525
1576 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } 1526 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; }
1577 1527
1578 virtual Variable* AssignedVariable() { 1528 virtual Variable* AssignedVariable() {
1579 return target()->AsVariableProxy()->AsVariable(); 1529 return target()->AsVariableProxy()->AsVariable();
1580 } 1530 }
1581 1531
1582 Token::Value binary_op() const; 1532 Token::Value binary_op() const;
1583 1533
1584 Token::Value op() const { return op_; } 1534 Token::Value op() const { return op_; }
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
2162 2112
2163 // Holds the result of copying an expression. 2113 // Holds the result of copying an expression.
2164 Expression* expr_; 2114 Expression* expr_;
2165 // Holds the result of copying a statement. 2115 // Holds the result of copying a statement.
2166 Statement* stmt_; 2116 Statement* stmt_;
2167 }; 2117 };
2168 2118
2169 } } // namespace v8::internal 2119 } } // namespace v8::internal
2170 2120
2171 #endif // V8_AST_H_ 2121 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast.cc » ('j') | src/data-flow.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698