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(
BIND(&has_access);
}
void PromiseBuiltinsAssembler::SetForwardingHandlerIfTrue(
Node* context, Node* condition, const NodeGenerator& object) {
void PromiseBuiltinsAssembler::SetForwardingHandlerIfTrue(Node* context,
Node* condition,
Node* object) {
Label done(this);
GotoIfNot(condition, &done);
SetPropertyStrict(
CAST(context), CAST(object()),
CAST(context), CAST(object),
HeapConstant(factory()->promise_forwarding_handler_symbol()),
TrueConstant());
Goto(&done);
......@@ -367,14 +368,14 @@ void PromiseBuiltinsAssembler::SetForwardingHandlerIfTrue(
void PromiseBuiltinsAssembler::SetPromiseHandledByIfTrue(
Node* context, Node* condition, Node* promise,
const NodeGenerator& handled_by) {
const NodeGenerator<Object>& handled_by) {
Label done(this);
GotoIfNot(condition, &done);
GotoIf(TaggedIsSmi(promise), &done);
GotoIfNot(HasInstanceType(promise, JS_PROMISE_TYPE), &done);
SetPropertyStrict(CAST(context), CAST(promise),
HeapConstant(factory()->promise_handled_by_symbol()),
CAST(handled_by()));
handled_by());
Goto(&done);
BIND(&done);
}
......
......@@ -157,15 +157,9 @@ class V8_EXPORT_PRIVATE PromiseBuiltinsAssembler : public CodeStubAssembler {
const PromiseAllResolvingElementFunction& create_reject_element_function,
Label* if_exception, TVariable<Object>* var_exception);
void SetForwardingHandlerIfTrue(Node* context, Node* condition,
const NodeGenerator& object);
inline void SetForwardingHandlerIfTrue(Node* context, Node* condition,
Node* object) {
return SetForwardingHandlerIfTrue(context, condition,
[object]() -> Node* { return object; });
}
void SetForwardingHandlerIfTrue(Node* context, Node* condition, Node* object);
void SetPromiseHandledByIfTrue(Node* context, Node* condition, Node* promise,
const NodeGenerator& handled_by);
const NodeGenerator<Object>& handled_by);
TNode<JSPromise> AllocateJSPromise(TNode<Context> context);
......
......@@ -73,7 +73,7 @@ void CodeStubAssembler::Assert(const BranchGenerator& branch,
#endif
}
void CodeStubAssembler::Assert(const NodeGenerator& condition_body,
void CodeStubAssembler::Assert(const NodeGenerator<BoolT>& condition_body,
const char* message, const char* file, int line,
std::initializer_list<ExtraNode> extra_nodes) {
#if defined(DEBUG)
......@@ -112,7 +112,7 @@ void CodeStubAssembler::Check(const BranchGenerator& branch,
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,
std::initializer_list<ExtraNode> extra_nodes) {
BranchGenerator branch = [=](Label* ok, Label* not_ok) {
......@@ -310,29 +310,6 @@ void CodeStubAssembler::FailAssert(
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(
SloppyTNode<BoolT> condition, int true_value, int false_value) {
return SelectConstant<Int32T>(condition, Int32Constant(true_value),
......@@ -9979,11 +9956,15 @@ void CodeStubAssembler::EmitElementStore(Node* object, Node* key, Node* value,
IsSealedElementsKind(elements_kind) ||
IsNonextensibleElementsKind(elements_kind));
Node* length = SelectImpl(
IsJSArray(object), [=]() { return LoadJSArrayLength(CAST(object)); },
[=]() { return LoadFixedArrayBaseLength(elements); },
MachineRepresentation::kTagged);
length = TaggedToParameter(length, parameter_mode);
TNode<Smi> smi_length = Select<Smi>(
IsJSArray(object),
[=]() {
// This is casting Number -> Smi which may not actually be safe.
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
// a smi before manipulating the backing store. Otherwise the backing store
......@@ -10140,14 +10121,13 @@ void CodeStubAssembler::TransitionElementsKind(TNode<JSObject> object,
ParameterMode mode = INTPTR_PARAMETERS;
TNode<IntPtrT> elements_length =
SmiUntag(LoadFixedArrayBaseLength(elements));
Node* array_length = SelectImpl(
TNode<IntPtrT> array_length = Select<IntPtrT>(
IsJSArray(object),
[=]() {
CSA_ASSERT(this, IsFastElementsKind(LoadElementsKind(object)));
return SmiUntag(LoadFastJSArrayLength(CAST(object)));
},
[=]() { return elements_length; },
MachineType::PointerRepresentation());
[=]() { return elements_length; });
CSA_ASSERT(this, WordNotEqual(elements_length, IntPtrConstant(0)));
......
......@@ -169,12 +169,8 @@ enum class PrimitiveType { kBoolean, kNumber, kString, kSymbol };
HEAP_IMMUTABLE_IMMOVABLE_OBJECT_LIST(V)
#ifdef DEBUG
#define CSA_CHECK(csa, x) \
(csa)->Check( \
[&]() -> compiler::Node* { \
return implicit_cast<SloppyTNode<Word32T>>(x); \
}, \
#x, __FILE__, __LINE__)
#define CSA_CHECK(csa, x) \
(csa)->Check([&]() -> TNode<BoolT> { return x; }, #x, __FILE__, __LINE__)
#else
#define CSA_CHECK(csa, x) (csa)->FastCheck(x)
#endif
......@@ -210,7 +206,7 @@ enum class PrimitiveType { kBoolean, kNumber, kString, kSymbol };
#define CSA_ASSERT_JS_ARGC_OP(csa, Op, op, expected) \
(csa)->Assert( \
[&]() -> compiler::Node* { \
[&]() -> TNode<BoolT> { \
const TNode<Word32T> argc = UncheckedCast<Word32T>( \
(csa)->Parameter(Descriptor::kJSActualArgumentsCount)); \
return (csa)->Op(argc, (csa)->Int32Constant(expected)); \
......@@ -823,13 +819,14 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
TNode<BoolT> IsRegularHeapObjectSize(TNode<IntPtrT> size);
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*>;
void Assert(const BranchGenerator& branch, const char* message,
const char* file, int line,
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,
std::initializer_list<ExtraNode> extra_nodes = {});
void Assert(SloppyTNode<Word32T> condition_node, const char* message,
......@@ -838,7 +835,7 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
void Check(const BranchGenerator& branch, const char* message,
const char* file, int line,
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,
std::initializer_list<ExtraNode> extra_nodes = {});
void Check(SloppyTNode<Word32T> condition_node, const char* message,
......@@ -886,14 +883,26 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
return ConstructWithTarget(context, new_target, new_target, args...);
}
template <class A, class F, class G>
TNode<A> Select(SloppyTNode<BoolT> condition, const F& true_body,
const G& false_body) {
return UncheckedCast<A>(SelectImpl(
condition,
[&]() -> Node* { return implicit_cast<TNode<A>>(true_body()); },
[&]() -> Node* { return implicit_cast<TNode<A>>(false_body()); },
MachineRepresentationOf<A>::value));
template <typename T>
TNode<T> Select(TNode<BoolT> condition, const NodeGenerator<T>& true_body,
const NodeGenerator<T>& false_body) {
TVARIABLE(T, value);
Label vtrue(this), vfalse(this), end(this);
Branch(condition, &vtrue, &vfalse);
BIND(&vtrue);
{
value = true_body();
Goto(&end);
}
BIND(&vfalse);
{
value = false_body();
Goto(&end);
}
BIND(&end);
return value.value();
}
template <class A>
......@@ -3796,9 +3805,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
TNode<Uint32T> length,
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.
template <typename 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