Commit 80ef93c8 authored by Seth Brenith's avatar Seth Brenith Committed by Commit Bot

[turbofan][cleanup] Add helper function for effect level

I noticed a pattern that has been copied around to various places and
thought a helper function might be appropriate.

Change-Id: I8944ac5166c649f15c09f587308406cab317b8d4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2346766Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#69344}
parent 3f071e3e
......@@ -598,11 +598,7 @@ void VisitBinop(InstructionSelector* selector, Node* node,
inputs[input_count++] = g.UseRegister(left);
inputs[input_count++] = g.UseImmediate(right);
} else {
int effect_level = selector->GetEffectLevel(node);
if (cont->IsBranch()) {
effect_level = selector->GetEffectLevel(
cont->true_block()->PredecessorAt(0)->control_input());
}
int effect_level = selector->GetEffectLevel(node, cont);
if (node->op()->HasProperty(Operator::kCommutative) &&
g.CanBeBetterLeftOperand(right) &&
(!g.CanBeBetterLeftOperand(left) ||
......@@ -664,11 +660,7 @@ void InstructionSelector::VisitStackPointerGreaterThan(
InstructionCode opcode =
kArchStackPointerGreaterThan | MiscField::encode(static_cast<int>(kind));
int effect_level = GetEffectLevel(node);
if (cont->IsBranch()) {
effect_level =
GetEffectLevel(cont->true_block()->PredecessorAt(0)->control_input());
}
int effect_level = GetEffectLevel(node, cont);
IA32OperandGenerator g(this);
......@@ -1442,11 +1434,7 @@ void VisitWordCompare(InstructionSelector* selector, Node* node,
InstructionCode narrowed_opcode =
TryNarrowOpcodeSize(opcode, left, right, cont);
int effect_level = selector->GetEffectLevel(node);
if (cont->IsBranch()) {
effect_level = selector->GetEffectLevel(
cont->true_block()->PredecessorAt(0)->control_input());
}
int effect_level = selector->GetEffectLevel(node, cont);
// If one of the two inputs is an immediate, make sure it's on the right, or
// if one of the two inputs is a memory operand, make sure it's on the left.
......
......@@ -422,6 +422,14 @@ int InstructionSelector::GetEffectLevel(Node* node) const {
return effect_level_[id];
}
int InstructionSelector::GetEffectLevel(Node* node,
FlagsContinuation* cont) const {
return cont->IsBranch()
? GetEffectLevel(
cont->true_block()->PredecessorAt(0)->control_input())
: GetEffectLevel(node);
}
void InstructionSelector::SetEffectLevel(Node* node, int effect_level) {
DCHECK_NOT_NULL(node);
size_t const id = node->id();
......
......@@ -440,6 +440,10 @@ class V8_EXPORT_PRIVATE InstructionSelector final {
// Gets the effect level of {node}.
int GetEffectLevel(Node* node) const;
// Gets the effect level of {node}, appropriately adjusted based on
// continuation flags if the node is a branch.
int GetEffectLevel(Node* node, FlagsContinuation* cont) const;
int GetVirtualRegister(const Node* node);
const std::map<NodeId, int> GetVirtualRegistersForTesting() const;
......
......@@ -1713,11 +1713,7 @@ void VisitWordCompare(InstructionSelector* selector, Node* node,
// If one of the two inputs is an immediate, make sure it's on the right, or
// if one of the two inputs is a memory operand, make sure it's on the left.
int effect_level = selector->GetEffectLevel(node);
if (cont->IsBranch()) {
effect_level = selector->GetEffectLevel(
cont->true_block()->PredecessorAt(0)->control_input());
}
int effect_level = selector->GetEffectLevel(node, cont);
if ((!g.CanBeImmediate(right, immediate_mode) &&
g.CanBeImmediate(left, immediate_mode)) ||
......@@ -1815,11 +1811,7 @@ void VisitLoadAndTest(InstructionSelector* selector, InstructionCode opcode,
size_t output_count = 0;
bool use_value = false;
int effect_level = selector->GetEffectLevel(node);
if (cont->IsBranch()) {
effect_level = selector->GetEffectLevel(
cont->true_block()->PredecessorAt(0)->control_input());
}
int effect_level = selector->GetEffectLevel(node, cont);
if (g.CanBeMemoryOperand(opcode, node, value, effect_level)) {
// generate memory operand
......
......@@ -514,11 +514,7 @@ static void VisitBinop(InstructionSelector* selector, Node* node,
inputs[input_count++] = g.UseRegister(left);
inputs[input_count++] = g.UseImmediate(right);
} else {
int effect_level = selector->GetEffectLevel(node);
if (cont->IsBranch()) {
effect_level = selector->GetEffectLevel(
cont->true_block()->PredecessorAt(0)->control_input());
}
int effect_level = selector->GetEffectLevel(node, cont);
if (node->op()->HasProperty(Operator::kCommutative) &&
g.CanBeBetterLeftOperand(right) &&
(!g.CanBeBetterLeftOperand(left) ||
......@@ -609,11 +605,7 @@ void InstructionSelector::VisitStackPointerGreaterThan(
InstructionCode opcode =
kArchStackPointerGreaterThan | MiscField::encode(static_cast<int>(kind));
int effect_level = GetEffectLevel(node);
if (cont->IsBranch()) {
effect_level =
GetEffectLevel(cont->true_block()->PredecessorAt(0)->control_input());
}
int effect_level = GetEffectLevel(node, cont);
X64OperandGenerator g(this);
Node* const value = node->InputAt(0);
......@@ -1864,11 +1856,7 @@ void VisitWordCompare(InstructionSelector* selector, Node* node,
// If one of the two inputs is an immediate, make sure it's on the right, or
// if one of the two inputs is a memory operand, make sure it's on the left.
int effect_level = selector->GetEffectLevel(node);
if (cont->IsBranch()) {
effect_level = selector->GetEffectLevel(
cont->true_block()->PredecessorAt(0)->control_input());
}
int effect_level = selector->GetEffectLevel(node, cont);
if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) ||
(g.CanBeMemoryOperand(opcode, node, right, effect_level) &&
......@@ -2005,11 +1993,7 @@ void VisitCompareZero(InstructionSelector* selector, Node* user, Node* node,
break;
}
}
int effect_level = selector->GetEffectLevel(node);
if (cont->IsBranch()) {
effect_level = selector->GetEffectLevel(
cont->true_block()->PredecessorAt(0)->control_input());
}
int effect_level = selector->GetEffectLevel(node, cont);
if (node->opcode() == IrOpcode::kLoad) {
switch (LoadRepresentationOf(node->op()).representation()) {
case MachineRepresentation::kWord8:
......
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