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

Side by Side Diff: src/IceGlobalContext.cpp

Issue 619893002: Subzero: Auto-awesome iterators. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Use AsmCodeByte instead of uint8_t Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/IceConverter.cpp ('k') | src/IceInst.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/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 // This file defines aspects of the compilation that persist across 10 // This file defines aspects of the compilation that persist across
(...skipping 24 matching lines...) Expand all
35 // KeyTypeHasFP with C++11. 35 // KeyTypeHasFP with C++11.
36 template <typename KeyType, typename ValueType, bool KeyTypeHasFP = false> 36 template <typename KeyType, typename ValueType, bool KeyTypeHasFP = false>
37 class TypePool { 37 class TypePool {
38 TypePool(const TypePool &) LLVM_DELETED_FUNCTION; 38 TypePool(const TypePool &) LLVM_DELETED_FUNCTION;
39 TypePool &operator=(const TypePool &) LLVM_DELETED_FUNCTION; 39 TypePool &operator=(const TypePool &) LLVM_DELETED_FUNCTION;
40 40
41 public: 41 public:
42 TypePool() : NextPoolID(0) {} 42 TypePool() : NextPoolID(0) {}
43 ValueType *getOrAdd(GlobalContext *Ctx, Type Ty, KeyType Key) { 43 ValueType *getOrAdd(GlobalContext *Ctx, Type Ty, KeyType Key) {
44 TupleType TupleKey = std::make_pair(Ty, Key); 44 TupleType TupleKey = std::make_pair(Ty, Key);
45 typename ContainerType::const_iterator Iter = Pool.find(TupleKey); 45 auto Iter = Pool.find(TupleKey);
46 if (Iter != Pool.end()) 46 if (Iter != Pool.end())
47 return Iter->second; 47 return Iter->second;
48 ValueType *Result = ValueType::create(Ctx, Ty, Key, NextPoolID++); 48 ValueType *Result = ValueType::create(Ctx, Ty, Key, NextPoolID++);
49 Pool[TupleKey] = Result; 49 Pool[TupleKey] = Result;
50 return Result; 50 return Result;
51 } 51 }
52 ConstantList getConstantPool() const { 52 ConstantList getConstantPool() const {
53 ConstantList Constants; 53 ConstantList Constants;
54 Constants.reserve(Pool.size()); 54 Constants.reserve(Pool.size());
55 // TODO: replace the loop with std::transform + lambdas. 55 for (auto &I : Pool)
56 for (typename ContainerType::const_iterator I = Pool.begin(), 56 Constants.push_back(I.second);
57 E = Pool.end();
58 I != E; ++I) {
59 Constants.push_back(I->second);
60 }
61 return Constants; 57 return Constants;
62 } 58 }
63 59
64 private: 60 private:
65 typedef std::pair<Type, KeyType> TupleType; 61 typedef std::pair<Type, KeyType> TupleType;
66 struct TupleCompare { 62 struct TupleCompare {
67 bool operator()(const TupleType &A, const TupleType &B) const { 63 bool operator()(const TupleType &A, const TupleType &B) const {
68 if (A.first != B.first) 64 if (A.first != B.first)
69 return A.first < B.first; 65 return A.first < B.first;
70 if (KeyTypeHasFP) 66 if (KeyTypeHasFP)
71 return memcmp(&A.second, &B.second, sizeof(KeyType)) < 0; 67 return memcmp(&A.second, &B.second, sizeof(KeyType)) < 0;
72 return A.second < B.second; 68 return A.second < B.second;
73 } 69 }
74 }; 70 };
75 typedef std::map<const TupleType, ValueType *, TupleCompare> ContainerType; 71 typedef std::map<const TupleType, ValueType *, TupleCompare> ContainerType;
76 ContainerType Pool; 72 ContainerType Pool;
77 uint32_t NextPoolID; 73 uint32_t NextPoolID;
78 }; 74 };
79 75
80 // UndefPool maps ICE types to the corresponding ConstantUndef values. 76 // UndefPool maps ICE types to the corresponding ConstantUndef values.
81 class UndefPool { 77 class UndefPool {
82 UndefPool(const UndefPool &) LLVM_DELETED_FUNCTION; 78 UndefPool(const UndefPool &) LLVM_DELETED_FUNCTION;
83 UndefPool &operator=(const UndefPool &) LLVM_DELETED_FUNCTION; 79 UndefPool &operator=(const UndefPool &) LLVM_DELETED_FUNCTION;
84 80
85 public: 81 public:
86 UndefPool() : NextPoolID(0) {} 82 UndefPool() : NextPoolID(0) {}
87 83
88 ConstantUndef *getOrAdd(GlobalContext *Ctx, Type Ty) { 84 ConstantUndef *getOrAdd(GlobalContext *Ctx, Type Ty) {
89 ContainerType::iterator I = Pool.find(Ty); 85 auto I = Pool.find(Ty);
90 if (I != Pool.end()) 86 if (I != Pool.end())
91 return I->second; 87 return I->second;
92 ConstantUndef *Undef = ConstantUndef::create(Ctx, Ty, NextPoolID++); 88 ConstantUndef *Undef = ConstantUndef::create(Ctx, Ty, NextPoolID++);
93 Pool[Ty] = Undef; 89 Pool[Ty] = Undef;
94 return Undef; 90 return Undef;
95 } 91 }
96 92
97 private: 93 private:
98 uint32_t NextPoolID; 94 uint32_t NextPoolID;
99 typedef std::map<Type, ConstantUndef *> ContainerType; 95 typedef std::map<Type, ConstantUndef *> ContainerType;
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 } else { 396 } else {
401 StatsFunction.dump(Name, getStrDump()); 397 StatsFunction.dump(Name, getStrDump());
402 StatsCumulative.dump("_TOTAL_", getStrDump()); 398 StatsCumulative.dump("_TOTAL_", getStrDump());
403 } 399 }
404 } 400 }
405 } 401 }
406 402
407 void GlobalContext::dumpTimers() { Timers->dump(getStrDump()); } 403 void GlobalContext::dumpTimers() { Timers->dump(getStrDump()); }
408 404
409 } // end of namespace Ice 405 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceConverter.cpp ('k') | src/IceInst.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698