OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 26 matching lines...) Expand all Loading... |
37 // Weight boundaries | 37 // Weight boundaries |
38 static const int MinWeight = 1; | 38 static const int MinWeight = 1; |
39 static const int MaxWeight = 1000000; | 39 static const int MaxWeight = 1000000; |
40 static const int InitialWeight = 100; | 40 static const int InitialWeight = 100; |
41 | 41 |
42 | 42 |
43 class UsageComputer: public AstVisitor { | 43 class UsageComputer: public AstVisitor { |
44 public: | 44 public: |
45 static bool Traverse(AstNode* node); | 45 static bool Traverse(AstNode* node); |
46 | 46 |
47 void VisitBlock(Block* node); | 47 // AST node visit functions. |
48 void VisitDeclaration(Declaration* node); | 48 #define DECLARE_VISIT(type) void Visit##type(type* node); |
49 void VisitExpressionStatement(ExpressionStatement* node); | 49 AST_NODE_LIST(DECLARE_VISIT) |
50 void VisitEmptyStatement(EmptyStatement* node); | 50 #undef DECLARE_VISIT |
51 void VisitIfStatement(IfStatement* node); | 51 |
52 void VisitContinueStatement(ContinueStatement* node); | 52 void VisitVariable(Variable* var); |
53 void VisitBreakStatement(BreakStatement* node); | |
54 void VisitReturnStatement(ReturnStatement* node); | |
55 void VisitWithEnterStatement(WithEnterStatement* node); | |
56 void VisitWithExitStatement(WithExitStatement* node); | |
57 void VisitSwitchStatement(SwitchStatement* node); | |
58 void VisitLoopStatement(LoopStatement* node); | |
59 void VisitForInStatement(ForInStatement* node); | |
60 void VisitTryCatch(TryCatch* node); | |
61 void VisitTryFinally(TryFinally* node); | |
62 void VisitDebuggerStatement(DebuggerStatement* node); | |
63 void VisitFunctionLiteral(FunctionLiteral* node); | |
64 void VisitFunctionBoilerplateLiteral(FunctionBoilerplateLiteral* node); | |
65 void VisitConditional(Conditional* node); | |
66 void VisitSlot(Slot* node); | |
67 void VisitVariable(Variable* node); | |
68 void VisitVariableProxy(VariableProxy* node); | |
69 void VisitLiteral(Literal* node); | |
70 void VisitRegExpLiteral(RegExpLiteral* node); | |
71 void VisitObjectLiteral(ObjectLiteral* node); | |
72 void VisitArrayLiteral(ArrayLiteral* node); | |
73 void VisitCatchExtensionObject(CatchExtensionObject* node); | |
74 void VisitAssignment(Assignment* node); | |
75 void VisitThrow(Throw* node); | |
76 void VisitProperty(Property* node); | |
77 void VisitCall(Call* node); | |
78 void VisitCallNew(CallNew* node); | |
79 void VisitCallRuntime(CallRuntime* node); | |
80 void VisitUnaryOperation(UnaryOperation* node); | |
81 void VisitCountOperation(CountOperation* node); | |
82 void VisitBinaryOperation(BinaryOperation* node); | |
83 void VisitCompareOperation(CompareOperation* node); | |
84 void VisitThisFunction(ThisFunction* node); | |
85 | 53 |
86 private: | 54 private: |
87 int weight_; | 55 int weight_; |
88 bool is_write_; | 56 bool is_write_; |
89 | 57 |
90 UsageComputer(int weight, bool is_write); | 58 UsageComputer(int weight, bool is_write); |
91 virtual ~UsageComputer(); | 59 virtual ~UsageComputer(); |
92 | 60 |
93 // Helper functions | 61 // Helper functions |
94 void RecordUses(UseCount* uses); | 62 void RecordUses(UseCount* uses); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 } | 290 } |
323 | 291 |
324 | 292 |
325 void UsageComputer::VisitCall(Call* node) { | 293 void UsageComputer::VisitCall(Call* node) { |
326 Read(node->expression()); | 294 Read(node->expression()); |
327 ReadList(node->arguments()); | 295 ReadList(node->arguments()); |
328 } | 296 } |
329 | 297 |
330 | 298 |
331 void UsageComputer::VisitCallNew(CallNew* node) { | 299 void UsageComputer::VisitCallNew(CallNew* node) { |
332 VisitCall(node); | 300 Read(node->expression()); |
| 301 ReadList(node->arguments()); |
333 } | 302 } |
334 | 303 |
335 | 304 |
336 void UsageComputer::VisitCallRuntime(CallRuntime* node) { | 305 void UsageComputer::VisitCallRuntime(CallRuntime* node) { |
337 ReadList(node->arguments()); | 306 ReadList(node->arguments()); |
338 } | 307 } |
339 | 308 |
340 | 309 |
341 void UsageComputer::VisitUnaryOperation(UnaryOperation* node) { | 310 void UsageComputer::VisitUnaryOperation(UnaryOperation* node) { |
342 Read(node->expression()); | 311 Read(node->expression()); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 // ---------------------------------------------------------------------------- | 406 // ---------------------------------------------------------------------------- |
438 // Interface to variable usage analysis | 407 // Interface to variable usage analysis |
439 | 408 |
440 bool AnalyzeVariableUsage(FunctionLiteral* lit) { | 409 bool AnalyzeVariableUsage(FunctionLiteral* lit) { |
441 if (!FLAG_usage_computation) return true; | 410 if (!FLAG_usage_computation) return true; |
442 HistogramTimerScope timer(&Counters::usage_analysis); | 411 HistogramTimerScope timer(&Counters::usage_analysis); |
443 return UsageComputer::Traverse(lit); | 412 return UsageComputer::Traverse(lit); |
444 } | 413 } |
445 | 414 |
446 } } // namespace v8::internal | 415 } } // namespace v8::internal |
OLD | NEW |