Commit c30d366c authored by Seth Brenith's avatar Seth Brenith Committed by Commit Bot

Use a Torque macro for searching context locals

This is a partial reland of https://crrev.com/c/v8/v8/+/2601880 .

This change improves readability and helps prepare for when ScopeInfo
will not be convertible to FixedArrayBase.

Change-Id: I8de453c2b72ced51e98161e3d9e6426cd6ff7267
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2707250Reviewed-by: 's avatarMythri Alle <mythria@chromium.org>
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#72920}
parent 4bc932bf
......@@ -2013,11 +2013,6 @@ TNode<IntPtrT> CodeStubAssembler::LoadArrayLength(
return LoadAndUntagWeakFixedArrayLength(array);
}
template <>
TNode<IntPtrT> CodeStubAssembler::LoadArrayLength(TNode<ScopeInfo> array) {
return LoadAndUntagFixedArrayBaseLength(array);
}
template <typename Array, typename TIndex, typename TValue>
TNode<TValue> CodeStubAssembler::LoadArrayElement(
TNode<Array> array, int array_header_size, TNode<TIndex> index_node,
......@@ -2048,10 +2043,6 @@ TNode<TValue> CodeStubAssembler::LoadArrayElement(
template V8_EXPORT_PRIVATE TNode<MaybeObject>
CodeStubAssembler::LoadArrayElement<TransitionArray, IntPtrT>(
TNode<TransitionArray>, int, TNode<IntPtrT>, int, LoadSensitivity);
template V8_EXPORT_PRIVATE TNode<MaybeObject>
CodeStubAssembler::LoadArrayElement<ScopeInfo, IntPtrT>(TNode<ScopeInfo>, int,
TNode<IntPtrT>, int,
LoadSensitivity);
template <typename TIndex>
TNode<Object> CodeStubAssembler::LoadFixedArrayElement(
......
......@@ -3074,35 +3074,15 @@ void AccessorAssembler::ScriptContextTableLookup(
TNode<ScopeInfo> scope_info =
CAST(LoadContextElement(script_context, Context::SCOPE_INFO_INDEX));
TVARIABLE(IntPtrT, scope_var_index,
IntPtrConstant(ScopeInfo::kVariablePartIndex - 1));
TNode<IntPtrT> num_scope_vars = SmiUntag(
CAST(LoadObjectField(scope_info, ScopeInfo::kContextLocalCountOffset)));
TNode<IntPtrT> end_index = IntPtrAdd(
num_scope_vars, IntPtrConstant(ScopeInfo::kVariablePartIndex));
Label loop_scope_info(this, &scope_var_index);
Goto(&loop_scope_info);
BIND(&loop_scope_info);
{
scope_var_index = IntPtrAdd(scope_var_index.value(), IntPtrConstant(1));
GotoIf(IntPtrGreaterThanOrEqual(scope_var_index.value(), end_index),
&loop);
FixedArrayBoundsCheck(scope_info, scope_var_index.value(), 0);
TNode<Object> var_name = CAST(LoadArrayElement(
scope_info, FixedArray::kHeaderSize, scope_var_index.value()));
GotoIf(TaggedNotEqual(var_name, name), &loop_scope_info);
TNode<IntPtrT> var_index =
IntPtrAdd(IntPtrConstant(Context::MIN_CONTEXT_SLOTS),
IntPtrSub(scope_var_index.value(),
IntPtrConstant(ScopeInfo::kVariablePartIndex)));
TNode<IntPtrT> context_local_index =
IndexOfLocalName(scope_info, name, &loop);
TNode<IntPtrT> var_index = IntPtrAdd(
IntPtrConstant(Context::MIN_CONTEXT_SLOTS), context_local_index);
TNode<Object> result = LoadContextElement(script_context, var_index);
GotoIf(IsTheHole(result), found_hole);
Return(result);
}
}
}
void AccessorAssembler::LoadGlobalIC_NoFeedback(TNode<Context> context,
......
......@@ -167,3 +167,17 @@ extern class ScopeInfo extends FixedArrayBase {
module_variables[flags.scope_type == ScopeType::MODULE_SCOPE ? module_variable_count[0] : 0]:
ModuleVariable;
}
// Returns the index of the named local in a ScopeInfo.
// Assumes that the given name is internalized; uses pointer comparisons.
@export
macro IndexOfLocalName(scopeInfo: ScopeInfo, name: Name):
intptr labels NotFound {
const count: intptr = Convert<intptr>(scopeInfo.context_local_count);
for (let i: intptr = 0; i < count; ++i) {
if (TaggedEqual(name, scopeInfo.context_local_names[i])) {
return i;
}
}
goto NotFound;
}
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