Commit 13cb1e54 authored by ishell's avatar ishell Committed by Commit bot

[stubs] Cleanup usages of CSA::Select().

1) CSA::Select() receives lambdas for generating true/false values.
   The representation parameter made mandatory.
2) CSA::Select[Type]Constant() methods receive true/false nodes directly.
   These methods are intended to be used for generating "selects" when
   true/false values are already computed.

BUG=

Review-Url: https://codereview.chromium.org/2550683003
Cr-Commit-Position: refs/heads/master@{#41483}
parent 3d618949
......@@ -914,7 +914,7 @@ void Generate_FlagGetter(CodeStubAssembler* a, JSRegExp::Flag flag,
{
// Refer to JSRegExp's flag property on the fast-path.
Node* const is_flag_set = FastFlagGetter(a, receiver, flag);
a->Return(a->Select(is_flag_set, a->TrueConstant(), a->FalseConstant()));
a->Return(a->SelectBooleanConstant(is_flag_set));
}
a->Bind(&if_isnotunmodifiedjsregexp);
......@@ -1192,8 +1192,8 @@ void Builtins::Generate_RegExpPrototypeTest(CodeAssemblerState* state) {
Node* const match_indices = RegExpExec(&a, context, receiver, string);
// Return true iff exec matched successfully.
Node* const result = a.Select(a.WordEqual(match_indices, a.NullConstant()),
a.FalseConstant(), a.TrueConstant());
Node* const result = a.SelectBooleanConstant(
a.WordNotEqual(match_indices, a.NullConstant()));
a.Return(result);
}
}
......
......@@ -971,7 +971,9 @@ void Builtins::Generate_StringPrototypeSubstr(
{
Node* const length_plus_start = a.SmiAdd(string_length, start_int);
var_start.Bind(a.Select(a.SmiLessThan(start_int, zero),
a.SmiMax(length_plus_start, zero), start_int));
[&] { return a.SmiMax(length_plus_start, zero); },
[&] { return start_int; },
MachineRepresentation::kTagged));
a.Goto(&handle_length);
}
......@@ -983,8 +985,8 @@ void Builtins::Generate_StringPrototypeSubstr(
// returning an empty string.
Node* const float_zero = a.Float64Constant(0.);
Node* const start_float = a.LoadHeapNumberValue(start_int);
var_start.Bind(a.Select(a.Float64LessThan(start_float, float_zero), zero,
string_length));
var_start.Bind(a.SelectTaggedConstant(
a.Float64LessThan(start_float, float_zero), zero, string_length));
a.Goto(&handle_length);
}
}
......@@ -1090,7 +1092,8 @@ compiler::Node* ToSmiBetweenZeroAnd(CodeStubAssembler* a,
a->Bind(&if_isoutofbounds);
{
Node* const zero = a->SmiConstant(Smi::kZero);
var_result.Bind(a->Select(a->SmiLessThan(value_int, zero), zero, limit));
var_result.Bind(a->SelectTaggedConstant(a->SmiLessThan(value_int, zero),
zero, limit));
a->Goto(&out);
}
}
......@@ -1103,8 +1106,8 @@ compiler::Node* ToSmiBetweenZeroAnd(CodeStubAssembler* a,
Node* const float_zero = a->Float64Constant(0.);
Node* const smi_zero = a->SmiConstant(Smi::kZero);
Node* const value_float = a->LoadHeapNumberValue(value_int);
var_result.Bind(a->Select(a->Float64LessThan(value_float, float_zero),
smi_zero, limit));
var_result.Bind(a->SelectTaggedConstant(
a->Float64LessThan(value_float, float_zero), smi_zero, limit));
a->Goto(&out);
}
......
......@@ -45,6 +45,60 @@ void CodeStubAssembler::Assert(const NodeGenerator& codition_body,
#endif
}
Node* CodeStubAssembler::Select(Node* condition, const NodeGenerator& true_body,
const NodeGenerator& false_body,
MachineRepresentation rep) {
Variable value(this, 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();
}
Node* CodeStubAssembler::SelectConstant(Node* condition, Node* true_value,
Node* false_value,
MachineRepresentation rep) {
return Select(condition, [=] { return true_value; },
[=] { return false_value; }, rep);
}
Node* CodeStubAssembler::SelectInt32Constant(Node* condition, int true_value,
int false_value) {
return SelectConstant(condition, Int32Constant(true_value),
Int32Constant(false_value),
MachineRepresentation::kWord32);
}
Node* CodeStubAssembler::SelectIntPtrConstant(Node* condition, int true_value,
int false_value) {
return SelectConstant(condition, IntPtrConstant(true_value),
IntPtrConstant(false_value),
MachineType::PointerRepresentation());
}
Node* CodeStubAssembler::SelectBooleanConstant(Node* condition) {
return SelectConstant(condition, TrueConstant(), FalseConstant(),
MachineRepresentation::kTagged);
}
Node* CodeStubAssembler::SelectTaggedConstant(Node* condition, Node* true_value,
Node* false_value) {
return SelectConstant(condition, true_value, false_value,
MachineRepresentation::kTagged);
}
Node* CodeStubAssembler::NoContextConstant() { return NumberConstant(0); }
#define HEAP_CONSTANT_ACCESSOR(rootName, name) \
......@@ -128,9 +182,11 @@ Node* CodeStubAssembler::IntPtrRoundUpToPowerOfTwo32(Node* value) {
Node* CodeStubAssembler::WordIsPowerOfTwo(Node* value) {
// value && !(value & (value - 1))
return WordEqual(
Select(WordEqual(value, IntPtrConstant(0)), IntPtrConstant(1),
WordAnd(value, IntPtrSub(value, IntPtrConstant(1))),
MachineType::PointerRepresentation()),
Select(
WordEqual(value, IntPtrConstant(0)),
[=] { return IntPtrConstant(1); },
[=] { return WordAnd(value, IntPtrSub(value, IntPtrConstant(1))); },
MachineType::PointerRepresentation()),
IntPtrConstant(0));
}
......@@ -421,11 +477,11 @@ Node* CodeStubAssembler::SmiLessThanOrEqual(Node* a, Node* b) {
}
Node* CodeStubAssembler::SmiMax(Node* a, Node* b) {
return Select(SmiLessThan(a, b), b, a);
return SelectTaggedConstant(SmiLessThan(a, b), b, a);
}
Node* CodeStubAssembler::SmiMin(Node* a, Node* b) {
return Select(SmiLessThan(a, b), a, b);
return SelectTaggedConstant(SmiLessThan(a, b), a, b);
}
Node* CodeStubAssembler::SmiMod(Node* a, Node* b) {
......@@ -2788,8 +2844,9 @@ Node* CodeStubAssembler::IsSpecialReceiverMap(Node* map) {
1 << Map::kHasNamedInterceptor | 1 << Map::kIsAccessCheckNeeded;
USE(mask);
// Interceptors or access checks imply special receiver.
CSA_ASSERT(this, Select(IsSetWord32(LoadMapBitField(map), mask), is_special,
Int32Constant(1), MachineRepresentation::kWord32));
CSA_ASSERT(this,
SelectConstant(IsSetWord32(LoadMapBitField(map), mask), is_special,
Int32Constant(1), MachineRepresentation::kWord32));
return is_special;
}
......@@ -4267,8 +4324,8 @@ Node* CodeStubAssembler::HashTableComputeCapacity(Node* at_least_space_for) {
}
Node* CodeStubAssembler::IntPtrMax(Node* left, Node* right) {
return Select(IntPtrGreaterThanOrEqual(left, right), left, right,
MachineType::PointerRepresentation());
return SelectConstant(IntPtrGreaterThanOrEqual(left, right), left, right,
MachineType::PointerRepresentation());
}
template <class Dictionary>
......@@ -7525,8 +7582,8 @@ Node* CodeStubAssembler::SameValue(Node* lhs, Node* rhs, Node* context) {
// Return true iff {rhs} is NaN.
Node* const result =
Select(Float64Equal(rhs_float, rhs_float), int_false, int_true,
MachineType::PointerRepresentation());
SelectConstant(Float64Equal(rhs_float, rhs_float), int_false,
int_true, MachineType::PointerRepresentation());
var_result.Bind(result);
Goto(&out);
}
......
......@@ -169,6 +169,18 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
void Assert(const NodeGenerator& condition_body, const char* string = nullptr,
const char* file = nullptr, int line = 0);
Node* Select(Node* condition, const NodeGenerator& true_body,
const NodeGenerator& false_body, MachineRepresentation rep);
Node* SelectConstant(Node* condition, Node* true_value, Node* false_value,
MachineRepresentation rep);
Node* SelectInt32Constant(Node* condition, int true_value, int false_value);
Node* SelectIntPtrConstant(Node* condition, int true_value, int false_value);
Node* SelectBooleanConstant(Node* condition);
Node* SelectTaggedConstant(Node* condition, Node* true_value,
Node* false_value);
// Check a value for smi-ness
Node* TaggedIsSmi(Node* a);
Node* TaggedIsNotSmi(Node* a);
......
......@@ -1061,11 +1061,10 @@ compiler::Node* MultiplyWithFeedbackStub::Generate(
// Both {lhs} and {rhs} are Smis. The result is not necessarily a smi,
// in case of overflow.
var_result.Bind(assembler->SmiMul(lhs, rhs));
var_type_feedback.Bind(assembler->Select(
var_type_feedback.Bind(assembler->SelectInt32Constant(
assembler->TaggedIsSmi(var_result.value()),
assembler->Int32Constant(BinaryOperationFeedback::kSignedSmall),
assembler->Int32Constant(BinaryOperationFeedback::kNumber),
MachineRepresentation::kWord32));
BinaryOperationFeedback::kSignedSmall,
BinaryOperationFeedback::kNumber));
assembler->Goto(&end);
}
......@@ -1442,10 +1441,10 @@ compiler::Node* ModulusWithFeedbackStub::Generate(
assembler->Bind(&divisor_is_smi);
{
var_result.Bind(assembler->SmiMod(dividend, divisor));
var_type_feedback.Bind(assembler->Select(
var_type_feedback.Bind(assembler->SelectInt32Constant(
assembler->TaggedIsSmi(var_result.value()),
assembler->Int32Constant(BinaryOperationFeedback::kSignedSmall),
assembler->Int32Constant(BinaryOperationFeedback::kNumber)));
BinaryOperationFeedback::kSignedSmall,
BinaryOperationFeedback::kNumber));
assembler->Goto(&end);
}
......@@ -2495,29 +2494,25 @@ compiler::Node* FastNewClosureStub::Generate(CodeStubAssembler* assembler,
assembler->Bind(&if_normal);
{
map_index.Bind(assembler->Select(
is_strict,
assembler->IntPtrConstant(Context::STRICT_FUNCTION_MAP_INDEX),
assembler->IntPtrConstant(Context::SLOPPY_FUNCTION_MAP_INDEX)));
map_index.Bind(assembler->SelectIntPtrConstant(
is_strict, Context::STRICT_FUNCTION_MAP_INDEX,
Context::SLOPPY_FUNCTION_MAP_INDEX));
assembler->Goto(&load_map);
}
assembler->Bind(&if_generator);
{
map_index.Bind(assembler->Select(
is_strict,
assembler->IntPtrConstant(Context::STRICT_GENERATOR_FUNCTION_MAP_INDEX),
assembler->IntPtrConstant(
Context::SLOPPY_GENERATOR_FUNCTION_MAP_INDEX)));
map_index.Bind(assembler->SelectIntPtrConstant(
is_strict, Context::STRICT_GENERATOR_FUNCTION_MAP_INDEX,
Context::SLOPPY_GENERATOR_FUNCTION_MAP_INDEX));
assembler->Goto(&load_map);
}
assembler->Bind(&if_async);
{
map_index.Bind(assembler->Select(
is_strict,
assembler->IntPtrConstant(Context::STRICT_ASYNC_FUNCTION_MAP_INDEX),
assembler->IntPtrConstant(Context::SLOPPY_ASYNC_FUNCTION_MAP_INDEX)));
map_index.Bind(assembler->SelectIntPtrConstant(
is_strict, Context::STRICT_ASYNC_FUNCTION_MAP_INDEX,
Context::SLOPPY_ASYNC_FUNCTION_MAP_INDEX));
assembler->Goto(&load_map);
}
......
......@@ -1033,27 +1033,6 @@ void CodeAssembler::Switch(Node* index, Label* default_label,
labels, case_count);
}
Node* CodeAssembler::Select(Node* condition, Node* true_value,
Node* false_value, MachineRepresentation rep) {
Variable value(this, rep);
Label vtrue(this), vfalse(this), end(this);
Branch(condition, &vtrue, &vfalse);
Bind(&vtrue);
{
value.Bind(true_value);
Goto(&end);
}
Bind(&vfalse);
{
value.Bind(false_value);
Goto(&end);
}
Bind(&end);
return value.value();
}
// RawMachineAssembler delegate helpers:
Isolate* CodeAssembler::isolate() const { return raw_assembler()->isolate(); }
......
......@@ -252,9 +252,6 @@ class V8_EXPORT_PRIVATE CodeAssembler {
void Switch(Node* index, Label* default_label, const int32_t* case_values,
Label** case_labels, size_t case_count);
Node* Select(Node* condition, Node* true_value, Node* false_value,
MachineRepresentation rep = MachineRepresentation::kTagged);
// Access to the frame pointer
Node* LoadFramePointer();
Node* LoadParentFramePointer();
......
......@@ -1058,10 +1058,9 @@ void Interpreter::DoCompareOpWithFeedback(Token::Value compare_op,
__ Bind(&lhs_is_not_oddball);
}
var_type_feedback.Bind(
__ Select(__ IsStringInstanceType(lhs_instance_type),
__ Int32Constant(CompareOperationFeedback::kString),
__ Int32Constant(CompareOperationFeedback::kAny)));
var_type_feedback.Bind(__ SelectInt32Constant(
__ IsStringInstanceType(lhs_instance_type),
CompareOperationFeedback::kString, CompareOperationFeedback::kAny));
__ Goto(&gather_rhs_type);
}
}
......@@ -1106,9 +1105,9 @@ void Interpreter::DoCompareOpWithFeedback(Token::Value compare_op,
var_type_feedback.Bind(__ Word32Or(
var_type_feedback.value(),
__ Select(__ IsStringInstanceType(rhs_instance_type),
__ Int32Constant(CompareOperationFeedback::kString),
__ Int32Constant(CompareOperationFeedback::kAny))));
__ SelectInt32Constant(__ IsStringInstanceType(rhs_instance_type),
CompareOperationFeedback::kString,
CompareOperationFeedback::kAny)));
__ Goto(&update_feedback);
}
}
......@@ -1244,10 +1243,9 @@ void Interpreter::DoBitwiseBinaryOp(Token::Value bitwise_op,
UNREACHABLE();
}
Node* result_type =
__ Select(__ TaggedIsSmi(result),
__ Int32Constant(BinaryOperationFeedback::kSignedSmall),
__ Int32Constant(BinaryOperationFeedback::kNumber));
Node* result_type = __ SelectInt32Constant(
__ TaggedIsSmi(result), BinaryOperationFeedback::kSignedSmall,
BinaryOperationFeedback::kNumber);
if (FLAG_debug_code) {
Label ok(assembler);
......@@ -1444,10 +1442,9 @@ void Interpreter::DoBitwiseOrSmi(InterpreterAssembler* assembler) {
Node* rhs_value = __ SmiToWord32(right);
Node* value = __ Word32Or(lhs_value, rhs_value);
Node* result = __ ChangeInt32ToTagged(value);
Node* result_type =
__ Select(__ TaggedIsSmi(result),
__ Int32Constant(BinaryOperationFeedback::kSignedSmall),
__ Int32Constant(BinaryOperationFeedback::kNumber));
Node* result_type = __ SelectInt32Constant(
__ TaggedIsSmi(result), BinaryOperationFeedback::kSignedSmall,
BinaryOperationFeedback::kNumber);
__ UpdateFeedback(__ Word32Or(result_type, var_lhs_type_feedback.value()),
type_feedback_vector, slot_index);
__ SetAccumulator(result);
......@@ -1472,10 +1469,9 @@ void Interpreter::DoBitwiseAndSmi(InterpreterAssembler* assembler) {
Node* rhs_value = __ SmiToWord32(right);
Node* value = __ Word32And(lhs_value, rhs_value);
Node* result = __ ChangeInt32ToTagged(value);
Node* result_type =
__ Select(__ TaggedIsSmi(result),
__ Int32Constant(BinaryOperationFeedback::kSignedSmall),
__ Int32Constant(BinaryOperationFeedback::kNumber));
Node* result_type = __ SelectInt32Constant(
__ TaggedIsSmi(result), BinaryOperationFeedback::kSignedSmall,
BinaryOperationFeedback::kNumber);
__ UpdateFeedback(__ Word32Or(result_type, var_lhs_type_feedback.value()),
type_feedback_vector, slot_index);
__ SetAccumulator(result);
......@@ -1502,10 +1498,9 @@ void Interpreter::DoShiftLeftSmi(InterpreterAssembler* assembler) {
Node* shift_count = __ Word32And(rhs_value, __ Int32Constant(0x1f));
Node* value = __ Word32Shl(lhs_value, shift_count);
Node* result = __ ChangeInt32ToTagged(value);
Node* result_type =
__ Select(__ TaggedIsSmi(result),
__ Int32Constant(BinaryOperationFeedback::kSignedSmall),
__ Int32Constant(BinaryOperationFeedback::kNumber));
Node* result_type = __ SelectInt32Constant(
__ TaggedIsSmi(result), BinaryOperationFeedback::kSignedSmall,
BinaryOperationFeedback::kNumber);
__ UpdateFeedback(__ Word32Or(result_type, var_lhs_type_feedback.value()),
type_feedback_vector, slot_index);
__ SetAccumulator(result);
......@@ -1532,10 +1527,9 @@ void Interpreter::DoShiftRightSmi(InterpreterAssembler* assembler) {
Node* shift_count = __ Word32And(rhs_value, __ Int32Constant(0x1f));
Node* value = __ Word32Sar(lhs_value, shift_count);
Node* result = __ ChangeInt32ToTagged(value);
Node* result_type =
__ Select(__ TaggedIsSmi(result),
__ Int32Constant(BinaryOperationFeedback::kSignedSmall),
__ Int32Constant(BinaryOperationFeedback::kNumber));
Node* result_type = __ SelectInt32Constant(
__ TaggedIsSmi(result), BinaryOperationFeedback::kSignedSmall,
BinaryOperationFeedback::kNumber);
__ UpdateFeedback(__ Word32Or(result_type, var_lhs_type_feedback.value()),
type_feedback_vector, slot_index);
__ SetAccumulator(result);
......
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