OLD | NEW |
1 //===- subzero/src/IceDefs.h - Common Subzero declaraions -------*- C++ -*-===// | 1 //===- subzero/src/IceDefs.h - Common Subzero declaraions -------*- C++ -*-===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file declares various useful types and classes that have | 10 // This file declares various useful types and classes that have |
11 // widespread use across Subzero. Every Subzero source file is | 11 // widespread use across Subzero. Every Subzero source file is |
12 // expected to include IceDefs.h. | 12 // expected to include IceDefs.h. |
13 // | 13 // |
14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
15 | 15 |
16 #ifndef SUBZERO_SRC_ICEDEFS_H | 16 #ifndef SUBZERO_SRC_ICEDEFS_H |
17 #define SUBZERO_SRC_ICEDEFS_H | 17 #define SUBZERO_SRC_ICEDEFS_H |
18 | 18 |
19 #include <cassert> | 19 #include <cassert> |
20 #include <cstdint> | 20 #include <cstdint> |
21 #include <cstdio> // snprintf | 21 #include <cstdio> // snprintf |
22 #include <functional> // std::less | 22 #include <functional> // std::less |
23 #include <limits> | 23 #include <limits> |
24 #include <list> | 24 #include <list> |
25 #include <map> | 25 #include <map> |
| 26 #include <mutex> |
26 #include <string> | 27 #include <string> |
| 28 #include <system_error> |
27 #include <vector> | 29 #include <vector> |
28 #include "llvm/ADT/ArrayRef.h" | 30 #include "llvm/ADT/ArrayRef.h" |
29 #include "llvm/ADT/BitVector.h" | 31 #include "llvm/ADT/BitVector.h" |
30 #include "llvm/ADT/ilist.h" | 32 #include "llvm/ADT/ilist.h" |
31 #include "llvm/ADT/ilist_node.h" | 33 #include "llvm/ADT/ilist_node.h" |
32 #include "llvm/ADT/iterator_range.h" | 34 #include "llvm/ADT/iterator_range.h" |
33 #include "llvm/ADT/SmallBitVector.h" | 35 #include "llvm/ADT/SmallBitVector.h" |
34 #include "llvm/ADT/SmallVector.h" | 36 #include "llvm/ADT/SmallVector.h" |
35 #include "llvm/ADT/STLExtras.h" | 37 #include "llvm/ADT/STLExtras.h" |
36 #include "llvm/Support/Allocator.h" | 38 #include "llvm/Support/Allocator.h" |
(...skipping 14 matching lines...) Expand all Loading... |
51 class FunctionDeclaration; | 53 class FunctionDeclaration; |
52 class GlobalContext; | 54 class GlobalContext; |
53 class GlobalDeclaration; | 55 class GlobalDeclaration; |
54 class Inst; | 56 class Inst; |
55 class InstAssign; | 57 class InstAssign; |
56 class InstPhi; | 58 class InstPhi; |
57 class InstTarget; | 59 class InstTarget; |
58 class LiveRange; | 60 class LiveRange; |
59 class Liveness; | 61 class Liveness; |
60 class Operand; | 62 class Operand; |
| 63 class TargetGlobalLowering; |
61 class TargetLowering; | 64 class TargetLowering; |
62 class Variable; | 65 class Variable; |
63 class VariableDeclaration; | 66 class VariableDeclaration; |
64 class VariablesMetadata; | 67 class VariablesMetadata; |
65 | 68 |
66 template <size_t SlabSize = 1024 * 1024> | 69 template <size_t SlabSize = 1024 * 1024> |
67 using ArenaAllocator = | 70 using ArenaAllocator = |
68 llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, SlabSize>; | 71 llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, SlabSize>; |
69 | 72 |
70 ArenaAllocator<> *getCurrentCfgAllocator(); | 73 ArenaAllocator<> *getCurrentCfgAllocator(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // Inst::Number value, giving the instruction number that begins or | 116 // Inst::Number value, giving the instruction number that begins or |
114 // ends a variable's live range. | 117 // ends a variable's live range. |
115 typedef std::pair<SizeT, InstNumberT> LiveBeginEndMapEntry; | 118 typedef std::pair<SizeT, InstNumberT> LiveBeginEndMapEntry; |
116 typedef std::vector<LiveBeginEndMapEntry, | 119 typedef std::vector<LiveBeginEndMapEntry, |
117 CfgLocalAllocator<LiveBeginEndMapEntry>> LiveBeginEndMap; | 120 CfgLocalAllocator<LiveBeginEndMapEntry>> LiveBeginEndMap; |
118 typedef llvm::BitVector LivenessBV; | 121 typedef llvm::BitVector LivenessBV; |
119 | 122 |
120 typedef uint32_t TimerStackIdT; | 123 typedef uint32_t TimerStackIdT; |
121 typedef uint32_t TimerIdT; | 124 typedef uint32_t TimerIdT; |
122 | 125 |
| 126 // Use alignas(MaxCacheLineSize) to isolate variables/fields that |
| 127 // might be contended while multithreading. Assumes the maximum cache |
| 128 // line size is 64. |
| 129 enum { |
| 130 MaxCacheLineSize = 64 |
| 131 }; |
| 132 // Use ICE_CACHELINE_BOUNDARY to force the next field in a declaration |
| 133 // list to be aligned to the next cache line. |
| 134 #define ICE_CACHELINE_BOUNDARY \ |
| 135 alignas(MaxCacheLineSize) struct {} |
| 136 |
123 // PNaCl is ILP32, so theoretically we should only need 32-bit offsets. | 137 // PNaCl is ILP32, so theoretically we should only need 32-bit offsets. |
124 typedef int32_t RelocOffsetT; | 138 typedef int32_t RelocOffsetT; |
125 enum { RelocAddrSize = 4 }; | 139 enum { RelocAddrSize = 4 }; |
126 | 140 |
127 enum LivenessMode { | 141 enum LivenessMode { |
128 // Basic version of live-range-end calculation. Marks the last uses | 142 // Basic version of live-range-end calculation. Marks the last uses |
129 // of variables based on dataflow analysis. Records the set of | 143 // of variables based on dataflow analysis. Records the set of |
130 // live-in and live-out variables for each block. Identifies and | 144 // live-in and live-out variables for each block. Identifies and |
131 // deletes dead instructions (primarily stores). | 145 // deletes dead instructions (primarily stores). |
132 Liveness_Basic, | 146 Liveness_Basic, |
(...skipping 23 matching lines...) Expand all Loading... |
156 IceV_AddrOpt = 1 << 9, | 170 IceV_AddrOpt = 1 << 9, |
157 IceV_Random = 1 << 10, | 171 IceV_Random = 1 << 10, |
158 IceV_All = ~IceV_None, | 172 IceV_All = ~IceV_None, |
159 IceV_Most = IceV_All & ~IceV_LinearScan | 173 IceV_Most = IceV_All & ~IceV_LinearScan |
160 }; | 174 }; |
161 typedef uint32_t VerboseMask; | 175 typedef uint32_t VerboseMask; |
162 | 176 |
163 typedef llvm::raw_ostream Ostream; | 177 typedef llvm::raw_ostream Ostream; |
164 typedef llvm::raw_fd_ostream Fdstream; | 178 typedef llvm::raw_fd_ostream Fdstream; |
165 | 179 |
| 180 typedef std::mutex GlobalLockType; |
| 181 |
| 182 enum ErrorCodes { |
| 183 EC_None = 0, |
| 184 EC_Args, |
| 185 EC_Bitcode, |
| 186 EC_Translation |
| 187 }; |
| 188 |
| 189 // Wrapper around std::error_code for allowing multiple errors to be |
| 190 // folded into one. The current implementation keeps track of the |
| 191 // first error, which is likely to be the most useful one, and this |
| 192 // could be extended to e.g. collect a vector of errors. |
| 193 class ErrorCode : public std::error_code { |
| 194 ErrorCode(const ErrorCode &) = delete; |
| 195 ErrorCode &operator=(const ErrorCode &) = delete; |
| 196 |
| 197 public: |
| 198 ErrorCode() : HasError(false) {} |
| 199 void assign(ErrorCodes Code) { |
| 200 if (!HasError) { |
| 201 HasError = true; |
| 202 std::error_code::assign(Code, std::generic_category()); |
| 203 } |
| 204 } |
| 205 void assign(int Code) { assign(static_cast<ErrorCodes>(Code)); } |
| 206 |
| 207 private: |
| 208 bool HasError; |
| 209 }; |
| 210 |
166 // Reverse range adaptors written in terms of llvm::make_range(). | 211 // Reverse range adaptors written in terms of llvm::make_range(). |
167 template <typename T> | 212 template <typename T> |
168 llvm::iterator_range<typename T::const_reverse_iterator> | 213 llvm::iterator_range<typename T::const_reverse_iterator> |
169 reverse_range(const T &Container) { | 214 reverse_range(const T &Container) { |
170 return llvm::make_range(Container.rbegin(), Container.rend()); | 215 return llvm::make_range(Container.rbegin(), Container.rend()); |
171 } | 216 } |
172 template <typename T> | 217 template <typename T> |
173 llvm::iterator_range<typename T::reverse_iterator> reverse_range(T &Container) { | 218 llvm::iterator_range<typename T::reverse_iterator> reverse_range(T &Container) { |
174 return llvm::make_range(Container.rbegin(), Container.rend()); | 219 return llvm::make_range(Container.rbegin(), Container.rend()); |
175 } | 220 } |
176 | 221 |
177 } // end of namespace Ice | 222 } // end of namespace Ice |
178 | 223 |
179 #endif // SUBZERO_SRC_ICEDEFS_H | 224 #endif // SUBZERO_SRC_ICEDEFS_H |
OLD | NEW |