summaryrefslogtreecommitdiff
path: root/compiler/optimizing/instruction_builder.cc
diff options
context:
space:
mode:
author Nicolas Geoffray <ngeoffray@google.com> 2021-12-23 18:07:38 +0000
committer Nicolas Geoffray <ngeoffray@google.com> 2023-10-17 08:34:49 +0000
commitf7bd87edf3b80ce3bbd6e571fd119c878cb79992 (patch)
treeb190e125c6e9f12040632644bf45ce7ab6fe82f7 /compiler/optimizing/instruction_builder.cc
parentb983874f2296c4d5a063d9e3d33f8a50fc865a09 (diff)
Add branch profiling in baseline compiler.
Currently unused. Follow-up CLs will make use of the data. Test: test.py Bug: 304969871 Change-Id: I486faba3de030061715d06ab9fdb33970d319d9b
Diffstat (limited to 'compiler/optimizing/instruction_builder.cc')
-rw-r--r--compiler/optimizing/instruction_builder.cc45
1 files changed, 29 insertions, 16 deletions
diff --git a/compiler/optimizing/instruction_builder.cc b/compiler/optimizing/instruction_builder.cc
index fd599f789e..281da6f9ec 100644
--- a/compiler/optimizing/instruction_builder.cc
+++ b/compiler/optimizing/instruction_builder.cc
@@ -665,22 +665,31 @@ void HInstructionBuilder::InitializeParameters() {
}
}
-template<typename T>
-void HInstructionBuilder::If_22t(const Instruction& instruction, uint32_t dex_pc) {
- HInstruction* first = LoadLocal(instruction.VRegA(), DataType::Type::kInt32);
- HInstruction* second = LoadLocal(instruction.VRegB(), DataType::Type::kInt32);
- T* comparison = new (allocator_) T(first, second, dex_pc);
- AppendInstruction(comparison);
- AppendInstruction(new (allocator_) HIf(comparison, dex_pc));
- current_block_ = nullptr;
-}
-
-template<typename T>
-void HInstructionBuilder::If_21t(const Instruction& instruction, uint32_t dex_pc) {
+template<typename T, bool kCompareWithZero>
+void HInstructionBuilder::If_21_22t(const Instruction& instruction, uint32_t dex_pc) {
HInstruction* value = LoadLocal(instruction.VRegA(), DataType::Type::kInt32);
- T* comparison = new (allocator_) T(value, graph_->GetIntConstant(0, dex_pc), dex_pc);
+ T* comparison = nullptr;
+ if (kCompareWithZero) {
+ comparison = new (allocator_) T(value, graph_->GetIntConstant(0, dex_pc), dex_pc);
+ } else {
+ HInstruction* second = LoadLocal(instruction.VRegB(), DataType::Type::kInt32);
+ comparison = new (allocator_) T(value, second, dex_pc);
+ }
AppendInstruction(comparison);
- AppendInstruction(new (allocator_) HIf(comparison, dex_pc));
+ HIf* if_instr = new (allocator_) HIf(comparison, dex_pc);
+
+ ProfilingInfo* info = graph_->GetProfilingInfo();
+ if (info != nullptr && !graph_->IsCompilingBaseline()) {
+ BranchCache* cache = info->GetBranchCache(dex_pc);
+ if (cache != nullptr) {
+ if_instr->SetTrueCount(cache->GetTrue());
+ if_instr->SetFalseCount(cache->GetFalse());
+ }
+ }
+
+ // Append after setting true/false count, so that the builder knows if the
+ // instruction needs an environment.
+ AppendInstruction(if_instr);
current_block_ = nullptr;
}
@@ -2879,8 +2888,12 @@ bool HInstructionBuilder::ProcessDexInstruction(const Instruction& instruction,
}
#define IF_XX(comparison, cond) \
- case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_pc); break; \
- case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_pc); break
+ case Instruction::IF_##cond: \
+ If_21_22t<comparison, /* kCompareWithZero= */ false>(instruction, dex_pc); \
+ break; \
+ case Instruction::IF_##cond##Z: \
+ If_21_22t<comparison, /* kCompareWithZero= */ true>(instruction, dex_pc); \
+ break;
IF_XX(HEqual, EQ);
IF_XX(HNotEqual, NE);