| OLD | NEW |
| 1 //===- subzero/src/IceDefs.h - Common Subzero declarations ------*- C++ -*-===// | 1 //===- subzero/src/IceDefs.h - Common Subzero declarations ------*- 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 /// \file | 10 /// \file |
| 11 /// \brief Declares various useful types and classes that have widespread use | 11 /// \brief Declares various useful types and classes that have widespread use |
| 12 /// across Subzero. | 12 /// across Subzero. |
| 13 /// | 13 /// |
| 14 /// Every Subzero source file is expected to include IceDefs.h. | |
| 15 /// | |
| 16 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
| 17 | 15 |
| 18 #ifndef SUBZERO_SRC_ICEDEFS_H | 16 #ifndef SUBZERO_SRC_ICEDEFS_H |
| 19 #define SUBZERO_SRC_ICEDEFS_H | 17 #define SUBZERO_SRC_ICEDEFS_H |
| 20 | 18 |
| 21 #include "IceBuildDefs.h" // TODO(stichnot): move into individual files | 19 #include "IceBuildDefs.h" // TODO(stichnot): move into individual files |
| 20 #include "IceMemory.h" |
| 22 #include "IceTLS.h" | 21 #include "IceTLS.h" |
| 23 | 22 |
| 24 #include "llvm/ADT/ArrayRef.h" | 23 #include "llvm/ADT/ArrayRef.h" |
| 25 #include "llvm/ADT/BitVector.h" | 24 #include "llvm/ADT/BitVector.h" |
| 26 #include "llvm/ADT/ilist.h" | 25 #include "llvm/ADT/ilist.h" |
| 27 #include "llvm/ADT/ilist_node.h" | 26 #include "llvm/ADT/ilist_node.h" |
| 28 #include "llvm/ADT/iterator_range.h" | 27 #include "llvm/ADT/iterator_range.h" |
| 29 #include "llvm/ADT/SmallBitVector.h" | |
| 30 #include "llvm/ADT/SmallVector.h" | 28 #include "llvm/ADT/SmallVector.h" |
| 31 #include "llvm/ADT/STLExtras.h" | 29 #include "llvm/ADT/STLExtras.h" |
| 32 #include "llvm/Support/Allocator.h" | |
| 33 #include "llvm/Support/Casting.h" | 30 #include "llvm/Support/Casting.h" |
| 34 #include "llvm/Support/ELF.h" | 31 #include "llvm/Support/ELF.h" |
| 35 #include "llvm/Support/raw_ostream.h" | 32 #include "llvm/Support/raw_ostream.h" |
| 36 | 33 |
| 37 #include <cassert> | 34 #include <cassert> |
| 38 #include <cstdint> | 35 #include <cstdint> |
| 39 #include <cstdio> // snprintf | 36 #include <cstdio> // snprintf |
| 40 #include <functional> // std::less | 37 #include <functional> // std::less |
| 41 #include <limits> | 38 #include <limits> |
| 42 #include <list> | 39 #include <list> |
| 43 #include <map> | 40 #include <map> |
| 44 #include <memory> | 41 #include <memory> |
| 45 #include <mutex> | 42 #include <mutex> |
| 46 #include <string> | 43 #include <string> |
| 47 #include <system_error> | 44 #include <system_error> |
| 48 #include <unordered_map> | 45 #include <unordered_map> |
| 46 #include <unordered_set> |
| 47 #include <utility> |
| 49 #include <vector> | 48 #include <vector> |
| 50 | 49 |
| 51 namespace Ice { | 50 namespace Ice { |
| 52 | 51 |
| 53 class Assembler; | 52 class Assembler; |
| 54 class Cfg; | 53 class Cfg; |
| 55 class CfgNode; | 54 class CfgNode; |
| 56 class Constant; | 55 class Constant; |
| 57 class ELFObjectWriter; | 56 class ELFObjectWriter; |
| 58 class ELFStreamer; | 57 class ELFStreamer; |
| 59 class FunctionDeclaration; | 58 class FunctionDeclaration; |
| 60 class GlobalContext; | 59 class GlobalContext; |
| 61 class GlobalDeclaration; | 60 class GlobalDeclaration; |
| 62 class Inst; | 61 class Inst; |
| 63 class InstAssign; | 62 class InstAssign; |
| 64 class InstJumpTable; | 63 class InstJumpTable; |
| 65 class InstPhi; | 64 class InstPhi; |
| 66 class InstSwitch; | 65 class InstSwitch; |
| 67 class InstTarget; | 66 class InstTarget; |
| 68 class LiveRange; | 67 class LiveRange; |
| 69 class Liveness; | 68 class Liveness; |
| 70 class Operand; | 69 class Operand; |
| 71 class TargetDataLowering; | 70 class TargetDataLowering; |
| 72 class TargetLowering; | 71 class TargetLowering; |
| 73 class Variable; | 72 class Variable; |
| 74 class VariableDeclaration; | 73 class VariableDeclaration; |
| 75 class VariablesMetadata; | 74 class VariablesMetadata; |
| 76 | 75 |
| 77 constexpr char GlobalOffsetTable[] = "_GLOBAL_OFFSET_TABLE_"; | 76 constexpr char GlobalOffsetTable[] = "_GLOBAL_OFFSET_TABLE_"; |
| 78 | |
| 79 template <size_t SlabSize = 1024 * 1024> | |
| 80 using ArenaAllocator = | |
| 81 llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, SlabSize>; | |
| 82 | |
| 83 ArenaAllocator<> *getCurrentCfgAllocator(); | |
| 84 | |
| 85 template <typename T> struct CfgLocalAllocator { | |
| 86 using value_type = T; | |
| 87 using pointer = T *; | |
| 88 using const_pointer = const T *; | |
| 89 using reference = T &; | |
| 90 using const_reference = const T &; | |
| 91 using size_type = std::size_t; | |
| 92 CfgLocalAllocator() = default; | |
| 93 template <class U> CfgLocalAllocator(const CfgLocalAllocator<U> &) {} | |
| 94 pointer allocate(size_type Num) { | |
| 95 return getCurrentCfgAllocator()->Allocate<T>(Num); | |
| 96 } | |
| 97 void deallocate(pointer, size_type) {} | |
| 98 template <class U> struct rebind { typedef CfgLocalAllocator<U> other; }; | |
| 99 void construct(pointer P, const T &Val) { | |
| 100 new (static_cast<void *>(P)) T(Val); | |
| 101 } | |
| 102 void destroy(pointer P) { P->~T(); } | |
| 103 }; | |
| 104 template <typename T, typename U> | |
| 105 inline bool operator==(const CfgLocalAllocator<T> &, | |
| 106 const CfgLocalAllocator<U> &) { | |
| 107 return true; | |
| 108 } | |
| 109 template <typename T, typename U> | |
| 110 inline bool operator!=(const CfgLocalAllocator<T> &, | |
| 111 const CfgLocalAllocator<U> &) { | |
| 112 return false; | |
| 113 } | |
| 114 | |
| 115 // makeUnique should be used when memory is expected to be allocated from the | 77 // makeUnique should be used when memory is expected to be allocated from the |
| 116 // heap (as opposed to allocated from some Allocator.) It is intended to be | 78 // heap (as opposed to allocated from some Allocator.) It is intended to be |
| 117 // used instead of new. | 79 // used instead of new. |
| 118 // | 80 // |
| 119 // The expected usage is as follows | 81 // The expected usage is as follows |
| 120 // | 82 // |
| 121 // class MyClass { | 83 // class MyClass { |
| 122 // public: | 84 // public: |
| 123 // static std::unique_ptr<MyClass> create(<ctor_args>) { | 85 // static std::unique_ptr<MyClass> create(<ctor_args>) { |
| 124 // return makeUnique<MyClass>(<ctor_args>); | 86 // return makeUnique<MyClass>(<ctor_args>); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 153 #define ENABLE_MAKE_UNIQUE friend struct ::Ice::Internal::MakeUniqueEnabler | 115 #define ENABLE_MAKE_UNIQUE friend struct ::Ice::Internal::MakeUniqueEnabler |
| 154 | 116 |
| 155 using IceString = std::string; | 117 using IceString = std::string; |
| 156 using InstList = llvm::ilist<Inst>; | 118 using InstList = llvm::ilist<Inst>; |
| 157 // Ideally PhiList would be llvm::ilist<InstPhi>, and similar for AssignList, | 119 // Ideally PhiList would be llvm::ilist<InstPhi>, and similar for AssignList, |
| 158 // but this runs into issues with SFINAE. | 120 // but this runs into issues with SFINAE. |
| 159 using PhiList = InstList; | 121 using PhiList = InstList; |
| 160 using AssignList = InstList; | 122 using AssignList = InstList; |
| 161 | 123 |
| 162 // Standard library containers with CfgLocalAllocator. | 124 // Standard library containers with CfgLocalAllocator. |
| 125 template <typename T> using CfgList = std::list<T, CfgLocalAllocator<T>>; |
| 126 template <typename T, typename H = std::hash<T>, typename Eq = std::equal_to<T>> |
| 127 using CfgUnorderedSet = std::unordered_set<T, H, Eq, CfgLocalAllocator<T>>; |
| 128 template <typename T, typename U, typename H = std::hash<T>, |
| 129 typename Eq = std::equal_to<T>> |
| 130 using CfgUnorderedMap = |
| 131 std::unordered_map<T, U, H, Eq, CfgLocalAllocator<std::pair<const T, U>>>; |
| 163 template <typename T> using CfgVector = std::vector<T, CfgLocalAllocator<T>>; | 132 template <typename T> using CfgVector = std::vector<T, CfgLocalAllocator<T>>; |
| 164 template <typename T> using CfgList = std::list<T, CfgLocalAllocator<T>>; | |
| 165 | 133 |
| 166 // Containers that are arena-allocated from the Cfg's allocator. | 134 // Containers that are arena-allocated from the Cfg's allocator. |
| 167 using OperandList = CfgVector<Operand *>; | 135 using OperandList = CfgVector<Operand *>; |
| 168 using VarList = CfgVector<Variable *>; | 136 using VarList = CfgVector<Variable *>; |
| 169 using NodeList = CfgVector<CfgNode *>; | 137 using NodeList = CfgVector<CfgNode *>; |
| 170 | 138 |
| 171 // Contains that use the default (global) allocator. | 139 // Containers that use the default (global) allocator. |
| 172 using ConstantList = std::vector<Constant *>; | 140 using ConstantList = std::vector<Constant *>; |
| 173 using FunctionDeclarationList = std::vector<FunctionDeclaration *>; | 141 using FunctionDeclarationList = std::vector<FunctionDeclaration *>; |
| 174 using VariableDeclarationList = std::vector<VariableDeclaration *>; | 142 using VariableDeclarationList = std::vector<VariableDeclaration *>; |
| 175 | 143 |
| 176 /// SizeT is for holding small-ish limits like number of source operands in an | 144 /// SizeT is for holding small-ish limits like number of source operands in an |
| 177 /// instruction. It is used instead of size_t (which may be 64-bits wide) when | 145 /// instruction. It is used instead of size_t (which may be 64-bits wide) when |
| 178 /// we want to save space. | 146 /// we want to save space. |
| 179 using SizeT = uint32_t; | 147 using SizeT = uint32_t; |
| 180 | 148 |
| 181 /// InstNumberT is for holding an instruction number. Instruction numbers are | 149 /// InstNumberT is for holding an instruction number. Instruction numbers are |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 RPE_PooledConstantReordering, | 277 RPE_PooledConstantReordering, |
| 310 RPE_RegAllocRandomization, | 278 RPE_RegAllocRandomization, |
| 311 RPE_num | 279 RPE_num |
| 312 }; | 280 }; |
| 313 | 281 |
| 314 using RelocOffsetArray = llvm::SmallVector<class RelocOffset *, 4>; | 282 using RelocOffsetArray = llvm::SmallVector<class RelocOffset *, 4>; |
| 315 | 283 |
| 316 } // end of namespace Ice | 284 } // end of namespace Ice |
| 317 | 285 |
| 318 #endif // SUBZERO_SRC_ICEDEFS_H | 286 #endif // SUBZERO_SRC_ICEDEFS_H |
| OLD | NEW |