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) {
......
...@@ -102,27 +102,27 @@ class BasicBlock; ...@@ -102,27 +102,27 @@ class BasicBlock;
V(Uint32Div) \ V(Uint32Div) \
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);
......
...@@ -38,24 +38,13 @@ namespace v8 { ...@@ -38,24 +38,13 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
namespace {
// Shorter lambda declarations with less visual clutter. // Shorter lambda declarations with less visual clutter.
#define _ [&]() // NOLINT(whitespace/braces) #define _ [&]() // NOLINT(whitespace/braces)
template <class T>
constexpr TNode<T> ToTNode(Node* node) {
return TNode<T>::UncheckedCast(node);
}
} // namespace
class JSCallReducerAssembler : public GraphAssembler { class JSCallReducerAssembler : public GraphAssembler {
public: public:
JSCallReducerAssembler(JSGraph* jsgraph, Zone* zone, Node* node) JSCallReducerAssembler(JSGraph* jsgraph, Zone* zone, Node* node)
: GraphAssembler(jsgraph, zone), : GraphAssembler(jsgraph, zone), node_(node), if_exception_nodes_(zone) {
node_(ToTNode<Object>(node)),
if_exception_nodes_(zone) {
InitializeEffectControl(NodeProperties::GetEffectInput(node), InitializeEffectControl(NodeProperties::GetEffectInput(node),
NodeProperties::GetControlInput(node)); NodeProperties::GetControlInput(node));
...@@ -83,7 +72,7 @@ class JSCallReducerAssembler : public GraphAssembler { ...@@ -83,7 +72,7 @@ class JSCallReducerAssembler : public GraphAssembler {
// Returns {value, effect, control}. // Returns {value, effect, control}.
std::tuple<Node*, Node*, Node*> MergeExceptionalPaths(); std::tuple<Node*, Node*, Node*> MergeExceptionalPaths();
Node* node_ptr() const { return static_cast<Node*>(node_); } Node* node_ptr() const { return node_; }
protected: protected:
using NodeGenerator0 = std::function<TNode<Object>()>; using NodeGenerator0 = std::function<TNode<Object>()>;
...@@ -204,7 +193,7 @@ class JSCallReducerAssembler : public GraphAssembler { ...@@ -204,7 +193,7 @@ class JSCallReducerAssembler : public GraphAssembler {
gasm_->Goto(&merge, else_result); gasm_->Goto(&merge, else_result);
gasm_->Bind(&merge); gasm_->Bind(&merge);
return ToTNode<T>(merge.PhiAt(0)); return merge.PhiAt<T>(0);
} }
private: private:
...@@ -305,7 +294,7 @@ class JSCallReducerAssembler : public GraphAssembler { ...@@ -305,7 +294,7 @@ class JSCallReducerAssembler : public GraphAssembler {
gasm_->Bind(&loop_header); gasm_->Bind(&loop_header);
Node* loop_header_control = gasm_->control(); // For LoopExit below. Node* loop_header_control = gasm_->control(); // For LoopExit below.
TNode<Number> i = ToTNode<Number>(loop_header.PhiAt(0)); TNode<Number> i = loop_header.PhiAt<Number>(0);
gasm_->BranchWithHint(cond_(i), &loop_body, &loop_exit, gasm_->BranchWithHint(cond_(i), &loop_body, &loop_exit,
BranchHint::kTrue); BranchHint::kTrue);
...@@ -332,20 +321,16 @@ class JSCallReducerAssembler : public GraphAssembler { ...@@ -332,20 +321,16 @@ class JSCallReducerAssembler : public GraphAssembler {
}; };
ForBuilder0 ForSmiZeroUntil(TNode<Number> excluded_limit) { ForBuilder0 ForSmiZeroUntil(TNode<Number> excluded_limit) {
TNode<Number> initial_value = ToTNode<Number>(ZeroConstant()); TNode<Number> initial_value = ZeroConstant();
auto cond = [=](TNode<Number> i) { auto cond = [=](TNode<Number> i) {
return NumberLessThan(i, excluded_limit); return NumberLessThan(i, excluded_limit);
}; };
auto step = [=](TNode<Number> i) { auto step = [=](TNode<Number> i) { return NumberAdd(i, OneConstant()); };
return NumberAdd(i, ToTNode<Number>(OneConstant()));
};
return {this, initial_value, cond, step}; return {this, initial_value, cond, step};
} }
ForBuilder0 Forever(TNode<Number> initial_value, const StepFunction1& step) { ForBuilder0 Forever(TNode<Number> initial_value, const StepFunction1& step) {
TNode<Boolean> true_constant = return {this, initial_value, [=](TNode<Number>) { return TrueConstant(); },
ToTNode<Boolean>(jsgraph()->BooleanConstant(true));
return {this, initial_value, [=](TNode<Number>) { return true_constant; },
step}; step};
} }
...@@ -379,8 +364,8 @@ class JSCallReducerAssembler : public GraphAssembler { ...@@ -379,8 +364,8 @@ class JSCallReducerAssembler : public GraphAssembler {
gasm_->Bind(&loop_header); gasm_->Bind(&loop_header);
Node* loop_header_control = gasm_->control(); // For LoopExit below. Node* loop_header_control = gasm_->control(); // For LoopExit below.
TNode<Number> i = ToTNode<Number>(loop_header.PhiAt(0)); TNode<Number> i = loop_header.PhiAt<Number>(0);
arg0 = ToTNode<Object>(loop_header.PhiAt(1)); arg0 = loop_header.PhiAt<Object>(1);
gasm_->BranchWithHint(cond_(i), &loop_body, &loop_exit, BranchHint::kTrue, gasm_->BranchWithHint(cond_(i), &loop_body, &loop_exit, BranchHint::kTrue,
arg0); arg0);
...@@ -395,7 +380,7 @@ class JSCallReducerAssembler : public GraphAssembler { ...@@ -395,7 +380,7 @@ class JSCallReducerAssembler : public GraphAssembler {
gasm_->LoopExit(loop_header_control); gasm_->LoopExit(loop_header_control);
gasm_->LoopExitEffect(); gasm_->LoopExitEffect();
return ToTNode<Object>(loop_exit.PhiAt(0)); return loop_exit.PhiAt<Object>(0);
} }
private: private:
...@@ -421,23 +406,27 @@ class JSCallReducerAssembler : public GraphAssembler { ...@@ -421,23 +406,27 @@ class JSCallReducerAssembler : public GraphAssembler {
} }
TNode<Object> ValueInput(int index) const { TNode<Object> ValueInput(int index) const {
return ToTNode<Object>(NodeProperties::GetValueInput(node_, index)); return TNode<Object>::UncheckedCast(
NodeProperties::GetValueInput(node_, index));
} }
TNode<Object> ValueInputOrNaN(int index) { TNode<Object> ValueInputOrNaN(int index) {
return ToTNode<Object>(node_ptr()->op()->ValueInputCount() > index return TNode<Object>::UncheckedCast(
? NodeProperties::GetValueInput(node_, index) node_ptr()->op()->ValueInputCount() > index
: NaNConstant()); ? NodeProperties::GetValueInput(node_, index)
: NaNConstant());
} }
TNode<Object> ValueInputOrUndefined(int index) { TNode<Object> ValueInputOrUndefined(int index) {
return ToTNode<Object>(node_ptr()->op()->ValueInputCount() > index return TNode<Object>::UncheckedCast(
? NodeProperties::GetValueInput(node_, index) node_ptr()->op()->ValueInputCount() > index
: UndefinedConstant()); ? NodeProperties::GetValueInput(node_, index)
: UndefinedConstant());
} }
TNode<Context> ContextInput() const { TNode<Context> ContextInput() const {
return ToTNode<Context>(NodeProperties::GetContextInput(node_)); return TNode<Context>::UncheckedCast(
NodeProperties::GetContextInput(node_));
} }
Node* FrameStateInput() const { Node* FrameStateInput() const {
...@@ -447,7 +436,7 @@ class JSCallReducerAssembler : public GraphAssembler { ...@@ -447,7 +436,7 @@ class JSCallReducerAssembler : public GraphAssembler {
JSOperatorBuilder* javascript() const { return jsgraph()->javascript(); } JSOperatorBuilder* javascript() const { return jsgraph()->javascript(); }
private: private:
const TNode<Object> node_; Node* const node_;
bool has_external_exception_handler_; bool has_external_exception_handler_;
Node* external_exception_handler_; Node* external_exception_handler_;
...@@ -490,28 +479,29 @@ class IteratingArrayBuiltinReducerAssembler : public JSCallReducerAssembler { ...@@ -490,28 +479,29 @@ class IteratingArrayBuiltinReducerAssembler : public JSCallReducerAssembler {
// Returns {index,value}. Assumes that the map has not changed, but possibly // Returns {index,value}. Assumes that the map has not changed, but possibly
// the length and backing store. // the length and backing store.
std::pair<TNode<Number>, TNode<Object>> SafeLoadElement(ElementsKind kind, std::pair<TNode<Number>, TNode<Object>> SafeLoadElement(ElementsKind kind,
TNode<Object> o, TNode<HeapObject> o,
TNode<Number> index) { TNode<Number> index) {
// Make sure that the access is still in bounds, since the callback could // Make sure that the access is still in bounds, since the callback could
// have changed the array's size. // have changed the array's size.
TNode<Number> length = TNode<Number> length =
ToTNode<Number>(LoadField(AccessBuilder::ForJSArrayLength(kind), o)); LoadField<Smi>(AccessBuilder::ForJSArrayLength(kind), o);
index = CheckBounds(index, length); index = CheckBounds(index, length);
// Reload the elements pointer before calling the callback, since the // Reload the elements pointer before calling the callback, since the
// previous callback might have resized the array causing the elements // previous callback might have resized the array causing the elements
// buffer to be re-allocated. // buffer to be re-allocated.
TNode<Object> elements = TNode<HeapObject> elements =
ToTNode<Object>(LoadField(AccessBuilder::ForJSObjectElements(), o)); LoadField<HeapObject>(AccessBuilder::ForJSObjectElements(), o);
TNode<Object> value = ToTNode<Object>(LoadElement( TNode<Object> value = LoadElement<Object>(
AccessBuilder::ForFixedArrayElement(kind, LoadSensitivity::kCritical), AccessBuilder::ForFixedArrayElement(kind, LoadSensitivity::kCritical),
elements, index)); elements, index);
return std::make_pair(index, value); return std::make_pair(index, value);
} }
TNode<Boolean> HoleCheck(ElementsKind kind, TNode<Object> v) { TNode<Boolean> HoleCheck(ElementsKind kind, TNode<Object> v) {
return ToTNode<Boolean>(IsDoubleElementsKind(kind) ? NumberIsFloat64Hole(v) return IsDoubleElementsKind(kind)
: IsTheHole(v)); ? NumberIsFloat64Hole(TNode<Number>::UncheckedCast(v))
: IsTheHole(v);
} }
}; };
...@@ -539,12 +529,12 @@ TNode<Number> JSCallReducerAssembler::CheckBounds(TNode<Number> value, ...@@ -539,12 +529,12 @@ TNode<Number> JSCallReducerAssembler::CheckBounds(TNode<Number> value,
} }
TNode<Smi> JSCallReducerAssembler::TypeGuardUnsignedSmall(TNode<Object> value) { TNode<Smi> JSCallReducerAssembler::TypeGuardUnsignedSmall(TNode<Object> value) {
return ToTNode<Smi>(TypeGuard(Type::UnsignedSmall(), value)); return TNode<Smi>::UncheckedCast(TypeGuard(Type::UnsignedSmall(), value));
} }
TNode<Object> JSCallReducerAssembler::TypeGuardNonInternal( TNode<Object> JSCallReducerAssembler::TypeGuardNonInternal(
TNode<Object> value) { TNode<Object> value) {
return ToTNode<Object>(TypeGuard(Type::NonInternal(), value)); return TNode<Object>::UncheckedCast(TypeGuard(Type::NonInternal(), value));
} }
TNode<Object> JSCallReducerAssembler::JSCall3( TNode<Object> JSCallReducerAssembler::JSCall3(
...@@ -620,7 +610,7 @@ JSCallReducerAssembler::MergeExceptionalPaths() { ...@@ -620,7 +610,7 @@ JSCallReducerAssembler::MergeExceptionalPaths() {
TNode<Object> JSCallReducerAssembler::ReduceMathUnary(const Operator* op) { TNode<Object> JSCallReducerAssembler::ReduceMathUnary(const Operator* op) {
TNode<Object> input = ValueInput(2); TNode<Object> input = ValueInput(2);
TNode<Number> input_as_number = SpeculativeToNumber(input); TNode<Number> input_as_number = SpeculativeToNumber(input);
return ToTNode<Object>(graph()->NewNode(op, input_as_number)); return TNode<Object>::UncheckedCast(graph()->NewNode(op, input_as_number));
} }
TNode<Object> JSCallReducerAssembler::ReduceMathBinary(const Operator* op) { TNode<Object> JSCallReducerAssembler::ReduceMathBinary(const Operator* op) {
...@@ -628,7 +618,8 @@ TNode<Object> JSCallReducerAssembler::ReduceMathBinary(const Operator* op) { ...@@ -628,7 +618,8 @@ TNode<Object> JSCallReducerAssembler::ReduceMathBinary(const Operator* op) {
TNode<Object> right = ValueInputOrNaN(3); TNode<Object> right = ValueInputOrNaN(3);
TNode<Number> left_number = SpeculativeToNumber(left); TNode<Number> left_number = SpeculativeToNumber(left);
TNode<Number> right_number = SpeculativeToNumber(right); TNode<Number> right_number = SpeculativeToNumber(right);
return ToTNode<Object>(graph()->NewNode(op, left_number, right_number)); return TNode<Object>::UncheckedCast(
graph()->NewNode(op, left_number, right_number));
} }
TNode<String> JSCallReducerAssembler::ReduceStringPrototypeSubstring() { TNode<String> JSCallReducerAssembler::ReduceStringPrototypeSubstring() {
...@@ -695,7 +686,7 @@ TNode<String> JSCallReducerAssembler::ReduceStringPrototypeSlice() { ...@@ -695,7 +686,7 @@ TNode<String> JSCallReducerAssembler::ReduceStringPrototypeSlice() {
return SelectIf<String>(NumberLessThan(from, to)) return SelectIf<String>(NumberLessThan(from, to))
.Then(_ { return StringSubstring(receiver_string, from, to); }) .Then(_ { return StringSubstring(receiver_string, from, to); })
.Else(_ { return ToTNode<String>(EmptyStringConstant()); }) .Else(_ { return EmptyStringConstant(); })
.ExpectTrue() .ExpectTrue()
.Value(); .Value();
} }
...@@ -747,20 +738,19 @@ IteratingArrayBuiltinReducerAssembler::ReduceArrayPrototypeForEach( ...@@ -747,20 +738,19 @@ IteratingArrayBuiltinReducerAssembler::ReduceArrayPrototypeForEach(
Node* outer_frame_state = FrameStateInput(); Node* outer_frame_state = FrameStateInput();
TNode<Context> context = ContextInput(); TNode<Context> context = ContextInput();
TNode<Object> target = ValueInput(0); TNode<Object> target = ValueInput(0);
TNode<Object> receiver = ValueInput(1); TNode<HeapObject> receiver = TNode<HeapObject>::UncheckedCast(ValueInput(1));
TNode<Object> fncallback = ValueInputOrUndefined(2); TNode<Object> fncallback = ValueInputOrUndefined(2);
TNode<Object> this_arg = ValueInputOrUndefined(3); TNode<Object> this_arg = ValueInputOrUndefined(3);
TNode<Number> original_length = ToTNode<Number>( TNode<Number> original_length =
LoadField(AccessBuilder::ForJSArrayLength(kind), receiver)); LoadField<Smi>(AccessBuilder::ForJSArrayLength(kind), receiver);
ForEachFrameStateParams frame_state_params{ ForEachFrameStateParams frame_state_params{
jsgraph(), shared, context, target, outer_frame_state, jsgraph(), shared, context, target, outer_frame_state,
receiver, fncallback, this_arg, original_length}; receiver, fncallback, this_arg, original_length};
ThrowIfNotCallable( ThrowIfNotCallable(fncallback, ForEachLoopLazyFrameState(frame_state_params,
fncallback, ForEachLoopLazyFrameState(frame_state_params, ZeroConstant()));
ToTNode<Object>(ZeroConstant())));
ForSmiZeroUntil(original_length).Do([&](TNode<Number> k) { ForSmiZeroUntil(original_length).Do([&](TNode<Number> k) {
Checkpoint(ForEachLoopEagerFrameState(frame_state_params, k)); Checkpoint(ForEachLoopEagerFrameState(frame_state_params, k));
...@@ -785,7 +775,7 @@ IteratingArrayBuiltinReducerAssembler::ReduceArrayPrototypeForEach( ...@@ -785,7 +775,7 @@ IteratingArrayBuiltinReducerAssembler::ReduceArrayPrototypeForEach(
element = TypeGuardNonInternal(element); element = TypeGuardNonInternal(element);
} }
TNode<Number> next_k = NumberAdd(k, ToTNode<Number>(OneConstant())); TNode<Number> next_k = NumberAdd(k, OneConstant());
JSCall3(fncallback, this_arg, element, k, receiver, JSCall3(fncallback, this_arg, element, k, receiver,
ForEachLoopLazyFrameState(frame_state_params, next_k)); ForEachLoopLazyFrameState(frame_state_params, next_k));
...@@ -878,21 +868,21 @@ TNode<Object> IteratingArrayBuiltinReducerAssembler::ReduceArrayPrototypeReduce( ...@@ -878,21 +868,21 @@ TNode<Object> IteratingArrayBuiltinReducerAssembler::ReduceArrayPrototypeReduce(
Node* outer_frame_state = FrameStateInput(); Node* outer_frame_state = FrameStateInput();
TNode<Context> context = ContextInput(); TNode<Context> context = ContextInput();
TNode<Object> target = ValueInput(0); TNode<Object> target = ValueInput(0);
TNode<Object> receiver = ValueInput(1); TNode<HeapObject> receiver = TNode<HeapObject>::UncheckedCast(ValueInput(1));
TNode<Object> fncallback = ValueInputOrUndefined(2); TNode<Object> fncallback = ValueInputOrUndefined(2);
ReduceFrameStateParams frame_state_params{ ReduceFrameStateParams frame_state_params{
jsgraph(), shared, direction, context, target, outer_frame_state}; jsgraph(), shared, direction, context, target, outer_frame_state};
TNode<Number> original_length = ToTNode<Number>( TNode<Number> original_length =
LoadField(AccessBuilder::ForJSArrayLength(kind), receiver)); LoadField<Smi>(AccessBuilder::ForJSArrayLength(kind), receiver);
// Set up variable behavior depending on the reduction kind (left/right). // Set up variable behavior depending on the reduction kind (left/right).
TNode<Number> k; TNode<Number> k;
StepFunction1 step; StepFunction1 step;
ConditionFunction1 cond; ConditionFunction1 cond;
TNode<Number> zero = ToTNode<Number>(ZeroConstant()); TNode<Number> zero = ZeroConstant();
TNode<Number> one = ToTNode<Number>(OneConstant()); TNode<Number> one = OneConstant();
if (direction == ArrayReduceDirection::kLeft) { if (direction == ArrayReduceDirection::kLeft) {
k = zero; k = zero;
step = [&](TNode<Number> i) { return NumberAdd(i, one); }; step = [&](TNode<Number> i) { return NumberAdd(i, one); };
...@@ -935,8 +925,8 @@ TNode<Object> IteratingArrayBuiltinReducerAssembler::ReduceArrayPrototypeReduce( ...@@ -935,8 +925,8 @@ TNode<Object> IteratingArrayBuiltinReducerAssembler::ReduceArrayPrototypeReduce(
// TODO(jgruber): This manual fiddling with blocks could be avoided by // TODO(jgruber): This manual fiddling with blocks could be avoided by
// implementing a `break` mechanic for loop builders. // implementing a `break` mechanic for loop builders.
Bind(&found_initial_element); Bind(&found_initial_element);
k = step(ToTNode<Number>(found_initial_element.PhiAt(0))); k = step(found_initial_element.PhiAt<Number>(0));
accumulator = ToTNode<Object>(found_initial_element.PhiAt(1)); accumulator = found_initial_element.PhiAt<Object>(1);
accumulator = TypeGuardNonInternal(accumulator); accumulator = TypeGuardNonInternal(accumulator);
} }
...@@ -975,7 +965,7 @@ TNode<Object> IteratingArrayBuiltinReducerAssembler::ReduceArrayPrototypeReduce( ...@@ -975,7 +965,7 @@ TNode<Object> IteratingArrayBuiltinReducerAssembler::ReduceArrayPrototypeReduce(
Goto(&continue_label, next_accumulator); Goto(&continue_label, next_accumulator);
Bind(&continue_label); Bind(&continue_label);
*accumulator = ToTNode<Object>(continue_label.PhiAt(0)); *accumulator = continue_label.PhiAt<Object>(0);
}) })
.Value(); .Value();
......
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