Commit 8d710631 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[csa] Add statically typed CSA::ElementOffsetFromIndex()

This is a first step towards removal of dynamic ParameterMode.

Bug: v8:9708
Change-Id: I3502584264952dc12b44fd85b91274c9a0ddf31d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1798622Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63688}
parent 9a34e1e6
......@@ -370,9 +370,10 @@ TNode<JSRegExpResult> RegExpBuiltinsAssembler::ConstructNewResultFromMatchInfo(
}
void RegExpBuiltinsAssembler::GetStringPointers(
Node* const string_data, Node* const offset, Node* const last_index,
Node* const string_length, String::Encoding encoding,
Variable* var_string_start, Variable* var_string_end) {
TNode<RawPtrT> string_data, TNode<IntPtrT> offset,
TNode<IntPtrT> last_index, TNode<IntPtrT> string_length,
String::Encoding encoding, TVariable<RawPtrT>* var_string_start,
TVariable<RawPtrT>* var_string_end) {
DCHECK_EQ(var_string_start->rep(), MachineType::PointerRepresentation());
DCHECK_EQ(var_string_end->rep(), MachineType::PointerRepresentation());
......@@ -380,13 +381,14 @@ void RegExpBuiltinsAssembler::GetStringPointers(
? UINT8_ELEMENTS
: UINT16_ELEMENTS;
TNode<IntPtrT> const from_offset = ElementOffsetFromIndex(
IntPtrAdd(offset, last_index), kind, INTPTR_PARAMETERS);
var_string_start->Bind(IntPtrAdd(string_data, from_offset));
TNode<IntPtrT> from_offset =
ElementOffsetFromIndex(IntPtrAdd(offset, last_index), kind);
*var_string_start =
ReinterpretCast<RawPtrT>(IntPtrAdd(string_data, from_offset));
TNode<IntPtrT> const to_offset = ElementOffsetFromIndex(
IntPtrAdd(offset, string_length), kind, INTPTR_PARAMETERS);
var_string_end->Bind(IntPtrAdd(string_data, to_offset));
TNode<IntPtrT> to_offset =
ElementOffsetFromIndex(IntPtrAdd(offset, string_length), kind);
*var_string_end = ReinterpretCast<RawPtrT>(IntPtrAdd(string_data, to_offset));
}
TNode<HeapObject> RegExpBuiltinsAssembler::RegExpExecInternal(
......
......@@ -57,10 +57,12 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler {
// Loads {var_string_start} and {var_string_end} with the corresponding
// offsets into the given {string_data}.
void GetStringPointers(Node* const string_data, Node* const offset,
Node* const last_index, Node* const string_length,
String::Encoding encoding, Variable* var_string_start,
Variable* var_string_end);
void GetStringPointers(TNode<RawPtrT> string_data, TNode<IntPtrT> offset,
TNode<IntPtrT> last_index,
TNode<IntPtrT> string_length,
String::Encoding encoding,
TVariable<RawPtrT>* var_string_start,
TVariable<RawPtrT>* var_string_end);
// Low level logic around the actual call into pattern matching code.
TNode<HeapObject> RegExpExecInternal(TNode<Context> context,
......
......@@ -5427,9 +5427,9 @@ void CodeStubAssembler::CopyStringCharacters(Node* from_string, Node* to_string,
TNode<IntPtrT> from_offset = ElementOffsetFromIndex(
from_index, from_kind, INTPTR_PARAMETERS, header_size);
TNode<IntPtrT> to_offset =
ElementOffsetFromIndex(to_index, to_kind, INTPTR_PARAMETERS, header_size);
ElementOffsetFromIndex(to_index, to_kind, header_size);
TNode<IntPtrT> byte_count =
ElementOffsetFromIndex(character_count, from_kind, INTPTR_PARAMETERS);
ElementOffsetFromIndex(character_count, from_kind);
TNode<WordT> limit_offset = IntPtrAdd(from_offset, byte_count);
// Prepare the fast loop
......@@ -10219,34 +10219,63 @@ TNode<IntPtrT> CodeStubAssembler::ElementOffsetFromIndex(Node* index_node,
ParameterMode mode,
int base_size) {
CSA_SLOW_ASSERT(this, MatchesParameterMode(index_node, mode));
if (mode == SMI_PARAMETERS) {
return ElementOffsetFromIndex(ReinterpretCast<Smi>(index_node), kind,
base_size);
} else {
DCHECK(mode == INTPTR_PARAMETERS);
return ElementOffsetFromIndex(ReinterpretCast<IntPtrT>(index_node), kind,
base_size);
}
}
template <typename TIndex>
TNode<IntPtrT> CodeStubAssembler::ElementOffsetFromIndex(
TNode<TIndex> index_node, ElementsKind kind, int base_size) {
static_assert(
std::is_same<TIndex, Smi>::value || std::is_same<TIndex, IntPtrT>::value,
"Only Smi or IntPtrT index nodes are allowed");
int element_size_shift = ElementsKindToShiftSize(kind);
int element_size = 1 << element_size_shift;
int const kSmiShiftBits = kSmiShiftSize + kSmiTagSize;
intptr_t index = 0;
TNode<IntPtrT> intptr_index_node;
bool constant_index = false;
if (mode == SMI_PARAMETERS) {
if (std::is_same<TIndex, Smi>::value) {
TNode<Smi> smi_index_node = ReinterpretCast<Smi>(index_node);
element_size_shift -= kSmiShiftBits;
Smi smi_index;
constant_index = ToSmiConstant(index_node, &smi_index);
constant_index = ToSmiConstant(smi_index_node, &smi_index);
if (constant_index) index = smi_index.value();
index_node = BitcastTaggedToWordForTagAndSmiBits(index_node);
intptr_index_node = BitcastTaggedToWordForTagAndSmiBits(smi_index_node);
} else {
DCHECK(mode == INTPTR_PARAMETERS);
constant_index = ToIntPtrConstant(index_node, &index);
intptr_index_node = ReinterpretCast<IntPtrT>(index_node);
constant_index = ToIntPtrConstant(intptr_index_node, &index);
}
if (constant_index) {
return IntPtrConstant(base_size + element_size * index);
}
TNode<WordT> shifted_index =
TNode<IntPtrT> shifted_index =
(element_size_shift == 0)
? UncheckedCast<WordT>(index_node)
? intptr_index_node
: ((element_size_shift > 0)
? WordShl(index_node, IntPtrConstant(element_size_shift))
: WordSar(index_node, IntPtrConstant(-element_size_shift)));
? WordShl(intptr_index_node,
IntPtrConstant(element_size_shift))
: WordSar(intptr_index_node,
IntPtrConstant(-element_size_shift)));
return IntPtrAdd(IntPtrConstant(base_size), Signed(shifted_index));
}
template V8_EXPORT_PRIVATE TNode<IntPtrT>
CodeStubAssembler::ElementOffsetFromIndex<Smi>(TNode<Smi> index_node,
ElementsKind kind,
int base_size);
template V8_EXPORT_PRIVATE TNode<IntPtrT>
CodeStubAssembler::ElementOffsetFromIndex<IntPtrT>(TNode<IntPtrT> index_node,
ElementsKind kind,
int base_size);
TNode<BoolT> CodeStubAssembler::IsOffsetInBounds(SloppyTNode<IntPtrT> offset,
SloppyTNode<IntPtrT> length,
int header_size,
......
......@@ -3470,6 +3470,10 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
TNode<UintPtrT> LoadJSTypedArrayLength(TNode<JSTypedArray> typed_array);
TNode<RawPtrT> LoadJSTypedArrayBackingStore(TNode<JSTypedArray> typed_array);
template <typename TIndex>
TNode<IntPtrT> ElementOffsetFromIndex(TNode<TIndex> index, ElementsKind kind,
int base_size = 0);
// TODO(v8:9708): remove once all uses are ported.
TNode<IntPtrT> ElementOffsetFromIndex(Node* index, ElementsKind kind,
ParameterMode mode, int base_size = 0);
......
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