| OLD | NEW |
| 1 //===- subzero/src/assembler.h - Integrated assembler -----------*- C++ -*-===// | 1 //===- subzero/src/assembler.h - Integrated assembler -----------*- C++ -*-===// |
| 2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
| 4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
| 5 // | 5 // |
| 6 // Modified by the Subzero authors. | 6 // Modified by the Subzero authors. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // The Subzero Code Generator | 10 // The Subzero Code Generator |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 155 |
| 156 // When building the C++ tests, assertion code is enabled. To allow | 156 // When building the C++ tests, assertion code is enabled. To allow |
| 157 // asserting that the user of the assembler buffer has ensured the | 157 // asserting that the user of the assembler buffer has ensured the |
| 158 // capacity needed for emitting, we add a dummy method in non-debug mode. | 158 // capacity needed for emitting, we add a dummy method in non-debug mode. |
| 159 bool HasEnsuredCapacity() const { return true; } | 159 bool HasEnsuredCapacity() const { return true; } |
| 160 #endif // NDEBUG | 160 #endif // NDEBUG |
| 161 | 161 |
| 162 // Returns the position in the instruction stream. | 162 // Returns the position in the instruction stream. |
| 163 intptr_t GetPosition() const { return cursor_ - contents_; } | 163 intptr_t GetPosition() const { return cursor_ - contents_; } |
| 164 | 164 |
| 165 // For bringup only. | 165 // List of pool-allocated fixups. |
| 166 AssemblerFixup *GetLatestFixup(intptr_t position) const; | 166 typedef std::vector<AssemblerFixup *> FixupList; |
| 167 FixupList::const_iterator fixups_begin() const { return fixups_.begin(); } |
| 168 FixupList::const_iterator fixups_end() const { return fixups_.end(); } |
| 167 | 169 |
| 168 private: | 170 private: |
| 169 // The limit is set to kMinimumGap bytes before the end of the data area. | 171 // The limit is set to kMinimumGap bytes before the end of the data area. |
| 170 // This leaves enough space for the longest possible instruction and allows | 172 // This leaves enough space for the longest possible instruction and allows |
| 171 // for a single, fast space check per instruction. | 173 // for a single, fast space check per instruction. |
| 172 static const intptr_t kMinimumGap = 32; | 174 static const intptr_t kMinimumGap = 32; |
| 173 | 175 |
| 174 uintptr_t contents_; | 176 uintptr_t contents_; |
| 175 uintptr_t cursor_; | 177 uintptr_t cursor_; |
| 176 uintptr_t limit_; | 178 uintptr_t limit_; |
| 177 Assembler &assembler_; | 179 Assembler &assembler_; |
| 178 std::vector<AssemblerFixup *> fixups_; | 180 FixupList fixups_; |
| 179 #ifndef NDEBUG | 181 #ifndef NDEBUG |
| 180 bool fixups_processed_; | 182 bool fixups_processed_; |
| 181 #endif // !NDEBUG | 183 #endif // !NDEBUG |
| 182 | 184 |
| 183 uintptr_t cursor() const { return cursor_; } | 185 uintptr_t cursor() const { return cursor_; } |
| 184 uintptr_t limit() const { return limit_; } | 186 uintptr_t limit() const { return limit_; } |
| 185 intptr_t Capacity() const { | 187 intptr_t Capacity() const { |
| 186 assert(limit_ >= contents_); | 188 assert(limit_ >= contents_); |
| 187 return (limit_ - contents_) + kMinimumGap; | 189 return (limit_ - contents_) + kMinimumGap; |
| 188 } | 190 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 199 void ExtendCapacity(); | 201 void ExtendCapacity(); |
| 200 | 202 |
| 201 friend class AssemblerFixup; | 203 friend class AssemblerFixup; |
| 202 }; | 204 }; |
| 203 | 205 |
| 204 class Assembler { | 206 class Assembler { |
| 205 Assembler(const Assembler &) = delete; | 207 Assembler(const Assembler &) = delete; |
| 206 Assembler &operator=(const Assembler &) = delete; | 208 Assembler &operator=(const Assembler &) = delete; |
| 207 | 209 |
| 208 public: | 210 public: |
| 209 Assembler() {} | 211 Assembler() : buffer_(*this) {} |
| 210 virtual ~Assembler() {} | 212 virtual ~Assembler() {} |
| 211 | 213 |
| 212 // Allocate a chunk of bytes using the per-Assembler allocator. | 214 // Allocate a chunk of bytes using the per-Assembler allocator. |
| 213 uintptr_t AllocateBytes(size_t bytes) { | 215 uintptr_t AllocateBytes(size_t bytes) { |
| 214 // For now, alignment is not related to NaCl bundle alignment, since | 216 // For now, alignment is not related to NaCl bundle alignment, since |
| 215 // the buffer's GetPosition is relative to the base. So NaCl bundle | 217 // the buffer's GetPosition is relative to the base. So NaCl bundle |
| 216 // alignment checks can be relative to that base. Later, the buffer | 218 // alignment checks can be relative to that base. Later, the buffer |
| 217 // will be copied out to a ".text" section (or an in memory-buffer | 219 // will be copied out to a ".text" section (or an in memory-buffer |
| 218 // that can be mprotect'ed with executable permission), and that | 220 // that can be mprotect'ed with executable permission), and that |
| 219 // second buffer should be aligned for NaCl. | 221 // second buffer should be aligned for NaCl. |
| 220 const size_t Alignment = 16; | 222 const size_t Alignment = 16; |
| 221 return reinterpret_cast<uintptr_t>(Allocator.Allocate(bytes, Alignment)); | 223 return reinterpret_cast<uintptr_t>(Allocator.Allocate(bytes, Alignment)); |
| 222 } | 224 } |
| 223 | 225 |
| 224 // Allocate data of type T using the per-Assembler allocator. | 226 // Allocate data of type T using the per-Assembler allocator. |
| 225 template <typename T> T *Allocate() { return Allocator.Allocate<T>(); } | 227 template <typename T> T *Allocate() { return Allocator.Allocate<T>(); } |
| 226 | 228 |
| 227 virtual void BindCfgNodeLabel(SizeT NodeNumber) = 0; | 229 virtual void BindCfgNodeLabel(SizeT NodeNumber) = 0; |
| 228 | 230 |
| 231 void emitIASBytes(GlobalContext *Ctx) const; |
| 232 |
| 229 private: | 233 private: |
| 230 llvm::BumpPtrAllocator Allocator; | 234 llvm::BumpPtrAllocator Allocator; |
| 235 |
| 236 protected: |
| 237 AssemblerBuffer buffer_; |
| 231 }; | 238 }; |
| 232 | 239 |
| 233 } // end of namespace Ice | 240 } // end of namespace Ice |
| 234 | 241 |
| 235 #endif // SUBZERO_SRC_ASSEMBLER_H_ | 242 #endif // SUBZERO_SRC_ASSEMBLER_H_ |
| OLD | NEW |