Commit 26653c94 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[cleanup] TNodify SelectImpl and NodeGenerator

Converts NodeGenerator and SelectImpl to return TNode<T>.

Also removes redundant
PromiseBuiltinsAssembler::SetForwardingHandlerIfTrue overload.

Bug: v8:10021
Change-Id: I65e23fb208e4d9bf041e0f9c9b2ea113aeac58a5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1980576Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65594}
parent b9d33036
...@@ -353,12 +353,13 @@ void PromiseBuiltinsAssembler::BranchIfAccessCheckFailed( ...@@ -353,12 +353,13 @@ void PromiseBuiltinsAssembler::BranchIfAccessCheckFailed(
BIND(&has_access); BIND(&has_access);
} }
void PromiseBuiltinsAssembler::SetForwardingHandlerIfTrue( void PromiseBuiltinsAssembler::SetForwardingHandlerIfTrue(Node* context,
Node* context, Node* condition, const NodeGenerator& object) { Node* condition,
Node* object) {
Label done(this); Label done(this);
GotoIfNot(condition, &done); GotoIfNot(condition, &done);
SetPropertyStrict( SetPropertyStrict(
CAST(context), CAST(object()), CAST(context), CAST(object),
HeapConstant(factory()->promise_forwarding_handler_symbol()), HeapConstant(factory()->promise_forwarding_handler_symbol()),
TrueConstant()); TrueConstant());
Goto(&done); Goto(&done);
...@@ -367,14 +368,14 @@ void PromiseBuiltinsAssembler::SetForwardingHandlerIfTrue( ...@@ -367,14 +368,14 @@ void PromiseBuiltinsAssembler::SetForwardingHandlerIfTrue(
void PromiseBuiltinsAssembler::SetPromiseHandledByIfTrue( void PromiseBuiltinsAssembler::SetPromiseHandledByIfTrue(
Node* context, Node* condition, Node* promise, Node* context, Node* condition, Node* promise,
const NodeGenerator& handled_by) { const NodeGenerator<Object>& handled_by) {
Label done(this); Label done(this);
GotoIfNot(condition, &done); GotoIfNot(condition, &done);
GotoIf(TaggedIsSmi(promise), &done); GotoIf(TaggedIsSmi(promise), &done);
GotoIfNot(HasInstanceType(promise, JS_PROMISE_TYPE), &done); GotoIfNot(HasInstanceType(promise, JS_PROMISE_TYPE), &done);
SetPropertyStrict(CAST(context), CAST(promise), SetPropertyStrict(CAST(context), CAST(promise),
HeapConstant(factory()->promise_handled_by_symbol()), HeapConstant(factory()->promise_handled_by_symbol()),
CAST(handled_by())); handled_by());
Goto(&done); Goto(&done);
BIND(&done); BIND(&done);
} }
......
...@@ -157,15 +157,9 @@ class V8_EXPORT_PRIVATE PromiseBuiltinsAssembler : public CodeStubAssembler { ...@@ -157,15 +157,9 @@ class V8_EXPORT_PRIVATE PromiseBuiltinsAssembler : public CodeStubAssembler {
const PromiseAllResolvingElementFunction& create_reject_element_function, const PromiseAllResolvingElementFunction& create_reject_element_function,
Label* if_exception, TVariable<Object>* var_exception); Label* if_exception, TVariable<Object>* var_exception);
void SetForwardingHandlerIfTrue(Node* context, Node* condition, void SetForwardingHandlerIfTrue(Node* context, Node* condition, Node* object);
const NodeGenerator& object);
inline void SetForwardingHandlerIfTrue(Node* context, Node* condition,
Node* object) {
return SetForwardingHandlerIfTrue(context, condition,
[object]() -> Node* { return object; });
}
void SetPromiseHandledByIfTrue(Node* context, Node* condition, Node* promise, void SetPromiseHandledByIfTrue(Node* context, Node* condition, Node* promise,
const NodeGenerator& handled_by); const NodeGenerator<Object>& handled_by);
TNode<JSPromise> AllocateJSPromise(TNode<Context> context); TNode<JSPromise> AllocateJSPromise(TNode<Context> context);
......
...@@ -73,7 +73,7 @@ void CodeStubAssembler::Assert(const BranchGenerator& branch, ...@@ -73,7 +73,7 @@ void CodeStubAssembler::Assert(const BranchGenerator& branch,
#endif #endif
} }
void CodeStubAssembler::Assert(const NodeGenerator& condition_body, void CodeStubAssembler::Assert(const NodeGenerator<BoolT>& condition_body,
const char* message, const char* file, int line, const char* message, const char* file, int line,
std::initializer_list<ExtraNode> extra_nodes) { std::initializer_list<ExtraNode> extra_nodes) {
#if defined(DEBUG) #if defined(DEBUG)
...@@ -112,7 +112,7 @@ void CodeStubAssembler::Check(const BranchGenerator& branch, ...@@ -112,7 +112,7 @@ void CodeStubAssembler::Check(const BranchGenerator& branch,
Comment("] Assert"); Comment("] Assert");
} }
void CodeStubAssembler::Check(const NodeGenerator& condition_body, void CodeStubAssembler::Check(const NodeGenerator<BoolT>& condition_body,
const char* message, const char* file, int line, const char* message, const char* file, int line,
std::initializer_list<ExtraNode> extra_nodes) { std::initializer_list<ExtraNode> extra_nodes) {
BranchGenerator branch = [=](Label* ok, Label* not_ok) { BranchGenerator branch = [=](Label* ok, Label* not_ok) {
...@@ -310,29 +310,6 @@ void CodeStubAssembler::FailAssert( ...@@ -310,29 +310,6 @@ void CodeStubAssembler::FailAssert(
Unreachable(); Unreachable();
} }
Node* CodeStubAssembler::SelectImpl(TNode<BoolT> condition,
const NodeGenerator& true_body,
const NodeGenerator& false_body,
MachineRepresentation rep) {
VARIABLE(value, rep);
Label vtrue(this), vfalse(this), end(this);
Branch(condition, &vtrue, &vfalse);
BIND(&vtrue);
{
value.Bind(true_body());
Goto(&end);
}
BIND(&vfalse);
{
value.Bind(false_body());
Goto(&end);
}
BIND(&end);
return value.value();
}
TNode<Int32T> CodeStubAssembler::SelectInt32Constant( TNode<Int32T> CodeStubAssembler::SelectInt32Constant(
SloppyTNode<BoolT> condition, int true_value, int false_value) { SloppyTNode<BoolT> condition, int true_value, int false_value) {
return SelectConstant<Int32T>(condition, Int32Constant(true_value), return SelectConstant<Int32T>(condition, Int32Constant(true_value),
...@@ -9979,11 +9956,15 @@ void CodeStubAssembler::EmitElementStore(Node* object, Node* key, Node* value, ...@@ -9979,11 +9956,15 @@ void CodeStubAssembler::EmitElementStore(Node* object, Node* key, Node* value,
IsSealedElementsKind(elements_kind) || IsSealedElementsKind(elements_kind) ||
IsNonextensibleElementsKind(elements_kind)); IsNonextensibleElementsKind(elements_kind));
Node* length = SelectImpl( TNode<Smi> smi_length = Select<Smi>(
IsJSArray(object), [=]() { return LoadJSArrayLength(CAST(object)); }, IsJSArray(object),
[=]() { return LoadFixedArrayBaseLength(elements); }, [=]() {
MachineRepresentation::kTagged); // This is casting Number -> Smi which may not actually be safe.
length = TaggedToParameter(length, parameter_mode); return CAST(LoadJSArrayLength(CAST(object)));
},
[=]() { return LoadFixedArrayBaseLength(elements); });
Node* length = TaggedToParameter(smi_length, parameter_mode);
// In case value is stored into a fast smi array, assure that the value is // In case value is stored into a fast smi array, assure that the value is
// a smi before manipulating the backing store. Otherwise the backing store // a smi before manipulating the backing store. Otherwise the backing store
...@@ -10140,14 +10121,13 @@ void CodeStubAssembler::TransitionElementsKind(TNode<JSObject> object, ...@@ -10140,14 +10121,13 @@ void CodeStubAssembler::TransitionElementsKind(TNode<JSObject> object,
ParameterMode mode = INTPTR_PARAMETERS; ParameterMode mode = INTPTR_PARAMETERS;
TNode<IntPtrT> elements_length = TNode<IntPtrT> elements_length =
SmiUntag(LoadFixedArrayBaseLength(elements)); SmiUntag(LoadFixedArrayBaseLength(elements));
Node* array_length = SelectImpl( TNode<IntPtrT> array_length = Select<IntPtrT>(
IsJSArray(object), IsJSArray(object),
[=]() { [=]() {
CSA_ASSERT(this, IsFastElementsKind(LoadElementsKind(object))); CSA_ASSERT(this, IsFastElementsKind(LoadElementsKind(object)));
return SmiUntag(LoadFastJSArrayLength(CAST(object))); return SmiUntag(LoadFastJSArrayLength(CAST(object)));
}, },
[=]() { return elements_length; }, [=]() { return elements_length; });
MachineType::PointerRepresentation());
CSA_ASSERT(this, WordNotEqual(elements_length, IntPtrConstant(0))); CSA_ASSERT(this, WordNotEqual(elements_length, IntPtrConstant(0)));
......
...@@ -169,12 +169,8 @@ enum class PrimitiveType { kBoolean, kNumber, kString, kSymbol }; ...@@ -169,12 +169,8 @@ enum class PrimitiveType { kBoolean, kNumber, kString, kSymbol };
HEAP_IMMUTABLE_IMMOVABLE_OBJECT_LIST(V) HEAP_IMMUTABLE_IMMOVABLE_OBJECT_LIST(V)
#ifdef DEBUG #ifdef DEBUG
#define CSA_CHECK(csa, x) \ #define CSA_CHECK(csa, x) \
(csa)->Check( \ (csa)->Check([&]() -> TNode<BoolT> { return x; }, #x, __FILE__, __LINE__)
[&]() -> compiler::Node* { \
return implicit_cast<SloppyTNode<Word32T>>(x); \
}, \
#x, __FILE__, __LINE__)
#else #else
#define CSA_CHECK(csa, x) (csa)->FastCheck(x) #define CSA_CHECK(csa, x) (csa)->FastCheck(x)
#endif #endif
...@@ -210,7 +206,7 @@ enum class PrimitiveType { kBoolean, kNumber, kString, kSymbol }; ...@@ -210,7 +206,7 @@ enum class PrimitiveType { kBoolean, kNumber, kString, kSymbol };
#define CSA_ASSERT_JS_ARGC_OP(csa, Op, op, expected) \ #define CSA_ASSERT_JS_ARGC_OP(csa, Op, op, expected) \
(csa)->Assert( \ (csa)->Assert( \
[&]() -> compiler::Node* { \ [&]() -> TNode<BoolT> { \
const TNode<Word32T> argc = UncheckedCast<Word32T>( \ const TNode<Word32T> argc = UncheckedCast<Word32T>( \
(csa)->Parameter(Descriptor::kJSActualArgumentsCount)); \ (csa)->Parameter(Descriptor::kJSActualArgumentsCount)); \
return (csa)->Op(argc, (csa)->Int32Constant(expected)); \ return (csa)->Op(argc, (csa)->Int32Constant(expected)); \
...@@ -823,13 +819,14 @@ class V8_EXPORT_PRIVATE CodeStubAssembler ...@@ -823,13 +819,14 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
TNode<BoolT> IsRegularHeapObjectSize(TNode<IntPtrT> size); TNode<BoolT> IsRegularHeapObjectSize(TNode<IntPtrT> size);
using BranchGenerator = std::function<void(Label*, Label*)>; using BranchGenerator = std::function<void(Label*, Label*)>;
using NodeGenerator = std::function<Node*()>; template <typename T>
using NodeGenerator = std::function<TNode<T>()>;
using ExtraNode = std::pair<TNode<Object>, const char*>; using ExtraNode = std::pair<TNode<Object>, const char*>;
void Assert(const BranchGenerator& branch, const char* message, void Assert(const BranchGenerator& branch, const char* message,
const char* file, int line, const char* file, int line,
std::initializer_list<ExtraNode> extra_nodes = {}); std::initializer_list<ExtraNode> extra_nodes = {});
void Assert(const NodeGenerator& condition_body, const char* message, void Assert(const NodeGenerator<BoolT>& condition_body, const char* message,
const char* file, int line, const char* file, int line,
std::initializer_list<ExtraNode> extra_nodes = {}); std::initializer_list<ExtraNode> extra_nodes = {});
void Assert(SloppyTNode<Word32T> condition_node, const char* message, void Assert(SloppyTNode<Word32T> condition_node, const char* message,
...@@ -838,7 +835,7 @@ class V8_EXPORT_PRIVATE CodeStubAssembler ...@@ -838,7 +835,7 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
void Check(const BranchGenerator& branch, const char* message, void Check(const BranchGenerator& branch, const char* message,
const char* file, int line, const char* file, int line,
std::initializer_list<ExtraNode> extra_nodes = {}); std::initializer_list<ExtraNode> extra_nodes = {});
void Check(const NodeGenerator& condition_body, const char* message, void Check(const NodeGenerator<BoolT>& condition_body, const char* message,
const char* file, int line, const char* file, int line,
std::initializer_list<ExtraNode> extra_nodes = {}); std::initializer_list<ExtraNode> extra_nodes = {});
void Check(SloppyTNode<Word32T> condition_node, const char* message, void Check(SloppyTNode<Word32T> condition_node, const char* message,
...@@ -886,14 +883,26 @@ class V8_EXPORT_PRIVATE CodeStubAssembler ...@@ -886,14 +883,26 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
return ConstructWithTarget(context, new_target, new_target, args...); return ConstructWithTarget(context, new_target, new_target, args...);
} }
template <class A, class F, class G> template <typename T>
TNode<A> Select(SloppyTNode<BoolT> condition, const F& true_body, TNode<T> Select(TNode<BoolT> condition, const NodeGenerator<T>& true_body,
const G& false_body) { const NodeGenerator<T>& false_body) {
return UncheckedCast<A>(SelectImpl( TVARIABLE(T, value);
condition, Label vtrue(this), vfalse(this), end(this);
[&]() -> Node* { return implicit_cast<TNode<A>>(true_body()); }, Branch(condition, &vtrue, &vfalse);
[&]() -> Node* { return implicit_cast<TNode<A>>(false_body()); },
MachineRepresentationOf<A>::value)); BIND(&vtrue);
{
value = true_body();
Goto(&end);
}
BIND(&vfalse);
{
value = false_body();
Goto(&end);
}
BIND(&end);
return value.value();
} }
template <class A> template <class A>
...@@ -3796,9 +3805,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler ...@@ -3796,9 +3805,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
TNode<Uint32T> length, TNode<Uint32T> length,
TNode<String> parent, TNode<Smi> offset); TNode<String> parent, TNode<Smi> offset);
Node* SelectImpl(TNode<BoolT> condition, const NodeGenerator& true_body,
const NodeGenerator& false_body, MachineRepresentation rep);
// Implements [Descriptor/Transition]Array::number_of_entries. // Implements [Descriptor/Transition]Array::number_of_entries.
template <typename Array> template <typename Array>
TNode<Uint32T> NumberOfEntries(TNode<Array> array); TNode<Uint32T> NumberOfEntries(TNode<Array> array);
......
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