[dart/compiler] Refactor negate/flip token utilities
Rationale:
Avoids code duplication, also for planned uses later.
Change-Id: I05b97809f016805a2692c1fca3ec5a26354c527a
Reviewed-on: https://dart-review.googlesource.com/c/87300
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Aart Bik <ajcbik@google.com>
diff --git a/runtime/vm/compiler/backend/il_dbc.cc b/runtime/vm/compiler/backend/il_dbc.cc
index 634b9dc..42beb69 100644
--- a/runtime/vm/compiler/backend/il_dbc.cc
+++ b/runtime/vm/compiler/backend/il_dbc.cc
@@ -1850,26 +1850,6 @@
}
}
-static Token::Kind FlipCondition(Token::Kind kind) {
- switch (kind) {
- case Token::kEQ:
- return Token::kNE;
- case Token::kNE:
- return Token::kEQ;
- case Token::kLT:
- return Token::kGTE;
- case Token::kGT:
- return Token::kLTE;
- case Token::kLTE:
- return Token::kGT;
- case Token::kGTE:
- return Token::kLT;
- default:
- UNREACHABLE();
- return Token::kNE;
- }
-}
-
static SimulatorBytecode::Opcode OpcodeForSmiCondition(Token::Kind kind) {
switch (kind) {
case Token::kEQ:
@@ -1919,11 +1899,11 @@
if (labels.fall_through != labels.false_label) {
// If we aren't falling through to the false label, we can save a Jump
// instruction in the case that the true case is the fall through by
- // flipping the sense of the test such that the instruction following the
+ // negating the sense of the test such that the instruction following the
// test is the Jump to the false label. In the case where both labels are
- // null we don't flip the sense of the test.
+ // null we don't negate the sense of the test.
condition = NEXT_IS_FALSE;
- comparison = FlipCondition(kind);
+ comparison = Token::NegateComparison(kind);
}
if (compiler->is_optimizing()) {
const Register left = locs->in(0).reg();
diff --git a/runtime/vm/compiler/backend/range_analysis.cc b/runtime/vm/compiler/backend/range_analysis.cc
index 554d61b..7fa08c0 100644
--- a/runtime/vm/compiler/backend/range_analysis.cc
+++ b/runtime/vm/compiler/backend/range_analysis.cc
@@ -114,28 +114,6 @@
}
}
-// For a comparison operation return an operation for the equivalent flipped
-// comparison: a (op) b === b (op') a.
-static Token::Kind FlipComparison(Token::Kind op) {
- switch (op) {
- case Token::kEQ:
- return Token::kEQ;
- case Token::kNE:
- return Token::kNE;
- case Token::kLT:
- return Token::kGT;
- case Token::kGT:
- return Token::kLT;
- case Token::kLTE:
- return Token::kGTE;
- case Token::kGTE:
- return Token::kLTE;
- default:
- UNREACHABLE();
- return Token::kILLEGAL;
- }
-}
-
// Given a boundary (right operand) and a comparison operation return
// a symbolic range constraint for the left operand of the comparison assuming
// that it evaluated to true.
@@ -208,7 +186,7 @@
boundary = rel_op->InputAt(0)->definition();
// InsertConstraintFor assumes that defn is left operand of a
// comparison if it is right operand flip the comparison.
- op_kind = FlipComparison(rel_op->kind());
+ op_kind = Token::FlipComparison(rel_op->kind());
}
// Constrain definition at the true successor.
diff --git a/runtime/vm/token.h b/runtime/vm/token.h
index adb0fba..ff8c682 100644
--- a/runtime/vm/token.h
+++ b/runtime/vm/token.h
@@ -322,6 +322,32 @@
}
}
+ // For a comparison operation return an operation for the equivalent flipped
+ // comparison: a (op) b === b (op') a.
+ static Token::Kind FlipComparison(Token::Kind op) {
+ switch (op) {
+ case Token::kEQ:
+ return Token::kEQ;
+ case Token::kNE:
+ return Token::kNE;
+ case Token::kLT:
+ return Token::kGT;
+ case Token::kGT:
+ return Token::kLT;
+ case Token::kLTE:
+ return Token::kGTE;
+ case Token::kGTE:
+ return Token::kLTE;
+ case Token::kEQ_STRICT:
+ return Token::kEQ_STRICT;
+ case Token::kNE_STRICT:
+ return Token::kNE_STRICT;
+ default:
+ UNREACHABLE();
+ return Token::kILLEGAL;
+ }
+ }
+
private:
static const char* name_[];
static const char* tok_str_[];