Commit 6b000846 authored by ishell's avatar ishell Committed by Commit bot

[stubs] Port LoadScriptContextFieldStub and StoreScriptContextFieldStub to TurboFan.

BUG=v8:5269

Review-Url: https://codereview.chromium.org/2325013004
Cr-Commit-Position: refs/heads/master@{#39376}
parent 28bd1181
......@@ -1172,9 +1172,13 @@ Node* CodeStubAssembler::LoadDoubleWithHoleCheck(Node* base, Node* offset,
return Load(machine_type, base, offset);
}
Node* CodeStubAssembler::LoadContextElement(Node* context, int slot_index) {
int offset = Context::SlotOffset(slot_index);
return Load(MachineType::AnyTagged(), context, IntPtrConstant(offset));
}
Node* CodeStubAssembler::LoadNativeContext(Node* context) {
return LoadFixedArrayElement(context,
IntPtrConstant(Context::NATIVE_CONTEXT_INDEX));
return LoadContextElement(context, Context::NATIVE_CONTEXT_INDEX);
}
Node* CodeStubAssembler::LoadJSArrayElementsMap(ElementsKind kind,
......@@ -4434,9 +4438,8 @@ void CodeStubAssembler::LoadGlobalIC(const LoadICParameters* p) {
AssertInstanceType(handler, CODE_TYPE);
LoadWithVectorDescriptor descriptor(isolate());
Node* native_context = LoadNativeContext(p->context);
Node* receiver = LoadFixedArrayElement(
native_context, IntPtrConstant(Context::EXTENSION_INDEX), 0,
INTPTR_PARAMETERS);
Node* receiver =
LoadContextElement(native_context, Context::EXTENSION_INDEX);
Node* fake_name = IntPtrConstant(0);
TailCallStub(descriptor, handler, p->context, receiver, fake_name, p->slot,
p->vector);
......@@ -4577,7 +4580,11 @@ Node* CodeStubAssembler::EmitKeyedSloppyArguments(Node* receiver, Node* key,
mapped_index = SmiUntag(mapped_index);
Node* the_context = LoadFixedArrayElement(elements, IntPtrConstant(0), 0,
INTPTR_PARAMETERS);
// Assert that we can use LoadFixedArrayElement/StoreFixedArrayElement
// methods for accessing Context.
STATIC_ASSERT(Context::kHeaderSize == FixedArray::kHeaderSize);
DCHECK_EQ(Context::SlotOffset(0) + kHeapObjectTag,
FixedArray::OffsetOfElementAt(0));
if (is_load) {
Node* result = LoadFixedArrayElement(the_context, mapped_index, 0,
INTPTR_PARAMETERS);
......@@ -4619,6 +4626,17 @@ Node* CodeStubAssembler::EmitKeyedSloppyArguments(Node* receiver, Node* key,
return var_result.value();
}
Node* CodeStubAssembler::LoadScriptContext(Node* context, int context_index) {
Node* native_context = LoadNativeContext(context);
Node* script_context_table =
LoadContextElement(native_context, Context::SCRIPT_CONTEXT_TABLE_INDEX);
int offset =
ScriptContextTable::GetContextOffset(context_index) - kHeapObjectTag;
return Load(MachineType::AnyTagged(), script_context_table,
IntPtrConstant(offset));
}
Node* CodeStubAssembler::EnumLength(Node* map) {
Node* bitfield_3 = LoadMapBitField3(map);
Node* enum_length = BitFieldDecode<Map::EnumLengthBits>(bitfield_3);
......
......@@ -274,6 +274,7 @@ class CodeStubAssembler : public compiler::CodeAssembler {
MachineType machine_type = MachineType::Float64());
// Context manipulation
compiler::Node* LoadContextElement(compiler::Node* context, int slot_index);
compiler::Node* LoadNativeContext(compiler::Node* context);
compiler::Node* LoadJSArrayElementsMap(ElementsKind kind,
......@@ -658,6 +659,9 @@ class CodeStubAssembler : public compiler::CodeAssembler {
EmitKeyedSloppyArguments(receiver, key, value, bailout);
}
// Loads script context from the script context table.
compiler::Node* LoadScriptContext(compiler::Node* context, int context_index);
void LoadIC(const LoadICParameters* p);
void LoadGlobalIC(const LoadICParameters* p);
void KeyedLoadIC(const LoadICParameters* p);
......
......@@ -418,40 +418,6 @@ Handle<Code> FastCloneShallowArrayStub::GenerateCode() {
return DoGenerateCode(this);
}
template <>
HValue* CodeStubGraphBuilder<LoadScriptContextFieldStub>::BuildCodeStub() {
int context_index = casted_stub()->context_index();
int slot_index = casted_stub()->slot_index();
HValue* script_context = BuildGetScriptContext(context_index);
return Add<HLoadNamedField>(script_context, nullptr,
HObjectAccess::ForContextSlot(slot_index));
}
Handle<Code> LoadScriptContextFieldStub::GenerateCode() {
return DoGenerateCode(this);
}
template <>
HValue* CodeStubGraphBuilder<StoreScriptContextFieldStub>::BuildCodeStub() {
int context_index = casted_stub()->context_index();
int slot_index = casted_stub()->slot_index();
HValue* script_context = BuildGetScriptContext(context_index);
Add<HStoreNamedField>(script_context,
HObjectAccess::ForContextSlot(slot_index),
GetParameter(2), STORE_TO_INITIALIZED_ENTRY);
// TODO(ishell): Remove this unused stub.
return GetParameter(2);
}
Handle<Code> StoreScriptContextFieldStub::GenerateCode() {
return DoGenerateCode(this);
}
HValue* CodeStubGraphBuilderBase::BuildPushElement(HValue* object, HValue* argc,
HValue* argument_elements,
ElementsKind kind) {
......
......@@ -4615,6 +4615,39 @@ void KeyedStoreSloppyArgumentsStub::GenerateAssembly(
}
}
void LoadScriptContextFieldStub::GenerateAssembly(
CodeStubAssembler* assembler) const {
typedef compiler::Node Node;
assembler->Comment("LoadScriptContextFieldStub: context_index=%d, slot=%d",
context_index(), slot_index());
Node* context = assembler->Parameter(Descriptor::kContext);
Node* script_context = assembler->LoadScriptContext(context, context_index());
Node* result = assembler->LoadFixedArrayElement(
script_context, assembler->IntPtrConstant(slot_index()), 0,
CodeStubAssembler::INTPTR_PARAMETERS);
assembler->Return(result);
}
void StoreScriptContextFieldStub::GenerateAssembly(
CodeStubAssembler* assembler) const {
typedef compiler::Node Node;
assembler->Comment("StoreScriptContextFieldStub: context_index=%d, slot=%d",
context_index(), slot_index());
Node* value = assembler->Parameter(Descriptor::kValue);
Node* context = assembler->Parameter(Descriptor::kContext);
Node* script_context = assembler->LoadScriptContext(context, context_index());
assembler->StoreFixedArrayElement(
script_context, assembler->IntPtrConstant(slot_index()), value,
UPDATE_WRITE_BARRIER, CodeStubAssembler::INTPTR_PARAMETERS);
assembler->Return(value);
}
// static
compiler::Node* LessThanStub::Generate(CodeStubAssembler* assembler,
compiler::Node* lhs, compiler::Node* rhs,
......
......@@ -86,9 +86,7 @@ class ObjectLiteral;
V(LoadDictionaryElement) \
V(LoadFastElement) \
V(LoadField) \
V(LoadScriptContextField) \
V(StoreFastElement) \
V(StoreScriptContextField) \
V(StoreTransition) \
/* These should never be ported to TF */ \
/* because they are either used only by */ \
......@@ -150,6 +148,8 @@ class ObjectLiteral;
V(NotEqual) \
V(KeyedLoadSloppyArguments) \
V(KeyedStoreSloppyArguments) \
V(LoadScriptContextField) \
V(StoreScriptContextField) \
V(StrictEqual) \
V(StrictNotEqual) \
V(StringEqual) \
......@@ -2682,23 +2682,21 @@ class DoubleToIStub : public PlatformCodeStub {
DEFINE_PLATFORM_CODE_STUB(DoubleToI, PlatformCodeStub);
};
class ScriptContextFieldStub : public HandlerStub {
class ScriptContextFieldStub : public TurboFanCodeStub {
public:
ScriptContextFieldStub(Isolate* isolate,
const ScriptContextTable::LookupResult* lookup_result)
: HandlerStub(isolate) {
: TurboFanCodeStub(isolate) {
DCHECK(Accepted(lookup_result));
STATIC_ASSERT(kContextIndexBits + kSlotIndexBits <= kSubMinorKeyBits);
set_sub_minor_key(ContextIndexBits::encode(lookup_result->context_index) |
SlotIndexBits::encode(lookup_result->slot_index));
minor_key_ = ContextIndexBits::encode(lookup_result->context_index) |
SlotIndexBits::encode(lookup_result->slot_index);
}
int context_index() const {
return ContextIndexBits::decode(sub_minor_key());
}
Code::Kind GetCodeKind() const override { return Code::HANDLER; }
int slot_index() const { return SlotIndexBits::decode(sub_minor_key()); }
int context_index() const { return ContextIndexBits::decode(minor_key_); }
int slot_index() const { return SlotIndexBits::decode(minor_key_); }
static bool Accepted(const ScriptContextTable::LookupResult* lookup_result) {
return ContextIndexBits::is_valid(lookup_result->context_index) &&
......@@ -2712,7 +2710,7 @@ class ScriptContextFieldStub : public HandlerStub {
class SlotIndexBits
: public BitField<int, kContextIndexBits, kSlotIndexBits> {};
DEFINE_CODE_STUB_BASE(ScriptContextFieldStub, HandlerStub);
DEFINE_CODE_STUB_BASE(ScriptContextFieldStub, TurboFanCodeStub);
};
......@@ -2722,11 +2720,11 @@ class LoadScriptContextFieldStub : public ScriptContextFieldStub {
Isolate* isolate, const ScriptContextTable::LookupResult* lookup_result)
: ScriptContextFieldStub(isolate, lookup_result) {}
private:
Code::Kind kind() const override { return Code::LOAD_IC; }
ExtraICState GetExtraICState() const override { return Code::LOAD_IC; }
private:
DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
DEFINE_HANDLER_CODE_STUB(LoadScriptContextField, ScriptContextFieldStub);
DEFINE_TURBOFAN_CODE_STUB(LoadScriptContextField, ScriptContextFieldStub);
};
......@@ -2736,11 +2734,11 @@ class StoreScriptContextFieldStub : public ScriptContextFieldStub {
Isolate* isolate, const ScriptContextTable::LookupResult* lookup_result)
: ScriptContextFieldStub(isolate, lookup_result) {}
private:
Code::Kind kind() const override { return Code::STORE_IC; }
ExtraICState GetExtraICState() const override { return Code::STORE_IC; }
private:
DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreWithVector);
DEFINE_HANDLER_CODE_STUB(StoreScriptContextField, ScriptContextFieldStub);
DEFINE_TURBOFAN_CODE_STUB(StoreScriptContextField, ScriptContextFieldStub);
};
......
......@@ -3402,16 +3402,6 @@ HInstruction* HGraphBuilder::BuildGetNativeContext(HValue* closure) {
}
HInstruction* HGraphBuilder::BuildGetScriptContext(int context_index) {
HValue* native_context = BuildGetNativeContext();
HValue* script_context_table = Add<HLoadNamedField>(
native_context, nullptr,
HObjectAccess::ForContextSlot(Context::SCRIPT_CONTEXT_TABLE_INDEX));
return Add<HLoadNamedField>(script_context_table, nullptr,
HObjectAccess::ForScriptContext(context_index));
}
HValue* HGraphBuilder::BuildGetParentContext(HValue* depth, int depth_value) {
HValue* script_context = context();
if (depth != NULL) {
......
......@@ -1860,7 +1860,7 @@ class HGraphBuilder {
HInstruction* BuildGetNativeContext(HValue* closure);
HInstruction* BuildGetNativeContext();
HInstruction* BuildGetScriptContext(int context_index);
// Builds a loop version if |depth| is specified or unrolls the loop to
// |depth_value| iterations otherwise.
HValue* BuildGetParentContext(HValue* depth, int depth_value);
......
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