From f7bd87edf3b80ce3bbd6e571fd119c878cb79992 Mon Sep 17 00:00:00 2001 From: Nicolas Geoffray Date: Thu, 23 Dec 2021 18:07:38 +0000 Subject: 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 --- compiler/optimizing/instruction_builder.cc | 45 +++++++++++++++++++----------- 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'compiler/optimizing/instruction_builder.cc') 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 -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 -void HInstructionBuilder::If_21t(const Instruction& instruction, uint32_t dex_pc) { +template +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(instruction, dex_pc); break; \ - case Instruction::IF_##cond##Z: If_21t(instruction, dex_pc); break + case Instruction::IF_##cond: \ + If_21_22t(instruction, dex_pc); \ + break; \ + case Instruction::IF_##cond##Z: \ + If_21_22t(instruction, dex_pc); \ + break; IF_XX(HEqual, EQ); IF_XX(HNotEqual, NE); -- cgit v1.2.3-59-g8ed1b