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