Clean up creating constant locations.
Change `Location::ConstantLocation()` to allow passing any
instruction and `DCHECK()` that it is indeed a constant.
Skip explicit calls to `HInstruction::AsConstant()` before
calling `Location::ConstantLocation()`.
Also cache results of `instuction->InputAt(.)` in some cases
when it's used more than once.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Test: run-gtests.sh
Test: testrunner.py --target --optimizing
Change-Id: I3c07642f6b3523b576ec229e4d234561ad74a20e
diff --git a/compiler/optimizing/locations.h b/compiler/optimizing/locations.h
index dc87284..7ee076f 100644
--- a/compiler/optimizing/locations.h
+++ b/compiler/optimizing/locations.h
@@ -103,8 +103,12 @@
return (value_ & kLocationConstantMask) == kConstant;
}
- static Location ConstantLocation(HConstant* constant) {
+ static Location ConstantLocation(HInstruction* constant) {
DCHECK(constant != nullptr);
+ if (kIsDebugBuild) {
+ // Call out-of-line helper to avoid circular dependency with `nodes.h`.
+ DCheckInstructionIsConstant(constant);
+ }
return Location(kConstant | reinterpret_cast<uintptr_t>(constant));
}
@@ -426,6 +430,8 @@
return PayloadField::Decode(value_);
}
+ static void DCheckInstructionIsConstant(HInstruction* instruction);
+
using KindField = BitField<Kind, 0, kBitsForKind>;
using PayloadField = BitField<uintptr_t, kBitsForKind, kBitsForPayload>;