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

Side by Side Diff: src/IceDefs.h

Issue 1181013016: Subzero. Fixes memory leaks. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Addresses codereview comments. Created 5 years, 6 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/IceELFObjectWriter.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/IceDefs.h - Common Subzero declaraions -------*- C++ -*-===// 1 //===- subzero/src/IceDefs.h - Common Subzero declaraions -------*- C++ -*-===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This file declares various useful types and classes that have 10 // This file declares various useful types and classes that have
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 inline bool operator==(const CfgLocalAllocator<T> &, 86 inline bool operator==(const CfgLocalAllocator<T> &,
87 const CfgLocalAllocator<U> &) { 87 const CfgLocalAllocator<U> &) {
88 return true; 88 return true;
89 } 89 }
90 template <typename T, typename U> 90 template <typename T, typename U>
91 inline bool operator!=(const CfgLocalAllocator<T> &, 91 inline bool operator!=(const CfgLocalAllocator<T> &,
92 const CfgLocalAllocator<U> &) { 92 const CfgLocalAllocator<U> &) {
93 return false; 93 return false;
94 } 94 }
95 95
96 // makeUnique should be used when memory is expected to be allocated from the
97 // heap (as opposed to allocated from some Allocator.) It is intended to be used
98 // instead of new.
99 //
100 // The expected usage is as follows
101 //
102 // class MyClass {
103 // public:
104 // static std::unique_ptr<MyClass> create(<ctor_args>) {
105 // return makeUnique<MyClass>(<ctor_args>);
106 // }
107 //
108 // private:
109 // ENABLE_MAKE_UNIQUE;
110 //
111 // MyClass(<ctor_args>) ...
112 // }
113 //
114 // ENABLE_MAKE_UNIQUE is a trick that is necessary if MyClass' ctor is private.
115 // Private ctors are highly encouraged when you're writing a class that you'd
116 // like to have allocated with makeUnique as it would prevent users from
117 // declaring stack allocated variables.
118 namespace Internal {
119 struct MakeUniqueEnabler {
120 template <class T, class... Args>
121 static std::unique_ptr<T> create(Args &&... TheArgs) {
122 std::unique_ptr<T> Unique(new T(std::forward<Args>(TheArgs)...));
123 return Unique;
124 }
125 };
126 } // end of namespace Internal
127
128 template <class T, class... Args>
129 static std::unique_ptr<T> makeUnique(Args &&... TheArgs) {
130 return ::Ice::Internal::MakeUniqueEnabler::create<T>(
131 std::forward<Args>(TheArgs)...);
132 }
133
134 #define ENABLE_MAKE_UNIQUE friend struct ::Ice::Internal::MakeUniqueEnabler
135
96 typedef std::string IceString; 136 typedef std::string IceString;
97 typedef llvm::ilist<Inst> InstList; 137 typedef llvm::ilist<Inst> InstList;
98 // Ideally PhiList would be llvm::ilist<InstPhi>, and similar for 138 // Ideally PhiList would be llvm::ilist<InstPhi>, and similar for
99 // AssignList, but this runs into issues with SFINAE. 139 // AssignList, but this runs into issues with SFINAE.
100 typedef InstList PhiList; 140 typedef InstList PhiList;
101 typedef InstList AssignList; 141 typedef InstList AssignList;
102 // VarList and NodeList are arena-allocated from the Cfg's allocator. 142 // VarList and NodeList are arena-allocated from the Cfg's allocator.
103 typedef std::vector<Variable *, CfgLocalAllocator<Variable *>> VarList; 143 typedef std::vector<Variable *, CfgLocalAllocator<Variable *>> VarList;
104 typedef std::vector<CfgNode *, CfgLocalAllocator<CfgNode *>> NodeList; 144 typedef std::vector<CfgNode *, CfgLocalAllocator<CfgNode *>> NodeList;
105 typedef std::vector<Constant *> ConstantList; 145 typedef std::vector<Constant *> ConstantList;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 return llvm::make_range(Container.rbegin(), Container.rend()); 261 return llvm::make_range(Container.rbegin(), Container.rend());
222 } 262 }
223 template <typename T> 263 template <typename T>
224 llvm::iterator_range<typename T::reverse_iterator> reverse_range(T &Container) { 264 llvm::iterator_range<typename T::reverse_iterator> reverse_range(T &Container) {
225 return llvm::make_range(Container.rbegin(), Container.rend()); 265 return llvm::make_range(Container.rbegin(), Container.rend());
226 } 266 }
227 267
228 } // end of namespace Ice 268 } // end of namespace Ice
229 269
230 #endif // SUBZERO_SRC_ICEDEFS_H 270 #endif // SUBZERO_SRC_ICEDEFS_H
OLDNEW
« no previous file with comments | « src/IceConverter.cpp ('k') | src/IceELFObjectWriter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698