Commit 39b9b263 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[gasm] Type constants and a few more methods

... for convenient TNode access (e.g.: PhiAt, LoadField, LoadElement).

Bug: v8:9972
Change-Id: Ie6f5f204079cf7c84279d1cb015055816f301916
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1940254
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65243}
parent a183b8be
...@@ -167,6 +167,11 @@ struct MachineRepresentationOf<ExternalReference> { ...@@ -167,6 +167,11 @@ struct MachineRepresentationOf<ExternalReference> {
static const MachineRepresentation value = RawPtrT::kMachineRepresentation; static const MachineRepresentation value = RawPtrT::kMachineRepresentation;
}; };
template <typename T>
constexpr bool IsMachineRepresentationOf(MachineRepresentation r) {
return MachineRepresentationOf<T>::value == r;
}
template <class T> template <class T>
struct is_valid_type_tag { struct is_valid_type_tag {
static const bool value = std::is_base_of<Object, T>::value || static const bool value = std::is_base_of<Object, T>::value ||
......
...@@ -4536,7 +4536,7 @@ Node* EffectControlLinearizer::SmiShiftBitsConstant() { ...@@ -4536,7 +4536,7 @@ Node* EffectControlLinearizer::SmiShiftBitsConstant() {
Node* EffectControlLinearizer::LowerPlainPrimitiveToNumber(Node* node) { Node* EffectControlLinearizer::LowerPlainPrimitiveToNumber(Node* node) {
Node* value = node->InputAt(0); Node* value = node->InputAt(0);
return __ ToNumber(value); return __ ToNumber(TNode<Object>::UncheckedCast(value));
} }
Node* EffectControlLinearizer::LowerPlainPrimitiveToWord32(Node* node) { Node* EffectControlLinearizer::LowerPlainPrimitiveToWord32(Node* node) {
...@@ -4551,7 +4551,7 @@ Node* EffectControlLinearizer::LowerPlainPrimitiveToWord32(Node* node) { ...@@ -4551,7 +4551,7 @@ Node* EffectControlLinearizer::LowerPlainPrimitiveToWord32(Node* node) {
__ Goto(&done, ChangeSmiToInt32(value)); __ Goto(&done, ChangeSmiToInt32(value));
__ Bind(&if_not_smi); __ Bind(&if_not_smi);
Node* to_number = __ ToNumber(value); Node* to_number = __ ToNumber(TNode<Object>::UncheckedCast(value));
Node* check1 = ObjectIsSmi(to_number); Node* check1 = ObjectIsSmi(to_number);
__ GotoIf(check1, &if_to_number_smi); __ GotoIf(check1, &if_to_number_smi);
...@@ -4578,7 +4578,7 @@ Node* EffectControlLinearizer::LowerPlainPrimitiveToFloat64(Node* node) { ...@@ -4578,7 +4578,7 @@ Node* EffectControlLinearizer::LowerPlainPrimitiveToFloat64(Node* node) {
__ Goto(&done, __ ChangeInt32ToFloat64(from_smi)); __ Goto(&done, __ ChangeInt32ToFloat64(from_smi));
__ Bind(&if_not_smi); __ Bind(&if_not_smi);
Node* to_number = __ ToNumber(value); Node* to_number = __ ToNumber(TNode<Object>::UncheckedCast(value));
Node* check1 = ObjectIsSmi(to_number); Node* check1 = ObjectIsSmi(to_number);
__ GotoIf(check1, &if_to_number_smi); __ GotoIf(check1, &if_to_number_smi);
......
...@@ -398,15 +398,15 @@ Node* GraphAssembler::LoadFramePointer() { ...@@ -398,15 +398,15 @@ Node* GraphAssembler::LoadFramePointer() {
return AddNode(graph()->NewNode(machine()->LoadFramePointer())); return AddNode(graph()->NewNode(machine()->LoadFramePointer()));
} }
#define SINGLETON_CONST_DEF(Name) \ #define SINGLETON_CONST_DEF(Name, Type) \
TNode<Object> GraphAssembler::Name##Constant() { \ TNode<Type> GraphAssembler::Name##Constant() { \
return TNode<Object>::UncheckedCast( \ return TNode<Type>::UncheckedCast( \
AddClonedNode(jsgraph()->Name##Constant())); \ AddClonedNode(jsgraph()->Name##Constant())); \
} }
JSGRAPH_SINGLETON_CONSTANT_LIST(SINGLETON_CONST_DEF) JSGRAPH_SINGLETON_CONSTANT_LIST(SINGLETON_CONST_DEF)
#undef SINGLETON_CONST_DEF #undef SINGLETON_CONST_DEF
#define SINGLETON_CONST_TEST_DEF(Name) \ #define SINGLETON_CONST_TEST_DEF(Name, ...) \
TNode<Boolean> GraphAssembler::Is##Name(TNode<Object> value) { \ TNode<Boolean> GraphAssembler::Is##Name(TNode<Object> value) { \
return TNode<Boolean>::UncheckedCast( \ return TNode<Boolean>::UncheckedCast( \
ReferenceEqual(value, Name##Constant())); \ ReferenceEqual(value, Name##Constant())); \
...@@ -516,8 +516,10 @@ TNode<Number> GraphAssembler::StringLength(TNode<String> string) { ...@@ -516,8 +516,10 @@ TNode<Number> GraphAssembler::StringLength(TNode<String> string) {
graph()->NewNode(simplified()->StringLength(), string)); graph()->NewNode(simplified()->StringLength(), string));
} }
Node* GraphAssembler::ReferenceEqual(Node* lhs, Node* rhs) { TNode<Boolean> GraphAssembler::ReferenceEqual(TNode<Object> lhs,
return AddNode(graph()->NewNode(simplified()->ReferenceEqual(), lhs, rhs)); TNode<Object> rhs) {
return AddNode<Boolean>(
graph()->NewNode(simplified()->ReferenceEqual(), lhs, rhs));
} }
TNode<Number> GraphAssembler::NumberMin(TNode<Number> lhs, TNode<Number> rhs) { TNode<Number> GraphAssembler::NumberMin(TNode<Number> lhs, TNode<Number> rhs) {
...@@ -550,13 +552,14 @@ TNode<Boolean> GraphAssembler::NumberLessThanOrEqual(TNode<Number> lhs, ...@@ -550,13 +552,14 @@ TNode<Boolean> GraphAssembler::NumberLessThanOrEqual(TNode<Number> lhs,
graph()->NewNode(simplified()->NumberLessThanOrEqual(), lhs, rhs)); graph()->NewNode(simplified()->NumberLessThanOrEqual(), lhs, rhs));
} }
TNode<String> GraphAssembler::StringSubstring(Node* string, Node* from, TNode<String> GraphAssembler::StringSubstring(TNode<String> string,
Node* to) { TNode<Number> from,
TNode<Number> to) {
return AddNode<String>(graph()->NewNode( return AddNode<String>(graph()->NewNode(
simplified()->StringSubstring(), string, from, to, effect(), control())); simplified()->StringSubstring(), string, from, to, effect(), control()));
} }
TNode<Boolean> GraphAssembler::ObjectIsCallable(Node* value) { TNode<Boolean> GraphAssembler::ObjectIsCallable(TNode<Object> value) {
return AddNode<Boolean>( return AddNode<Boolean>(
graph()->NewNode(simplified()->ObjectIsCallable(), value)); graph()->NewNode(simplified()->ObjectIsCallable(), value));
} }
...@@ -566,8 +569,9 @@ Node* GraphAssembler::CheckIf(Node* cond, DeoptimizeReason reason) { ...@@ -566,8 +569,9 @@ Node* GraphAssembler::CheckIf(Node* cond, DeoptimizeReason reason) {
control())); control()));
} }
Node* GraphAssembler::NumberIsFloat64Hole(Node* value) { TNode<Boolean> GraphAssembler::NumberIsFloat64Hole(TNode<Number> value) {
return AddNode(graph()->NewNode(simplified()->NumberIsFloat64Hole(), value)); return AddNode<Boolean>(
graph()->NewNode(simplified()->NumberIsFloat64Hole(), value));
} }
Node* GraphAssembler::TypeGuard(Type type, Node* value) { Node* GraphAssembler::TypeGuard(Type type, Node* value) {
...@@ -642,9 +646,10 @@ Node* GraphAssembler::UnsafePointerAdd(Node* base, Node* external) { ...@@ -642,9 +646,10 @@ Node* GraphAssembler::UnsafePointerAdd(Node* base, Node* external) {
effect(), control())); effect(), control()));
} }
Node* GraphAssembler::ToNumber(Node* value) { TNode<Number> GraphAssembler::ToNumber(TNode<Object> value) {
return AddNode(graph()->NewNode(ToNumberOperator(), ToNumberBuiltinConstant(), return AddNode<Number>(graph()->NewNode(ToNumberOperator(),
value, NoContextConstant(), effect())); ToNumberBuiltinConstant(), value,
NoContextConstant(), effect()));
} }
Node* GraphAssembler::BitcastWordToTagged(Node* value) { Node* GraphAssembler::BitcastWordToTagged(Node* value) {
......
...@@ -103,26 +103,26 @@ class BasicBlock; ...@@ -103,26 +103,26 @@ class BasicBlock;
V(Uint32Mod) V(Uint32Mod)
#define JSGRAPH_SINGLETON_CONSTANT_LIST(V) \ #define JSGRAPH_SINGLETON_CONSTANT_LIST(V) \
V(AllocateInOldGenerationStub) \ V(AllocateInOldGenerationStub, Code) \
V(AllocateInYoungGenerationStub) \ V(AllocateInYoungGenerationStub, Code) \
V(AllocateRegularInOldGenerationStub) \ V(AllocateRegularInOldGenerationStub, Code) \
V(AllocateRegularInYoungGenerationStub) \ V(AllocateRegularInYoungGenerationStub, Code) \
V(BigIntMap) \ V(BigIntMap, Map) \
V(BooleanMap) \ V(BooleanMap, Map) \
V(EmptyString) \ V(EmptyString, String) \
V(False) \ V(False, Boolean) \
V(FixedArrayMap) \ V(FixedArrayMap, Map) \
V(FixedDoubleArrayMap) \ V(FixedDoubleArrayMap, Map) \
V(HeapNumberMap) \ V(HeapNumberMap, Map) \
V(NaN) \ V(NaN, Number) \
V(NoContext) \ V(NoContext, Object) \
V(Null) \ V(Null, Oddball) \
V(One) \ V(One, Number) \
V(TheHole) \ V(TheHole, Oddball) \
V(ToNumberBuiltin) \ V(ToNumberBuiltin, Code) \
V(True) \ V(True, Boolean) \
V(Undefined) \ V(Undefined, Oddball) \
V(Zero) V(Zero, Number)
class GraphAssembler; class GraphAssembler;
...@@ -134,6 +134,13 @@ class GraphAssemblerLabel { ...@@ -134,6 +134,13 @@ class GraphAssemblerLabel {
public: public:
Node* PhiAt(size_t index); Node* PhiAt(size_t index);
template <typename T>
TNode<T> PhiAt(size_t index) {
// TODO(jgruber): Investigate issues on ptr compression bots and enable.
// DCHECK(IsMachineRepresentationOf<T>(representations_[index]));
return TNode<T>::UncheckedCast(PhiAt(index));
}
template <typename... Reps> template <typename... Reps>
explicit GraphAssemblerLabel(GraphAssemblerLabelType type, explicit GraphAssemblerLabel(GraphAssemblerLabelType type,
BasicBlock* basic_block, Reps... reps) BasicBlock* basic_block, Reps... reps)
...@@ -225,11 +232,11 @@ class V8_EXPORT_PRIVATE GraphAssembler { ...@@ -225,11 +232,11 @@ class V8_EXPORT_PRIVATE GraphAssembler {
Node* LoadFramePointer(); Node* LoadFramePointer();
#define SINGLETON_CONST_DECL(Name) TNode<Object> Name##Constant(); #define SINGLETON_CONST_DECL(Name, Type) TNode<Type> Name##Constant();
JSGRAPH_SINGLETON_CONSTANT_LIST(SINGLETON_CONST_DECL) JSGRAPH_SINGLETON_CONSTANT_LIST(SINGLETON_CONST_DECL)
#undef SINGLETON_CONST_DECL #undef SINGLETON_CONST_DECL
#define SINGLETON_CONST_TEST_DECL(Name) \ #define SINGLETON_CONST_TEST_DECL(Name, ...) \
TNode<Boolean> Is##Name(TNode<Object> value); TNode<Boolean> Is##Name(TNode<Object> value);
JSGRAPH_SINGLETON_CONSTANT_LIST(SINGLETON_CONST_TEST_DECL) JSGRAPH_SINGLETON_CONSTANT_LIST(SINGLETON_CONST_TEST_DECL)
#undef SINGLETON_CONST_TEST_DECL #undef SINGLETON_CONST_TEST_DECL
...@@ -257,28 +264,44 @@ class V8_EXPORT_PRIVATE GraphAssembler { ...@@ -257,28 +264,44 @@ class V8_EXPORT_PRIVATE GraphAssembler {
Node* Float64RoundDown(Node* value); Node* Float64RoundDown(Node* value);
Node* Float64RoundTruncate(Node* value); Node* Float64RoundTruncate(Node* value);
Node* ToNumber(Node* value); TNode<Number> ToNumber(TNode<Object> value);
Node* BitcastWordToTagged(Node* value); Node* BitcastWordToTagged(Node* value);
Node* BitcastTaggedToWord(Node* value); Node* BitcastTaggedToWord(Node* value);
Node* BitcastTaggedToWordForTagAndSmiBits(Node* value); Node* BitcastTaggedToWordForTagAndSmiBits(Node* value);
Node* Allocate(AllocationType allocation, Node* size); Node* Allocate(AllocationType allocation, Node* size);
Node* LoadField(FieldAccess const&, Node* object); Node* LoadField(FieldAccess const&, Node* object);
template <typename T>
TNode<T> LoadField(FieldAccess const& access, TNode<HeapObject> object) {
// TODO(jgruber): Investigate issues on ptr compression bots and enable.
// DCHECK(IsMachineRepresentationOf<T>(
// access.machine_type.representation()));
return TNode<T>::UncheckedCast(LoadField(access, object));
}
Node* LoadElement(ElementAccess const&, Node* object, Node* index); Node* LoadElement(ElementAccess const&, Node* object, Node* index);
template <typename T>
TNode<T> LoadElement(ElementAccess const& access, TNode<HeapObject> object,
TNode<Number> index) {
// TODO(jgruber): Investigate issues on ptr compression bots and enable.
// DCHECK(IsMachineRepresentationOf<T>(
// access.machine_type.representation()));
return TNode<T>::UncheckedCast(LoadElement(access, object, index));
}
Node* StoreField(FieldAccess const&, Node* object, Node* value); Node* StoreField(FieldAccess const&, Node* object, Node* value);
Node* StoreElement(ElementAccess const&, Node* object, Node* index, Node* StoreElement(ElementAccess const&, Node* object, Node* index,
Node* value); Node* value);
TNode<Number> StringLength(TNode<String> string); TNode<Number> StringLength(TNode<String> string);
Node* ReferenceEqual(Node* lhs, Node* rhs); TNode<Boolean> ReferenceEqual(TNode<Object> lhs, TNode<Object> rhs);
TNode<Number> NumberMin(TNode<Number> lhs, TNode<Number> rhs); TNode<Number> NumberMin(TNode<Number> lhs, TNode<Number> rhs);
TNode<Number> NumberMax(TNode<Number> lhs, TNode<Number> rhs); TNode<Number> NumberMax(TNode<Number> lhs, TNode<Number> rhs);
TNode<Boolean> NumberLessThan(TNode<Number> lhs, TNode<Number> rhs); TNode<Boolean> NumberLessThan(TNode<Number> lhs, TNode<Number> rhs);
TNode<Boolean> NumberLessThanOrEqual(TNode<Number> lhs, TNode<Number> rhs); TNode<Boolean> NumberLessThanOrEqual(TNode<Number> lhs, TNode<Number> rhs);
TNode<Number> NumberAdd(TNode<Number> lhs, TNode<Number> rhs); TNode<Number> NumberAdd(TNode<Number> lhs, TNode<Number> rhs);
TNode<Number> NumberSubtract(TNode<Number> lhs, TNode<Number> rhs); TNode<Number> NumberSubtract(TNode<Number> lhs, TNode<Number> rhs);
TNode<String> StringSubstring(Node* string, Node* from, Node* to); TNode<String> StringSubstring(TNode<String> string, TNode<Number> from,
TNode<Boolean> ObjectIsCallable(Node* value); TNode<Number> to);
TNode<Boolean> ObjectIsCallable(TNode<Object> value);
Node* CheckIf(Node* cond, DeoptimizeReason reason); Node* CheckIf(Node* cond, DeoptimizeReason reason);
Node* NumberIsFloat64Hole(Node* value); TNode<Boolean> NumberIsFloat64Hole(TNode<Number> value);
Node* TypeGuard(Type type, Node* value); Node* TypeGuard(Type type, Node* value);
Node* Checkpoint(Node* frame_state); Node* Checkpoint(Node* frame_state);
......
This diff is collapsed.
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