Commit 9e720e3f authored by ishell's avatar ishell Committed by Commit bot

[ic] Refactoring definition of a smi-encoded load handlers.

BUG=

Review-Url: https://chromiumcodereview.appspot.com/2433333002
Cr-Commit-Position: refs/heads/master@{#40469}
parent 8a80c3b7
......@@ -5296,18 +5296,20 @@ void CodeStubAssembler::HandleLoadICHandlerCase(
Node* holder = var_holder.value();
Node* handler_word = SmiUntag(var_smi_handler.value());
Node* handler_type = DecodeWord<LoadHandlerTypeBits>(handler_word);
Node* handler_kind = DecodeWord<LoadHandler::KindBits>(handler_word);
if (support_elements == kSupportElements) {
Label property(this);
GotoUnless(
WordEqual(handler_type, IntPtrConstant(kLoadICHandlerForElements)),
WordEqual(handler_kind, IntPtrConstant(LoadHandler::kForElements)),
&property);
Comment("element_load");
Node* intptr_index = TryToIntptr(p->name, miss);
Node* elements = LoadElements(holder);
Node* is_jsarray_condition = IsSetWord<KeyedLoadIsJsArray>(handler_word);
Node* elements_kind = DecodeWord<KeyedLoadElementsKind>(handler_word);
Node* is_jsarray_condition =
IsSetWord<LoadHandler::IsJsArrayBits>(handler_word);
Node* elements_kind =
DecodeWord<LoadHandler::ElementsKindBits>(handler_word);
Label if_hole(this), unimplemented_elements_kind(this);
Label* out_of_bounds = miss;
EmitElementLoad(holder, elements, elements_kind, intptr_index,
......@@ -5326,7 +5328,7 @@ void CodeStubAssembler::HandleLoadICHandlerCase(
Bind(&if_hole);
{
Comment("convert hole");
GotoUnless(IsSetWord<KeyedLoadConvertHole>(handler_word), miss);
GotoUnless(IsSetWord<LoadHandler::ConvertHoleBits>(handler_word), miss);
Node* protector_cell = LoadRoot(Heap::kArrayProtectorRootIndex);
DCHECK(isolate()->heap()->array_protector()->IsPropertyCell());
GotoUnless(
......@@ -5342,22 +5344,22 @@ void CodeStubAssembler::HandleLoadICHandlerCase(
}
Label constant(this), field(this);
Branch(WordEqual(handler_type, IntPtrConstant(kLoadICHandlerForFields)),
Branch(WordEqual(handler_kind, IntPtrConstant(LoadHandler::kForFields)),
&field, &constant);
Bind(&field);
{
Comment("field_load");
Node* offset = DecodeWord<FieldOffsetOffset>(handler_word);
Node* offset = DecodeWord<LoadHandler::FieldOffsetBits>(handler_word);
Label inobject(this), out_of_object(this);
Branch(IsSetWord<FieldOffsetIsInobject>(handler_word), &inobject,
Branch(IsSetWord<LoadHandler::IsInobjectBits>(handler_word), &inobject,
&out_of_object);
Bind(&inobject);
{
Label is_double(this);
GotoIf(IsSetWord<FieldOffsetIsDouble>(handler_word), &is_double);
GotoIf(IsSetWord<LoadHandler::IsDoubleBits>(handler_word), &is_double);
Return(LoadObjectField(holder, offset));
Bind(&is_double);
......@@ -5376,7 +5378,7 @@ void CodeStubAssembler::HandleLoadICHandlerCase(
Label is_double(this);
Node* properties = LoadProperties(holder);
Node* value = LoadObjectField(properties, offset);
GotoIf(IsSetWord<FieldOffsetIsDouble>(handler_word), &is_double);
GotoIf(IsSetWord<LoadHandler::IsDoubleBits>(handler_word), &is_double);
Return(value);
Bind(&is_double);
......@@ -5392,7 +5394,8 @@ void CodeStubAssembler::HandleLoadICHandlerCase(
{
Comment("constant_load");
Node* descriptors = LoadMapDescriptors(LoadMap(holder));
Node* descriptor = DecodeWord<ValueIndexInDescriptorArray>(handler_word);
Node* descriptor =
DecodeWord<LoadHandler::DescriptorValueIndexBits>(handler_word);
#if defined(DEBUG)
CSA_ASSERT(UintPtrLessThan(
descriptor, LoadAndUntagFixedArrayBaseLength(descriptors)));
......
......@@ -634,8 +634,8 @@ Handle<Object> ElementHandlerCompiler::GetKeyedLoadHandler(
if (elements_kind == DICTIONARY_ELEMENTS) {
if (FLAG_tf_load_ic_stub) {
TRACE_HANDLER_STATS(isolate, KeyedLoadIC_LoadElementDH);
return SmiHandler::MakeKeyedLoadHandler(isolate, elements_kind, false,
is_js_array);
return LoadHandler::LoadElement(isolate, elements_kind, false,
is_js_array);
}
TRACE_HANDLER_STATS(isolate, KeyedLoadIC_LoadDictionaryElementStub);
return LoadDictionaryElementStub(isolate).GetCode();
......@@ -648,8 +648,8 @@ Handle<Object> ElementHandlerCompiler::GetKeyedLoadHandler(
*receiver_map == isolate->get_initial_js_array_map(elements_kind);
if (FLAG_tf_load_ic_stub) {
TRACE_HANDLER_STATS(isolate, KeyedLoadIC_LoadElementDH);
return SmiHandler::MakeKeyedLoadHandler(
isolate, elements_kind, convert_hole_to_undefined, is_js_array);
return LoadHandler::LoadElement(isolate, elements_kind,
convert_hole_to_undefined, is_js_array);
} else {
TRACE_HANDLER_STATS(isolate, KeyedLoadIC_LoadFastElementStub);
return LoadFastElementStub(isolate, is_js_array, elements_kind,
......
......@@ -13,31 +13,30 @@
namespace v8 {
namespace internal {
Handle<Object> SmiHandler::MakeLoadFieldHandler(Isolate* isolate,
FieldIndex field_index) {
int config = LoadHandlerTypeBits::encode(kLoadICHandlerForFields) |
FieldOffsetIsInobject::encode(field_index.is_inobject()) |
FieldOffsetIsDouble::encode(field_index.is_double()) |
FieldOffsetOffset::encode(field_index.offset());
Handle<Object> LoadHandler::LoadField(Isolate* isolate,
FieldIndex field_index) {
int config = KindBits::encode(kForFields) |
IsInobjectBits::encode(field_index.is_inobject()) |
IsDoubleBits::encode(field_index.is_double()) |
FieldOffsetBits::encode(field_index.offset());
return handle(Smi::FromInt(config), isolate);
}
Handle<Object> SmiHandler::MakeLoadConstantHandler(Isolate* isolate,
int descriptor) {
int config = LoadHandlerTypeBits::encode(kLoadICHandlerForConstants) |
ValueIndexInDescriptorArray::encode(
Handle<Object> LoadHandler::LoadConstant(Isolate* isolate, int descriptor) {
int config = KindBits::encode(kForConstants) |
DescriptorValueIndexBits::encode(
DescriptorArray::ToValueIndex(descriptor));
return handle(Smi::FromInt(config), isolate);
}
Handle<Object> SmiHandler::MakeKeyedLoadHandler(Isolate* isolate,
ElementsKind elements_kind,
bool convert_hole_to_undefined,
bool is_js_array) {
int config = LoadHandlerTypeBits::encode(kLoadICHandlerForElements) |
KeyedLoadElementsKind::encode(elements_kind) |
KeyedLoadConvertHole::encode(convert_hole_to_undefined) |
KeyedLoadIsJsArray::encode(is_js_array);
Handle<Object> LoadHandler::LoadElement(Isolate* isolate,
ElementsKind elements_kind,
bool convert_hole_to_undefined,
bool is_js_array) {
int config = KindBits::encode(kForElements) |
ElementsKindBits::encode(elements_kind) |
ConvertHoleBits::encode(convert_hole_to_undefined) |
IsJsArrayBits::encode(is_js_array);
return handle(Smi::FromInt(config), isolate);
}
......
......@@ -13,57 +13,57 @@
namespace v8 {
namespace internal {
enum LoadHandlerType {
kLoadICHandlerForElements = 0,
kLoadICHandlerForFields = 1,
kLoadICHandlerForConstants = 2
};
// A set of bit fields representing Smi handlers for loads.
class LoadHandler {
public:
enum Kind { kForElements, kForFields, kForConstants };
class KindBits : public BitField<Kind, 0, 2> {};
class LoadHandlerTypeBits : public BitField<LoadHandlerType, 0, 2> {};
//
// Encoding when KindBits contains kForConstants.
//
// Encoding for configuration Smis for constants loads (when LoadHandlerTypeBits
// contain LoadICHandlerForConstants):
class ValueIndexInDescriptorArray
: public BitField<int, LoadHandlerTypeBits::kNext,
kDescriptorIndexBitCount + 2> {};
// Make sure we don't overflow into the sign bit.
STATIC_ASSERT(ValueIndexInDescriptorArray::kNext <= kSmiValueSize - 1);
// +2 here is because each descriptor entry occupies 3 slots in array.
class DescriptorValueIndexBits
: public BitField<unsigned, KindBits::kNext,
kDescriptorIndexBitCount + 2> {};
// Make sure we don't overflow the smi.
STATIC_ASSERT(DescriptorValueIndexBits::kNext <= kSmiValueSize);
// Encoding for configuration Smis for field loads (when LoadHandlerTypeBits
// contain LoadICHandlerForFields):
class FieldOffsetIsInobject
: public BitField<bool, LoadHandlerTypeBits::kNext, 1> {};
class FieldOffsetIsDouble
: public BitField<bool, FieldOffsetIsInobject::kNext, 1> {};
class FieldOffsetOffset : public BitField<int, FieldOffsetIsDouble::kNext, 26> {
};
// Make sure we don't overflow into the sign bit.
STATIC_ASSERT(FieldOffsetOffset::kNext <= kSmiValueSize - 1);
//
// Encoding when KindBits contains kForFields.
//
class IsInobjectBits : public BitField<bool, KindBits::kNext, 1> {};
class IsDoubleBits : public BitField<bool, IsInobjectBits::kNext, 1> {};
// +1 here is to cover all possible JSObject header sizes.
class FieldOffsetBits
: public BitField<unsigned, IsDoubleBits::kNext,
kDescriptorIndexBitCount + 1 + kPointerSizeLog2> {};
// Make sure we don't overflow the smi.
STATIC_ASSERT(FieldOffsetBits::kNext <= kSmiValueSize);
// Encoding for configuration Smis for elements loads (when LoadHandlerTypeBits
// contain LoadICHandlerForElements)
class KeyedLoadIsJsArray
: public BitField<bool, LoadHandlerTypeBits::kNext, 1> {};
class KeyedLoadConvertHole
: public BitField<bool, KeyedLoadIsJsArray::kNext, 1> {};
class KeyedLoadElementsKind
: public BitField<ElementsKind, KeyedLoadConvertHole::kNext, 8> {};
// Make sure we don't overflow into the sign bit.
STATIC_ASSERT(KeyedLoadElementsKind::kNext <= kSmiValueSize - 1);
//
// Encoding when KindBits contains kForElements.
//
class IsJsArrayBits : public BitField<bool, KindBits::kNext, 1> {};
class ConvertHoleBits : public BitField<bool, IsJsArrayBits::kNext, 1> {};
class ElementsKindBits
: public BitField<ElementsKind, ConvertHoleBits::kNext, 8> {};
// Make sure we don't overflow the smi.
STATIC_ASSERT(ElementsKindBits::kNext <= kSmiValueSize);
// This class is a collection of factory methods for various Smi-encoded
// IC handlers consumed by respective IC dispatchers.
class SmiHandler {
public:
static inline Handle<Object> MakeLoadFieldHandler(Isolate* isolate,
FieldIndex field_index);
// Creates a Smi-handler for loading a field from fast object.
static inline Handle<Object> LoadField(Isolate* isolate,
FieldIndex field_index);
static inline Handle<Object> MakeLoadConstantHandler(Isolate* isolate,
int descriptor);
// Creates a Smi-handler for loading a constant from fast object.
static inline Handle<Object> LoadConstant(Isolate* isolate, int descriptor);
static inline Handle<Object> MakeKeyedLoadHandler(
Isolate* isolate, ElementsKind elements_kind,
bool convert_hole_to_undefined, bool is_js_array);
// Creates a Smi-handler for loading an element.
static inline Handle<Object> LoadElement(Isolate* isolate,
ElementsKind elements_kind,
bool convert_hole_to_undefined,
bool is_js_array);
};
} // namespace internal
......
......@@ -836,7 +836,7 @@ Handle<Code> KeyedStoreIC::ChooseMegamorphicStub(Isolate* isolate,
Handle<Object> LoadIC::SimpleFieldLoad(FieldIndex index) {
if (FLAG_tf_load_ic_stub) {
TRACE_HANDLER_STATS(isolate(), LoadIC_LoadFieldDH);
return SmiHandler::MakeLoadFieldHandler(isolate(), index);
return LoadHandler::LoadField(isolate(), index);
}
TRACE_HANDLER_STATS(isolate(), LoadIC_LoadFieldStub);
LoadFieldStub stub(isolate(), index);
......@@ -1200,8 +1200,8 @@ Handle<Object> LoadIC::GetMapIndependentHandler(LookupIterator* lookup) {
// -------------- Constant properties --------------
DCHECK(lookup->property_details().type() == DATA_CONSTANT);
if (FLAG_tf_load_ic_stub) {
Handle<Object> smi_handler = SmiHandler::MakeLoadConstantHandler(
isolate(), lookup->GetConstantIndex());
Handle<Object> smi_handler =
LoadHandler::LoadConstant(isolate(), lookup->GetConstantIndex());
if (receiver_is_holder) {
TRACE_HANDLER_STATS(isolate(), LoadIC_LoadConstantDH);
return smi_handler;
......
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