1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2016 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker #ifndef ART_COMPILER_OPTIMIZING_REGISTER_ALLOCATION_RESOLVER_H_ 18*795d594fSAndroid Build Coastguard Worker #define ART_COMPILER_OPTIMIZING_REGISTER_ALLOCATION_RESOLVER_H_ 19*795d594fSAndroid Build Coastguard Worker 20*795d594fSAndroid Build Coastguard Worker #include "base/array_ref.h" 21*795d594fSAndroid Build Coastguard Worker #include "base/macros.h" 22*795d594fSAndroid Build Coastguard Worker #include "base/value_object.h" 23*795d594fSAndroid Build Coastguard Worker #include "data_type.h" 24*795d594fSAndroid Build Coastguard Worker 25*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN { 26*795d594fSAndroid Build Coastguard Worker 27*795d594fSAndroid Build Coastguard Worker class ArenaAllocator; 28*795d594fSAndroid Build Coastguard Worker class CodeGenerator; 29*795d594fSAndroid Build Coastguard Worker class HBasicBlock; 30*795d594fSAndroid Build Coastguard Worker class HInstruction; 31*795d594fSAndroid Build Coastguard Worker class HParallelMove; 32*795d594fSAndroid Build Coastguard Worker class LiveInterval; 33*795d594fSAndroid Build Coastguard Worker class Location; 34*795d594fSAndroid Build Coastguard Worker class SsaLivenessAnalysis; 35*795d594fSAndroid Build Coastguard Worker 36*795d594fSAndroid Build Coastguard Worker /** 37*795d594fSAndroid Build Coastguard Worker * Reconciles the locations assigned to live intervals with the location 38*795d594fSAndroid Build Coastguard Worker * summary of each instruction, and inserts moves to resolve split intervals, 39*795d594fSAndroid Build Coastguard Worker * nonlinear control flow, and phi inputs. 40*795d594fSAndroid Build Coastguard Worker */ 41*795d594fSAndroid Build Coastguard Worker class RegisterAllocationResolver : ValueObject { 42*795d594fSAndroid Build Coastguard Worker public: 43*795d594fSAndroid Build Coastguard Worker RegisterAllocationResolver(CodeGenerator* codegen, const SsaLivenessAnalysis& liveness); 44*795d594fSAndroid Build Coastguard Worker 45*795d594fSAndroid Build Coastguard Worker void Resolve(ArrayRef<HInstruction* const> safepoints, 46*795d594fSAndroid Build Coastguard Worker size_t reserved_out_slots, // Includes slot(s) for the art method. 47*795d594fSAndroid Build Coastguard Worker size_t int_spill_slots, 48*795d594fSAndroid Build Coastguard Worker size_t long_spill_slots, 49*795d594fSAndroid Build Coastguard Worker size_t float_spill_slots, 50*795d594fSAndroid Build Coastguard Worker size_t double_spill_slots, 51*795d594fSAndroid Build Coastguard Worker size_t catch_phi_spill_slots, 52*795d594fSAndroid Build Coastguard Worker ArrayRef<LiveInterval* const> temp_intervals); 53*795d594fSAndroid Build Coastguard Worker 54*795d594fSAndroid Build Coastguard Worker private: 55*795d594fSAndroid Build Coastguard Worker // Update live registers of safepoint location summary. 56*795d594fSAndroid Build Coastguard Worker void UpdateSafepointLiveRegisters(); 57*795d594fSAndroid Build Coastguard Worker 58*795d594fSAndroid Build Coastguard Worker // Calculate the maximum size of the spill area for safepoints. 59*795d594fSAndroid Build Coastguard Worker size_t CalculateMaximumSafepointSpillSize(ArrayRef<HInstruction* const> safepoints); 60*795d594fSAndroid Build Coastguard Worker 61*795d594fSAndroid Build Coastguard Worker // Connect adjacent siblings within blocks, and resolve inputs along the way. 62*795d594fSAndroid Build Coastguard Worker void ConnectSiblings(LiveInterval* interval); 63*795d594fSAndroid Build Coastguard Worker 64*795d594fSAndroid Build Coastguard Worker // Connect siblings between block entries and exits. 65*795d594fSAndroid Build Coastguard Worker void ConnectSplitSiblings(LiveInterval* interval, HBasicBlock* from, HBasicBlock* to) const; 66*795d594fSAndroid Build Coastguard Worker 67*795d594fSAndroid Build Coastguard Worker // Helper methods for inserting parallel moves in the graph. 68*795d594fSAndroid Build Coastguard Worker void InsertParallelMoveAtExitOf(HBasicBlock* block, 69*795d594fSAndroid Build Coastguard Worker HInstruction* instruction, 70*795d594fSAndroid Build Coastguard Worker Location source, 71*795d594fSAndroid Build Coastguard Worker Location destination) const; 72*795d594fSAndroid Build Coastguard Worker void InsertParallelMoveAtEntryOf(HBasicBlock* block, 73*795d594fSAndroid Build Coastguard Worker HInstruction* instruction, 74*795d594fSAndroid Build Coastguard Worker Location source, 75*795d594fSAndroid Build Coastguard Worker Location destination) const; 76*795d594fSAndroid Build Coastguard Worker void InsertMoveAfter(HInstruction* instruction, Location source, Location destination) const; 77*795d594fSAndroid Build Coastguard Worker void AddInputMoveFor(HInstruction* input, 78*795d594fSAndroid Build Coastguard Worker HInstruction* user, 79*795d594fSAndroid Build Coastguard Worker Location source, 80*795d594fSAndroid Build Coastguard Worker Location destination) const; 81*795d594fSAndroid Build Coastguard Worker void InsertParallelMoveAt(size_t position, 82*795d594fSAndroid Build Coastguard Worker HInstruction* instruction, 83*795d594fSAndroid Build Coastguard Worker Location source, 84*795d594fSAndroid Build Coastguard Worker Location destination) const; 85*795d594fSAndroid Build Coastguard Worker void AddMove(HParallelMove* move, 86*795d594fSAndroid Build Coastguard Worker Location source, 87*795d594fSAndroid Build Coastguard Worker Location destination, 88*795d594fSAndroid Build Coastguard Worker HInstruction* instruction, 89*795d594fSAndroid Build Coastguard Worker DataType::Type type) const; 90*795d594fSAndroid Build Coastguard Worker 91*795d594fSAndroid Build Coastguard Worker ArenaAllocator* const allocator_; 92*795d594fSAndroid Build Coastguard Worker CodeGenerator* const codegen_; 93*795d594fSAndroid Build Coastguard Worker const SsaLivenessAnalysis& liveness_; 94*795d594fSAndroid Build Coastguard Worker 95*795d594fSAndroid Build Coastguard Worker DISALLOW_COPY_AND_ASSIGN(RegisterAllocationResolver); 96*795d594fSAndroid Build Coastguard Worker }; 97*795d594fSAndroid Build Coastguard Worker 98*795d594fSAndroid Build Coastguard Worker } // namespace art 99*795d594fSAndroid Build Coastguard Worker 100*795d594fSAndroid Build Coastguard Worker #endif // ART_COMPILER_OPTIMIZING_REGISTER_ALLOCATION_RESOLVER_H_ 101