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

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: Rebase 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
« no previous file with comments | « Makefile.standalone ('k') | src/IceAssemblerARM32.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 // 11 //
12 // This file is distributed under the University of Illinois Open Source 12 // This file is distributed under the University of Illinois Open Source
13 // License. See LICENSE.TXT for details. 13 // License. See LICENSE.TXT for details.
14 // 14 //
15 //===----------------------------------------------------------------------===// 15 //===----------------------------------------------------------------------===//
16 /// 16 ///
17 /// \file 17 /// \file
18 /// This file declares the Assembler base class. Instructions are assembled 18 /// This file declares the Assembler base class. Instructions are assembled
19 /// by architecture-specific assemblers that derive from this base class. 19 /// by architecture-specific assemblers that derive from this base class.
20 /// This base class manages buffers and fixups for emitting code, etc. 20 /// This base class manages buffers and fixups for emitting code, etc.
21 /// 21 ///
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 #include "IceUtils.h"
29 30
30 namespace Ice { 31 namespace Ice {
31 32
33 /// A Label can be in one of three states:
34 /// - Unused.
35 /// - Linked, unplaced and tracking the position of branches to the label.
36 /// - Bound, placed and tracking its position.
37 class Label {
38 Label(const Label &) = delete;
39 Label &operator=(const Label &) = delete;
40
41 public:
42 Label() = default;
43 ~Label() = default;
44
45 virtual void finalCheck() const {
46 // Assert if label is being destroyed with unresolved branches pending.
47 assert(!isLinked());
48 }
49
50 /// Returns the position for bound labels (branches that come after this are
51 /// considered backward branches). Cannot be used for unused or linked labels.
52 intptr_t getPosition() const {
53 assert(isBound());
54 return -Position - kWordSize;
55 }
56
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
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
61 /// linked to this label.
62 intptr_t getLinkPosition() const {
63 assert(isLinked());
64 return Position - kWordSize;
65 }
66
67 bool isBound() const { return Position < 0; }
68 bool isLinked() const { return Position > 0; }
69 virtual bool isUnused() const { return Position == 0; }
70
71 protected:
72 void bindTo(intptr_t position) {
73 assert(!isBound());
74 Position = -position - kWordSize;
75 assert(isBound());
76 }
77
78 void linkTo(intptr_t position) {
79 assert(!isBound());
80 Position = position + kWordSize;
81 assert(isLinked());
82 }
83
84 intptr_t Position = 0;
85
86 private:
87 // TODO(jvoung): why are labels offset by this?
88 static constexpr uint32_t kWordSize = sizeof(uint32_t);
89 };
90
32 /// Assembler buffers are used to emit binary code. They grow on demand. 91 /// Assembler buffers are used to emit binary code. They grow on demand.
33 class AssemblerBuffer { 92 class AssemblerBuffer {
34 AssemblerBuffer(const AssemblerBuffer &) = delete; 93 AssemblerBuffer(const AssemblerBuffer &) = delete;
35 AssemblerBuffer &operator=(const AssemblerBuffer &) = delete; 94 AssemblerBuffer &operator=(const AssemblerBuffer &) = delete;
36 95
37 public: 96 public:
38 AssemblerBuffer(Assembler &); 97 AssemblerBuffer(Assembler &);
39 ~AssemblerBuffer(); 98 ~AssemblerBuffer();
40 99
41 /// Basic support for emitting, loading, and storing. 100 /// 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. 227 // second buffer should be aligned for NaCl.
169 const size_t Alignment = 16; 228 const size_t Alignment = 16;
170 return reinterpret_cast<uintptr_t>(Allocator.Allocate(bytes, Alignment)); 229 return reinterpret_cast<uintptr_t>(Allocator.Allocate(bytes, Alignment));
171 } 230 }
172 231
173 /// Allocate data of type T using the per-Assembler allocator. 232 /// Allocate data of type T using the per-Assembler allocator.
174 template <typename T> T *allocate() { return Allocator.Allocate<T>(); } 233 template <typename T> T *allocate() { return Allocator.Allocate<T>(); }
175 234
176 /// Align the tail end of the function to the required target alignment. 235 /// Align the tail end of the function to the required target alignment.
177 virtual void alignFunction() = 0; 236 virtual void alignFunction() = 0;
237 /// Align the tail end of the basic block to the required target alignment.
238 void alignCfgNode() {
239 const SizeT Align = 1 << getBundleAlignLog2Bytes();
240 padWithNop(Utils::OffsetToAlignment(Buffer.getPosition(), Align));
241 }
178 242
179 /// Add nop padding of a particular width to the current bundle. 243 /// Add nop padding of a particular width to the current bundle.
180 virtual void padWithNop(intptr_t Padding) = 0; 244 virtual void padWithNop(intptr_t Padding) = 0;
181 245
182 virtual SizeT getBundleAlignLog2Bytes() const = 0; 246 virtual SizeT getBundleAlignLog2Bytes() const = 0;
183 247
184 virtual const char *getNonExecPadDirective() const = 0; 248 virtual const char *getAlignDirective() const = 0;
185 virtual llvm::ArrayRef<uint8_t> getNonExecBundlePadding() const = 0; 249 virtual llvm::ArrayRef<uint8_t> getNonExecBundlePadding() const = 0;
186 250
251 /// Get the label for a CfgNode.
252 virtual Label *getOrCreateCfgNodeLabel(SizeT NodeNumber) = 0;
187 /// Mark the current text location as the start of a CFG node 253 /// Mark the current text location as the start of a CFG node
188 /// (represented by NodeNumber). 254 /// (represented by NodeNumber).
189 virtual void bindCfgNodeLabel(SizeT NodeNumber) = 0; 255 virtual void bindCfgNodeLabel(SizeT NodeNumber) = 0;
190 256
191 virtual bool fixupIsPCRel(FixupKind Kind) const = 0; 257 virtual bool fixupIsPCRel(FixupKind Kind) const = 0;
192 258
193 // Return a view of all the bytes of code for the current function. 259 // Return a view of all the bytes of code for the current function.
194 llvm::StringRef getBufferView() const; 260 llvm::StringRef getBufferView() const;
195 261
196 const FixupRefList &fixups() const { return Buffer.fixups(); } 262 const FixupRefList &fixups() const { return Buffer.fixups(); }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 protected: 300 protected:
235 // Buffer's constructor uses the Allocator, so it needs to appear after it. 301 // 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 302 // TODO(jpp): dependencies on construction order are a nice way of shooting
237 // yourself in the foot. Fix this. 303 // yourself in the foot. Fix this.
238 AssemblerBuffer Buffer; 304 AssemblerBuffer Buffer;
239 }; 305 };
240 306
241 } // end of namespace Ice 307 } // end of namespace Ice
242 308
243 #endif // SUBZERO_SRC_ICEASSEMBLER_H_ 309 #endif // SUBZERO_SRC_ICEASSEMBLER_H_
OLDNEW
« no previous file with comments | « Makefile.standalone ('k') | src/IceAssemblerARM32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698