Chromium Code Reviews| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 #endif // NDEBUG | 108 #endif // NDEBUG |
| 109 | 109 |
| 110 // Returns the position in the instruction stream. | 110 // Returns the position in the instruction stream. |
| 111 intptr_t GetPosition() const { return cursor_ - contents_; } | 111 intptr_t GetPosition() const { return cursor_ - contents_; } |
| 112 | 112 |
| 113 // Create and track a fixup in the current function. | 113 // Create and track a fixup in the current function. |
| 114 AssemblerFixup *createFixup(FixupKind Kind, const Constant *Value); | 114 AssemblerFixup *createFixup(FixupKind Kind, const Constant *Value); |
| 115 | 115 |
| 116 const FixupRefList &fixups() const { return fixups_; } | 116 const FixupRefList &fixups() const { return fixups_; } |
| 117 | 117 |
| 118 void setSize(intptr_t NewSize) { | |
| 119 assert(NewSize <= Size()); | |
| 120 cursor_ = contents_ + NewSize; | |
| 121 } | |
| 122 | |
| 118 private: | 123 private: |
| 119 // The limit is set to kMinimumGap bytes before the end of the data area. | 124 // The limit is set to kMinimumGap bytes before the end of the data area. |
| 120 // This leaves enough space for the longest possible instruction and allows | 125 // This leaves enough space for the longest possible instruction and allows |
| 121 // for a single, fast space check per instruction. | 126 // for a single, fast space check per instruction. |
| 122 static const intptr_t kMinimumGap = 32; | 127 static const intptr_t kMinimumGap = 32; |
| 123 | 128 |
| 124 uintptr_t contents_; | 129 uintptr_t contents_; |
| 125 uintptr_t cursor_; | 130 uintptr_t cursor_; |
| 126 uintptr_t limit_; | 131 uintptr_t limit_; |
| 127 Assembler &assembler_; | 132 Assembler &assembler_; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 142 } | 147 } |
| 143 | 148 |
| 144 void ExtendCapacity(); | 149 void ExtendCapacity(); |
| 145 }; | 150 }; |
| 146 | 151 |
| 147 class Assembler { | 152 class Assembler { |
| 148 Assembler(const Assembler &) = delete; | 153 Assembler(const Assembler &) = delete; |
| 149 Assembler &operator=(const Assembler &) = delete; | 154 Assembler &operator=(const Assembler &) = delete; |
| 150 | 155 |
| 151 public: | 156 public: |
| 152 Assembler() : FunctionName(""), IsInternal(false), buffer_(*this) {} | 157 Assembler() |
| 158 : FunctionName(""), IsInternal(false), Preliminary(false), | |
| 159 buffer_(*this) {} | |
| 153 virtual ~Assembler() {} | 160 virtual ~Assembler() {} |
| 154 | 161 |
| 155 // Allocate a chunk of bytes using the per-Assembler allocator. | 162 // Allocate a chunk of bytes using the per-Assembler allocator. |
| 156 uintptr_t AllocateBytes(size_t bytes) { | 163 uintptr_t AllocateBytes(size_t bytes) { |
| 157 // For now, alignment is not related to NaCl bundle alignment, since | 164 // For now, alignment is not related to NaCl bundle alignment, since |
| 158 // the buffer's GetPosition is relative to the base. So NaCl bundle | 165 // the buffer's GetPosition is relative to the base. So NaCl bundle |
| 159 // alignment checks can be relative to that base. Later, the buffer | 166 // alignment checks can be relative to that base. Later, the buffer |
| 160 // will be copied out to a ".text" section (or an in memory-buffer | 167 // will be copied out to a ".text" section (or an in memory-buffer |
| 161 // that can be mprotect'ed with executable permission), and that | 168 // that can be mprotect'ed with executable permission), and that |
| 162 // second buffer should be aligned for NaCl. | 169 // second buffer should be aligned for NaCl. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 187 | 194 |
| 188 AssemblerFixup *createFixup(FixupKind Kind, const Constant *Value) { | 195 AssemblerFixup *createFixup(FixupKind Kind, const Constant *Value) { |
| 189 return buffer_.createFixup(Kind, Value); | 196 return buffer_.createFixup(Kind, Value); |
| 190 } | 197 } |
| 191 | 198 |
| 192 void emitIASBytes(GlobalContext *Ctx) const; | 199 void emitIASBytes(GlobalContext *Ctx) const; |
| 193 bool getInternal() const { return IsInternal; } | 200 bool getInternal() const { return IsInternal; } |
| 194 void setInternal(bool Internal) { IsInternal = Internal; } | 201 void setInternal(bool Internal) { IsInternal = Internal; } |
| 195 const IceString &getFunctionName() { return FunctionName; } | 202 const IceString &getFunctionName() { return FunctionName; } |
| 196 void setFunctionName(const IceString &NewName) { FunctionName = NewName; } | 203 void setFunctionName(const IceString &NewName) { FunctionName = NewName; } |
| 204 intptr_t getBufferSize() const { return buffer_.Size(); } | |
| 205 // Roll back to a (smaller) size. | |
| 206 void setBufferSize(intptr_t NewSize) { buffer_.setSize(NewSize); } | |
| 207 void setPreliminary(bool Value) { Preliminary = Value; } | |
| 208 bool getPreliminary() const { return Preliminary; } | |
| 209 // Add nop padding of a particular width. | |
| 210 virtual void padWithNop(intptr_t Padding) = 0; | |
|
jvoung (off chromium)
2015/02/19 21:01:47
Maybe put this padWithNop along with the alignFunc
Jim Stichnoth
2015/02/19 23:17:39
Done.
| |
| 197 | 211 |
| 198 private: | 212 private: |
| 199 ArenaAllocator<32 * 1024> Allocator; | 213 ArenaAllocator<32 * 1024> Allocator; |
| 200 // FunctionName and IsInternal are transferred from the original Cfg | 214 // FunctionName and IsInternal are transferred from the original Cfg |
| 201 // object, since the Cfg object may be deleted by the time the | 215 // object, since the Cfg object may be deleted by the time the |
| 202 // assembler buffer is emitted. | 216 // assembler buffer is emitted. |
| 203 IceString FunctionName; | 217 IceString FunctionName; |
| 204 bool IsInternal; | 218 bool IsInternal; |
| 219 bool Preliminary; | |
|
jvoung (off chromium)
2015/02/19 21:01:47
Document what Preliminary does
Jim Stichnoth
2015/02/19 23:17:39
Done.
| |
| 205 | 220 |
| 206 protected: | 221 protected: |
| 207 AssemblerBuffer buffer_; | 222 AssemblerBuffer buffer_; |
| 208 }; | 223 }; |
| 209 | 224 |
| 210 } // end of namespace Ice | 225 } // end of namespace Ice |
| 211 | 226 |
| 212 #endif // SUBZERO_SRC_ASSEMBLER_H_ | 227 #endif // SUBZERO_SRC_ASSEMBLER_H_ |
| OLD | NEW |