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/arena_containers.h" 21 #include "base/array_ref.h" 22 #include "base/value_object.h" 23 #include "primitive.h" 24 25 namespace art { 26 27 class ArenaAllocator; 28 class CodeGenerator; 29 class HBasicBlock; 30 class HInstruction; 31 class HParallelMove; 32 class LiveInterval; 33 class Location; 34 class SsaLivenessAnalysis; 35 36 /** 37 * Reconciles the locations assigned to live intervals with the location 38 * summary of each instruction, and inserts moves to resolve split intervals, 39 * nonlinear control flow, and phi inputs. 40 */ 41 class RegisterAllocationResolver : ValueObject { 42 public: 43 RegisterAllocationResolver(ArenaAllocator* allocator, 44 CodeGenerator* codegen, 45 const SsaLivenessAnalysis& liveness); 46 47 void Resolve(ArrayRef<HInstruction* const> safepoints, 48 size_t reserved_out_slots, // Includes slot(s) for the art method. 49 size_t int_spill_slots, 50 size_t long_spill_slots, 51 size_t float_spill_slots, 52 size_t double_spill_slots, 53 size_t catch_phi_spill_slots, 54 const ArenaVector<LiveInterval*>& temp_intervals); 55 56 private: 57 // Update live registers of safepoint location summary. 58 void UpdateSafepointLiveRegisters(); 59 60 // Calculate the maximum size of the spill area for safepoints. 61 size_t CalculateMaximumSafepointSpillSize(ArrayRef<HInstruction* const> safepoints); 62 63 // Connect adjacent siblings within blocks, and resolve inputs along the way. 64 void ConnectSiblings(LiveInterval* interval); 65 66 // Connect siblings between block entries and exits. 67 void ConnectSplitSiblings(LiveInterval* interval, HBasicBlock* from, HBasicBlock* to) const; 68 69 // Helper methods for inserting parallel moves in the graph. 70 void InsertParallelMoveAtExitOf(HBasicBlock* block, 71 HInstruction* instruction, 72 Location source, 73 Location destination) const; 74 void InsertParallelMoveAtEntryOf(HBasicBlock* block, 75 HInstruction* instruction, 76 Location source, 77 Location destination) const; 78 void InsertMoveAfter(HInstruction* instruction, Location source, Location destination) const; 79 void AddInputMoveFor(HInstruction* input, 80 HInstruction* user, 81 Location source, 82 Location destination) const; 83 void InsertParallelMoveAt(size_t position, 84 HInstruction* instruction, 85 Location source, 86 Location destination) const; 87 void AddMove(HParallelMove* move, 88 Location source, 89 Location destination, 90 HInstruction* instruction, 91 Primitive::Type type) const; 92 93 ArenaAllocator* const allocator_; 94 CodeGenerator* const codegen_; 95 const SsaLivenessAnalysis& liveness_; 96 97 DISALLOW_COPY_AND_ASSIGN(RegisterAllocationResolver); 98 }; 99 100 } // namespace art 101 102 #endif // ART_COMPILER_OPTIMIZING_REGISTER_ALLOCATION_RESOLVER_H_ 103