From 372f10e5b0b34e2bb6e2b79aeba6c441e14afd1f Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Tue, 17 May 2016 16:30:10 +0100 Subject: Refactor handling of input records. Introduce HInstruction::GetInputRecords(), a new virtual function that returns an ArrayRef<> to all input records. Implement all other functions dealing with input records as wrappers around GetInputRecords(). Rewrite functions that previously used multiple virtual calls to deal with input records, especially in loops, to prefetch the ArrayRef<> only once for each instruction. Besides avoiding all the extra calls, this also allows the compiler (clang++) to perform additional optimizations. This speeds up the Nexus 5 boot image compilation by ~0.5s (4% of "Compile Dex File", 2% of dex2oat time) on AOSP ToT. Change-Id: Id8ebe0fb9405e38d918972a11bd724146e4ca578 --- compiler/optimizing/register_allocator.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'compiler/optimizing/register_allocator.cc') diff --git a/compiler/optimizing/register_allocator.cc b/compiler/optimizing/register_allocator.cc index 4405b803e0..4a6b835e80 100644 --- a/compiler/optimizing/register_allocator.cc +++ b/compiler/optimizing/register_allocator.cc @@ -305,7 +305,7 @@ void RegisterAllocator::ProcessInstruction(HInstruction* instruction) { BlockRegisters(position, position + 1, /* caller_save_only */ true); } - for (size_t i = 0; i < instruction->InputCount(); ++i) { + for (size_t i = 0; i < locations->GetInputCount(); ++i) { Location input = locations->InAt(i); if (input.IsRegister() || input.IsFpuRegister()) { BlockRegister(input, position, position + 1); @@ -753,10 +753,11 @@ bool RegisterAllocator::TryAllocateFreeReg(LiveInterval* current) { if (defined_by != nullptr && !current->IsSplit()) { LocationSummary* locations = defined_by->GetLocations(); if (!locations->OutputCanOverlapWithInputs() && locations->Out().IsUnallocated()) { - for (size_t i = 0, e = defined_by->InputCount(); i < e; ++i) { + auto&& inputs = defined_by->GetInputs(); + for (size_t i = 0; i < inputs.size(); ++i) { // Take the last interval of the input. It is the location of that interval // that will be used at `defined_by`. - LiveInterval* interval = defined_by->InputAt(i)->GetLiveInterval()->GetLastSibling(); + LiveInterval* interval = inputs[i]->GetLiveInterval()->GetLastSibling(); // Note that interval may have not been processed yet. // TODO: Handle non-split intervals last in the work list. if (locations->InAt(i).IsValid() -- cgit v1.2.3-59-g8ed1b