OLD | NEW |
1 //===- subzero/src/IceAssembler.h - Integrated assembler --------*- C++ -*-===// | 1 //===- subzero/src/IceAssembler.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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 /// Returns the position of an earlier branch instruction that was linked to | 57 /// Returns the position of an earlier branch instruction that was linked to |
58 /// this label (branches that use this are considered forward branches). The | 58 /// this label (branches that use this are considered forward branches). The |
59 /// linked instructions form a linked list, of sorts, using the instruction's | 59 /// linked instructions form a linked list, of sorts, using the instruction's |
60 /// displacement field for the location of the next instruction that is also | 60 /// displacement field for the location of the next instruction that is also |
61 /// linked to this label. | 61 /// linked to this label. |
62 intptr_t getLinkPosition() const { | 62 intptr_t getLinkPosition() const { |
63 assert(isLinked()); | 63 assert(isLinked()); |
64 return Position - kWordSize; | 64 return Position - kWordSize; |
65 } | 65 } |
66 | 66 |
| 67 void setPosition(intptr_t NewValue) { Position = NewValue; } |
| 68 |
67 bool isBound() const { return Position < 0; } | 69 bool isBound() const { return Position < 0; } |
68 bool isLinked() const { return Position > 0; } | 70 bool isLinked() const { return Position > 0; } |
| 71 |
69 virtual bool isUnused() const { return Position == 0; } | 72 virtual bool isUnused() const { return Position == 0; } |
70 | 73 |
71 protected: | |
72 void bindTo(intptr_t position) { | 74 void bindTo(intptr_t position) { |
73 assert(!isBound()); | 75 assert(!isBound()); |
74 Position = -position - kWordSize; | 76 Position = -position - kWordSize; |
75 assert(isBound()); | 77 assert(isBound()); |
76 } | 78 } |
77 | 79 |
| 80 protected: |
78 void linkTo(intptr_t position) { | 81 void linkTo(intptr_t position) { |
79 assert(!isBound()); | 82 assert(!isBound()); |
80 Position = position + kWordSize; | 83 Position = position + kWordSize; |
81 assert(isLinked()); | 84 assert(isLinked()); |
82 } | 85 } |
83 | 86 |
84 intptr_t Position = 0; | 87 intptr_t Position = 0; |
85 | 88 |
86 private: | |
87 // TODO(jvoung): why are labels offset by this? | 89 // TODO(jvoung): why are labels offset by this? |
88 static constexpr uint32_t kWordSize = sizeof(uint32_t); | 90 static constexpr uint32_t kWordSize = sizeof(uint32_t); |
89 }; | 91 }; |
90 | 92 |
91 /// Assembler buffers are used to emit binary code. They grow on demand. | 93 /// Assembler buffers are used to emit binary code. They grow on demand. |
92 class AssemblerBuffer { | 94 class AssemblerBuffer { |
93 AssemblerBuffer(const AssemblerBuffer &) = delete; | 95 AssemblerBuffer(const AssemblerBuffer &) = delete; |
94 AssemblerBuffer &operator=(const AssemblerBuffer &) = delete; | 96 AssemblerBuffer &operator=(const AssemblerBuffer &) = delete; |
95 | 97 |
96 public: | 98 public: |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 267 |
266 // Return a view of all the bytes of code for the current function. | 268 // Return a view of all the bytes of code for the current function. |
267 llvm::StringRef getBufferView() const; | 269 llvm::StringRef getBufferView() const; |
268 | 270 |
269 const FixupRefList &fixups() const { return Buffer.fixups(); } | 271 const FixupRefList &fixups() const { return Buffer.fixups(); } |
270 | 272 |
271 AssemblerFixup *createFixup(FixupKind Kind, const Constant *Value) { | 273 AssemblerFixup *createFixup(FixupKind Kind, const Constant *Value) { |
272 return Buffer.createFixup(Kind, Value); | 274 return Buffer.createFixup(Kind, Value); |
273 } | 275 } |
274 | 276 |
275 void emitIASBytes(GlobalContext *Ctx) const; | 277 void emitIASBytes() const; |
276 bool getInternal() const { return IsInternal; } | 278 bool getInternal() const { return IsInternal; } |
277 void setInternal(bool Internal) { IsInternal = Internal; } | 279 void setInternal(bool Internal) { IsInternal = Internal; } |
278 const IceString &getFunctionName() { return FunctionName; } | 280 const IceString &getFunctionName() { return FunctionName; } |
279 void setFunctionName(const IceString &NewName) { FunctionName = NewName; } | 281 void setFunctionName(const IceString &NewName) { FunctionName = NewName; } |
280 intptr_t getBufferSize() const { return Buffer.size(); } | 282 intptr_t getBufferSize() const { return Buffer.size(); } |
281 /// Roll back to a (smaller) size. | 283 /// Roll back to a (smaller) size. |
282 void setBufferSize(intptr_t NewSize) { Buffer.setSize(NewSize); } | 284 void setBufferSize(intptr_t NewSize) { Buffer.setSize(NewSize); } |
283 void setPreliminary(bool Value) { Preliminary = Value; } | 285 void setPreliminary(bool Value) { Preliminary = Value; } |
284 bool getPreliminary() const { return Preliminary; } | 286 bool getPreliminary() const { return Preliminary; } |
285 | 287 |
286 AssemblerKind getKind() const { return Kind; } | 288 AssemblerKind getKind() const { return Kind; } |
287 | 289 |
288 protected: | 290 protected: |
289 explicit Assembler(AssemblerKind Kind) | 291 explicit Assembler(AssemblerKind Kind, GlobalContext *Ctx) |
290 : Kind(Kind), Allocator(), Buffer(*this) {} | 292 : Kind(Kind), Allocator(), Ctx(Ctx), Buffer(*this) {} |
291 | 293 |
292 private: | 294 private: |
293 const AssemblerKind Kind; | 295 const AssemblerKind Kind; |
294 | 296 |
295 ArenaAllocator<32 * 1024> Allocator; | 297 ArenaAllocator<32 * 1024> Allocator; |
296 /// FunctionName and IsInternal are transferred from the original Cfg object, | 298 /// FunctionName and IsInternal are transferred from the original Cfg object, |
297 /// since the Cfg object may be deleted by the time the assembler buffer is | 299 /// since the Cfg object may be deleted by the time the assembler buffer is |
298 /// emitted. | 300 /// emitted. |
299 IceString FunctionName = ""; | 301 IceString FunctionName = ""; |
300 bool IsInternal = false; | 302 bool IsInternal = false; |
301 /// Preliminary indicates whether a preliminary pass is being made for | 303 /// Preliminary indicates whether a preliminary pass is being made for |
302 /// calculating bundle padding (Preliminary=true), versus the final pass where | 304 /// calculating bundle padding (Preliminary=true), versus the final pass where |
303 /// all changes to label bindings, label links, and relocation fixups are | 305 /// all changes to label bindings, label links, and relocation fixups are |
304 /// fully committed (Preliminary=false). | 306 /// fully committed (Preliminary=false). |
305 bool Preliminary = false; | 307 bool Preliminary = false; |
306 | 308 |
307 protected: | 309 protected: |
| 310 GlobalContext *Ctx; |
308 // Buffer's constructor uses the Allocator, so it needs to appear after it. | 311 // Buffer's constructor uses the Allocator, so it needs to appear after it. |
309 // TODO(jpp): dependencies on construction order are a nice way of shooting | 312 // TODO(jpp): dependencies on construction order are a nice way of shooting |
310 // yourself in the foot. Fix this. | 313 // yourself in the foot. Fix this. |
311 AssemblerBuffer Buffer; | 314 AssemblerBuffer Buffer; |
312 }; | 315 }; |
313 | 316 |
314 } // end of namespace Ice | 317 } // end of namespace Ice |
315 | 318 |
316 #endif // SUBZERO_SRC_ICEASSEMBLER_H_ | 319 #endif // SUBZERO_SRC_ICEASSEMBLER_H_ |
OLD | NEW |