mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
[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>
This commit is contained in:
parent
5054079c7a
commit
fa181d94ef
3 changed files with 30 additions and 46 deletions
|
@ -1850,26 +1850,6 @@ EMIT_NATIVE_CODE(MathMinMax, 2, Location::RequiresRegister()) {
|
|||
}
|
||||
}
|
||||
|
||||
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 @@ static Condition EmitSmiComparisonOp(FlowGraphCompiler* compiler,
|
|||
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();
|
||||
|
|
|
@ -114,28 +114,6 @@ void RangeAnalysis::CollectValues() {
|
|||
}
|
||||
}
|
||||
|
||||
// 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 @@ bool RangeAnalysis::ConstrainValueAfterBranch(Value* use, Definition* defn) {
|
|||
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.
|
||||
|
|
|
@ -322,6 +322,32 @@ class Token {
|
|||
}
|
||||
}
|
||||
|
||||
// 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_[];
|
||||
|
|
Loading…
Reference in a new issue