Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceGlobalContext.cpp - Global context defs -------------===// |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 2 | // |
| 3 | // The Subzero Code Generator |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
Jim Stichnoth | 92a6e5b | 2015-12-02 16:52:44 -0800 | [diff] [blame] | 11 | /// \brief Defines aspects of the compilation that persist across multiple |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 12 | /// functions. |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 13 | /// |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 14 | //===----------------------------------------------------------------------===// |
| 15 | |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 16 | #include "IceGlobalContext.h" |
Jim Stichnoth | 639c921 | 2014-12-11 10:04:32 -0800 | [diff] [blame] | 17 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 18 | #include "IceCfg.h" |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 19 | #include "IceCfgNode.h" |
Jim Stichnoth | 989a703 | 2014-08-08 10:13:44 -0700 | [diff] [blame] | 20 | #include "IceClFlags.h" |
Jim Stichnoth | a18cc9c | 2014-09-30 19:10:22 -0700 | [diff] [blame] | 21 | #include "IceDefs.h" |
Jan Voung | ec27073 | 2015-01-12 17:00:22 -0800 | [diff] [blame] | 22 | #include "IceELFObjectWriter.h" |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 23 | #include "IceGlobalInits.h" |
John Porto | 7bb9cab | 2016-04-01 05:43:09 -0700 | [diff] [blame] | 24 | #include "IceLiveness.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 25 | #include "IceOperand.h" |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 26 | #include "IceTargetLowering.h" |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 27 | #include "IceTimerTree.h" |
Karl Schimpf | 20070e8 | 2016-03-17 13:30:13 -0700 | [diff] [blame] | 28 | #include "IceTypes.def" |
Jim Stichnoth | a18cc9c | 2014-09-30 19:10:22 -0700 | [diff] [blame] | 29 | #include "IceTypes.h" |
Jim Stichnoth | 98da966 | 2015-06-27 06:38:08 -0700 | [diff] [blame] | 30 | |
Jim Stichnoth | b0051df | 2016-01-13 11:39:15 -0800 | [diff] [blame] | 31 | #ifdef __clang__ |
Jim Stichnoth | 98da966 | 2015-06-27 06:38:08 -0700 | [diff] [blame] | 32 | #pragma clang diagnostic push |
| 33 | #pragma clang diagnostic ignored "-Wunused-parameter" |
Jim Stichnoth | b0051df | 2016-01-13 11:39:15 -0800 | [diff] [blame] | 34 | #endif // __clang__ |
| 35 | |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 36 | #include "llvm/Support/Timer.h" |
Jim Stichnoth | b0051df | 2016-01-13 11:39:15 -0800 | [diff] [blame] | 37 | |
| 38 | #ifdef __clang__ |
Jim Stichnoth | 98da966 | 2015-06-27 06:38:08 -0700 | [diff] [blame] | 39 | #pragma clang diagnostic pop |
Jim Stichnoth | b0051df | 2016-01-13 11:39:15 -0800 | [diff] [blame] | 40 | #endif // __clang__ |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 41 | |
Qining Lu | 7cd5351 | 2015-06-26 09:36:00 -0700 | [diff] [blame] | 42 | #include <algorithm> // max() |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 43 | |
Jim Stichnoth | dddaf9c | 2014-12-04 14:09:21 -0800 | [diff] [blame] | 44 | namespace std { |
| 45 | template <> struct hash<Ice::RelocatableTuple> { |
| 46 | size_t operator()(const Ice::RelocatableTuple &Key) const { |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 47 | // Use the relocatable's name, plus the hash of a combination of the number |
| 48 | // of OffsetExprs and the known, fixed offset for the reloc. We left shift |
| 49 | // the known relocatable by 5 trying to minimize the interaction between the |
| 50 | // bits in OffsetExpr.size() and Key.Offset. |
| 51 | return hash<Ice::SizeT>()(Key.Name.getID()) + |
John Porto | e82b560 | 2016-02-24 15:58:55 -0800 | [diff] [blame] | 52 | hash<std::size_t>()(Key.OffsetExpr.size() + (Key.Offset << 5)); |
Jim Stichnoth | d2cb436 | 2014-11-20 11:24:42 -0800 | [diff] [blame] | 53 | } |
| 54 | }; |
Jim Stichnoth | dddaf9c | 2014-12-04 14:09:21 -0800 | [diff] [blame] | 55 | } // end of namespace std |
Jim Stichnoth | d2cb436 | 2014-11-20 11:24:42 -0800 | [diff] [blame] | 56 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 57 | namespace Ice { |
| 58 | |
Jim Stichnoth | 5bfe215 | 2015-03-19 13:51:56 -0700 | [diff] [blame] | 59 | namespace { |
| 60 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 61 | // Define the key comparison function for the constant pool's unordered_map, |
| 62 | // but only for key types of interest: integer types, floating point types, and |
| 63 | // the special RelocatableTuple. |
Jim Stichnoth | 5bfe215 | 2015-03-19 13:51:56 -0700 | [diff] [blame] | 64 | template <typename KeyType, class Enable = void> struct KeyCompare {}; |
| 65 | |
| 66 | template <typename KeyType> |
| 67 | struct KeyCompare<KeyType, |
| 68 | typename std::enable_if< |
| 69 | std::is_integral<KeyType>::value || |
| 70 | std::is_same<KeyType, RelocatableTuple>::value>::type> { |
| 71 | bool operator()(const KeyType &Value1, const KeyType &Value2) const { |
| 72 | return Value1 == Value2; |
| 73 | } |
| 74 | }; |
| 75 | template <typename KeyType> |
| 76 | struct KeyCompare<KeyType, typename std::enable_if< |
| 77 | std::is_floating_point<KeyType>::value>::type> { |
| 78 | bool operator()(const KeyType &Value1, const KeyType &Value2) const { |
| 79 | return !memcmp(&Value1, &Value2, sizeof(KeyType)); |
| 80 | } |
| 81 | }; |
| 82 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 83 | // Define a key comparison function for sorting the constant pool's values |
| 84 | // after they are dumped to a vector. This covers integer types, floating point |
| 85 | // types, and ConstantRelocatable values. |
Jim Stichnoth | 6e293c8 | 2015-04-09 09:11:18 -0700 | [diff] [blame] | 86 | template <typename ValueType, class Enable = void> struct KeyCompareLess {}; |
| 87 | |
| 88 | template <typename ValueType> |
| 89 | struct KeyCompareLess<ValueType, |
| 90 | typename std::enable_if<std::is_floating_point< |
| 91 | typename ValueType::PrimType>::value>::type> { |
| 92 | bool operator()(const Constant *Const1, const Constant *Const2) const { |
Andrew Scull | 8072bae | 2015-09-14 16:01:26 -0700 | [diff] [blame] | 93 | using CompareType = uint64_t; |
Jim Stichnoth | 6e293c8 | 2015-04-09 09:11:18 -0700 | [diff] [blame] | 94 | static_assert(sizeof(typename ValueType::PrimType) <= sizeof(CompareType), |
| 95 | "Expected floating-point type of width 64-bit or less"); |
| 96 | typename ValueType::PrimType V1 = llvm::cast<ValueType>(Const1)->getValue(); |
| 97 | typename ValueType::PrimType V2 = llvm::cast<ValueType>(Const2)->getValue(); |
| 98 | // We avoid "V1<V2" because of NaN. |
| 99 | // We avoid "memcmp(&V1,&V2,sizeof(V1))<0" which depends on the |
| 100 | // endian-ness of the host system running Subzero. |
| 101 | // Instead, compare the result of bit_cast to uint64_t. |
| 102 | uint64_t I1 = 0, I2 = 0; |
| 103 | memcpy(&I1, &V1, sizeof(V1)); |
| 104 | memcpy(&I2, &V2, sizeof(V2)); |
| 105 | return I1 < I2; |
| 106 | } |
| 107 | }; |
| 108 | template <typename ValueType> |
| 109 | struct KeyCompareLess<ValueType, |
| 110 | typename std::enable_if<std::is_integral< |
| 111 | typename ValueType::PrimType>::value>::type> { |
| 112 | bool operator()(const Constant *Const1, const Constant *Const2) const { |
| 113 | typename ValueType::PrimType V1 = llvm::cast<ValueType>(Const1)->getValue(); |
| 114 | typename ValueType::PrimType V2 = llvm::cast<ValueType>(Const2)->getValue(); |
| 115 | return V1 < V2; |
| 116 | } |
| 117 | }; |
| 118 | template <typename ValueType> |
| 119 | struct KeyCompareLess< |
| 120 | ValueType, typename std::enable_if< |
| 121 | std::is_same<ValueType, ConstantRelocatable>::value>::type> { |
| 122 | bool operator()(const Constant *Const1, const Constant *Const2) const { |
Jim Stichnoth | 5bff61c | 2015-10-28 09:26:00 -0700 | [diff] [blame] | 123 | auto *V1 = llvm::cast<ValueType>(Const1); |
| 124 | auto *V2 = llvm::cast<ValueType>(Const2); |
Jim Stichnoth | 6e293c8 | 2015-04-09 09:11:18 -0700 | [diff] [blame] | 125 | if (V1->getName() == V2->getName()) |
| 126 | return V1->getOffset() < V2->getOffset(); |
| 127 | return V1->getName() < V2->getName(); |
| 128 | } |
| 129 | }; |
| 130 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 131 | // TypePool maps constants of type KeyType (e.g. float) to pointers to |
Jim Stichnoth | d2cb436 | 2014-11-20 11:24:42 -0800 | [diff] [blame] | 132 | // type ValueType (e.g. ConstantFloat). |
| 133 | template <Type Ty, typename KeyType, typename ValueType> class TypePool { |
Jim Stichnoth | 0795ba0 | 2014-10-01 14:23:01 -0700 | [diff] [blame] | 134 | TypePool(const TypePool &) = delete; |
| 135 | TypePool &operator=(const TypePool &) = delete; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 136 | |
| 137 | public: |
Jim Stichnoth | eafb56c | 2015-06-22 10:35:22 -0700 | [diff] [blame] | 138 | TypePool() = default; |
Jim Stichnoth | d2cb436 | 2014-11-20 11:24:42 -0800 | [diff] [blame] | 139 | ValueType *getOrAdd(GlobalContext *Ctx, KeyType Key) { |
| 140 | auto Iter = Pool.find(Key); |
Jim Stichnoth | 9f9aa2c | 2016-03-07 08:25:24 -0800 | [diff] [blame] | 141 | if (Iter != Pool.end()) { |
| 142 | Iter->second->updateLookupCount(); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 143 | return Iter->second; |
Jim Stichnoth | 9f9aa2c | 2016-03-07 08:25:24 -0800 | [diff] [blame] | 144 | } |
Jim Stichnoth | 54f3d51 | 2015-12-11 09:53:00 -0800 | [diff] [blame] | 145 | auto *Result = ValueType::create(Ctx, Ty, Key); |
Jim Stichnoth | d2cb436 | 2014-11-20 11:24:42 -0800 | [diff] [blame] | 146 | Pool[Key] = Result; |
Jim Stichnoth | 9f9aa2c | 2016-03-07 08:25:24 -0800 | [diff] [blame] | 147 | Result->updateLookupCount(); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 148 | return Result; |
| 149 | } |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 150 | ConstantList getConstantPool() const { |
| 151 | ConstantList Constants; |
| 152 | Constants.reserve(Pool.size()); |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 153 | for (auto &I : Pool) |
| 154 | Constants.push_back(I.second); |
Andrew Scull | 8072bae | 2015-09-14 16:01:26 -0700 | [diff] [blame] | 155 | // The sort (and its KeyCompareLess machinery) is not strictly necessary, |
| 156 | // but is desirable for producing output that is deterministic across |
| 157 | // unordered_map::iterator implementations. |
Jim Stichnoth | 6e293c8 | 2015-04-09 09:11:18 -0700 | [diff] [blame] | 158 | std::sort(Constants.begin(), Constants.end(), KeyCompareLess<ValueType>()); |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 159 | return Constants; |
| 160 | } |
Jim Stichnoth | 3d5e08d | 2016-03-01 12:22:29 -0800 | [diff] [blame] | 161 | size_t size() const { return Pool.size(); } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 162 | |
| 163 | private: |
Andrew Scull | 8072bae | 2015-09-14 16:01:26 -0700 | [diff] [blame] | 164 | // Use the default hash function, and a custom key comparison function. The |
| 165 | // key comparison function for floating point variables can't use the default |
| 166 | // == based implementation because of special C++ semantics regarding +0.0, |
| 167 | // -0.0, and NaN comparison. However, it's OK to use the default hash for |
| 168 | // floating point values because KeyCompare is the final source of truth - in |
| 169 | // the worst case a "false" collision must be resolved. |
| 170 | using ContainerType = |
| 171 | std::unordered_map<KeyType, ValueType *, std::hash<KeyType>, |
| 172 | KeyCompare<KeyType>>; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 173 | ContainerType Pool; |
| 174 | }; |
| 175 | |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 176 | // UndefPool maps ICE types to the corresponding ConstantUndef values. |
| 177 | class UndefPool { |
Jim Stichnoth | 0795ba0 | 2014-10-01 14:23:01 -0700 | [diff] [blame] | 178 | UndefPool(const UndefPool &) = delete; |
| 179 | UndefPool &operator=(const UndefPool &) = delete; |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 180 | |
| 181 | public: |
Jim Stichnoth | eafb56c | 2015-06-22 10:35:22 -0700 | [diff] [blame] | 182 | UndefPool() : Pool(IceType_NUM) {} |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 183 | |
| 184 | ConstantUndef *getOrAdd(GlobalContext *Ctx, Type Ty) { |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 185 | if (Pool[Ty] == nullptr) |
Jim Stichnoth | b36757e | 2015-10-05 13:55:11 -0700 | [diff] [blame] | 186 | Pool[Ty] = ConstantUndef::create(Ctx, Ty); |
Jim Stichnoth | d2cb436 | 2014-11-20 11:24:42 -0800 | [diff] [blame] | 187 | return Pool[Ty]; |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | private: |
Jim Stichnoth | d2cb436 | 2014-11-20 11:24:42 -0800 | [diff] [blame] | 191 | std::vector<ConstantUndef *> Pool; |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 192 | }; |
| 193 | |
Jim Stichnoth | 5bfe215 | 2015-03-19 13:51:56 -0700 | [diff] [blame] | 194 | } // end of anonymous namespace |
| 195 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 196 | // The global constant pool bundles individual pools of each type of |
| 197 | // interest. |
| 198 | class ConstantPool { |
Jim Stichnoth | 0795ba0 | 2014-10-01 14:23:01 -0700 | [diff] [blame] | 199 | ConstantPool(const ConstantPool &) = delete; |
| 200 | ConstantPool &operator=(const ConstantPool &) = delete; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 201 | |
| 202 | public: |
Jim Stichnoth | eafb56c | 2015-06-22 10:35:22 -0700 | [diff] [blame] | 203 | ConstantPool() = default; |
Jim Stichnoth | d2cb436 | 2014-11-20 11:24:42 -0800 | [diff] [blame] | 204 | TypePool<IceType_f32, float, ConstantFloat> Floats; |
| 205 | TypePool<IceType_f64, double, ConstantDouble> Doubles; |
| 206 | TypePool<IceType_i1, int8_t, ConstantInteger32> Integers1; |
| 207 | TypePool<IceType_i8, int8_t, ConstantInteger32> Integers8; |
| 208 | TypePool<IceType_i16, int16_t, ConstantInteger32> Integers16; |
| 209 | TypePool<IceType_i32, int32_t, ConstantInteger32> Integers32; |
| 210 | TypePool<IceType_i64, int64_t, ConstantInteger64> Integers64; |
| 211 | TypePool<IceType_i32, RelocatableTuple, ConstantRelocatable> Relocatables; |
Jan Voung | 261cae3 | 2015-02-01 10:31:03 -0800 | [diff] [blame] | 212 | TypePool<IceType_i32, RelocatableTuple, ConstantRelocatable> |
| 213 | ExternRelocatables; |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 214 | UndefPool Undefs; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 215 | }; |
| 216 | |
Karl Schimpf | e8457a2 | 2016-03-31 10:20:23 -0700 | [diff] [blame] | 217 | void GlobalContext::waitForWorkerThreads() { |
| 218 | if (WaitForWorkerThreadsCalled.exchange(true)) |
| 219 | return; |
| 220 | optQueueNotifyEnd(); |
| 221 | for (std::thread &Worker : TranslationThreads) { |
| 222 | Worker.join(); |
| 223 | } |
| 224 | TranslationThreads.clear(); |
| 225 | |
| 226 | // Only notify the emit queue to end after all the translation threads have |
| 227 | // ended. |
| 228 | emitQueueNotifyEnd(); |
| 229 | for (std::thread &Worker : EmitterThreads) { |
| 230 | Worker.join(); |
| 231 | } |
| 232 | EmitterThreads.clear(); |
| 233 | |
| 234 | if (BuildDefs::timers()) { |
| 235 | auto Timers = getTimers(); |
| 236 | for (ThreadContext *TLS : AllThreadContexts) |
| 237 | Timers->mergeFrom(TLS->Timers); |
| 238 | } |
| 239 | if (BuildDefs::dump()) { |
| 240 | // Do a separate loop over AllThreadContexts to avoid holding two locks at |
| 241 | // once. |
| 242 | auto Stats = getStatsCumulative(); |
| 243 | for (ThreadContext *TLS : AllThreadContexts) |
| 244 | Stats->add(TLS->StatsCumulative); |
| 245 | } |
| 246 | } |
| 247 | |
Jim Stichnoth | b5eee3d | 2016-03-31 11:05:39 -0700 | [diff] [blame] | 248 | void GlobalContext::CodeStats::dump(const Cfg *Func, GlobalContext *Ctx) { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 249 | if (!BuildDefs::dump()) |
Jim Stichnoth | 639c921 | 2014-12-11 10:04:32 -0800 | [diff] [blame] | 250 | return; |
Jim Stichnoth | 3d5e08d | 2016-03-01 12:22:29 -0800 | [diff] [blame] | 251 | OstreamLocker _(Ctx); |
| 252 | Ostream &Str = Ctx->getStrDump(); |
Jim Stichnoth | b5eee3d | 2016-03-31 11:05:39 -0700 | [diff] [blame] | 253 | const std::string Name = |
| 254 | (Func == nullptr ? "_FINAL_" : Func->getFunctionNameAndSize()); |
Jim Stichnoth | a1dd3cc | 2015-01-31 10:48:11 -0800 | [diff] [blame] | 255 | #define X(str, tag) \ |
| 256 | Str << "|" << Name << "|" str "|" << Stats[CS_##tag] << "\n"; |
| 257 | CODESTATS_TABLE |
| 258 | #undef X |
| 259 | Str << "|" << Name << "|Spills+Fills|" |
| 260 | << Stats[CS_NumSpills] + Stats[CS_NumFills] << "\n"; |
John Porto | a3984a1 | 2016-04-01 11:14:30 -0700 | [diff] [blame] | 261 | Str << "|" << Name << "|Memory Usage |"; |
| 262 | if (const auto MemUsed = static_cast<size_t>( |
| 263 | llvm::TimeRecord::getCurrentTime(false).getMemUsed())) { |
| 264 | static constexpr size_t _1MB = 1024 * 1024; |
| 265 | Str << (MemUsed / _1MB) << " MB"; |
| 266 | } else { |
Jim Stichnoth | 639c921 | 2014-12-11 10:04:32 -0800 | [diff] [blame] | 267 | Str << "(requires '-track-memory')"; |
John Porto | a3984a1 | 2016-04-01 11:14:30 -0700 | [diff] [blame] | 268 | } |
Jim Stichnoth | 639c921 | 2014-12-11 10:04:32 -0800 | [diff] [blame] | 269 | Str << "\n"; |
Jim Stichnoth | 3d5e08d | 2016-03-01 12:22:29 -0800 | [diff] [blame] | 270 | Str << "|" << Name << "|CPool Sizes "; |
| 271 | { |
| 272 | auto Pool = Ctx->getConstPool(); |
| 273 | Str << "|f32=" << Pool->Floats.size(); |
| 274 | Str << "|f64=" << Pool->Doubles.size(); |
| 275 | Str << "|i1=" << Pool->Integers1.size(); |
| 276 | Str << "|i8=" << Pool->Integers8.size(); |
| 277 | Str << "|i16=" << Pool->Integers16.size(); |
| 278 | Str << "|i32=" << Pool->Integers32.size(); |
| 279 | Str << "|i64=" << Pool->Integers64.size(); |
| 280 | Str << "|Rel=" << Pool->Relocatables.size(); |
| 281 | Str << "|ExtRel=" << Pool->ExternRelocatables.size(); |
| 282 | } |
| 283 | Str << "\n"; |
Jim Stichnoth | b5eee3d | 2016-03-31 11:05:39 -0700 | [diff] [blame] | 284 | if (Func != nullptr) { |
John Porto | a3984a1 | 2016-04-01 11:14:30 -0700 | [diff] [blame] | 285 | Str << "|" << Name << "|Cfg Memory |" << Func->getTotalMemoryMB() |
| 286 | << " MB\n"; |
| 287 | Str << "|" << Name << "|Liveness Memory |" << Func->getLivenessMemoryMB() |
Jim Stichnoth | b5eee3d | 2016-03-31 11:05:39 -0700 | [diff] [blame] | 288 | << " MB\n"; |
| 289 | } |
Jim Stichnoth | 639c921 | 2014-12-11 10:04:32 -0800 | [diff] [blame] | 290 | } |
| 291 | |
Karl Schimpf | 3018cf2 | 2016-04-11 14:49:01 -0700 | [diff] [blame^] | 292 | namespace { |
| 293 | |
| 294 | // By default, wake up the main parser thread when the OptQ gets half empty. |
| 295 | static constexpr size_t DefaultOptQWakeupSize = GlobalContext::MaxOptQSize >> 1; |
| 296 | |
| 297 | } // end of anonymous namespace |
| 298 | |
Karl Schimpf | 2f67b92 | 2015-04-22 15:20:16 -0700 | [diff] [blame] | 299 | GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, Ostream *OsError, |
Jim Stichnoth | 98ba006 | 2016-03-07 09:26:22 -0800 | [diff] [blame] | 300 | ELFStreamer *ELFStr) |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 301 | : Strings(new StringPool()), ConstPool(new ConstantPool()), ErrorStatus(), |
| 302 | StrDump(OsDump), StrEmit(OsEmit), StrError(OsError), IntrinsicsInfo(this), |
Karl Schimpf | 3018cf2 | 2016-04-11 14:49:01 -0700 | [diff] [blame^] | 303 | ObjectWriter(), |
| 304 | OptQWakeupSize(std::max(DefaultOptQWakeupSize, |
| 305 | size_t(getFlags().getNumTranslationThreads()))), |
| 306 | OptQ(/*Sequential=*/getFlags().isSequential(), |
| 307 | /*MaxSize=*/ |
| 308 | getFlags().isParseParallel() |
| 309 | ? MaxOptQSize |
| 310 | : getFlags().getNumTranslationThreads()), |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 311 | // EmitQ is allowed unlimited size. |
Karl Schimpf | d469994 | 2016-04-02 09:55:31 -0700 | [diff] [blame] | 312 | EmitQ(/*Sequential=*/getFlags().isSequential()), |
John Porto | 1bec8bc | 2015-06-22 10:51:13 -0700 | [diff] [blame] | 313 | DataLowering(TargetDataLowering::createLowering(this)) { |
Karl Schimpf | 2f67b92 | 2015-04-22 15:20:16 -0700 | [diff] [blame] | 314 | assert(OsDump && "OsDump is not defined for GlobalContext"); |
| 315 | assert(OsEmit && "OsEmit is not defined for GlobalContext"); |
| 316 | assert(OsError && "OsError is not defined for GlobalContext"); |
Jim Stichnoth | a5fe17a | 2015-01-26 11:10:03 -0800 | [diff] [blame] | 317 | // Make sure thread_local fields are properly initialized before any |
| 318 | // accesses are made. Do this here instead of at the start of |
| 319 | // main() so that all clients (e.g. unit tests) can benefit for |
| 320 | // free. |
| 321 | GlobalContext::TlsInit(); |
| 322 | Cfg::TlsInit(); |
John Porto | 7bb9cab | 2016-04-01 05:43:09 -0700 | [diff] [blame] | 323 | Liveness::TlsInit(); |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 324 | // Create a new ThreadContext for the current thread. No need to |
| 325 | // lock AllThreadContexts at this point since no other threads have |
| 326 | // access yet to this GlobalContext object. |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 327 | ThreadContext *MyTLS = new ThreadContext(); |
| 328 | AllThreadContexts.push_back(MyTLS); |
| 329 | ICE_TLS_SET_FIELD(TLS, MyTLS); |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 330 | // Pre-register built-in stack names. |
Jim Stichnoth | b88d8c8 | 2016-03-11 15:33:00 -0800 | [diff] [blame] | 331 | if (BuildDefs::timers()) { |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 332 | // TODO(stichnot): There needs to be a strong relationship between |
| 333 | // the newTimerStackID() return values and TSK_Default/TSK_Funcs. |
Jim Stichnoth | 1c44d81 | 2014-12-08 14:57:52 -0800 | [diff] [blame] | 334 | newTimerStackID("Total across all functions"); |
| 335 | newTimerStackID("Per-function summary"); |
| 336 | } |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 337 | Timers.initInto(MyTLS->Timers); |
Karl Schimpf | d469994 | 2016-04-02 09:55:31 -0700 | [diff] [blame] | 338 | switch (getFlags().getOutFileType()) { |
Jim Stichnoth | d442e7e | 2015-02-12 14:01:48 -0800 | [diff] [blame] | 339 | case FT_Elf: |
Jan Voung | 08c3bcd | 2014-12-01 17:55:16 -0800 | [diff] [blame] | 340 | ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); |
Jim Stichnoth | d442e7e | 2015-02-12 14:01:48 -0800 | [diff] [blame] | 341 | break; |
| 342 | case FT_Asm: |
| 343 | case FT_Iasm: |
| 344 | break; |
Jan Voung | 08c3bcd | 2014-12-01 17:55:16 -0800 | [diff] [blame] | 345 | } |
Karl Schimpf | 20070e8 | 2016-03-17 13:30:13 -0700 | [diff] [blame] | 346 | // Cache up front common constants. |
| 347 | #define X(tag, sizeLog2, align, elts, elty, str, rcstr) \ |
| 348 | ConstZeroForType[IceType_##tag] = getConstantZeroInternal(IceType_##tag); |
| 349 | ICETYPE_TABLE; |
| 350 | #undef X |
| 351 | ConstantTrue = getConstantInt1Internal(1); |
| 352 | // Define runtime helper functions. |
| 353 | #define X(Tag, Name) \ |
| 354 | RuntimeHelperFunc[static_cast<size_t>(RuntimeHelper::H_##Tag)] = \ |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 355 | getConstantExternSym(getGlobalString(Name)); |
Karl Schimpf | 20070e8 | 2016-03-17 13:30:13 -0700 | [diff] [blame] | 356 | RUNTIME_HELPER_FUNCTIONS_TABLE |
| 357 | #undef X |
John Porto | 1bec8bc | 2015-06-22 10:51:13 -0700 | [diff] [blame] | 358 | |
Karl Schimpf | 5403f5d | 2016-01-15 11:07:46 -0800 | [diff] [blame] | 359 | TargetLowering::staticInit(this); |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 360 | } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 361 | |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 362 | void GlobalContext::translateFunctions() { |
Karl Schimpf | b6e9b89 | 2016-03-08 12:27:12 -0800 | [diff] [blame] | 363 | TimerMarker Timer(TimerStack::TT_translateFunctions, this); |
Karl Schimpf | e8457a2 | 2016-03-31 10:20:23 -0700 | [diff] [blame] | 364 | while (std::unique_ptr<OptWorkItem> OptItem = optQueueBlockingPop()) { |
| 365 | auto Func = OptItem->getParsedCfg(); |
Jim Stichnoth | 8e92838 | 2015-02-02 17:03:08 -0800 | [diff] [blame] | 366 | // Install Func in TLS for Cfg-specific container allocators. |
John Porto | e82b560 | 2016-02-24 15:58:55 -0800 | [diff] [blame] | 367 | CfgLocalAllocatorScope _(Func.get()); |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 368 | // Reset per-function stats being accumulated in TLS. |
| 369 | resetStats(); |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 370 | // Set verbose level to none if the current function does NOT |
| 371 | // match the -verbose-focus command-line option. |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 372 | if (!matchSymbolName(Func->getFunctionName(), |
| 373 | getFlags().getVerboseFocusOn())) |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 374 | Func->setVerbose(IceV_None); |
| 375 | // Disable translation if -notranslate is specified, or if the |
| 376 | // current function matches the -translate-only option. If |
| 377 | // translation is disabled, just dump the high-level IR and |
| 378 | // continue. |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 379 | if (getFlags().getDisableTranslation() || |
| 380 | !matchSymbolName(Func->getFunctionName(), |
| 381 | getFlags().getTranslateOnly())) { |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 382 | Func->dump(); |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 383 | continue; // Func goes out of scope and gets deleted |
| 384 | } |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 385 | |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 386 | Func->translate(); |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 387 | std::unique_ptr<EmitterWorkItem> Item; |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 388 | if (Func->hasError()) { |
| 389 | getErrorStatus()->assign(EC_Translation); |
| 390 | OstreamLocker L(this); |
Karl Schimpf | 2f67b92 | 2015-04-22 15:20:16 -0700 | [diff] [blame] | 391 | getStrError() << "ICE translation error: " << Func->getFunctionName() |
Jim Stichnoth | b40595a | 2016-01-29 06:14:31 -0800 | [diff] [blame] | 392 | << ": " << Func->getError() << ": " |
| 393 | << Func->getFunctionNameAndSize() << "\n"; |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 394 | Item = makeUnique<EmitterWorkItem>(Func->getSequenceNumber()); |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 395 | } else { |
Jim Stichnoth | 24824e7 | 2015-02-12 21:35:34 -0800 | [diff] [blame] | 396 | Func->getAssembler<>()->setInternal(Func->getInternal()); |
Jim Stichnoth | d442e7e | 2015-02-12 14:01:48 -0800 | [diff] [blame] | 397 | switch (getFlags().getOutFileType()) { |
| 398 | case FT_Elf: |
| 399 | case FT_Iasm: { |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 400 | Func->emitIAS(); |
| 401 | // The Cfg has already emitted into the assembly buffer, so |
| 402 | // stats have been fully collected into this thread's TLS. |
| 403 | // Dump them before TLS is reset for the next Cfg. |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 404 | if (BuildDefs::dump()) |
Jim Stichnoth | b5eee3d | 2016-03-31 11:05:39 -0700 | [diff] [blame] | 405 | dumpStats(Func.get()); |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 406 | auto Asm = Func->releaseAssembler(); |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 407 | // Copy relevant fields into Asm before Func is deleted. |
| 408 | Asm->setFunctionName(Func->getFunctionName()); |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 409 | Item = makeUnique<EmitterWorkItem>(Func->getSequenceNumber(), |
| 410 | std::move(Asm)); |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 411 | Item->setGlobalInits(Func->getGlobalInits()); |
Jim Stichnoth | d442e7e | 2015-02-12 14:01:48 -0800 | [diff] [blame] | 412 | } break; |
| 413 | case FT_Asm: |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 414 | // The Cfg has not been emitted yet, so stats are not ready |
| 415 | // to be dumped. |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 416 | std::unique_ptr<VariableDeclarationList> GlobalInits = |
| 417 | Func->getGlobalInits(); |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 418 | Item = makeUnique<EmitterWorkItem>(Func->getSequenceNumber(), |
| 419 | std::move(Func)); |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 420 | Item->setGlobalInits(std::move(GlobalInits)); |
Jim Stichnoth | d442e7e | 2015-02-12 14:01:48 -0800 | [diff] [blame] | 421 | break; |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 422 | } |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 423 | } |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 424 | assert(Item != nullptr); |
| 425 | emitQueueBlockingPush(std::move(Item)); |
Jim Stichnoth | 8e92838 | 2015-02-02 17:03:08 -0800 | [diff] [blame] | 426 | // The Cfg now gets deleted as Func goes out of scope. |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 430 | namespace { |
| 431 | |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 432 | // Ensure Pending is large enough that Pending[Index] is valid. |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 433 | void resizePending(std::vector<std::unique_ptr<EmitterWorkItem>> *Pending, |
| 434 | uint32_t Index) { |
| 435 | if (Index >= Pending->size()) |
| 436 | Utils::reserveAndResize(*Pending, Index + 1); |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | } // end of anonymous namespace |
| 440 | |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 441 | void GlobalContext::emitFileHeader() { |
Karl Schimpf | b6e9b89 | 2016-03-08 12:27:12 -0800 | [diff] [blame] | 442 | TimerMarker T1(Ice::TimerStack::TT_emitAsm, this); |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 443 | if (getFlags().getOutFileType() == FT_Elf) { |
| 444 | getObjectWriter()->writeInitialELFHeader(); |
| 445 | } else { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 446 | if (!BuildDefs::dump()) { |
Jim Stichnoth | c879968 | 2015-06-22 13:04:10 -0700 | [diff] [blame] | 447 | getStrError() << "emitFileHeader for non-ELF"; |
| 448 | getErrorStatus()->assign(EC_Translation); |
| 449 | } |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 450 | TargetHeaderLowering::createLowering(this)->lower(); |
| 451 | } |
| 452 | } |
| 453 | |
Jim Stichnoth | cac003e | 2015-06-18 12:48:58 -0700 | [diff] [blame] | 454 | void GlobalContext::lowerConstants() { DataLowering->lowerConstants(); } |
John Porto | 8b1a705 | 2015-06-17 13:20:08 -0700 | [diff] [blame] | 455 | |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 456 | void GlobalContext::lowerJumpTables() { DataLowering->lowerJumpTables(); } |
| 457 | |
John Porto | a78e4ba | 2016-03-15 09:28:04 -0700 | [diff] [blame] | 458 | void GlobalContext::saveBlockInfoPtrs() { |
| 459 | for (VariableDeclaration *Global : Globals) { |
John Porto | 844211e | 2016-02-04 08:42:48 -0800 | [diff] [blame] | 460 | if (Cfg::isProfileGlobal(*Global)) { |
John Porto | a78e4ba | 2016-03-15 09:28:04 -0700 | [diff] [blame] | 461 | ProfileBlockInfos.push_back(Global); |
John Porto | 844211e | 2016-02-04 08:42:48 -0800 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | } |
| 465 | |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 466 | void GlobalContext::lowerGlobals(const std::string &SectionSuffix) { |
John Porto | 8b1a705 | 2015-06-17 13:20:08 -0700 | [diff] [blame] | 467 | TimerMarker T(TimerStack::TT_emitGlobalInitializers, this); |
Karl Schimpf | d469994 | 2016-04-02 09:55:31 -0700 | [diff] [blame] | 468 | const bool DumpGlobalVariables = |
| 469 | BuildDefs::dump() && (getFlags().getVerbose() & IceV_GlobalInit) && |
| 470 | getFlags().getVerboseFocusOn().empty(); |
John Porto | 8b1a705 | 2015-06-17 13:20:08 -0700 | [diff] [blame] | 471 | if (DumpGlobalVariables) { |
| 472 | OstreamLocker L(this); |
| 473 | Ostream &Stream = getStrDump(); |
| 474 | for (const Ice::VariableDeclaration *Global : Globals) { |
Jim Stichnoth | 98ba006 | 2016-03-07 09:26:22 -0800 | [diff] [blame] | 475 | Global->dump(Stream); |
John Porto | 8b1a705 | 2015-06-17 13:20:08 -0700 | [diff] [blame] | 476 | } |
| 477 | } |
Karl Schimpf | d469994 | 2016-04-02 09:55:31 -0700 | [diff] [blame] | 478 | if (getFlags().getDisableTranslation()) |
John Porto | 8b1a705 | 2015-06-17 13:20:08 -0700 | [diff] [blame] | 479 | return; |
| 480 | |
John Porto | a78e4ba | 2016-03-15 09:28:04 -0700 | [diff] [blame] | 481 | saveBlockInfoPtrs(); |
Qining Lu | 7cd5351 | 2015-06-26 09:36:00 -0700 | [diff] [blame] | 482 | // If we need to shuffle the layout of global variables, shuffle them now. |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 483 | if (getFlags().getReorderGlobalVariables()) { |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 484 | // Create a random number generator for global variable reordering. |
| 485 | RandomNumberGenerator RNG(getFlags().getRandomSeed(), |
| 486 | RPE_GlobalVariableReordering); |
Qining Lu | 7cd5351 | 2015-06-26 09:36:00 -0700 | [diff] [blame] | 487 | RandomShuffle(Globals.begin(), Globals.end(), |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 488 | [&RNG](int N) { return (uint32_t)RNG.next(N); }); |
Qining Lu | 7cd5351 | 2015-06-26 09:36:00 -0700 | [diff] [blame] | 489 | } |
John Porto | 8b1a705 | 2015-06-17 13:20:08 -0700 | [diff] [blame] | 490 | DataLowering->lowerGlobals(Globals, SectionSuffix); |
John Porto | a78e4ba | 2016-03-15 09:28:04 -0700 | [diff] [blame] | 491 | if (ProfileBlockInfos.empty() && DisposeGlobalVariablesAfterLowering) { |
| 492 | Globals.clearAndPurge(); |
| 493 | } else { |
| 494 | Globals.clear(); |
John Porto | 1bec8bc | 2015-06-22 10:51:13 -0700 | [diff] [blame] | 495 | } |
John Porto | 8b1a705 | 2015-06-17 13:20:08 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | void GlobalContext::lowerProfileData() { |
John Porto | 1bec8bc | 2015-06-22 10:51:13 -0700 | [diff] [blame] | 499 | // ProfileBlockInfoVarDecl is initialized in the constructor, and will only |
| 500 | // ever be nullptr after this method completes. This assertion is a convoluted |
| 501 | // way of ensuring lowerProfileData is invoked a single time. |
John Porto | a78e4ba | 2016-03-15 09:28:04 -0700 | [diff] [blame] | 502 | assert(ProfileBlockInfoVarDecl == nullptr); |
| 503 | |
| 504 | auto GlobalVariablePool = getInitializerAllocator(); |
| 505 | ProfileBlockInfoVarDecl = |
| 506 | VariableDeclaration::createExternal(GlobalVariablePool.get()); |
| 507 | ProfileBlockInfoVarDecl->setAlignment(typeWidthInBytes(IceType_i64)); |
| 508 | ProfileBlockInfoVarDecl->setIsConstant(true); |
| 509 | |
| 510 | // Note: if you change this symbol, make sure to update |
| 511 | // runtime/szrt_profiler.c as well. |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 512 | ProfileBlockInfoVarDecl->setName(this, "__Sz_block_profile_info"); |
John Porto | a78e4ba | 2016-03-15 09:28:04 -0700 | [diff] [blame] | 513 | |
| 514 | for (const VariableDeclaration *PBI : ProfileBlockInfos) { |
| 515 | if (Cfg::isProfileGlobal(*PBI)) { |
| 516 | constexpr RelocOffsetT BlockExecutionCounterOffset = 0; |
| 517 | ProfileBlockInfoVarDecl->addInitializer( |
| 518 | VariableDeclaration::RelocInitializer::create( |
| 519 | GlobalVariablePool.get(), PBI, |
| 520 | {RelocOffset::create(this, BlockExecutionCounterOffset)})); |
| 521 | } |
| 522 | } |
| 523 | |
John Porto | 8b1a705 | 2015-06-17 13:20:08 -0700 | [diff] [blame] | 524 | // This adds a 64-bit sentinel entry to the end of our array. For 32-bit |
| 525 | // architectures this will waste 4 bytes. |
| 526 | const SizeT Sizeof64BitNullPtr = typeWidthInBytes(IceType_i64); |
| 527 | ProfileBlockInfoVarDecl->addInitializer( |
John Porto | a78e4ba | 2016-03-15 09:28:04 -0700 | [diff] [blame] | 528 | VariableDeclaration::ZeroInitializer::create(GlobalVariablePool.get(), |
| 529 | Sizeof64BitNullPtr)); |
John Porto | 1bec8bc | 2015-06-22 10:51:13 -0700 | [diff] [blame] | 530 | Globals.push_back(ProfileBlockInfoVarDecl); |
John Porto | 8b1a705 | 2015-06-17 13:20:08 -0700 | [diff] [blame] | 531 | constexpr char ProfileDataSection[] = "$sz_profiler$"; |
| 532 | lowerGlobals(ProfileDataSection); |
| 533 | } |
| 534 | |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 535 | bool GlobalContext::matchSymbolName(const GlobalString &SymbolName, |
| 536 | const std::string &Match) { |
| 537 | return Match.empty() || Match == SymbolName.toString(); |
| 538 | } |
| 539 | |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 540 | void GlobalContext::emitItems() { |
| 541 | const bool Threaded = !getFlags().isSequential(); |
| 542 | // Pending is a vector containing the reassembled, ordered list of |
| 543 | // work items. When we're ready for the next item, we first check |
| 544 | // whether it's in the Pending list. If not, we take an item from |
| 545 | // the work queue, and if it's not the item we're waiting for, we |
| 546 | // insert it into Pending and repeat. The work item is deleted |
| 547 | // after it is processed. |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 548 | std::vector<std::unique_ptr<EmitterWorkItem>> Pending; |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 549 | uint32_t DesiredSequenceNumber = getFirstSequenceNumber(); |
Qining Lu | 7cd5351 | 2015-06-26 09:36:00 -0700 | [diff] [blame] | 550 | uint32_t ShuffleStartIndex = DesiredSequenceNumber; |
| 551 | uint32_t ShuffleEndIndex = DesiredSequenceNumber; |
| 552 | bool EmitQueueEmpty = false; |
| 553 | const uint32_t ShuffleWindowSize = |
| 554 | std::max(1u, getFlags().getReorderFunctionsWindowSize()); |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 555 | bool Shuffle = Threaded && getFlags().getReorderFunctions(); |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 556 | // Create a random number generator for function reordering. |
| 557 | RandomNumberGenerator RNG(getFlags().getRandomSeed(), RPE_FunctionReordering); |
| 558 | |
Qining Lu | 7cd5351 | 2015-06-26 09:36:00 -0700 | [diff] [blame] | 559 | while (!EmitQueueEmpty) { |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 560 | resizePending(&Pending, DesiredSequenceNumber); |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 561 | // See if Pending contains DesiredSequenceNumber. |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 562 | if (Pending[DesiredSequenceNumber] == nullptr) { |
Qining Lu | 7cd5351 | 2015-06-26 09:36:00 -0700 | [diff] [blame] | 563 | // We need to fetch an EmitterWorkItem from the queue. |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 564 | auto RawItem = emitQueueBlockingPop(); |
Qining Lu | 7cd5351 | 2015-06-26 09:36:00 -0700 | [diff] [blame] | 565 | if (RawItem == nullptr) { |
| 566 | // This is the notifier for an empty queue. |
| 567 | EmitQueueEmpty = true; |
| 568 | } else { |
| 569 | // We get an EmitterWorkItem, we need to add it to Pending. |
| 570 | uint32_t ItemSeq = RawItem->getSequenceNumber(); |
| 571 | if (Threaded && ItemSeq != DesiredSequenceNumber) { |
| 572 | // Not the desired one, add it to Pending but do not increase |
| 573 | // DesiredSequenceNumber. Continue the loop, do not emit the item. |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 574 | resizePending(&Pending, ItemSeq); |
| 575 | Pending[ItemSeq] = std::move(RawItem); |
Qining Lu | 7cd5351 | 2015-06-26 09:36:00 -0700 | [diff] [blame] | 576 | continue; |
| 577 | } |
| 578 | // ItemSeq == DesiredSequenceNumber, we need to check if we should |
| 579 | // emit it or not. If !Threaded, we're OK with ItemSeq != |
| 580 | // DesiredSequenceNumber. |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 581 | Pending[DesiredSequenceNumber] = std::move(RawItem); |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 582 | } |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 583 | } |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 584 | const auto *CurrentWorkItem = Pending[DesiredSequenceNumber].get(); |
| 585 | |
Qining Lu | 7cd5351 | 2015-06-26 09:36:00 -0700 | [diff] [blame] | 586 | // We have the desired EmitterWorkItem or nullptr as the end notifier. |
| 587 | // If the emitter queue is not empty, increase DesiredSequenceNumber and |
| 588 | // ShuffleEndIndex. |
| 589 | if (!EmitQueueEmpty) { |
| 590 | DesiredSequenceNumber++; |
| 591 | ShuffleEndIndex++; |
| 592 | } |
| 593 | |
| 594 | if (Shuffle) { |
| 595 | // Continue fetching EmitterWorkItem if function reordering is turned on, |
| 596 | // and emit queue is not empty, and the number of consecutive pending |
| 597 | // items is smaller than the window size, and RawItem is not a |
| 598 | // WI_GlobalInits kind. Emit WI_GlobalInits kind block first to avoid |
| 599 | // holding an arbitrarily large GlobalDeclarationList. |
| 600 | if (!EmitQueueEmpty && |
| 601 | ShuffleEndIndex - ShuffleStartIndex < ShuffleWindowSize && |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 602 | CurrentWorkItem->getKind() != EmitterWorkItem::WI_GlobalInits) |
Qining Lu | 7cd5351 | 2015-06-26 09:36:00 -0700 | [diff] [blame] | 603 | continue; |
| 604 | |
| 605 | // Emit the EmitterWorkItem between Pending[ShuffleStartIndex] to |
| 606 | // Pending[ShuffleEndIndex]. If function reordering turned on, shuffle the |
| 607 | // pending items from Pending[ShuffleStartIndex] to |
| 608 | // Pending[ShuffleEndIndex]. |
| 609 | RandomShuffle(Pending.begin() + ShuffleStartIndex, |
| 610 | Pending.begin() + ShuffleEndIndex, |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 611 | [&RNG](uint64_t N) { return (uint32_t)RNG.next(N); }); |
Qining Lu | 7cd5351 | 2015-06-26 09:36:00 -0700 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | // Emit the item from ShuffleStartIndex to ShuffleEndIndex. |
| 615 | for (uint32_t I = ShuffleStartIndex; I < ShuffleEndIndex; I++) { |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 616 | std::unique_ptr<EmitterWorkItem> Item = std::move(Pending[I]); |
Qining Lu | 7cd5351 | 2015-06-26 09:36:00 -0700 | [diff] [blame] | 617 | |
| 618 | switch (Item->getKind()) { |
| 619 | case EmitterWorkItem::WI_Nop: |
| 620 | break; |
| 621 | case EmitterWorkItem::WI_GlobalInits: { |
| 622 | accumulateGlobals(Item->getGlobalInits()); |
| 623 | } break; |
| 624 | case EmitterWorkItem::WI_Asm: { |
| 625 | lowerGlobalsIfNoCodeHasBeenSeen(); |
| 626 | accumulateGlobals(Item->getGlobalInits()); |
| 627 | |
| 628 | std::unique_ptr<Assembler> Asm = Item->getAsm(); |
| 629 | Asm->alignFunction(); |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 630 | GlobalString Name = Asm->getFunctionName(); |
Qining Lu | 7cd5351 | 2015-06-26 09:36:00 -0700 | [diff] [blame] | 631 | switch (getFlags().getOutFileType()) { |
| 632 | case FT_Elf: |
Jim Stichnoth | 98ba006 | 2016-03-07 09:26:22 -0800 | [diff] [blame] | 633 | getObjectWriter()->writeFunctionCode(Name, Asm->getInternal(), |
Qining Lu | 7cd5351 | 2015-06-26 09:36:00 -0700 | [diff] [blame] | 634 | Asm.get()); |
| 635 | break; |
| 636 | case FT_Iasm: { |
| 637 | OstreamLocker L(this); |
Jim Stichnoth | 98ba006 | 2016-03-07 09:26:22 -0800 | [diff] [blame] | 638 | Cfg::emitTextHeader(Name, this, Asm.get()); |
Jim Stichnoth | 5bff61c | 2015-10-28 09:26:00 -0700 | [diff] [blame] | 639 | Asm->emitIASBytes(this); |
Qining Lu | 7cd5351 | 2015-06-26 09:36:00 -0700 | [diff] [blame] | 640 | } break; |
| 641 | case FT_Asm: |
| 642 | llvm::report_fatal_error("Unexpected FT_Asm"); |
| 643 | break; |
| 644 | } |
| 645 | } break; |
| 646 | case EmitterWorkItem::WI_Cfg: { |
| 647 | if (!BuildDefs::dump()) |
| 648 | llvm::report_fatal_error("WI_Cfg work item created inappropriately"); |
| 649 | lowerGlobalsIfNoCodeHasBeenSeen(); |
| 650 | accumulateGlobals(Item->getGlobalInits()); |
| 651 | |
| 652 | assert(getFlags().getOutFileType() == FT_Asm); |
| 653 | std::unique_ptr<Cfg> Func = Item->getCfg(); |
| 654 | // Unfortunately, we have to temporarily install the Cfg in TLS |
| 655 | // because Variable::asType() uses the allocator to create the |
| 656 | // differently-typed copy. |
John Porto | e82b560 | 2016-02-24 15:58:55 -0800 | [diff] [blame] | 657 | CfgLocalAllocatorScope _(Func.get()); |
Qining Lu | 7cd5351 | 2015-06-26 09:36:00 -0700 | [diff] [blame] | 658 | Func->emit(); |
Jim Stichnoth | b5eee3d | 2016-03-31 11:05:39 -0700 | [diff] [blame] | 659 | dumpStats(Func.get()); |
Qining Lu | 7cd5351 | 2015-06-26 09:36:00 -0700 | [diff] [blame] | 660 | } break; |
| 661 | } |
| 662 | } |
| 663 | // Update the start index for next shuffling queue |
| 664 | ShuffleStartIndex = ShuffleEndIndex; |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 665 | } |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 666 | |
John Porto | 8b1a705 | 2015-06-17 13:20:08 -0700 | [diff] [blame] | 667 | // In case there are no code to be generated, we invoke the conditional |
| 668 | // lowerGlobals again -- this is a no-op if code has been emitted. |
| 669 | lowerGlobalsIfNoCodeHasBeenSeen(); |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 670 | } |
| 671 | |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 672 | GlobalContext::~GlobalContext() { |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 673 | llvm::DeleteContainerPointers(AllThreadContexts); |
John Porto | 1bec8bc | 2015-06-22 10:51:13 -0700 | [diff] [blame] | 674 | LockedPtr<DestructorArray> Dtors = getDestructors(); |
| 675 | // Destructors are invoked in the opposite object construction order. |
Andrew Scull | 00741a0 | 2015-09-16 19:04:09 -0700 | [diff] [blame] | 676 | for (const auto &Dtor : reverse_range(*Dtors)) |
| 677 | Dtor(); |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 678 | } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 679 | |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 680 | void GlobalContext::dumpStrings() { |
| 681 | if (!getFlags().getDumpStrings()) |
| 682 | return; |
| 683 | OstreamLocker _(this); |
| 684 | Ostream &Str = getStrDump(); |
| 685 | Str << "GlobalContext strings:\n"; |
| 686 | getStrings()->dump(Str); |
| 687 | } |
| 688 | |
Jim Stichnoth | 9f9aa2c | 2016-03-07 08:25:24 -0800 | [diff] [blame] | 689 | void GlobalContext::dumpConstantLookupCounts() { |
| 690 | if (!BuildDefs::dump()) |
| 691 | return; |
Karl Schimpf | d469994 | 2016-04-02 09:55:31 -0700 | [diff] [blame] | 692 | const bool DumpCounts = (getFlags().getVerbose() & IceV_ConstPoolStats) && |
| 693 | getFlags().getVerboseFocusOn().empty(); |
Jim Stichnoth | 9f9aa2c | 2016-03-07 08:25:24 -0800 | [diff] [blame] | 694 | if (!DumpCounts) |
| 695 | return; |
| 696 | |
| 697 | OstreamLocker _(this); |
| 698 | Ostream &Str = getStrDump(); |
| 699 | Str << "Constant pool use stats: count+value+type\n"; |
| 700 | #define X(WhichPool) \ |
| 701 | for (auto *C : getConstPool()->WhichPool.getConstantPool()) { \ |
| 702 | Str << C->getLookupCount() << " "; \ |
| 703 | C->dump(Str); \ |
| 704 | Str << " " << C->getType() << "\n"; \ |
| 705 | } |
| 706 | X(Integers1); |
| 707 | X(Integers8); |
| 708 | X(Integers16); |
| 709 | X(Integers32); |
| 710 | X(Integers64); |
| 711 | X(Floats); |
| 712 | X(Doubles); |
| 713 | X(Relocatables); |
| 714 | X(ExternRelocatables); |
| 715 | #undef X |
| 716 | } |
| 717 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 718 | // TODO(stichnot): Consider adding thread-local caches of constant pool entries |
| 719 | // to reduce contention. |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 720 | |
| 721 | // All locking is done by the getConstantInt[0-9]+() target function. |
Jim Stichnoth | d2cb436 | 2014-11-20 11:24:42 -0800 | [diff] [blame] | 722 | Constant *GlobalContext::getConstantInt(Type Ty, int64_t Value) { |
| 723 | switch (Ty) { |
| 724 | case IceType_i1: |
| 725 | return getConstantInt1(Value); |
| 726 | case IceType_i8: |
| 727 | return getConstantInt8(Value); |
| 728 | case IceType_i16: |
| 729 | return getConstantInt16(Value); |
| 730 | case IceType_i32: |
| 731 | return getConstantInt32(Value); |
| 732 | case IceType_i64: |
| 733 | return getConstantInt64(Value); |
| 734 | default: |
| 735 | llvm_unreachable("Bad integer type for getConstant"); |
| 736 | } |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 737 | return nullptr; |
Jan Voung | bc00463 | 2014-09-16 15:09:10 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Karl Schimpf | 20070e8 | 2016-03-17 13:30:13 -0700 | [diff] [blame] | 740 | Constant *GlobalContext::getConstantInt1Internal(int8_t ConstantInt1) { |
Jim Stichnoth | d2cb436 | 2014-11-20 11:24:42 -0800 | [diff] [blame] | 741 | ConstantInt1 &= INT8_C(1); |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 742 | return getConstPool()->Integers1.getOrAdd(this, ConstantInt1); |
Jim Stichnoth | d2cb436 | 2014-11-20 11:24:42 -0800 | [diff] [blame] | 743 | } |
| 744 | |
Karl Schimpf | 20070e8 | 2016-03-17 13:30:13 -0700 | [diff] [blame] | 745 | Constant *GlobalContext::getConstantInt8Internal(int8_t ConstantInt8) { |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 746 | return getConstPool()->Integers8.getOrAdd(this, ConstantInt8); |
Jim Stichnoth | d2cb436 | 2014-11-20 11:24:42 -0800 | [diff] [blame] | 747 | } |
| 748 | |
Karl Schimpf | 20070e8 | 2016-03-17 13:30:13 -0700 | [diff] [blame] | 749 | Constant *GlobalContext::getConstantInt16Internal(int16_t ConstantInt16) { |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 750 | return getConstPool()->Integers16.getOrAdd(this, ConstantInt16); |
Jim Stichnoth | d2cb436 | 2014-11-20 11:24:42 -0800 | [diff] [blame] | 751 | } |
| 752 | |
Karl Schimpf | 20070e8 | 2016-03-17 13:30:13 -0700 | [diff] [blame] | 753 | Constant *GlobalContext::getConstantInt32Internal(int32_t ConstantInt32) { |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 754 | return getConstPool()->Integers32.getOrAdd(this, ConstantInt32); |
Jim Stichnoth | d2cb436 | 2014-11-20 11:24:42 -0800 | [diff] [blame] | 755 | } |
| 756 | |
Karl Schimpf | 20070e8 | 2016-03-17 13:30:13 -0700 | [diff] [blame] | 757 | Constant *GlobalContext::getConstantInt64Internal(int64_t ConstantInt64) { |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 758 | return getConstPool()->Integers64.getOrAdd(this, ConstantInt64); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | Constant *GlobalContext::getConstantFloat(float ConstantFloat) { |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 762 | return getConstPool()->Floats.getOrAdd(this, ConstantFloat); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | Constant *GlobalContext::getConstantDouble(double ConstantDouble) { |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 766 | return getConstPool()->Doubles.getOrAdd(this, ConstantDouble); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 767 | } |
| 768 | |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 769 | Constant *GlobalContext::getConstantSymWithEmitString( |
| 770 | const RelocOffsetT Offset, const RelocOffsetArray &OffsetExpr, |
| 771 | GlobalString Name, const std::string &EmitString) { |
John Porto | 27fddcc | 2016-02-02 15:06:09 -0800 | [diff] [blame] | 772 | return getConstPool()->Relocatables.getOrAdd( |
Jim Stichnoth | 98ba006 | 2016-03-07 09:26:22 -0800 | [diff] [blame] | 773 | this, RelocatableTuple(Offset, OffsetExpr, Name, EmitString)); |
John Porto | 27fddcc | 2016-02-02 15:06:09 -0800 | [diff] [blame] | 774 | } |
| 775 | |
Jim Stichnoth | d2cb436 | 2014-11-20 11:24:42 -0800 | [diff] [blame] | 776 | Constant *GlobalContext::getConstantSym(RelocOffsetT Offset, |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 777 | GlobalString Name) { |
John Porto | 27fddcc | 2016-02-02 15:06:09 -0800 | [diff] [blame] | 778 | constexpr char EmptyEmitString[] = ""; |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 779 | return getConstantSymWithEmitString(Offset, {}, Name, EmptyEmitString); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 782 | Constant *GlobalContext::getConstantExternSym(GlobalString Name) { |
Jim Stichnoth | 5bff61c | 2015-10-28 09:26:00 -0700 | [diff] [blame] | 783 | constexpr RelocOffsetT Offset = 0; |
Jan Voung | 261cae3 | 2015-02-01 10:31:03 -0800 | [diff] [blame] | 784 | return getConstPool()->ExternRelocatables.getOrAdd( |
Jim Stichnoth | 98ba006 | 2016-03-07 09:26:22 -0800 | [diff] [blame] | 785 | this, RelocatableTuple(Offset, {}, Name)); |
Jan Voung | 261cae3 | 2015-02-01 10:31:03 -0800 | [diff] [blame] | 786 | } |
| 787 | |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 788 | Constant *GlobalContext::getConstantUndef(Type Ty) { |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 789 | return getConstPool()->Undefs.getOrAdd(this, Ty); |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | Constant *GlobalContext::getConstantZero(Type Ty) { |
Karl Schimpf | 20070e8 | 2016-03-17 13:30:13 -0700 | [diff] [blame] | 793 | Constant *Zero = ConstZeroForType[Ty]; |
| 794 | if (Zero == nullptr) |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 795 | llvm::report_fatal_error("Unsupported constant type: " + typeStdString(Ty)); |
Karl Schimpf | 20070e8 | 2016-03-17 13:30:13 -0700 | [diff] [blame] | 796 | return Zero; |
| 797 | } |
| 798 | |
| 799 | // All locking is done by the getConstant*() target function. |
| 800 | Constant *GlobalContext::getConstantZeroInternal(Type Ty) { |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 801 | switch (Ty) { |
| 802 | case IceType_i1: |
Karl Schimpf | 20070e8 | 2016-03-17 13:30:13 -0700 | [diff] [blame] | 803 | return getConstantInt1Internal(0); |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 804 | case IceType_i8: |
Karl Schimpf | 20070e8 | 2016-03-17 13:30:13 -0700 | [diff] [blame] | 805 | return getConstantInt8Internal(0); |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 806 | case IceType_i16: |
Karl Schimpf | 20070e8 | 2016-03-17 13:30:13 -0700 | [diff] [blame] | 807 | return getConstantInt16Internal(0); |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 808 | case IceType_i32: |
Karl Schimpf | 20070e8 | 2016-03-17 13:30:13 -0700 | [diff] [blame] | 809 | return getConstantInt32Internal(0); |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 810 | case IceType_i64: |
Karl Schimpf | 20070e8 | 2016-03-17 13:30:13 -0700 | [diff] [blame] | 811 | return getConstantInt64Internal(0); |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 812 | case IceType_f32: |
| 813 | return getConstantFloat(0); |
| 814 | case IceType_f64: |
| 815 | return getConstantDouble(0); |
Karl Schimpf | 20070e8 | 2016-03-17 13:30:13 -0700 | [diff] [blame] | 816 | default: |
| 817 | return nullptr; |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 818 | } |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 819 | } |
| 820 | |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 821 | ConstantList GlobalContext::getConstantPool(Type Ty) { |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 822 | switch (Ty) { |
| 823 | case IceType_i1: |
| 824 | case IceType_i8: |
Qining Lu | 253dc8a | 2015-06-22 10:10:23 -0700 | [diff] [blame] | 825 | return getConstPool()->Integers8.getConstantPool(); |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 826 | case IceType_i16: |
Qining Lu | 253dc8a | 2015-06-22 10:10:23 -0700 | [diff] [blame] | 827 | return getConstPool()->Integers16.getConstantPool(); |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 828 | case IceType_i32: |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 829 | return getConstPool()->Integers32.getConstantPool(); |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 830 | case IceType_i64: |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 831 | return getConstPool()->Integers64.getConstantPool(); |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 832 | case IceType_f32: |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 833 | return getConstPool()->Floats.getConstantPool(); |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 834 | case IceType_f64: |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 835 | return getConstPool()->Doubles.getConstantPool(); |
Matt Wala | 928f129 | 2014-07-07 16:50:46 -0700 | [diff] [blame] | 836 | case IceType_v4i1: |
| 837 | case IceType_v8i1: |
| 838 | case IceType_v16i1: |
| 839 | case IceType_v16i8: |
| 840 | case IceType_v8i16: |
| 841 | case IceType_v4i32: |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 842 | case IceType_v4f32: |
| 843 | llvm::report_fatal_error("Unsupported constant type: " + typeStdString(Ty)); |
| 844 | break; |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 845 | case IceType_void: |
| 846 | case IceType_NUM: |
| 847 | break; |
| 848 | } |
| 849 | llvm_unreachable("Unknown type"); |
| 850 | } |
| 851 | |
Jan Voung | 261cae3 | 2015-02-01 10:31:03 -0800 | [diff] [blame] | 852 | ConstantList GlobalContext::getConstantExternSyms() { |
| 853 | return getConstPool()->ExternRelocatables.getConstantPool(); |
| 854 | } |
| 855 | |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 856 | GlobalString GlobalContext::getGlobalString(const std::string &Name) { |
| 857 | return GlobalString::createWithString(this, Name); |
| 858 | } |
| 859 | |
Andrew Scull | 1eda90a | 2015-08-04 17:03:19 -0700 | [diff] [blame] | 860 | JumpTableDataList GlobalContext::getJumpTables() { |
| 861 | JumpTableDataList JumpTables(*getJumpTableList()); |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 862 | // Make order deterministic by sorting into functions and then ID of the jump |
| 863 | // table within that function. |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 864 | std::sort(JumpTables.begin(), JumpTables.end(), |
| 865 | [](const JumpTableData &A, const JumpTableData &B) { |
| 866 | if (A.getFunctionName() != B.getFunctionName()) |
| 867 | return A.getFunctionName() < B.getFunctionName(); |
| 868 | return A.getId() < B.getId(); |
| 869 | }); |
| 870 | |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 871 | if (getFlags().getReorderPooledConstants()) { |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 872 | // If reorder-pooled-constants option is set to true, we also shuffle the |
| 873 | // jump tables before emitting them. |
| 874 | |
| 875 | // Create a random number generator for jump tables reordering, considering |
| 876 | // jump tables as pooled constants. |
| 877 | RandomNumberGenerator RNG(getFlags().getRandomSeed(), |
| 878 | RPE_PooledConstantReordering); |
John Porto | e0d9afa | 2015-08-05 10:13:44 -0700 | [diff] [blame] | 879 | RandomShuffle(JumpTables.begin(), JumpTables.end(), |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 880 | [&RNG](uint64_t N) { return (uint32_t)RNG.next(N); }); |
Andrew Scull | 1eda90a | 2015-08-04 17:03:19 -0700 | [diff] [blame] | 881 | } |
| 882 | return JumpTables; |
| 883 | } |
| 884 | |
John Porto | 0307721 | 2016-04-05 06:30:21 -0700 | [diff] [blame] | 885 | void GlobalContext::addJumpTableData(JumpTableData JumpTable) { |
| 886 | getJumpTableList()->emplace_back(std::move(JumpTable)); |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 889 | TimerStackIdT GlobalContext::newTimerStackID(const std::string &Name) { |
Jim Stichnoth | b88d8c8 | 2016-03-11 15:33:00 -0800 | [diff] [blame] | 890 | if (!BuildDefs::timers()) |
Jim Stichnoth | 1c44d81 | 2014-12-08 14:57:52 -0800 | [diff] [blame] | 891 | return 0; |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 892 | auto Timers = getTimers(); |
| 893 | TimerStackIdT NewID = Timers->size(); |
| 894 | Timers->push_back(TimerStack(Name)); |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 895 | return NewID; |
| 896 | } |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 897 | |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 898 | TimerIdT GlobalContext::getTimerID(TimerStackIdT StackID, |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 899 | const std::string &Name) { |
Jim Stichnoth | 2b000fd | 2016-04-06 06:37:15 -0700 | [diff] [blame] | 900 | auto *Timers = &ICE_TLS_GET_FIELD(TLS)->Timers; |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 901 | assert(StackID < Timers->size()); |
| 902 | return Timers->at(StackID).getTimerID(Name); |
| 903 | } |
| 904 | |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 905 | void GlobalContext::pushTimer(TimerIdT ID, TimerStackIdT StackID) { |
Jim Stichnoth | 2b000fd | 2016-04-06 06:37:15 -0700 | [diff] [blame] | 906 | auto *Timers = &ICE_TLS_GET_FIELD(TLS)->Timers; |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 907 | assert(StackID < Timers->size()); |
| 908 | Timers->at(StackID).push(ID); |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | void GlobalContext::popTimer(TimerIdT ID, TimerStackIdT StackID) { |
Jim Stichnoth | 2b000fd | 2016-04-06 06:37:15 -0700 | [diff] [blame] | 912 | auto *Timers = &ICE_TLS_GET_FIELD(TLS)->Timers; |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 913 | assert(StackID < Timers->size()); |
| 914 | Timers->at(StackID).pop(ID); |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 915 | } |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 916 | |
Jim Stichnoth | d14b1a0 | 2014-10-08 08:28:36 -0700 | [diff] [blame] | 917 | void GlobalContext::resetTimer(TimerStackIdT StackID) { |
Jim Stichnoth | 2b000fd | 2016-04-06 06:37:15 -0700 | [diff] [blame] | 918 | auto *Timers = &ICE_TLS_GET_FIELD(TLS)->Timers; |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 919 | assert(StackID < Timers->size()); |
| 920 | Timers->at(StackID).reset(); |
Jim Stichnoth | d14b1a0 | 2014-10-08 08:28:36 -0700 | [diff] [blame] | 921 | } |
| 922 | |
Jim Stichnoth | 2b000fd | 2016-04-06 06:37:15 -0700 | [diff] [blame] | 923 | std::string GlobalContext::getTimerName(TimerStackIdT StackID) { |
| 924 | auto *Timers = &ICE_TLS_GET_FIELD(TLS)->Timers; |
| 925 | assert(StackID < Timers->size()); |
| 926 | return Timers->at(StackID).getName(); |
| 927 | } |
| 928 | |
Jim Stichnoth | d14b1a0 | 2014-10-08 08:28:36 -0700 | [diff] [blame] | 929 | void GlobalContext::setTimerName(TimerStackIdT StackID, |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 930 | const std::string &NewName) { |
Jim Stichnoth | 2b000fd | 2016-04-06 06:37:15 -0700 | [diff] [blame] | 931 | auto *Timers = &ICE_TLS_GET_FIELD(TLS)->Timers; |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 932 | assert(StackID < Timers->size()); |
| 933 | Timers->at(StackID).setName(NewName); |
Jim Stichnoth | d14b1a0 | 2014-10-08 08:28:36 -0700 | [diff] [blame] | 934 | } |
| 935 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 936 | // Note: optQueueBlockingPush and optQueueBlockingPop use unique_ptr at the |
| 937 | // interface to take and transfer ownership, but they internally store the raw |
| 938 | // Cfg pointer in the work queue. This allows e.g. future queue optimizations |
| 939 | // such as the use of atomics to modify queue elements. |
Karl Schimpf | e8457a2 | 2016-03-31 10:20:23 -0700 | [diff] [blame] | 940 | void GlobalContext::optQueueBlockingPush(std::unique_ptr<OptWorkItem> Item) { |
| 941 | assert(Item); |
Jim Stichnoth | b88d8c8 | 2016-03-11 15:33:00 -0800 | [diff] [blame] | 942 | { |
| 943 | TimerMarker _(TimerStack::TT_qTransPush, this); |
Karl Schimpf | e8457a2 | 2016-03-31 10:20:23 -0700 | [diff] [blame] | 944 | OptQ.blockingPush(std::move(Item)); |
Jim Stichnoth | b88d8c8 | 2016-03-11 15:33:00 -0800 | [diff] [blame] | 945 | } |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 946 | if (getFlags().isSequential()) |
| 947 | translateFunctions(); |
Jim Stichnoth | 8e92838 | 2015-02-02 17:03:08 -0800 | [diff] [blame] | 948 | } |
| 949 | |
Karl Schimpf | e8457a2 | 2016-03-31 10:20:23 -0700 | [diff] [blame] | 950 | std::unique_ptr<OptWorkItem> GlobalContext::optQueueBlockingPop() { |
Jim Stichnoth | b88d8c8 | 2016-03-11 15:33:00 -0800 | [diff] [blame] | 951 | TimerMarker _(TimerStack::TT_qTransPop, this); |
Karl Schimpf | 3018cf2 | 2016-04-11 14:49:01 -0700 | [diff] [blame^] | 952 | return OptQ.blockingPop(OptQWakeupSize); |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 953 | } |
| 954 | |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 955 | void GlobalContext::emitQueueBlockingPush( |
| 956 | std::unique_ptr<EmitterWorkItem> Item) { |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 957 | assert(Item); |
Jim Stichnoth | b88d8c8 | 2016-03-11 15:33:00 -0800 | [diff] [blame] | 958 | { |
| 959 | TimerMarker _(TimerStack::TT_qEmitPush, this); |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 960 | EmitQ.blockingPush(std::move(Item)); |
Jim Stichnoth | b88d8c8 | 2016-03-11 15:33:00 -0800 | [diff] [blame] | 961 | } |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 962 | if (getFlags().isSequential()) |
| 963 | emitItems(); |
| 964 | } |
| 965 | |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 966 | std::unique_ptr<EmitterWorkItem> GlobalContext::emitQueueBlockingPop() { |
Jim Stichnoth | b88d8c8 | 2016-03-11 15:33:00 -0800 | [diff] [blame] | 967 | TimerMarker _(TimerStack::TT_qEmitPop, this); |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 968 | return EmitQ.blockingPop(); |
Jim Stichnoth | 8e92838 | 2015-02-02 17:03:08 -0800 | [diff] [blame] | 969 | } |
| 970 | |
Jim Stichnoth | b5eee3d | 2016-03-31 11:05:39 -0700 | [diff] [blame] | 971 | void GlobalContext::dumpStats(const Cfg *Func) { |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 972 | if (!getFlags().getDumpStats()) |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 973 | return; |
Jim Stichnoth | b5eee3d | 2016-03-31 11:05:39 -0700 | [diff] [blame] | 974 | if (Func == nullptr) { |
| 975 | getStatsCumulative()->dump(Func, this); |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 976 | } else { |
Jim Stichnoth | b5eee3d | 2016-03-31 11:05:39 -0700 | [diff] [blame] | 977 | ICE_TLS_GET_FIELD(TLS)->StatsFunction.dump(Func, this); |
Jim Stichnoth | 1873560 | 2014-09-16 19:59:35 -0700 | [diff] [blame] | 978 | } |
| 979 | } |
| 980 | |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 981 | void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) { |
Jim Stichnoth | b88d8c8 | 2016-03-11 15:33:00 -0800 | [diff] [blame] | 982 | if (!BuildDefs::timers()) |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 983 | return; |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 984 | auto Timers = getTimers(); |
| 985 | assert(Timers->size() > StackID); |
| 986 | OstreamLocker L(this); |
| 987 | Timers->at(StackID).dump(getStrDump(), DumpCumulative); |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 988 | } |
| 989 | |
Jim Stichnoth | 2b000fd | 2016-04-06 06:37:15 -0700 | [diff] [blame] | 990 | void GlobalContext::dumpLocalTimers(const std::string &TimerNameOverride, |
| 991 | TimerStackIdT StackID, |
| 992 | bool DumpCumulative) { |
| 993 | if (!BuildDefs::timers()) |
| 994 | return; |
| 995 | auto *Timers = &ICE_TLS_GET_FIELD(TLS)->Timers; |
| 996 | assert(Timers->size() > StackID); |
| 997 | // Temporarily override the thread-local timer name with the given name. |
| 998 | // Don't do it permanently because the final timer merge at the end expects |
| 999 | // the thread-local timer names to be the same as the global timer name. |
| 1000 | auto OrigName = getTimerName(StackID); |
| 1001 | setTimerName(StackID, TimerNameOverride); |
| 1002 | { |
| 1003 | OstreamLocker _(this); |
| 1004 | Timers->at(StackID).dump(getStrDump(), DumpCumulative); |
| 1005 | } |
| 1006 | setTimerName(StackID, OrigName); |
| 1007 | } |
| 1008 | |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 1009 | LockedPtr<StringPool> |
| 1010 | GlobalStringPoolTraits::getStrings(const GlobalContext *PoolOwner) { |
| 1011 | return PoolOwner->getStrings(); |
| 1012 | } |
| 1013 | |
Jim Stichnoth | b88d8c8 | 2016-03-11 15:33:00 -0800 | [diff] [blame] | 1014 | TimerIdT TimerMarker::getTimerIdFromFuncName(GlobalContext *Ctx, |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 1015 | const std::string &FuncName) { |
Jim Stichnoth | b88d8c8 | 2016-03-11 15:33:00 -0800 | [diff] [blame] | 1016 | if (!BuildDefs::timers()) |
| 1017 | return 0; |
Karl Schimpf | d469994 | 2016-04-02 09:55:31 -0700 | [diff] [blame] | 1018 | if (!getFlags().getTimeEachFunction()) |
Jim Stichnoth | b88d8c8 | 2016-03-11 15:33:00 -0800 | [diff] [blame] | 1019 | return 0; |
| 1020 | return Ctx->getTimerID(GlobalContext::TSK_Funcs, FuncName); |
| 1021 | } |
| 1022 | |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 1023 | void TimerMarker::push() { |
| 1024 | switch (StackID) { |
| 1025 | case GlobalContext::TSK_Default: |
Jim Stichnoth | 318c01b | 2016-04-03 21:58:03 -0700 | [diff] [blame] | 1026 | Active = getFlags().getSubzeroTimingEnabled() || |
| 1027 | !getFlags().getTimingFocusOn().empty(); |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 1028 | break; |
| 1029 | case GlobalContext::TSK_Funcs: |
Karl Schimpf | d469994 | 2016-04-02 09:55:31 -0700 | [diff] [blame] | 1030 | Active = getFlags().getTimeEachFunction(); |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 1031 | break; |
| 1032 | default: |
| 1033 | break; |
Jim Stichnoth | 1c44d81 | 2014-12-08 14:57:52 -0800 | [diff] [blame] | 1034 | } |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 1035 | if (Active) |
| 1036 | Ctx->pushTimer(ID, StackID); |
| 1037 | } |
| 1038 | |
| 1039 | void TimerMarker::pushCfg(const Cfg *Func) { |
| 1040 | Ctx = Func->getContext(); |
Karl Schimpf | d469994 | 2016-04-02 09:55:31 -0700 | [diff] [blame] | 1041 | Active = Func->getFocusedTiming() || getFlags().getSubzeroTimingEnabled(); |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 1042 | if (Active) |
| 1043 | Ctx->pushTimer(ID, StackID); |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 1044 | } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 1045 | |
Jim Stichnoth | a5fe17a | 2015-01-26 11:10:03 -0800 | [diff] [blame] | 1046 | ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 1047 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 1048 | } // end of namespace Ice |