[compiler] Generalize context load/store operations in code-stub-assembler.
The existing Load/StoreContextElement operations take the index as an int. This CL adds versions that take the index as a Node. These already existed in the interpreter-assembler, from which they are now removed. R=mstarzinger@chromium.org, rmcilroy@chromium.org BUG= Review-Url: https://codereview.chromium.org/2473003004 Cr-Commit-Position: refs/heads/master@{#40810}
This commit is contained in:
parent
56b8afc1c3
commit
08da5c98cf
@ -1265,6 +1265,13 @@ Node* CodeStubAssembler::LoadContextElement(Node* context, int slot_index) {
|
||||
return Load(MachineType::AnyTagged(), context, IntPtrConstant(offset));
|
||||
}
|
||||
|
||||
Node* CodeStubAssembler::LoadContextElement(Node* context, Node* slot_index) {
|
||||
Node* offset =
|
||||
IntPtrAdd(WordShl(slot_index, kPointerSizeLog2),
|
||||
IntPtrConstant(Context::kHeaderSize - kHeapObjectTag));
|
||||
return Load(MachineType::AnyTagged(), context, offset);
|
||||
}
|
||||
|
||||
Node* CodeStubAssembler::StoreContextElement(Node* context, int slot_index,
|
||||
Node* value) {
|
||||
int offset = Context::SlotOffset(slot_index);
|
||||
@ -1272,6 +1279,14 @@ Node* CodeStubAssembler::StoreContextElement(Node* context, int slot_index,
|
||||
value);
|
||||
}
|
||||
|
||||
Node* CodeStubAssembler::StoreContextElement(Node* context, Node* slot_index,
|
||||
Node* value) {
|
||||
Node* offset =
|
||||
IntPtrAdd(WordShl(slot_index, kPointerSizeLog2),
|
||||
IntPtrConstant(Context::kHeaderSize - kHeapObjectTag));
|
||||
return Store(MachineRepresentation::kTagged, context, offset, value);
|
||||
}
|
||||
|
||||
Node* CodeStubAssembler::LoadNativeContext(Node* context) {
|
||||
return LoadContextElement(context, Context::NATIVE_CONTEXT_INDEX);
|
||||
}
|
||||
|
@ -331,8 +331,13 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
|
||||
|
||||
// Context manipulation
|
||||
compiler::Node* LoadContextElement(compiler::Node* context, int slot_index);
|
||||
compiler::Node* LoadContextElement(compiler::Node* context,
|
||||
compiler::Node* slot_index);
|
||||
compiler::Node* StoreContextElement(compiler::Node* context, int slot_index,
|
||||
compiler::Node* value);
|
||||
compiler::Node* StoreContextElement(compiler::Node* context,
|
||||
compiler::Node* slot_index,
|
||||
compiler::Node* value);
|
||||
compiler::Node* LoadNativeContext(compiler::Node* context);
|
||||
|
||||
compiler::Node* LoadJSArrayElementsMap(ElementsKind kind,
|
||||
|
@ -485,21 +485,6 @@ Node* InterpreterAssembler::LoadAndUntagConstantPoolEntry(Node* index) {
|
||||
}
|
||||
}
|
||||
|
||||
Node* InterpreterAssembler::LoadContextSlot(Node* context, Node* slot_index) {
|
||||
Node* offset =
|
||||
IntPtrAdd(WordShl(slot_index, kPointerSizeLog2),
|
||||
IntPtrConstant(Context::kHeaderSize - kHeapObjectTag));
|
||||
return Load(MachineType::AnyTagged(), context, offset);
|
||||
}
|
||||
|
||||
Node* InterpreterAssembler::StoreContextSlot(Node* context, Node* slot_index,
|
||||
Node* value) {
|
||||
Node* offset =
|
||||
IntPtrAdd(WordShl(slot_index, kPointerSizeLog2),
|
||||
IntPtrConstant(Context::kHeaderSize - kHeapObjectTag));
|
||||
return Store(MachineRepresentation::kTagged, context, offset, value);
|
||||
}
|
||||
|
||||
Node* InterpreterAssembler::LoadTypeFeedbackVector() {
|
||||
Node* function = LoadRegister(Register::function_closure());
|
||||
Node* literals = LoadObjectField(function, JSFunction::kLiteralsOffset);
|
||||
|
@ -93,14 +93,6 @@ class V8_EXPORT_PRIVATE InterpreterAssembler : public CodeStubAssembler {
|
||||
// Load and untag constant at |index| in the constant pool.
|
||||
compiler::Node* LoadAndUntagConstantPoolEntry(compiler::Node* index);
|
||||
|
||||
// Load |slot_index| from |context|.
|
||||
compiler::Node* LoadContextSlot(compiler::Node* context,
|
||||
compiler::Node* slot_index);
|
||||
// Stores |value| into |slot_index| of |context|.
|
||||
compiler::Node* StoreContextSlot(compiler::Node* context,
|
||||
compiler::Node* slot_index,
|
||||
compiler::Node* value);
|
||||
|
||||
// Load the TypeFeedbackVector for the current function.
|
||||
compiler::Node* LoadTypeFeedbackVector();
|
||||
|
||||
|
@ -541,14 +541,14 @@ compiler::Node* Interpreter::BuildLoadContextSlot(
|
||||
Node* slot_index = __ BytecodeOperandIdx(1);
|
||||
Node* depth = __ BytecodeOperandUImm(2);
|
||||
Node* slot_context = __ GetContextAtDepth(context, depth);
|
||||
return __ LoadContextSlot(slot_context, slot_index);
|
||||
return __ LoadContextElement(slot_context, slot_index);
|
||||
}
|
||||
|
||||
compiler::Node* Interpreter::BuildLoadCurrentContextSlot(
|
||||
InterpreterAssembler* assembler) {
|
||||
Node* slot_index = __ BytecodeOperandIdx(0);
|
||||
Node* slot_context = __ GetContext();
|
||||
return __ LoadContextSlot(slot_context, slot_index);
|
||||
return __ LoadContextElement(slot_context, slot_index);
|
||||
}
|
||||
|
||||
// LdaContextSlot <context> <slot_index> <depth>
|
||||
@ -602,7 +602,7 @@ void Interpreter::DoStaContextSlot(InterpreterAssembler* assembler) {
|
||||
Node* slot_index = __ BytecodeOperandIdx(1);
|
||||
Node* depth = __ BytecodeOperandUImm(2);
|
||||
Node* slot_context = __ GetContextAtDepth(context, depth);
|
||||
__ StoreContextSlot(slot_context, slot_index, value);
|
||||
__ StoreContextElement(slot_context, slot_index, value);
|
||||
__ Dispatch();
|
||||
}
|
||||
|
||||
@ -614,7 +614,7 @@ void Interpreter::DoStaCurrentContextSlot(InterpreterAssembler* assembler) {
|
||||
Node* value = __ GetAccumulator();
|
||||
Node* slot_index = __ BytecodeOperandIdx(0);
|
||||
Node* slot_context = __ GetContext();
|
||||
__ StoreContextSlot(slot_context, slot_index, value);
|
||||
__ StoreContextElement(slot_context, slot_index, value);
|
||||
__ Dispatch();
|
||||
}
|
||||
|
||||
@ -659,7 +659,7 @@ void Interpreter::DoLdaLookupContextSlot(Runtime::FunctionId function_id,
|
||||
// Fast path does a normal load context.
|
||||
{
|
||||
Node* slot_context = __ GetContextAtDepth(context, depth);
|
||||
Node* result = __ LoadContextSlot(slot_context, slot_index);
|
||||
Node* result = __ LoadContextElement(slot_context, slot_index);
|
||||
__ SetAccumulator(result);
|
||||
__ Dispatch();
|
||||
}
|
||||
@ -1758,7 +1758,7 @@ void Interpreter::DoCallJSRuntime(InterpreterAssembler* assembler) {
|
||||
// Get the function to call from the native context.
|
||||
Node* context = __ GetContext();
|
||||
Node* native_context = __ LoadNativeContext(context);
|
||||
Node* function = __ LoadContextSlot(native_context, context_index);
|
||||
Node* function = __ LoadContextElement(native_context, context_index);
|
||||
|
||||
// Call the function.
|
||||
Node* result = __ CallJS(function, context, first_arg, args_count,
|
||||
|
@ -606,39 +606,6 @@ TARGET_TEST_F(InterpreterAssemblerTest, LoadObjectField) {
|
||||
}
|
||||
}
|
||||
|
||||
TARGET_TEST_F(InterpreterAssemblerTest, LoadContextSlot) {
|
||||
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
||||
InterpreterAssemblerForTest m(this, bytecode);
|
||||
Node* context = m.IntPtrConstant(1);
|
||||
Node* slot_index = m.IntPtrConstant(22);
|
||||
Node* load_context_slot = m.LoadContextSlot(context, slot_index);
|
||||
|
||||
Matcher<Node*> offset =
|
||||
IsIntPtrAdd(IsWordShl(slot_index, IsIntPtrConstant(kPointerSizeLog2)),
|
||||
IsIntPtrConstant(Context::kHeaderSize - kHeapObjectTag));
|
||||
EXPECT_THAT(load_context_slot,
|
||||
m.IsLoad(MachineType::AnyTagged(), context, offset));
|
||||
}
|
||||
}
|
||||
|
||||
TARGET_TEST_F(InterpreterAssemblerTest, StoreContextSlot) {
|
||||
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
||||
InterpreterAssemblerForTest m(this, bytecode);
|
||||
Node* context = m.IntPtrConstant(1);
|
||||
Node* slot_index = m.IntPtrConstant(22);
|
||||
Node* value = m.SmiConstant(Smi::FromInt(100));
|
||||
Node* store_context_slot = m.StoreContextSlot(context, slot_index, value);
|
||||
|
||||
Matcher<Node*> offset =
|
||||
IsIntPtrAdd(IsWordShl(slot_index, IsIntPtrConstant(kPointerSizeLog2)),
|
||||
IsIntPtrConstant(Context::kHeaderSize - kHeapObjectTag));
|
||||
EXPECT_THAT(store_context_slot,
|
||||
m.IsStore(StoreRepresentation(MachineRepresentation::kTagged,
|
||||
kFullWriteBarrier),
|
||||
context, offset, value));
|
||||
}
|
||||
}
|
||||
|
||||
TARGET_TEST_F(InterpreterAssemblerTest, CallRuntime2) {
|
||||
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
||||
InterpreterAssemblerForTest m(this, bytecode);
|
||||
|
Loading…
Reference in New Issue
Block a user