OLD | NEW |
1 //===- subzero/src/IceGlobalContext.cpp - Global context defs -------------===// | 1 //===- subzero/src/IceGlobalContext.cpp - Global context defs -------------===// |
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 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // TypePool maps constants of type KeyType (e.g. float) to pointers to | 136 // TypePool maps constants of type KeyType (e.g. float) to pointers to |
137 // type ValueType (e.g. ConstantFloat). | 137 // type ValueType (e.g. ConstantFloat). |
138 template <Type Ty, typename KeyType, typename ValueType> class TypePool { | 138 template <Type Ty, typename KeyType, typename ValueType> class TypePool { |
139 TypePool(const TypePool &) = delete; | 139 TypePool(const TypePool &) = delete; |
140 TypePool &operator=(const TypePool &) = delete; | 140 TypePool &operator=(const TypePool &) = delete; |
141 | 141 |
142 public: | 142 public: |
143 TypePool() = default; | 143 TypePool() = default; |
144 ValueType *getOrAdd(GlobalContext *Ctx, KeyType Key) { | 144 ValueType *getOrAdd(GlobalContext *Ctx, KeyType Key) { |
145 auto Iter = Pool.find(Key); | 145 auto Iter = Pool.find(Key); |
146 if (Iter != Pool.end()) | 146 if (Iter != Pool.end()) { |
| 147 Iter->second->updateLookupCount(); |
147 return Iter->second; | 148 return Iter->second; |
| 149 } |
148 auto *Result = ValueType::create(Ctx, Ty, Key); | 150 auto *Result = ValueType::create(Ctx, Ty, Key); |
149 Pool[Key] = Result; | 151 Pool[Key] = Result; |
| 152 Result->updateLookupCount(); |
150 return Result; | 153 return Result; |
151 } | 154 } |
152 ConstantList getConstantPool() const { | 155 ConstantList getConstantPool() const { |
153 ConstantList Constants; | 156 ConstantList Constants; |
154 Constants.reserve(Pool.size()); | 157 Constants.reserve(Pool.size()); |
155 for (auto &I : Pool) | 158 for (auto &I : Pool) |
156 Constants.push_back(I.second); | 159 Constants.push_back(I.second); |
157 // The sort (and its KeyCompareLess machinery) is not strictly necessary, | 160 // The sort (and its KeyCompareLess machinery) is not strictly necessary, |
158 // but is desirable for producing output that is deterministic across | 161 // but is desirable for producing output that is deterministic across |
159 // unordered_map::iterator implementations. | 162 // unordered_map::iterator implementations. |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 ProfileBlockInfo->addInitializer( | 406 ProfileBlockInfo->addInitializer( |
404 VariableDeclaration::RelocInitializer::create( | 407 VariableDeclaration::RelocInitializer::create( |
405 Global, | 408 Global, |
406 {RelocOffset::create(this, BlockExecutionCounterOffset)})); | 409 {RelocOffset::create(this, BlockExecutionCounterOffset)})); |
407 } | 410 } |
408 } | 411 } |
409 } | 412 } |
410 | 413 |
411 void GlobalContext::lowerGlobals(const IceString &SectionSuffix) { | 414 void GlobalContext::lowerGlobals(const IceString &SectionSuffix) { |
412 TimerMarker T(TimerStack::TT_emitGlobalInitializers, this); | 415 TimerMarker T(TimerStack::TT_emitGlobalInitializers, this); |
413 const bool DumpGlobalVariables = | 416 const bool DumpGlobalVariables = BuildDefs::dump() && |
414 BuildDefs::dump() && | 417 (Flags.getVerbose() & IceV_GlobalInit) && |
415 (Flags.getVerbose() & IceV_GlobalInit & Cfg::defaultVerboseMask()) && | 418 Flags.getVerboseFocusOn().empty(); |
416 Flags.getVerboseFocusOn().empty(); | |
417 if (DumpGlobalVariables) { | 419 if (DumpGlobalVariables) { |
418 OstreamLocker L(this); | 420 OstreamLocker L(this); |
419 Ostream &Stream = getStrDump(); | 421 Ostream &Stream = getStrDump(); |
420 for (const Ice::VariableDeclaration *Global : Globals) { | 422 for (const Ice::VariableDeclaration *Global : Globals) { |
421 Global->dump(this, Stream); | 423 Global->dump(this, Stream); |
422 } | 424 } |
423 } | 425 } |
424 if (Flags.getDisableTranslation()) | 426 if (Flags.getDisableTranslation()) |
425 return; | 427 return; |
426 | 428 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 } | 753 } |
752 | 754 |
753 GlobalContext::~GlobalContext() { | 755 GlobalContext::~GlobalContext() { |
754 llvm::DeleteContainerPointers(AllThreadContexts); | 756 llvm::DeleteContainerPointers(AllThreadContexts); |
755 LockedPtr<DestructorArray> Dtors = getDestructors(); | 757 LockedPtr<DestructorArray> Dtors = getDestructors(); |
756 // Destructors are invoked in the opposite object construction order. | 758 // Destructors are invoked in the opposite object construction order. |
757 for (const auto &Dtor : reverse_range(*Dtors)) | 759 for (const auto &Dtor : reverse_range(*Dtors)) |
758 Dtor(); | 760 Dtor(); |
759 } | 761 } |
760 | 762 |
| 763 void GlobalContext::dumpConstantLookupCounts() { |
| 764 if (!BuildDefs::dump()) |
| 765 return; |
| 766 const bool DumpCounts = (Flags.getVerbose() & IceV_ConstPoolStats) && |
| 767 Flags.getVerboseFocusOn().empty(); |
| 768 if (!DumpCounts) |
| 769 return; |
| 770 |
| 771 OstreamLocker _(this); |
| 772 Ostream &Str = getStrDump(); |
| 773 Str << "Constant pool use stats: count+value+type\n"; |
| 774 #define X(WhichPool) \ |
| 775 for (auto *C : getConstPool()->WhichPool.getConstantPool()) { \ |
| 776 Str << C->getLookupCount() << " "; \ |
| 777 C->dump(Str); \ |
| 778 Str << " " << C->getType() << "\n"; \ |
| 779 } |
| 780 X(Integers1); |
| 781 X(Integers8); |
| 782 X(Integers16); |
| 783 X(Integers32); |
| 784 X(Integers64); |
| 785 X(Floats); |
| 786 X(Doubles); |
| 787 X(Relocatables); |
| 788 X(ExternRelocatables); |
| 789 #undef X |
| 790 } |
| 791 |
761 // TODO(stichnot): Consider adding thread-local caches of constant pool entries | 792 // TODO(stichnot): Consider adding thread-local caches of constant pool entries |
762 // to reduce contention. | 793 // to reduce contention. |
763 | 794 |
764 // All locking is done by the getConstantInt[0-9]+() target function. | 795 // All locking is done by the getConstantInt[0-9]+() target function. |
765 Constant *GlobalContext::getConstantInt(Type Ty, int64_t Value) { | 796 Constant *GlobalContext::getConstantInt(Type Ty, int64_t Value) { |
766 switch (Ty) { | 797 switch (Ty) { |
767 case IceType_i1: | 798 case IceType_i1: |
768 return getConstantInt1(Value); | 799 return getConstantInt1(Value); |
769 case IceType_i8: | 800 case IceType_i8: |
770 return getConstantInt8(Value); | 801 return getConstantInt8(Value); |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 Ctx = Func->getContext(); | 1080 Ctx = Func->getContext(); |
1050 Active = | 1081 Active = |
1051 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); | 1082 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); |
1052 if (Active) | 1083 if (Active) |
1053 Ctx->pushTimer(ID, StackID); | 1084 Ctx->pushTimer(ID, StackID); |
1054 } | 1085 } |
1055 | 1086 |
1056 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); | 1087 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); |
1057 | 1088 |
1058 } // end of namespace Ice | 1089 } // end of namespace Ice |
OLD | NEW |