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

Side by Side Diff: src/variables.h

Issue 669270: Remove unneeded variable usage analysis. (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 | « src/usage-analyzer.cc ('k') | src/variables.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_VARIABLES_H_ 28 #ifndef V8_VARIABLES_H_
29 #define V8_VARIABLES_H_ 29 #define V8_VARIABLES_H_
30 30
31 #include "zone.h" 31 #include "zone.h"
32 32
33 namespace v8 { 33 namespace v8 {
34 namespace internal { 34 namespace internal {
35 35
36 class UseCount BASE_EMBEDDED {
37 public:
38 UseCount();
39
40 // Inform the node of a "use". The weight can be used to indicate
41 // heavier use, for instance if the variable is accessed inside a loop.
42 void RecordRead(int weight);
43 void RecordWrite(int weight);
44 void RecordAccess(int weight); // records a read & write
45 void RecordUses(UseCount* uses);
46
47 int nreads() const { return nreads_; }
48 int nwrites() const { return nwrites_; }
49 int nuses() const { return nreads_ + nwrites_; }
50
51 bool is_read() const { return nreads() > 0; }
52 bool is_written() const { return nwrites() > 0; }
53 bool is_used() const { return nuses() > 0; }
54
55 #ifdef DEBUG
56 void Print();
57 #endif
58
59 private:
60 int nreads_;
61 int nwrites_;
62 };
63
64
65 // Variables and AST expression nodes can track their "type" to enable 36 // Variables and AST expression nodes can track their "type" to enable
66 // optimizations and removal of redundant checks when generating code. 37 // optimizations and removal of redundant checks when generating code.
67 38
68 class StaticType { 39 class StaticType {
69 public: 40 public:
70 enum Kind { 41 enum Kind {
71 UNKNOWN, 42 UNKNOWN,
72 LIKELY_SMI 43 LIKELY_SMI
73 }; 44 };
74 45
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 // in an outer scope about which we don't know anything (it may not 132 // in an outer scope about which we don't know anything (it may not
162 // be the global scope). scope() is NULL in that case. Currently the 133 // be the global scope). scope() is NULL in that case. Currently the
163 // scope is only used to follow the context chain length. 134 // scope is only used to follow the context chain length.
164 Scope* scope() const { return scope_; } 135 Scope* scope() const { return scope_; }
165 136
166 Handle<String> name() const { return name_; } 137 Handle<String> name() const { return name_; }
167 Mode mode() const { return mode_; } 138 Mode mode() const { return mode_; }
168 bool is_accessed_from_inner_scope() const { 139 bool is_accessed_from_inner_scope() const {
169 return is_accessed_from_inner_scope_; 140 return is_accessed_from_inner_scope_;
170 } 141 }
171 UseCount* var_uses() { return &var_uses_; } 142 bool is_used() { return is_used_; }
172 UseCount* obj_uses() { return &obj_uses_; } 143 void set_is_used(bool flag) { is_used_ = flag; }
173 144
174 bool IsVariable(Handle<String> n) const { 145 bool IsVariable(Handle<String> n) const {
175 return !is_this() && name().is_identical_to(n); 146 return !is_this() && name().is_identical_to(n);
176 } 147 }
177 148
178 bool is_dynamic() const { 149 bool is_dynamic() const {
179 return (mode_ == DYNAMIC || 150 return (mode_ == DYNAMIC ||
180 mode_ == DYNAMIC_GLOBAL || 151 mode_ == DYNAMIC_GLOBAL ||
181 mode_ == DYNAMIC_LOCAL); 152 mode_ == DYNAMIC_LOCAL);
182 } 153 }
(...skipping 26 matching lines...) Expand all
209 Scope* scope_; 180 Scope* scope_;
210 Handle<String> name_; 181 Handle<String> name_;
211 Mode mode_; 182 Mode mode_;
212 bool is_valid_LHS_; 183 bool is_valid_LHS_;
213 Kind kind_; 184 Kind kind_;
214 185
215 Variable* local_if_not_shadowed_; 186 Variable* local_if_not_shadowed_;
216 187
217 // Usage info. 188 // Usage info.
218 bool is_accessed_from_inner_scope_; // set by variable resolver 189 bool is_accessed_from_inner_scope_; // set by variable resolver
219 UseCount var_uses_; // uses of the variable value 190 bool is_used_;
220 UseCount obj_uses_; // uses of the object the variable points to
221 191
222 // Static type information 192 // Static type information
223 StaticType type_; 193 StaticType type_;
224 194
225 // Code generation. 195 // Code generation.
226 // rewrite_ is usually a Slot or a Property, but may be any expression. 196 // rewrite_ is usually a Slot or a Property, but may be any expression.
227 Expression* rewrite_; 197 Expression* rewrite_;
228 198
229 friend class Scope; // Has explicit access to rewrite_. 199 friend class Scope; // Has explicit access to rewrite_.
230 }; 200 };
231 201
232 202
233 } } // namespace v8::internal 203 } } // namespace v8::internal
234 204
235 #endif // V8_VARIABLES_H_ 205 #endif // V8_VARIABLES_H_
OLDNEW
« no previous file with comments | « src/usage-analyzer.cc ('k') | src/variables.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698