Shih-wei Liao | e94d9b2 | 2012-05-22 09:01:24 -0700 | [diff] [blame] | 1 | /* |
| 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_LIR_FUNCTION_H_ |
| 18 | #define ART_SRC_GREENLAND_LIR_FUNCTION_H_ |
| 19 | |
| 20 | #include "lir.h" |
| 21 | |
| 22 | #include <llvm/ADT/ilist.h> |
| 23 | #include <llvm/Support/Allocator.h> |
| 24 | #include <llvm/Support/Recycler.h> |
| 25 | |
| 26 | namespace llvm { |
| 27 | |
| 28 | template <> |
| 29 | struct ilist_traits<art::greenland::LIR> : |
| 30 | public ilist_default_traits<art::greenland::LIR> { |
| 31 | private: |
| 32 | mutable ilist_half_node<art::greenland::LIR> sentinel_; |
| 33 | |
| 34 | friend class art::greenland::LIRFunction; |
| 35 | art::greenland::LIRFunction* parent_; |
| 36 | |
| 37 | public: |
| 38 | art::greenland::LIR *createSentinel() const { |
| 39 | return static_cast<art::greenland::LIR*>(&sentinel_); |
| 40 | } |
| 41 | void destroySentinel(art::greenland::LIR *) const {} |
| 42 | |
| 43 | art::greenland::LIR *provideInitialHead() const { |
| 44 | return createSentinel(); |
| 45 | } |
| 46 | art::greenland::LIR *ensureHead(art::greenland::LIR*) const { |
| 47 | return createSentinel(); |
| 48 | } |
| 49 | static void noteHead(art::greenland::LIR*, art::greenland::LIR*) {} |
| 50 | |
| 51 | void addNodeToList(art::greenland::LIR* N); |
| 52 | void removeNodeFromList(art::greenland::LIR* N); |
| 53 | void transferNodesFromList(ilist_traits &src_traits, |
| 54 | ilist_iterator<art::greenland::LIR> first, |
| 55 | ilist_iterator<art::greenland::LIR> last); |
| 56 | void deleteNode(art::greenland::LIR *N); |
| 57 | private: |
| 58 | void createNode(const art::greenland::LIR &); |
| 59 | }; |
| 60 | |
| 61 | } // namespace llvm |
| 62 | |
| 63 | namespace art { |
| 64 | namespace greenland { |
| 65 | |
| 66 | class LIRFrameInfo; |
| 67 | |
| 68 | class LIRFunction { |
| 69 | private: |
| 70 | llvm::ilist<LIR> lirs_; |
| 71 | |
| 72 | // Pool-allocate the objects reside in this instance |
| 73 | llvm::BumpPtrAllocator allocator_; |
| 74 | |
| 75 | // Allocation management for instructions in function. |
| 76 | llvm::Recycler<LIR> lir_recycler_; |
| 77 | |
| 78 | // The stack information |
| 79 | LIRFrameInfo* frame_info_; |
| 80 | |
| 81 | public: |
| 82 | LIRFunction(); |
| 83 | ~LIRFunction(); |
| 84 | |
| 85 | public: |
| 86 | //---------------------------------------------------------------------------- |
| 87 | // LIR Accessor Functions |
| 88 | //---------------------------------------------------------------------------- |
| 89 | typedef llvm::ilist<LIR>::iterator iterator; |
| 90 | typedef llvm::ilist<LIR>::const_iterator const_iterator; |
| 91 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 92 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 93 | |
| 94 | unsigned GetNumLIRs() const { |
| 95 | return static_cast<unsigned>(lirs_.size()); |
| 96 | } |
| 97 | bool IsEmpty() const { |
| 98 | return lirs_.empty(); |
| 99 | } |
| 100 | |
| 101 | LIR& front() { return lirs_.front(); } |
| 102 | LIR& back() { return lirs_.back(); } |
| 103 | const LIR& front() const { return lirs_.front(); } |
| 104 | const LIR& back() const { return lirs_.back(); } |
| 105 | |
| 106 | iterator begin() { return lirs_.begin(); } |
| 107 | const_iterator begin() const { return lirs_.begin(); } |
| 108 | iterator end() { return lirs_.end(); } |
| 109 | const_iterator end() const { return lirs_.end(); } |
| 110 | reverse_iterator rbegin() { return lirs_.rbegin(); } |
| 111 | const_reverse_iterator rbegin() const { return lirs_.rbegin(); } |
| 112 | reverse_iterator rend () { return lirs_.rend(); } |
| 113 | const_reverse_iterator rend () const { return lirs_.rend(); } |
| 114 | |
| 115 | void pop_front() { |
| 116 | lirs_.pop_front(); |
| 117 | } |
| 118 | |
| 119 | void push_back(LIR *lir) { |
| 120 | lirs_.push_back(lir); |
| 121 | } |
| 122 | |
| 123 | iterator insert(iterator i, LIR* lir) { |
| 124 | return lirs_.insert(i, lir); |
| 125 | } |
| 126 | |
| 127 | iterator erase(iterator i) { |
| 128 | return lirs_.erase(i); |
| 129 | } |
| 130 | |
| 131 | LIR* remove(iterator i) { |
| 132 | return lirs_.remove(i); |
| 133 | } |
| 134 | |
| 135 | public: |
| 136 | //---------------------------------------------------------------------------- |
| 137 | // LIR Memory Allocation |
| 138 | //---------------------------------------------------------------------------- |
| 139 | LIR* CreateLIR(const LIRDesc& desc); |
| 140 | |
| 141 | void DeleteLIR(LIR* lir); |
| 142 | |
| 143 | public: |
| 144 | const LIRFrameInfo& GetFrameInfo() const { |
| 145 | return *frame_info_; |
| 146 | } |
| 147 | LIRFrameInfo& GetFrameInfo() { |
| 148 | return *frame_info_; |
| 149 | } |
| 150 | |
| 151 | private: |
| 152 | DISALLOW_COPY_AND_ASSIGN(LIRFunction); |
| 153 | }; |
| 154 | |
| 155 | } // namespace greenland |
| 156 | } // namespace art |
| 157 | |
| 158 | #endif // ART_SRC_GREENLAND_LIR_FUNCTION_H_ |