Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: src/IceAssembler.h

Issue 1257283004: Iasm and obj lowering for advanced switch lowering. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 11 matching lines...) Expand all
22 //===----------------------------------------------------------------------===// 22 //===----------------------------------------------------------------------===//
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 29
30 namespace Ice { 30 namespace Ice {
31 31
32 /// A Label can be in one of three states:
33 /// - Unused.
34 /// - Linked, unplaced and tracking the position of branches to the label.
35 /// - Bound, placed and tracking its position.
36 class Label {
37 Label(const Label &) = delete;
38 Label &operator=(const Label &) = delete;
39
40 public:
41 Label() = default;
42 ~Label() = default;
43
44 virtual void finalCheck() const {
45 // Assert if label is being destroyed with unresolved branches pending.
46 assert(!isLinked());
47 }
48
49 // TODO(jvoung): why are labels offset by this?
50 static const uint32_t kWordSize = sizeof(uint32_t);
51
52 /// Returns the position for bound labels (branches that come after this are
53 /// considered backward branches). Cannot be used for unused or linked labels.
54 intptr_t getPosition() const {
55 assert(isBound());
56 return -Position - kWordSize;
57 }
58
59 /// Returns the position of an earlier branch instruction that was linked to
60 /// this label (branches that use this are considered forward branches). The
61 /// linked instructions form a linked list, of sorts, using the instruction's
62 /// displacement field for the location of the next instruction that is also
63 /// linked to this label.
64 intptr_t getLinkPosition() const {
65 assert(isLinked());
66 return Position - kWordSize;
67 }
68
69 bool isBound() const { return Position < 0; }
70 bool isLinked() const { return Position > 0; }
71 virtual bool isUnused() const { return Position == 0; }
72
73 protected:
74 void bindTo(intptr_t position) {
75 assert(!isBound());
76 Position = -position - kWordSize;
77 assert(isBound());
78 }
79
80 void linkTo(intptr_t position) {
81 assert(!isBound());
82 Position = position + kWordSize;
83 assert(isLinked());
84 }
85
86 intptr_t Position = 0;
87 };
88
32 /// Assembler buffers are used to emit binary code. They grow on demand. 89 /// Assembler buffers are used to emit binary code. They grow on demand.
33 class AssemblerBuffer { 90 class AssemblerBuffer {
34 AssemblerBuffer(const AssemblerBuffer &) = delete; 91 AssemblerBuffer(const AssemblerBuffer &) = delete;
35 AssemblerBuffer &operator=(const AssemblerBuffer &) = delete; 92 AssemblerBuffer &operator=(const AssemblerBuffer &) = delete;
36 93
37 public: 94 public:
38 AssemblerBuffer(Assembler &); 95 AssemblerBuffer(Assembler &);
39 ~AssemblerBuffer(); 96 ~AssemblerBuffer();
40 97
41 /// Basic support for emitting, loading, and storing. 98 /// Basic support for emitting, loading, and storing.
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // second buffer should be aligned for NaCl. 225 // second buffer should be aligned for NaCl.
169 const size_t Alignment = 16; 226 const size_t Alignment = 16;
170 return reinterpret_cast<uintptr_t>(Allocator.Allocate(bytes, Alignment)); 227 return reinterpret_cast<uintptr_t>(Allocator.Allocate(bytes, Alignment));
171 } 228 }
172 229
173 /// Allocate data of type T using the per-Assembler allocator. 230 /// Allocate data of type T using the per-Assembler allocator.
174 template <typename T> T *allocate() { return Allocator.Allocate<T>(); } 231 template <typename T> T *allocate() { return Allocator.Allocate<T>(); }
175 232
176 /// Align the tail end of the function to the required target alignment. 233 /// Align the tail end of the function to the required target alignment.
177 virtual void alignFunction() = 0; 234 virtual void alignFunction() = 0;
235 /// Align the tail end of the basic block to the required target alignment.
236 virtual void alignCfgNode() = 0;
jvoung (off chromium) 2015/07/29 21:31:16 You might be able to make this non-virtual if it c
ascull 2015/07/29 22:43:04 Done.
178 237
179 /// Add nop padding of a particular width to the current bundle. 238 /// Add nop padding of a particular width to the current bundle.
180 virtual void padWithNop(intptr_t Padding) = 0; 239 virtual void padWithNop(intptr_t Padding) = 0;
181 240
182 virtual SizeT getBundleAlignLog2Bytes() const = 0; 241 virtual SizeT getBundleAlignLog2Bytes() const = 0;
183 242
184 virtual const char *getNonExecPadDirective() const = 0; 243 virtual const char *getNonExecPadDirective() const = 0;
185 virtual llvm::ArrayRef<uint8_t> getNonExecBundlePadding() const = 0; 244 virtual llvm::ArrayRef<uint8_t> getNonExecBundlePadding() const = 0;
186 245
246 /// Get the label for a CfgNode.
247 virtual Label *getOrCreateCfgNodeLabel(SizeT NodeNumber) = 0;
187 /// Mark the current text location as the start of a CFG node 248 /// Mark the current text location as the start of a CFG node
188 /// (represented by NodeNumber). 249 /// (represented by NodeNumber).
189 virtual void bindCfgNodeLabel(SizeT NodeNumber) = 0; 250 virtual void bindCfgNodeLabel(SizeT NodeNumber) = 0;
190 251
191 virtual bool fixupIsPCRel(FixupKind Kind) const = 0; 252 virtual bool fixupIsPCRel(FixupKind Kind) const = 0;
192 253
193 // Return a view of all the bytes of code for the current function. 254 // Return a view of all the bytes of code for the current function.
194 llvm::StringRef getBufferView() const; 255 llvm::StringRef getBufferView() const;
195 256
196 const FixupRefList &fixups() const { return Buffer.fixups(); } 257 const FixupRefList &fixups() const { return Buffer.fixups(); }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 protected: 295 protected:
235 // Buffer's constructor uses the Allocator, so it needs to appear after it. 296 // Buffer's constructor uses the Allocator, so it needs to appear after it.
236 // TODO(jpp): dependencies on construction order are a nice way of shooting 297 // TODO(jpp): dependencies on construction order are a nice way of shooting
237 // yourself in the foot. Fix this. 298 // yourself in the foot. Fix this.
238 AssemblerBuffer Buffer; 299 AssemblerBuffer Buffer;
239 }; 300 };
240 301
241 } // end of namespace Ice 302 } // end of namespace Ice
242 303
243 #endif // SUBZERO_SRC_ICEASSEMBLER_H_ 304 #endif // SUBZERO_SRC_ICEASSEMBLER_H_
OLDNEW
« no previous file with comments | « Makefile.standalone ('k') | src/IceAssemblerARM32.h » ('j') | src/IceCfg.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698