blob: ffe091414ad62e795508905662eafaa602930ebc [file] [log] [blame]
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001/*
2 * Copyright (C) 2012 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_SRC_GREENLAND_REGISTER_ALLOCATOR_H_
18#define ART_SRC_GREENLAND_REGISTER_ALLOCATOR_H_
19
20#include "backend_types.h"
21
22#include "lir_basic_block.h"
23
24#include <stdint.h>
25#include <list>
26#include <map>
27
28namespace art {
29namespace greenland {
30
31class LIR;
32class LIRFunction;
33class TargetRegisterInfo;
34
35class RegisterAllocator {
36 private:
37 enum RegTypeTag {
38 kPhyRegType = 0, kFrameType, kInStackType, kNoneType = -1
39 };
40
41 struct Storage {
42 int index;
43 RegTypeTag regTag;
44 };
45
46 // Storage Allocation
47 Storage AllocateStorage(LIRFunction &lir_func, unsigned vreg_idx);
48 void KeepStorage(const LIR& lir);
49 void FreeStorage(unsigned vreg_idx);
50 void HandleInsnCopy(LIRBasicBlock& bb,
51 LIRBasicBlock::iterator it,
52 LIRBasicBlock::iterator next_lir);
53
54 // Pre-RA
55 void BuildKillInfo(LIRFunction& lir_func);
56 void PHIElimination(LIRFunction& lir_func);
57
58 void InitializeAllocation(LIRFunction& lir_func);
59 void PreRegisterAllocation(LIRFunction& lir_func);
60 void FunctionRegisterAllocation(LIRFunction& lir_func);
61 public:
62 RegisterAllocator(const TargetRegisterInfo& info) : reg_info_(info) { }
63 ~RegisterAllocator() { }
64
65 void AllocateRegisters(LIRFunction& lir_func) {
66 InitializeAllocation(lir_func);
67 PreRegisterAllocation(lir_func);
68 FunctionRegisterAllocation(lir_func);
69 }
70
71 private:
72 std::list<unsigned> allocatable_list_;
73 std::list<unsigned> stackstorage_list_;
74 std::map<unsigned, Storage> allocated_map_;
75 const TargetRegisterInfo& reg_info_;
76 DISALLOW_COPY_AND_ASSIGN(RegisterAllocator);
77};
78
79} // namespace greenland
80} // namespace art
81
82#endif // ART_SRC_GREENLAND_REGISTER_ALLOCATOR_H_