Reviewers: Toon Verwaest,

Message:
Using a simpler and more generic approach in inlining immutable properties like
Math.PI. PTAL.

Description:
Inline loading of immutable properties

Adds detection for property loads that are immutable (non-configurable and
non-writable) and inlines them where possible.

BUG=
[email protected]

Please review this at https://codereview.chromium.org/220163012/

SVN Base: https://github.com/v8/v8.git@master

Affected files (+25, -0 lines):
  M src/hydrogen.cc


Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 6587ce97199ca944f8daaa8938bcbf73b23f6414..36ceb32b43c0b09cafc5708f1f88ba60417b8d4a 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -6716,6 +6716,31 @@ void HOptimizedGraphBuilder::BuildLoad(Property* expr,
     Handle<String> name = expr->key()->AsLiteral()->AsPropertyName();
     HValue* object = Pop();

+ // See if the property to be loaded is non-configurable and non-writable
+    if (object->IsConstant() &&
+        HConstant::cast(object)->handle(isolate())->IsJSObject()) {
+      Handle<JSObject> js_object =
+ Handle<JSObject>::cast(HConstant::cast(object)->handle(isolate()));
+
+      if (!js_object->map()->is_observed()) {
+        LookupResult lookup(isolate());
+        js_object->LocalLookup(*name, &lookup, false);
+
+        if (lookup.IsFound() && lookup.IsCacheable() &&
+            (js_object->map()->is_frozen() ||
+            (lookup.IsReadOnly() && lookup.IsDontDelete()))) {
+          Handle<Object> value = handle(lookup.GetLazyValue(), isolate());
+
+          if (!value.is_null() &&
+              !value->IsTheHole() &&
+              !value->IsCallable()) {
+            instr = New<HConstant>(value);
+            return ast_context()->ReturnInstruction(instr, ast_id);
+          }
+        }
+      }
+    }
+
     instr = BuildNamedAccess(LOAD, ast_id, expr->LoadId(), expr,
                              object, name, NULL, expr->IsUninitialized());
     if (instr == NULL) return;


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to