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> {
static const MachineRepresentation value = RawPtrT::kMachineRepresentation;
};
template <typename T>
constexpr bool IsMachineRepresentationOf(MachineRepresentation r) {
return MachineRepresentationOf<T>::value == r;
}
template <class T>
struct is_valid_type_tag {
static const bool value = std::is_base_of<Object, T>::value ||
......
......@@ -4536,7 +4536,7 @@ Node* EffectControlLinearizer::SmiShiftBitsConstant() {
Node* EffectControlLinearizer::LowerPlainPrimitiveToNumber(Node* node) {
Node* value = node->InputAt(0);
return __ ToNumber(value);
return __ ToNumber(TNode<Object>::UncheckedCast(value));
}
Node* EffectControlLinearizer::LowerPlainPrimitiveToWord32(Node* node) {
......@@ -4551,7 +4551,7 @@ Node* EffectControlLinearizer::LowerPlainPrimitiveToWord32(Node* node) {
__ Goto(&done, ChangeSmiToInt32(value));
__ Bind(&if_not_smi);
Node* to_number = __ ToNumber(value);
Node* to_number = __ ToNumber(TNode<Object>::UncheckedCast(value));
Node* check1 = ObjectIsSmi(to_number);
__ GotoIf(check1, &if_to_number_smi);
......@@ -4578,7 +4578,7 @@ Node* EffectControlLinearizer::LowerPlainPrimitiveToFloat64(Node* node) {
__ Goto(&done, __ ChangeInt32ToFloat64(from_smi));
__ Bind(&if_not_smi);
Node* to_number = __ ToNumber(value);
Node* to_number = __ ToNumber(TNode<Object>::UncheckedCast(value));
Node* check1 = ObjectIsSmi(to_number);
__ GotoIf(check1, &if_to_number_smi);
......
......@@ -398,15 +398,15 @@ Node* GraphAssembler::LoadFramePointer() {
return AddNode(graph()->NewNode(machine()->LoadFramePointer()));
}
#define SINGLETON_CONST_DEF(Name) \
TNode<Object> GraphAssembler::Name##Constant() { \
return TNode<Object>::UncheckedCast( \
#define SINGLETON_CONST_DEF(Name, Type) \
TNode<Type> GraphAssembler::Name##Constant() { \
return TNode<Type>::UncheckedCast( \
AddClonedNode(jsgraph()->Name##Constant())); \
}
JSGRAPH_SINGLETON_CONSTANT_LIST(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) { \
return TNode<Boolean>::UncheckedCast( \
ReferenceEqual(value, Name##Constant())); \
......@@ -516,8 +516,10 @@ TNode<Number> GraphAssembler::StringLength(TNode<String> string) {
graph()->NewNode(simplified()->StringLength(), string));
}
Node* GraphAssembler::ReferenceEqual(Node* lhs, Node* rhs) {
return AddNode(graph()->NewNode(simplified()->ReferenceEqual(), lhs, rhs));
TNode<Boolean> GraphAssembler::ReferenceEqual(TNode<Object> lhs,
TNode<Object> rhs) {
return AddNode<Boolean>(
graph()->NewNode(simplified()->ReferenceEqual(), lhs, rhs));
}
TNode<Number> GraphAssembler::NumberMin(TNode<Number> lhs, TNode<Number> rhs) {
......@@ -550,13 +552,14 @@ TNode<Boolean> GraphAssembler::NumberLessThanOrEqual(TNode<Number> lhs,
graph()->NewNode(simplified()->NumberLessThanOrEqual(), lhs, rhs));
}
TNode<String> GraphAssembler::StringSubstring(Node* string, Node* from,
Node* to) {
TNode<String> GraphAssembler::StringSubstring(TNode<String> string,
TNode<Number> from,
TNode<Number> to) {
return AddNode<String>(graph()->NewNode(
simplified()->StringSubstring(), string, from, to, effect(), control()));
}
TNode<Boolean> GraphAssembler::ObjectIsCallable(Node* value) {
TNode<Boolean> GraphAssembler::ObjectIsCallable(TNode<Object> value) {
return AddNode<Boolean>(
graph()->NewNode(simplified()->ObjectIsCallable(), value));
}
......@@ -566,8 +569,9 @@ Node* GraphAssembler::CheckIf(Node* cond, DeoptimizeReason reason) {
control()));
}
Node* GraphAssembler::NumberIsFloat64Hole(Node* value) {
return AddNode(graph()->NewNode(simplified()->NumberIsFloat64Hole(), value));
TNode<Boolean> GraphAssembler::NumberIsFloat64Hole(TNode<Number> value) {
return AddNode<Boolean>(
graph()->NewNode(simplified()->NumberIsFloat64Hole(), value));
}
Node* GraphAssembler::TypeGuard(Type type, Node* value) {
......@@ -642,9 +646,10 @@ Node* GraphAssembler::UnsafePointerAdd(Node* base, Node* external) {
effect(), control()));
}
Node* GraphAssembler::ToNumber(Node* value) {
return AddNode(graph()->NewNode(ToNumberOperator(), ToNumberBuiltinConstant(),
value, NoContextConstant(), effect()));
TNode<Number> GraphAssembler::ToNumber(TNode<Object> value) {
return AddNode<Number>(graph()->NewNode(ToNumberOperator(),
ToNumberBuiltinConstant(), value,
NoContextConstant(), effect()));
}
Node* GraphAssembler::BitcastWordToTagged(Node* value) {
......
......@@ -103,26 +103,26 @@ class BasicBlock;
V(Uint32Mod)
#define JSGRAPH_SINGLETON_CONSTANT_LIST(V) \
V(AllocateInOldGenerationStub) \
V(AllocateInYoungGenerationStub) \
V(AllocateRegularInOldGenerationStub) \
V(AllocateRegularInYoungGenerationStub) \
V(BigIntMap) \
V(BooleanMap) \
V(EmptyString) \
V(False) \
V(FixedArrayMap) \
V(FixedDoubleArrayMap) \
V(HeapNumberMap) \
V(NaN) \
V(NoContext) \
V(Null) \
V(One) \
V(TheHole) \
V(ToNumberBuiltin) \
V(True) \
V(Undefined) \
V(Zero)
V(AllocateInOldGenerationStub, Code) \
V(AllocateInYoungGenerationStub, Code) \
V(AllocateRegularInOldGenerationStub, Code) \
V(AllocateRegularInYoungGenerationStub, Code) \
V(BigIntMap, Map) \
V(BooleanMap, Map) \
V(EmptyString, String) \
V(False, Boolean) \
V(FixedArrayMap, Map) \
V(FixedDoubleArrayMap, Map) \
V(HeapNumberMap, Map) \
V(NaN, Number) \
V(NoContext, Object) \
V(Null, Oddball) \
V(One, Number) \
V(TheHole, Oddball) \
V(ToNumberBuiltin, Code) \
V(True, Boolean) \
V(Undefined, Oddball) \
V(Zero, Number)
class GraphAssembler;
......@@ -134,6 +134,13 @@ class GraphAssemblerLabel {
public:
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>
explicit GraphAssemblerLabel(GraphAssemblerLabelType type,
BasicBlock* basic_block, Reps... reps)
......@@ -225,11 +232,11 @@ class V8_EXPORT_PRIVATE GraphAssembler {
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)
#undef SINGLETON_CONST_DECL
#define SINGLETON_CONST_TEST_DECL(Name) \
#define SINGLETON_CONST_TEST_DECL(Name, ...) \
TNode<Boolean> Is##Name(TNode<Object> value);
JSGRAPH_SINGLETON_CONSTANT_LIST(SINGLETON_CONST_TEST_DECL)
#undef SINGLETON_CONST_TEST_DECL
......@@ -257,28 +264,44 @@ class V8_EXPORT_PRIVATE GraphAssembler {
Node* Float64RoundDown(Node* value);
Node* Float64RoundTruncate(Node* value);
Node* ToNumber(Node* value);
TNode<Number> ToNumber(TNode<Object> value);
Node* BitcastWordToTagged(Node* value);
Node* BitcastTaggedToWord(Node* value);
Node* BitcastTaggedToWordForTagAndSmiBits(Node* value);
Node* Allocate(AllocationType allocation, Node* size);
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);
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* StoreElement(ElementAccess const&, Node* object, Node* index,
Node* value);
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> NumberMax(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<Number> NumberAdd(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<Boolean> ObjectIsCallable(Node* value);
TNode<String> StringSubstring(TNode<String> string, TNode<Number> from,
TNode<Number> to);
TNode<Boolean> ObjectIsCallable(TNode<Object> value);
Node* CheckIf(Node* cond, DeoptimizeReason reason);
Node* NumberIsFloat64Hole(Node* value);
TNode<Boolean> NumberIsFloat64Hole(TNode<Number> value);
Node* TypeGuard(Type type, Node* value);
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