summaryrefslogtreecommitdiff
path: root/compiler/optimizing/nodes_vector.h
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2023-04-05 10:33:07 +0000
committer VladimĂ­r Marko <vmarko@google.com> 2023-04-27 10:52:39 +0000
commit79dc217688a774fc532584f6551a0aec8b45bc4a (patch)
tree5abfe4bd90364e66b593088ab4d1b407b51dada5 /compiler/optimizing/nodes_vector.h
parentd60aff547dedefc35265ce57707d406e8ccc4dc6 (diff)
Optimizing: Rename `As##type` to `As##type##OrNull`.
The null type check in the current implementation of `HInstruction::As##type()` often cannot be optimized away by clang++. It is therefore beneficial to have two functions HInstruction::As##type() HInstruction::As##type##OrNull() where the first function never returns null but the second one can return null. The additional text "OrNull" shall also flag the possibility of yielding null to the developer which may help avoid bugs similar to what we have seen previously. This requires renaming the existing function that can return null and introducing new function that cannot. However, defining the new function `HInstruction::As##type()` in the same change as renaming the old one would risk introducing bugs by missing a rename. Therefore we simply rename the old function here and the new function shall be introduced in a separate change with all behavioral changes being explicit. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Test: buildbot-build.sh --target Bug: 181943478 Change-Id: I4defd85038e28fe3506903ba3f33f723682b3298
Diffstat (limited to 'compiler/optimizing/nodes_vector.h')
-rw-r--r--compiler/optimizing/nodes_vector.h44
1 files changed, 30 insertions, 14 deletions
diff --git a/compiler/optimizing/nodes_vector.h b/compiler/optimizing/nodes_vector.h
index 73f6c40a0d..223c06e1dc 100644
--- a/compiler/optimizing/nodes_vector.h
+++ b/compiler/optimizing/nodes_vector.h
@@ -142,7 +142,8 @@ class HVecOperation : public HVariableInputSizeInstruction {
DCHECK(IsPredicated());
HInstruction* pred_input = InputAt(InputCount() - 1);
DCHECK(pred_input->IsVecPredSetOperation());
- return pred_input->AsVecPredSetOperation();
+ // TODO: Remove "OrNull".
+ return pred_input->AsVecPredSetOperationOrNull();
}
// Returns whether two vector operations are predicated by the same vector predicate
@@ -188,7 +189,8 @@ class HVecOperation : public HVariableInputSizeInstruction {
// those fields in its own method *and* call all super methods.
bool InstructionDataEquals(const HInstruction* other) const override {
DCHECK(other->IsVecOperation());
- const HVecOperation* o = other->AsVecOperation();
+ // TODO: Remove "OrNull".
+ const HVecOperation* o = other->AsVecOperationOrNull();
return GetVectorLength() == o->GetVectorLength() && GetPackedType() == o->GetPackedType();
}
@@ -350,7 +352,8 @@ class HVecMemoryOperation : public HVecOperation {
bool InstructionDataEquals(const HInstruction* other) const override {
DCHECK(other->IsVecMemoryOperation());
- const HVecMemoryOperation* o = other->AsVecMemoryOperation();
+ // TODO: Remove "OrNull".
+ const HVecMemoryOperation* o = other->AsVecMemoryOperationOrNull();
return HVecOperation::InstructionDataEquals(o) && GetAlignment() == o->GetAlignment();
}
@@ -371,7 +374,8 @@ inline static bool HasConsistentPackedTypes(HInstruction* input, DataType::Type
return input->GetType() == HVecOperation::kSIMDType; // carries SIMD
}
DCHECK(input->IsVecOperation());
- DataType::Type input_type = input->AsVecOperation()->GetPackedType();
+ // TODO: Remove "OrNull".
+ DataType::Type input_type = input->AsVecOperationOrNull()->GetPackedType();
DCHECK_EQ(HVecOperation::ToUnsignedType(input_type) == HVecOperation::ToUnsignedType(type),
HVecOperation::ToSignedType(input_type) == HVecOperation::ToSignedType(type));
return HVecOperation::ToSignedType(input_type) == HVecOperation::ToSignedType(type);
@@ -465,7 +469,8 @@ class HVecReduce final : public HVecUnaryOperation {
bool InstructionDataEquals(const HInstruction* other) const override {
DCHECK(other->IsVecReduce());
- const HVecReduce* o = other->AsVecReduce();
+ // TODO: Remove "OrNull".
+ const HVecReduce* o = other->AsVecReduceOrNull();
return HVecOperation::InstructionDataEquals(o) && GetReductionKind() == o->GetReductionKind();
}
@@ -492,7 +497,10 @@ class HVecCnv final : public HVecUnaryOperation {
DCHECK_NE(GetInputType(), GetResultType()); // actual convert
}
- DataType::Type GetInputType() const { return InputAt(0)->AsVecOperation()->GetPackedType(); }
+ DataType::Type GetInputType() const {
+ // TODO: Remove "OrNull".
+ return InputAt(0)->AsVecOperationOrNull()->GetPackedType();
+ }
DataType::Type GetResultType() const { return GetPackedType(); }
bool CanBeMoved() const override { return true; }
@@ -646,7 +654,8 @@ class HVecHalvingAdd final : public HVecBinaryOperation {
bool InstructionDataEquals(const HInstruction* other) const override {
DCHECK(other->IsVecHalvingAdd());
- const HVecHalvingAdd* o = other->AsVecHalvingAdd();
+ // TODO: Remove "OrNull".
+ const HVecHalvingAdd* o = other->AsVecHalvingAddOrNull();
return HVecOperation::InstructionDataEquals(o) && IsRounded() == o->IsRounded();
}
@@ -1036,7 +1045,8 @@ class HVecMultiplyAccumulate final : public HVecOperation {
bool InstructionDataEquals(const HInstruction* other) const override {
DCHECK(other->IsVecMultiplyAccumulate());
- const HVecMultiplyAccumulate* o = other->AsVecMultiplyAccumulate();
+ // TODO: Remove "OrNull".
+ const HVecMultiplyAccumulate* o = other->AsVecMultiplyAccumulateOrNull();
return HVecOperation::InstructionDataEquals(o) && GetOpKind() == o->GetOpKind();
}
@@ -1076,8 +1086,9 @@ class HVecSADAccumulate final : public HVecOperation {
DCHECK(HasConsistentPackedTypes(accumulator, packed_type));
DCHECK(sad_left->IsVecOperation());
DCHECK(sad_right->IsVecOperation());
- DCHECK_EQ(ToSignedType(sad_left->AsVecOperation()->GetPackedType()),
- ToSignedType(sad_right->AsVecOperation()->GetPackedType()));
+ // TODO: Remove "OrNull".
+ DCHECK_EQ(ToSignedType(sad_left->AsVecOperationOrNull()->GetPackedType()),
+ ToSignedType(sad_right->AsVecOperationOrNull()->GetPackedType()));
SetRawInputAt(0, accumulator);
SetRawInputAt(1, sad_left);
SetRawInputAt(2, sad_right);
@@ -1124,8 +1135,9 @@ class HVecDotProd final : public HVecOperation {
DCHECK(DataType::IsIntegralType(packed_type));
DCHECK(left->IsVecOperation());
DCHECK(right->IsVecOperation());
- DCHECK_EQ(ToSignedType(left->AsVecOperation()->GetPackedType()),
- ToSignedType(right->AsVecOperation()->GetPackedType()));
+ // TODO: Remove "OrNull".
+ DCHECK_EQ(ToSignedType(left->AsVecOperationOrNull()->GetPackedType()),
+ ToSignedType(right->AsVecOperationOrNull()->GetPackedType()));
SetRawInputAt(0, accumulator);
SetRawInputAt(1, left);
SetRawInputAt(2, right);
@@ -1179,7 +1191,8 @@ class HVecLoad final : public HVecMemoryOperation {
bool InstructionDataEquals(const HInstruction* other) const override {
DCHECK(other->IsVecLoad());
- const HVecLoad* o = other->AsVecLoad();
+ // TODO: Remove "OrNull".
+ const HVecLoad* o = other->AsVecLoadOrNull();
return HVecMemoryOperation::InstructionDataEquals(o) && IsStringCharAt() == o->IsStringCharAt();
}
@@ -1310,7 +1323,10 @@ class HVecPredSetAll final : public HVecPredSetOperation {
// Having governing predicate doesn't make sense for set all TRUE/FALSE instruction.
bool MustBePredicatedInPredicatedSIMDMode() override { return false; }
- bool IsSetTrue() const { return InputAt(0)->AsIntConstant()->IsTrue(); }
+ bool IsSetTrue() const {
+ // TODO: Remove "OrNull".
+ return InputAt(0)->AsIntConstantOrNull()->IsTrue();
+ }
// Vector predicates are not kept alive across vector loop boundaries.
bool CanBeMoved() const override { return false; }