Commit a6e0a0b7 authored by Kanghua Yu's avatar Kanghua Yu Committed by Commit Bot

[csa] Introduce CodeAssembler::Branch(condition, true_body, false_body)

Benefit from constant folding, this CL reduce snapshot by 704 bytes
for {Call,Construct}WithArrayLike builtins.

R=tebbi@chromium.org

Change-Id: I34f055c9b46039698150f560644459aa492cde9e
Reviewed-on: https://chromium-review.googlesource.com/1168739
Commit-Queue: Kanghua Yu <kanghua.yu@intel.com>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55008}
parent 70f2bd0d
......@@ -237,7 +237,6 @@ void CallOrConstructBuiltinsAssembler::CallOrConstructDoubleVarargs(
TNode<Object> target, SloppyTNode<Object> new_target,
TNode<FixedDoubleArray> elements, TNode<Int32T> length,
TNode<Int32T> args_count, TNode<Context> context, TNode<Int32T> kind) {
Label if_holey_double(this), if_packed_double(this), if_done(this);
const ElementsKind new_kind = PACKED_ELEMENTS;
const WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER;
......@@ -248,35 +247,25 @@ void CallOrConstructBuiltinsAssembler::CallOrConstructDoubleVarargs(
TNode<FixedArray> new_elements = AllocateFixedArray(
new_kind, intptr_length, CodeStubAssembler::kAllowLargeObjectAllocation);
Branch(Word32Equal(kind, Int32Constant(HOLEY_DOUBLE_ELEMENTS)),
&if_holey_double, &if_packed_double);
[=] {
// Fill the FixedArray with pointers to HeapObjects.
CopyFixedArrayElements(HOLEY_DOUBLE_ELEMENTS, elements, new_kind,
new_elements, intptr_length, intptr_length,
barrier_mode);
},
[=] {
CopyFixedArrayElements(PACKED_DOUBLE_ELEMENTS, elements, new_kind,
new_elements, intptr_length, intptr_length,
barrier_mode);
});
BIND(&if_holey_double);
{
// Fill the FixedArray with pointers to HeapObjects.
CopyFixedArrayElements(HOLEY_DOUBLE_ELEMENTS, elements, new_kind,
new_elements, intptr_length, intptr_length,
barrier_mode);
Goto(&if_done);
}
BIND(&if_packed_double);
{
CopyFixedArrayElements(PACKED_DOUBLE_ELEMENTS, elements, new_kind,
new_elements, intptr_length, intptr_length,
barrier_mode);
Goto(&if_done);
}
BIND(&if_done);
{
if (new_target == nullptr) {
Callable callable = CodeFactory::CallVarargs(isolate());
TailCallStub(callable, context, target, args_count, new_elements, length);
} else {
Callable callable = CodeFactory::ConstructVarargs(isolate());
TailCallStub(callable, context, target, new_target, args_count,
new_elements, length);
}
if (new_target == nullptr) {
Callable callable = CodeFactory::CallVarargs(isolate());
TailCallStub(callable, context, target, args_count, new_elements, length);
} else {
Callable callable = CodeFactory::ConstructVarargs(isolate());
TailCallStub(callable, context, target, new_target, args_count,
new_elements, length);
}
}
......
......@@ -1384,6 +1384,29 @@ void CodeAssembler::Branch(SloppyTNode<IntegralT> condition, Label* true_label,
false_label->label_);
}
void CodeAssembler::Branch(TNode<BoolT> condition,
std::function<void()> true_body,
std::function<void()> false_body) {
int32_t constant;
if (ToInt32Constant(condition, constant)) {
return constant ? true_body() : false_body();
}
Label vtrue(this), vfalse(this), end(this);
Branch(condition, &vtrue, &vfalse);
Bind(&vtrue);
{
true_body();
Goto(&end);
}
Bind(&vfalse);
{
false_body();
Goto(&end);
}
Bind(&end);
}
void CodeAssembler::Switch(Node* index, Label* default_label,
const int32_t* case_values, Label** case_labels,
size_t case_count) {
......
......@@ -773,6 +773,9 @@ class V8_EXPORT_PRIVATE CodeAssembler {
void Branch(SloppyTNode<IntegralT> condition, Label* true_label,
Label* false_label);
void Branch(TNode<BoolT> condition, std::function<void()> true_body,
std::function<void()> false_body);
void Switch(Node* index, Label* default_label, const int32_t* case_values,
Label** case_labels, size_t case_count);
......
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