Commit 88976125 authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[maglev] Implement LdaContextSlot

In the simplest way possible.

Bug: v8:7700
Change-Id: I155aaf85192b75c89617820d6f127a2ae04c7d9b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3599484
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarVictor Gomes <victorgomes@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80089}
parent 3623415e
......@@ -289,8 +289,30 @@ void MaglevGraphBuilder::VisitLdaFalse() {
void MaglevGraphBuilder::VisitLdaConstant() {
SetAccumulator(GetConstant(GetRefOperand<HeapObject>(0)));
}
MAGLEV_UNIMPLEMENTED_BYTECODE(LdaContextSlot)
MAGLEV_UNIMPLEMENTED_BYTECODE(LdaImmutableContextSlot)
void MaglevGraphBuilder::VisitLdaContextSlot() {
ValueNode* context = LoadRegisterTagged(0);
int slot_index = iterator_.GetIndexOperand(1);
int depth = iterator_.GetUnsignedImmediateOperand(2);
for (int i = 0; i < depth; ++i) {
context = AddNewNode<LoadField>(
{context}, LoadSimpleFieldHandler(FieldIndex::ForInObjectOffset(
Context::OffsetOfElementAt(Context::PREVIOUS_INDEX),
FieldIndex::kTagged)));
}
// TODO(leszeks): Passing a LoadHandler to LoadField here is a bit of
// a hack, maybe we should have a LoadRawOffset or similar.
SetAccumulator(AddNewNode<LoadField>(
{context},
LoadSimpleFieldHandler(FieldIndex::ForInObjectOffset(
Context::OffsetOfElementAt(slot_index), FieldIndex::kTagged))));
}
void MaglevGraphBuilder::VisitLdaImmutableContextSlot() {
// TODO(leszeks): Consider context specialising.
VisitLdaCurrentContextSlot();
}
void MaglevGraphBuilder::VisitLdaCurrentContextSlot() {
ValueNode* context = GetContext();
int slot_index = iterator_.GetIndexOperand(0);
......@@ -306,6 +328,7 @@ void MaglevGraphBuilder::VisitLdaImmutableCurrentContextSlot() {
// TODO(leszeks): Consider context specialising.
VisitLdaCurrentContextSlot();
}
void MaglevGraphBuilder::VisitStar() {
MoveNodeBetweenRegisters(interpreter::Register::virtual_accumulator(),
iterator_.GetRegisterOperand(0));
......
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --maglev --no-stress-opt
function factory() {
var x = 1;
x = 2;
return function foo() {
return x;
}
}
let foo = factory();
%PrepareFunctionForOptimization(foo);
assertEquals(2, foo());
assertEquals(2, foo());
%OptimizeMaglevOnNextCall(foo);
assertEquals(2, foo());
function nested_factory() {
var x = 1;
x = 2;
return (function() {
var z = 3;
return function foo(){
// Add two values from different contexts to force an
// LdaImmutableCurrentContextSlot
return x+z;
}
})();
}
foo = nested_factory();
%PrepareFunctionForOptimization(foo);
assertEquals(5, foo());
assertEquals(5, foo());
%OptimizeMaglevOnNextCall(foo);
assertEquals(5, foo());
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment