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 17 matching lines...) Expand all Loading... |
28 #include "IceFixups.h" | 28 #include "IceFixups.h" |
29 #include "llvm/Support/Allocator.h" | 29 #include "llvm/Support/Allocator.h" |
30 | 30 |
31 namespace Ice { | 31 namespace Ice { |
32 | 32 |
33 // Forward declarations. | 33 // Forward declarations. |
34 class Assembler; | 34 class Assembler; |
35 class AssemblerFixup; | 35 class AssemblerFixup; |
36 class AssemblerBuffer; | 36 class AssemblerBuffer; |
37 class ConstantRelocatable; | 37 class ConstantRelocatable; |
38 class MemoryRegion; | |
39 | 38 |
40 // Assembler fixups are positions in generated code that hold relocation | 39 // Assembler fixups are positions in generated code that hold relocation |
41 // information that needs to be processed before finalizing the code | 40 // information that needs to be processed before finalizing the code |
42 // into executable memory. | 41 // into executable memory. |
43 class AssemblerFixup { | 42 class AssemblerFixup { |
44 AssemblerFixup(const AssemblerFixup &) = delete; | 43 AssemblerFixup(const AssemblerFixup &) = delete; |
45 AssemblerFixup &operator=(const AssemblerFixup &) = delete; | 44 AssemblerFixup &operator=(const AssemblerFixup &) = delete; |
46 | 45 |
47 public: | 46 public: |
48 virtual void Process(const MemoryRegion ®ion, intptr_t position) = 0; | |
49 | 47 |
50 // It would be ideal if the destructor method could be made private, | 48 // It would be ideal if the destructor method could be made private, |
51 // but the g++ compiler complains when this is subclassed. | 49 // but the g++ compiler complains when this is subclassed. |
52 virtual ~AssemblerFixup() { llvm_unreachable("~AssemblerFixup used"); } | 50 virtual ~AssemblerFixup() { llvm_unreachable("~AssemblerFixup used"); } |
53 | 51 |
54 intptr_t position() const { return position_; } | 52 intptr_t position() const { return position_; } |
55 | 53 |
56 FixupKind kind() const { return kind_; } | 54 FixupKind kind() const { return kind_; } |
57 | 55 |
58 const ConstantRelocatable *value() const { return value_; } | 56 const ConstantRelocatable *value() const { return value_; } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // Emit a fixup at the current location. | 100 // Emit a fixup at the current location. |
103 void EmitFixup(AssemblerFixup *fixup) { | 101 void EmitFixup(AssemblerFixup *fixup) { |
104 fixup->set_position(Size()); | 102 fixup->set_position(Size()); |
105 fixups_.push_back(fixup); | 103 fixups_.push_back(fixup); |
106 } | 104 } |
107 | 105 |
108 // Get the size of the emitted code. | 106 // Get the size of the emitted code. |
109 intptr_t Size() const { return cursor_ - contents_; } | 107 intptr_t Size() const { return cursor_ - contents_; } |
110 uintptr_t contents() const { return contents_; } | 108 uintptr_t contents() const { return contents_; } |
111 | 109 |
112 // Copy the assembled instructions into the specified memory block | |
113 // and apply all fixups. | |
114 // TODO(jvoung): This will be different. We'll be writing the text | |
115 // and reloc section to a file? | |
116 void FinalizeInstructions(const MemoryRegion ®ion); | |
117 | |
118 // To emit an instruction to the assembler buffer, the EnsureCapacity helper | 110 // To emit an instruction to the assembler buffer, the EnsureCapacity helper |
119 // must be used to guarantee that the underlying data area is big enough to | 111 // must be used to guarantee that the underlying data area is big enough to |
120 // hold the emitted instruction. Usage: | 112 // hold the emitted instruction. Usage: |
121 // | 113 // |
122 // AssemblerBuffer buffer; | 114 // AssemblerBuffer buffer; |
123 // AssemblerBuffer::EnsureCapacity ensured(&buffer); | 115 // AssemblerBuffer::EnsureCapacity ensured(&buffer); |
124 // ... emit bytes for single instruction ... | 116 // ... emit bytes for single instruction ... |
125 | 117 |
126 #ifndef NDEBUG | 118 #ifndef NDEBUG |
127 class EnsureCapacity { | 119 class EnsureCapacity { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 bool fixups_processed_; | 174 bool fixups_processed_; |
183 #endif // !NDEBUG | 175 #endif // !NDEBUG |
184 | 176 |
185 uintptr_t cursor() const { return cursor_; } | 177 uintptr_t cursor() const { return cursor_; } |
186 uintptr_t limit() const { return limit_; } | 178 uintptr_t limit() const { return limit_; } |
187 intptr_t Capacity() const { | 179 intptr_t Capacity() const { |
188 assert(limit_ >= contents_); | 180 assert(limit_ >= contents_); |
189 return (limit_ - contents_) + kMinimumGap; | 181 return (limit_ - contents_) + kMinimumGap; |
190 } | 182 } |
191 | 183 |
192 // Process the fixup chain. | |
193 void ProcessFixups(const MemoryRegion ®ion); | |
194 | |
195 // Compute the limit based on the data area and the capacity. See | 184 // Compute the limit based on the data area and the capacity. See |
196 // description of kMinimumGap for the reasoning behind the value. | 185 // description of kMinimumGap for the reasoning behind the value. |
197 static uintptr_t ComputeLimit(uintptr_t data, intptr_t capacity) { | 186 static uintptr_t ComputeLimit(uintptr_t data, intptr_t capacity) { |
198 return data + capacity - kMinimumGap; | 187 return data + capacity - kMinimumGap; |
199 } | 188 } |
200 | 189 |
201 void ExtendCapacity(); | 190 void ExtendCapacity(); |
202 | 191 |
203 friend class AssemblerFixup; | 192 friend class AssemblerFixup; |
204 }; | 193 }; |
(...skipping 14 matching lines...) Expand all Loading... |
219 // will be copied out to a ".text" section (or an in memory-buffer | 208 // will be copied out to a ".text" section (or an in memory-buffer |
220 // that can be mprotect'ed with executable permission), and that | 209 // that can be mprotect'ed with executable permission), and that |
221 // second buffer should be aligned for NaCl. | 210 // second buffer should be aligned for NaCl. |
222 const size_t Alignment = 16; | 211 const size_t Alignment = 16; |
223 return reinterpret_cast<uintptr_t>(Allocator.Allocate(bytes, Alignment)); | 212 return reinterpret_cast<uintptr_t>(Allocator.Allocate(bytes, Alignment)); |
224 } | 213 } |
225 | 214 |
226 // Allocate data of type T using the per-Assembler allocator. | 215 // Allocate data of type T using the per-Assembler allocator. |
227 template <typename T> T *Allocate() { return Allocator.Allocate<T>(); } | 216 template <typename T> T *Allocate() { return Allocator.Allocate<T>(); } |
228 | 217 |
| 218 // Align the tail end of the function to the required target alignment. |
| 219 virtual void alignFunction() = 0; |
| 220 |
| 221 virtual SizeT getBundleAlignLog2Bytes() const = 0; |
| 222 |
| 223 virtual llvm::ArrayRef<uint8_t> getNonExecBundlePadding() const = 0; |
| 224 |
| 225 // Mark the current text location as the start of a CFG node |
| 226 // (represented by NodeNumber). |
229 virtual void BindCfgNodeLabel(SizeT NodeNumber) = 0; | 227 virtual void BindCfgNodeLabel(SizeT NodeNumber) = 0; |
230 | 228 |
| 229 // Return a view of all the bytes of code for the current function. |
| 230 llvm::StringRef getBufferView() const; |
| 231 |
231 void emitIASBytes(GlobalContext *Ctx) const; | 232 void emitIASBytes(GlobalContext *Ctx) const; |
232 | 233 |
233 private: | 234 private: |
234 llvm::BumpPtrAllocator Allocator; | 235 llvm::BumpPtrAllocator Allocator; |
235 | 236 |
236 protected: | 237 protected: |
237 AssemblerBuffer buffer_; | 238 AssemblerBuffer buffer_; |
238 }; | 239 }; |
239 | 240 |
240 } // end of namespace Ice | 241 } // end of namespace Ice |
241 | 242 |
242 #endif // SUBZERO_SRC_ASSEMBLER_H_ | 243 #endif // SUBZERO_SRC_ASSEMBLER_H_ |
OLD | NEW |