Chromium Code Reviews| 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 12 matching lines...) Expand all Loading... | |
| 23 | 23 |
| 24 #ifndef SUBZERO_SRC_ICEASSEMBLER_H | 24 #ifndef SUBZERO_SRC_ICEASSEMBLER_H |
| 25 #define SUBZERO_SRC_ICEASSEMBLER_H | 25 #define SUBZERO_SRC_ICEASSEMBLER_H |
| 26 | 26 |
| 27 #include "IceDefs.h" | 27 #include "IceDefs.h" |
| 28 #include "IceFixups.h" | 28 #include "IceFixups.h" |
| 29 #include "IceUtils.h" | 29 #include "IceUtils.h" |
| 30 | 30 |
| 31 namespace Ice { | 31 namespace Ice { |
| 32 | 32 |
| 33 class GlobalContext; | |
|
Jim Stichnoth
2015/10/08 23:50:41
GlobalContext is already forward-declared in IceDe
John
2015/10/09 12:12:23
ah, the beauty of forward decs and cyclic includes
Jim Stichnoth
2015/10/09 13:36:30
Well, I tried out the patch and everything compile
Karl
2015/10/09 19:08:18
Removed.
| |
| 34 | |
| 33 /// A Label can be in one of three states: | 35 /// A Label can be in one of three states: |
| 34 /// - Unused. | 36 /// - Unused. |
| 35 /// - Linked, unplaced and tracking the position of branches to the label. | 37 /// - Linked, unplaced and tracking the position of branches to the label. |
| 36 /// - Bound, placed and tracking its position. | 38 /// - Bound, placed and tracking its position. |
| 37 class Label { | 39 class Label { |
| 38 Label(const Label &) = delete; | 40 Label(const Label &) = delete; |
| 39 Label &operator=(const Label &) = delete; | 41 Label &operator=(const Label &) = delete; |
| 40 | 42 |
| 41 public: | 43 public: |
| 42 Label() = default; | 44 Label() = default; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 57 /// Returns the position of an earlier branch instruction that was linked to | 59 /// Returns the position of an earlier branch instruction that was linked to |
| 58 /// this label (branches that use this are considered forward branches). The | 60 /// this label (branches that use this are considered forward branches). The |
| 59 /// linked instructions form a linked list, of sorts, using the instruction's | 61 /// 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 | 62 /// displacement field for the location of the next instruction that is also |
| 61 /// linked to this label. | 63 /// linked to this label. |
| 62 intptr_t getLinkPosition() const { | 64 intptr_t getLinkPosition() const { |
| 63 assert(isLinked()); | 65 assert(isLinked()); |
| 64 return Position - kWordSize; | 66 return Position - kWordSize; |
| 65 } | 67 } |
| 66 | 68 |
| 69 void setPosition(intptr_t NewValue) { Position = NewValue; } | |
| 70 | |
| 67 bool isBound() const { return Position < 0; } | 71 bool isBound() const { return Position < 0; } |
| 68 bool isLinked() const { return Position > 0; } | 72 bool isLinked() const { return Position > 0; } |
| 73 | |
| 69 virtual bool isUnused() const { return Position == 0; } | 74 virtual bool isUnused() const { return Position == 0; } |
| 70 | 75 |
| 71 protected: | |
| 72 void bindTo(intptr_t position) { | 76 void bindTo(intptr_t position) { |
| 73 assert(!isBound()); | 77 assert(!isBound()); |
| 74 Position = -position - kWordSize; | 78 Position = -position - kWordSize; |
| 75 assert(isBound()); | 79 assert(isBound()); |
| 76 } | 80 } |
| 77 | 81 |
| 82 protected: | |
| 78 void linkTo(intptr_t position) { | 83 void linkTo(intptr_t position) { |
| 79 assert(!isBound()); | 84 assert(!isBound()); |
| 80 Position = position + kWordSize; | 85 Position = position + kWordSize; |
| 81 assert(isLinked()); | 86 assert(isLinked()); |
| 82 } | 87 } |
| 83 | 88 |
| 84 intptr_t Position = 0; | 89 intptr_t Position = 0; |
| 85 | 90 |
| 86 private: | |
| 87 // TODO(jvoung): why are labels offset by this? | 91 // TODO(jvoung): why are labels offset by this? |
| 88 static constexpr uint32_t kWordSize = sizeof(uint32_t); | 92 static constexpr uint32_t kWordSize = sizeof(uint32_t); |
| 89 }; | 93 }; |
| 90 | 94 |
| 91 /// Assembler buffers are used to emit binary code. They grow on demand. | 95 /// Assembler buffers are used to emit binary code. They grow on demand. |
| 92 class AssemblerBuffer { | 96 class AssemblerBuffer { |
| 93 AssemblerBuffer(const AssemblerBuffer &) = delete; | 97 AssemblerBuffer(const AssemblerBuffer &) = delete; |
| 94 AssemblerBuffer &operator=(const AssemblerBuffer &) = delete; | 98 AssemblerBuffer &operator=(const AssemblerBuffer &) = delete; |
| 95 | 99 |
| 96 public: | 100 public: |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 | 269 |
| 266 // Return a view of all the bytes of code for the current function. | 270 // Return a view of all the bytes of code for the current function. |
| 267 llvm::StringRef getBufferView() const; | 271 llvm::StringRef getBufferView() const; |
| 268 | 272 |
| 269 const FixupRefList &fixups() const { return Buffer.fixups(); } | 273 const FixupRefList &fixups() const { return Buffer.fixups(); } |
| 270 | 274 |
| 271 AssemblerFixup *createFixup(FixupKind Kind, const Constant *Value) { | 275 AssemblerFixup *createFixup(FixupKind Kind, const Constant *Value) { |
| 272 return Buffer.createFixup(Kind, Value); | 276 return Buffer.createFixup(Kind, Value); |
| 273 } | 277 } |
| 274 | 278 |
| 279 // TODO(kschimpf): Remove Ctx argument, no longer needed. | |
|
Jim Stichnoth
2015/10/08 23:50:41
Can you just do it now, and not leave a TODO?
| |
| 275 void emitIASBytes(GlobalContext *Ctx) const; | 280 void emitIASBytes(GlobalContext *Ctx) const; |
|
John
2015/10/09 12:12:23
Just a personal preference, but I would not introd
Karl
2015/10/09 19:08:17
While I agree with this comment in general, the gl
| |
| 276 bool getInternal() const { return IsInternal; } | 281 bool getInternal() const { return IsInternal; } |
| 277 void setInternal(bool Internal) { IsInternal = Internal; } | 282 void setInternal(bool Internal) { IsInternal = Internal; } |
| 278 const IceString &getFunctionName() { return FunctionName; } | 283 const IceString &getFunctionName() { return FunctionName; } |
| 279 void setFunctionName(const IceString &NewName) { FunctionName = NewName; } | 284 void setFunctionName(const IceString &NewName) { FunctionName = NewName; } |
| 280 intptr_t getBufferSize() const { return Buffer.size(); } | 285 intptr_t getBufferSize() const { return Buffer.size(); } |
| 281 /// Roll back to a (smaller) size. | 286 /// Roll back to a (smaller) size. |
| 282 void setBufferSize(intptr_t NewSize) { Buffer.setSize(NewSize); } | 287 void setBufferSize(intptr_t NewSize) { Buffer.setSize(NewSize); } |
| 283 void setPreliminary(bool Value) { Preliminary = Value; } | 288 void setPreliminary(bool Value) { Preliminary = Value; } |
| 284 bool getPreliminary() const { return Preliminary; } | 289 bool getPreliminary() const { return Preliminary; } |
| 285 | 290 |
| 286 AssemblerKind getKind() const { return Kind; } | 291 AssemblerKind getKind() const { return Kind; } |
| 287 | 292 |
| 288 protected: | 293 protected: |
| 289 explicit Assembler(AssemblerKind Kind) | 294 explicit Assembler(AssemblerKind Kind, GlobalContext *Ctx) |
| 290 : Kind(Kind), Allocator(), Buffer(*this) {} | 295 : Kind(Kind), Allocator(), Ctx(Ctx), Buffer(*this) {} |
| 291 | 296 |
| 292 private: | 297 private: |
| 293 const AssemblerKind Kind; | 298 const AssemblerKind Kind; |
| 294 | 299 |
| 295 ArenaAllocator<32 * 1024> Allocator; | 300 ArenaAllocator<32 * 1024> Allocator; |
| 296 /// FunctionName and IsInternal are transferred from the original Cfg object, | 301 /// 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 | 302 /// since the Cfg object may be deleted by the time the assembler buffer is |
| 298 /// emitted. | 303 /// emitted. |
| 299 IceString FunctionName = ""; | 304 IceString FunctionName = ""; |
| 300 bool IsInternal = false; | 305 bool IsInternal = false; |
| 301 /// Preliminary indicates whether a preliminary pass is being made for | 306 /// Preliminary indicates whether a preliminary pass is being made for |
| 302 /// calculating bundle padding (Preliminary=true), versus the final pass where | 307 /// calculating bundle padding (Preliminary=true), versus the final pass where |
| 303 /// all changes to label bindings, label links, and relocation fixups are | 308 /// all changes to label bindings, label links, and relocation fixups are |
| 304 /// fully committed (Preliminary=false). | 309 /// fully committed (Preliminary=false). |
| 305 bool Preliminary = false; | 310 bool Preliminary = false; |
| 306 | 311 |
| 307 protected: | 312 protected: |
| 313 GlobalContext *Ctx; | |
| 308 // Buffer's constructor uses the Allocator, so it needs to appear after it. | 314 // 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 | 315 // TODO(jpp): dependencies on construction order are a nice way of shooting |
| 310 // yourself in the foot. Fix this. | 316 // yourself in the foot. Fix this. |
| 311 AssemblerBuffer Buffer; | 317 AssemblerBuffer Buffer; |
| 312 }; | 318 }; |
| 313 | 319 |
| 314 } // end of namespace Ice | 320 } // end of namespace Ice |
| 315 | 321 |
| 316 #endif // SUBZERO_SRC_ICEASSEMBLER_H_ | 322 #endif // SUBZERO_SRC_ICEASSEMBLER_H_ |
| OLD | NEW |