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