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

Unified Diff: src/variables.h

Issue 8835: Track whether a node or variable are likely to be a Smi value. Propagate that... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 12 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/rewriter.cc ('k') | src/variables.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/variables.h
===================================================================
--- src/variables.h (revision 629)
+++ src/variables.h (working copy)
@@ -61,6 +61,48 @@
};
+// Variables and AST expression nodes can track their "type" to enable
+// optimizations and removal of redundant checks when generating code.
+
+class StaticType BASE_EMBEDDED {
+ public:
+ enum Kind {
+ UNKNOWN,
+ LIKELY_SMI
+ };
+
+ StaticType() : kind_(UNKNOWN) {}
+
+ bool Is(Kind kind) const { return kind_ == kind; }
+
+ bool IsKnown() const { return !Is(UNKNOWN); }
+ bool IsUnknown() const { return Is(UNKNOWN); }
+ bool IsLikelySmi() const { return Is(LIKELY_SMI); }
+
+ void CopyFrom(StaticType* other) {
+ kind_ = other->kind_;
+ }
+
+ static char* Type2String(StaticType* type);
+
+ // LIKELY_SMI accessors
+ void SetAsLikelySmi() {
+ kind_ = LIKELY_SMI;
+ }
+
+ void SetAsLikelySmiIfUnknown() {
+ if (IsUnknown()) {
+ SetAsLikelySmi();
+ }
+ }
+
+ private:
+ Kind kind_;
+
+ DISALLOW_COPY_AND_ASSIGN(StaticType);
+};
+
+
// The AST refers to variables via VariableProxies - placeholders for the actual
// variables. Variables themselves are never directly referred to from the AST,
// they are maintained by scopes, and referred to from VariableProxies and Slots
@@ -114,6 +156,8 @@
Expression* rewrite() const { return rewrite_; }
Slot* slot() const;
+ StaticType* type() { return &type_; }
+
private:
Variable(Scope* scope, Handle<String> name, Mode mode, bool is_valid_LHS,
bool is_this);
@@ -129,6 +173,9 @@
UseCount var_uses_; // uses of the variable value
UseCount obj_uses_; // uses of the object the variable points to
+ // Static type information
+ StaticType type_;
+
// Code generation.
// rewrite_ is usually a Slot or a Property, but maybe any expression.
Expression* rewrite_;
« no previous file with comments | « src/rewriter.cc ('k') | src/variables.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698