diff options
Diffstat (limited to 'compiler/optimizing/bounds_check_elimination.cc')
-rw-r--r-- | compiler/optimizing/bounds_check_elimination.cc | 78 |
1 files changed, 26 insertions, 52 deletions
diff --git a/compiler/optimizing/bounds_check_elimination.cc b/compiler/optimizing/bounds_check_elimination.cc index 6b3d06e4fc..c0d4c37659 100644 --- a/compiler/optimizing/bounds_check_elimination.cc +++ b/compiler/optimizing/bounds_check_elimination.cc @@ -37,8 +37,7 @@ class ValueBound : public ValueObject { ValueBound(HInstruction* instruction, int32_t constant) { if (instruction != nullptr && instruction->IsIntConstant()) { // Normalize ValueBound with constant instruction. - // TODO: Remove "OrNull". - int32_t instr_const = instruction->AsIntConstantOrNull()->GetValue(); + int32_t instr_const = instruction->AsIntConstant()->GetValue(); if (!WouldAddOverflowOrUnderflow(instr_const, constant)) { instruction_ = nullptr; constant_ = instr_const + constant; @@ -72,13 +71,11 @@ class ValueBound : public ValueObject { HInstruction* left_so_far = nullptr; int32_t right_so_far = 0; while (instruction->IsAdd() || instruction->IsSub()) { - // TODO: Remove "OrNull". - HBinaryOperation* bin_op = instruction->AsBinaryOperationOrNull(); + HBinaryOperation* bin_op = instruction->AsBinaryOperation(); HInstruction* left = bin_op->GetLeft(); HInstruction* right = bin_op->GetRight(); if (right->IsIntConstant()) { - // TODO: Remove "OrNull". - int32_t v = right->AsIntConstantOrNull()->GetValue(); + int32_t v = right->AsIntConstant()->GetValue(); int32_t c = instruction->IsAdd() ? v : -v; if (!WouldAddOverflowOrUnderflow(right_so_far, c)) { instruction = left; @@ -98,8 +95,7 @@ class ValueBound : public ValueObject { // Expresses any instruction as a value bound. static ValueBound AsValueBound(HInstruction* instruction) { if (instruction->IsIntConstant()) { - // TODO: Remove "OrNull". - return ValueBound(nullptr, instruction->AsIntConstantOrNull()->GetValue()); + return ValueBound(nullptr, instruction->AsIntConstant()->GetValue()); } HInstruction *left; int32_t right; @@ -115,8 +111,7 @@ class ValueBound : public ValueObject { DCHECK(instruction != nullptr); if (instruction->IsIntConstant()) { *found = true; - // TODO: Remove "OrNull". - return ValueBound(nullptr, instruction->AsIntConstantOrNull()->GetValue()); + return ValueBound(nullptr, instruction->AsIntConstant()->GetValue()); } if (instruction->IsArrayLength()) { @@ -446,8 +441,7 @@ class MonotonicValueRange : public ValueRange { // Be conservative first, assume last number in the sequence hits upper. int32_t last_num_in_sequence = upper; if (initial_->IsIntConstant()) { - // TODO: Remove "OrNull". - int32_t initial_constant = initial_->AsIntConstantOrNull()->GetValue(); + int32_t initial_constant = initial_->AsIntConstant()->GetValue(); if (upper <= initial_constant) { last_num_in_sequence = upper; } else { @@ -883,14 +877,12 @@ class BCEVisitor final : public HGraphVisitor { } } else { // Constant index. - // TODO: Remove "OrNull". - int32_t constant = index->AsIntConstantOrNull()->GetValue(); + int32_t constant = index->AsIntConstant()->GetValue(); if (constant < 0) { // Will always throw exception. return; } else if (array_length->IsIntConstant()) { - // TODO: Remove "OrNull". - if (constant < array_length->AsIntConstantOrNull()->GetValue()) { + if (constant < array_length->AsIntConstant()->GetValue()) { ReplaceInstruction(bounds_check, index); } return; @@ -1017,8 +1009,7 @@ class BCEVisitor final : public HGraphVisitor { void VisitIf(HIf* instruction) override { if (instruction->InputAt(0)->IsCondition()) { - // TODO: Remove "OrNull". - HCondition* cond = instruction->InputAt(0)->AsConditionOrNull(); + HCondition* cond = instruction->InputAt(0)->AsCondition(); HandleIf(instruction, cond->GetLeft(), cond->GetRight(), cond->GetCondition()); } } @@ -1060,24 +1051,20 @@ class BCEVisitor final : public HGraphVisitor { if (!mul->GetLeft()->IsDiv() || !mul->GetRight()->IsConstant()) { return false; } - // TODO: Remove "OrNull". - div = mul->GetLeft()->AsDivOrNull(); - // TODO: Remove "OrNull". - const_divisor = Int64FromConstant(mul->GetRight()->AsConstantOrNull()); + div = mul->GetLeft()->AsDiv(); + const_divisor = Int64FromConstant(mul->GetRight()->AsConstant()); } else if (HAdd* add = instruction->GetRight()->AsAddOrNull()) { HShl* shl = add->GetRight()->AsShlOrNull(); if (!is_needed_shl(shl)) { return false; } - // TODO: Remove "OrNull". - div = shl->GetLeft()->AsDivOrNull(); + div = shl->GetLeft()->AsDiv(); if (add->GetLeft() != div) { return false; } - // TODO: Remove "OrNull". - int32_t n = shl->GetRight()->AsIntConstantOrNull()->GetValue(); + int32_t n = shl->GetRight()->AsIntConstant()->GetValue(); if (n == BitSizeOf<int32_t>() - 1) { // 2^n + 1 will be negative. return false; @@ -1089,14 +1076,12 @@ class BCEVisitor final : public HGraphVisitor { return false; } - // TODO: Remove "OrNull". - div = shl->GetLeft()->AsDivOrNull(); + div = shl->GetLeft()->AsDiv(); if (sub->GetRight() != div) { return false; } - // TODO: Remove "OrNull". - int32_t n = shl->GetRight()->AsIntConstantOrNull()->GetValue(); + int32_t n = shl->GetRight()->AsIntConstant()->GetValue(); const_divisor = (1LL << n) - 1; } @@ -1133,8 +1118,7 @@ class BCEVisitor final : public HGraphVisitor { if (left_range == nullptr) { return; } - // TODO: Remove "OrNull". - ValueRange* range = left_range->Add(right->AsIntConstantOrNull()->GetValue()); + ValueRange* range = left_range->Add(right->AsIntConstant()->GetValue()); if (range != nullptr) { AssignRange(add->GetBlock(), add, range); } @@ -1153,8 +1137,7 @@ class BCEVisitor final : public HGraphVisitor { if (left_range == nullptr) { return; } - // TODO: Remove "OrNull". - ValueRange* range = left_range->Add(-right->AsIntConstantOrNull()->GetValue()); + ValueRange* range = left_range->Add(-right->AsIntConstant()->GetValue()); if (range != nullptr) { AssignRange(sub->GetBlock(), sub, range); return; @@ -1174,8 +1157,7 @@ class BCEVisitor final : public HGraphVisitor { // The value of left input of the sub equals (left + right_const). if (left->IsArrayLength()) { - // TODO: Remove "OrNull". - HInstruction* array_length = left->AsArrayLengthOrNull(); + HInstruction* array_length = left->AsArrayLength(); ValueRange* right_range = LookupValueRange(right, sub->GetBlock()); if (right_range != nullptr) { ValueBound lower = right_range->GetLower(); @@ -1211,8 +1193,7 @@ class BCEVisitor final : public HGraphVisitor { HInstruction* right = instruction->GetRight(); int32_t right_const; if (right->IsIntConstant()) { - // TODO: Remove "OrNull". - right_const = right->AsIntConstantOrNull()->GetValue(); + right_const = right->AsIntConstant()->GetValue(); // Detect division by two or more. if ((instruction->IsDiv() && right_const <= 1) || (instruction->IsShr() && right_const < 1) || @@ -1264,8 +1245,7 @@ class BCEVisitor final : public HGraphVisitor { void VisitAnd(HAnd* instruction) override { if (instruction->GetRight()->IsIntConstant()) { - // TODO: Remove "OrNull". - int32_t constant = instruction->GetRight()->AsIntConstantOrNull()->GetValue(); + int32_t constant = instruction->GetRight()->AsIntConstant()->GetValue(); if (constant > 0) { // constant serves as a mask so any number masked with it // gets a [0, constant] value range. @@ -1285,8 +1265,7 @@ class BCEVisitor final : public HGraphVisitor { // Handle 'i % CONST' format expression in array index, e.g: // array[i % 20]; if (right->IsIntConstant()) { - // TODO: Remove "OrNull". - int32_t right_const = std::abs(right->AsIntConstantOrNull()->GetValue()); + int32_t right_const = std::abs(right->AsIntConstant()->GetValue()); if (right_const == 0) { return; } @@ -1318,8 +1297,7 @@ class BCEVisitor final : public HGraphVisitor { if (right->IsDivZeroCheck()) { // if array_length can pass div-by-zero check, // array_length must be > 0. - // TODO: Remove "OrNull". - right = right->AsDivZeroCheckOrNull()->InputAt(0); + right = right->AsDivZeroCheck()->InputAt(0); } // Handle 'i % array.length' format expression in array index, e.g: @@ -1456,8 +1434,7 @@ class BCEVisitor final : public HGraphVisitor { HInstruction* user = use.GetUser(); HBasicBlock* other_block = user->GetBlock(); if (user->IsBoundsCheck() && block->Dominates(other_block)) { - // TODO: Remove "OrNull". - HBoundsCheck* other_bounds_check = user->AsBoundsCheckOrNull(); + HBoundsCheck* other_bounds_check = user->AsBoundsCheck(); HInstruction* other_index = other_bounds_check->InputAt(0); HInstruction* other_array_length = other_bounds_check->InputAt(1); ValueBound other_value = ValueBound::AsValueBound(other_index); @@ -1575,8 +1552,7 @@ class BCEVisitor final : public HGraphVisitor { for (const HUseListNode<HInstruction*>& use : array_length->GetUses()) { HInstruction* user = use.GetUser(); if (user->IsBoundsCheck() && loop == user->GetBlock()->GetLoopInformation()) { - // TODO: Remove "OrNull". - HBoundsCheck* other_bounds_check = user->AsBoundsCheckOrNull(); + HBoundsCheck* other_bounds_check = user->AsBoundsCheck(); HInstruction* other_index = other_bounds_check->InputAt(0); HInstruction* other_array_length = other_bounds_check->InputAt(1); ValueBound other_value = ValueBound::AsValueBound(other_index); @@ -1811,11 +1787,9 @@ class BCEVisitor final : public HGraphVisitor { // ensure upper bound cannot cause an infinite loop. HInstruction* control = loop->GetHeader()->GetLastInstruction(); if (control->IsIf()) { - // TODO: Remove "OrNull". - HInstruction* if_expr = control->AsIfOrNull()->InputAt(0); + HInstruction* if_expr = control->AsIf()->InputAt(0); if (if_expr->IsCondition()) { - // TODO: Remove "OrNull". - HCondition* condition = if_expr->AsConditionOrNull(); + HCondition* condition = if_expr->AsCondition(); if (index == condition->InputAt(0) || index == condition->InputAt(1)) { finite_loop_.insert(loop_id); |