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

Side by Side Diff: src/IceCfg.h

Issue 802183004: Subzero: Use CFG-local arena allocation for relevant containers. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Typo fix Created 6 years 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 | « ALLOCATION.rst ('k') | src/IceCfg.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/IceCfg.h - Control flow graph ----------------*- C++ -*-===// 1 //===- subzero/src/IceCfg.h - Control flow graph ----------------*- 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 the Cfg class, which represents the control flow 10 // This file declares the Cfg class, which represents the control flow
11 // graph and the overall per-function compilation context. 11 // graph and the overall per-function compilation context.
12 // 12 //
13 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
14 14
15 #ifndef SUBZERO_SRC_ICECFG_H 15 #ifndef SUBZERO_SRC_ICECFG_H
16 #define SUBZERO_SRC_ICECFG_H 16 #define SUBZERO_SRC_ICECFG_H
17 17
18 #include <memory> 18 #include <memory>
19 19
20 #include "llvm/Support/Allocator.h"
21
22 #include "assembler.h" 20 #include "assembler.h"
23 #include "IceClFlags.h" 21 #include "IceClFlags.h"
24 #include "IceDefs.h" 22 #include "IceDefs.h"
25 #include "IceGlobalContext.h" 23 #include "IceGlobalContext.h"
26 #include "IceTypes.h" 24 #include "IceTypes.h"
27 25
28 namespace Ice { 26 namespace Ice {
29 27
30 class Cfg { 28 class Cfg {
31 Cfg(const Cfg &) = delete; 29 Cfg(const Cfg &) = delete;
32 Cfg &operator=(const Cfg &) = delete; 30 Cfg &operator=(const Cfg &) = delete;
33 31
34 public: 32 public:
35 Cfg(GlobalContext *Ctx);
36 ~Cfg(); 33 ~Cfg();
37 34
35 // TODO(stichnot): Change this to return unique_ptr<Cfg>, and plumb
36 // it through the callers, to make ownership and lifetime and
37 // destruction requirements more explicit.
38 static Cfg *create(GlobalContext *Ctx) {
39 Cfg *Func = new Cfg(Ctx);
40 CurrentCfg = Func;
41 return Func;
42 }
43 // Gets a pointer to the current thread's Cfg.
44 static const Cfg *getCurrentCfg() { return CurrentCfg; }
45 // Gets a pointer to the current thread's Cfg's allocator.
46 static ArenaAllocator *getCurrentCfgAllocator() {
47 assert(CurrentCfg);
48 return CurrentCfg->Allocator.get();
49 }
50
38 GlobalContext *getContext() const { return Ctx; } 51 GlobalContext *getContext() const { return Ctx; }
39 52
40 // Manage the name and return type of the function being translated. 53 // Manage the name and return type of the function being translated.
41 void setFunctionName(const IceString &Name) { FunctionName = Name; } 54 void setFunctionName(const IceString &Name) { FunctionName = Name; }
42 IceString getFunctionName() const { return FunctionName; } 55 IceString getFunctionName() const { return FunctionName; }
43 void setReturnType(Type Ty) { ReturnType = Ty; } 56 void setReturnType(Type Ty) { ReturnType = Ty; }
44 57
45 // Manage the "internal" attribute of the function. 58 // Manage the "internal" attribute of the function.
46 void setInternal(bool Internal) { IsInternalLinkage = Internal; } 59 void setInternal(bool Internal) { IsInternalLinkage = Internal; }
47 bool getInternal() const { return IsInternalLinkage; } 60 bool getInternal() const { return IsInternalLinkage; }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 void setCurrentNode(const CfgNode *Node) { CurrentNode = Node; } 156 void setCurrentNode(const CfgNode *Node) { CurrentNode = Node; }
144 void resetCurrentNode() { setCurrentNode(NULL); } 157 void resetCurrentNode() { setCurrentNode(NULL); }
145 const CfgNode *getCurrentNode() const { return CurrentNode; } 158 const CfgNode *getCurrentNode() const { return CurrentNode; }
146 159
147 void emit(); 160 void emit();
148 void emitIAS(); 161 void emitIAS();
149 void emitTextHeader(const IceString &MangledName); 162 void emitTextHeader(const IceString &MangledName);
150 void dump(const IceString &Message = ""); 163 void dump(const IceString &Message = "");
151 164
152 // Allocate data of type T using the per-Cfg allocator. 165 // Allocate data of type T using the per-Cfg allocator.
153 template <typename T> T *allocate() { return Allocator.Allocate<T>(); } 166 template <typename T> T *allocate() { return Allocator->Allocate<T>(); }
154
155 // Allocate an instruction of type T using the per-Cfg instruction allocator.
156 template <typename T> T *allocateInst() { return Allocator.Allocate<T>(); }
157 167
158 // Allocate an array of data of type T using the per-Cfg allocator. 168 // Allocate an array of data of type T using the per-Cfg allocator.
159 template <typename T> T *allocateArrayOf(size_t NumElems) { 169 template <typename T> T *allocateArrayOf(size_t NumElems) {
160 return Allocator.Allocate<T>(NumElems); 170 return Allocator->Allocate<T>(NumElems);
161 } 171 }
162 172
163 // Deallocate data that was allocated via allocate<T>(). 173 // Deallocate data that was allocated via allocate<T>().
164 template <typename T> void deallocate(T *Object) { 174 template <typename T> void deallocate(T *Object) {
165 Allocator.Deallocate(Object); 175 Allocator->Deallocate(Object);
166 }
167
168 // Deallocate data that was allocated via allocateInst<T>().
169 template <typename T> void deallocateInst(T *Instr) {
170 Allocator.Deallocate(Instr);
171 } 176 }
172 177
173 // Deallocate data that was allocated via allocateArrayOf<T>(). 178 // Deallocate data that was allocated via allocateArrayOf<T>().
174 template <typename T> void deallocateArrayOf(T *Array) { 179 template <typename T> void deallocateArrayOf(T *Array) {
175 Allocator.Deallocate(Array); 180 Allocator->Deallocate(Array);
176 } 181 }
177 182
178 private: 183 private:
179 // TODO: for now, everything is allocated from the same allocator. In the 184 Cfg(GlobalContext *Ctx);
180 // future we may want to split this to several allocators, for example in
181 // order to use a "Recycler" to preserve memory. If we keep all allocation
182 // requests from the Cfg exposed via methods, we can always switch the
183 // implementation over at a later point.
184 llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 1024 * 1024> Allocator;
185 185
186 GlobalContext *Ctx; 186 GlobalContext *Ctx;
187 IceString FunctionName; 187 IceString FunctionName;
188 Type ReturnType; 188 Type ReturnType;
189 bool IsInternalLinkage; 189 bool IsInternalLinkage;
190 bool HasError; 190 bool HasError;
191 bool FocusedTiming; 191 bool FocusedTiming;
192 IceString ErrorMessage; 192 IceString ErrorMessage;
193 CfgNode *Entry; // entry basic block 193 CfgNode *Entry; // entry basic block
194 NodeList Nodes; // linearized node list; Entry should be first 194 NodeList Nodes; // linearized node list; Entry should be first
195 std::vector<IceString> IdentifierNames; 195 std::vector<IceString> IdentifierNames;
196 InstNumberT NextInstNumber; 196 InstNumberT NextInstNumber;
197 VarList Variables; 197 VarList Variables;
198 VarList Args; // subset of Variables, in argument order 198 VarList Args; // subset of Variables, in argument order
199 VarList ImplicitArgs; // subset of Variables 199 VarList ImplicitArgs; // subset of Variables
200 std::unique_ptr<ArenaAllocator> Allocator;
200 std::unique_ptr<Liveness> Live; 201 std::unique_ptr<Liveness> Live;
201 std::unique_ptr<TargetLowering> Target; 202 std::unique_ptr<TargetLowering> Target;
202 std::unique_ptr<VariablesMetadata> VMetadata; 203 std::unique_ptr<VariablesMetadata> VMetadata;
203 std::unique_ptr<Assembler> TargetAssembler; 204 std::unique_ptr<Assembler> TargetAssembler;
204 205
205 // CurrentNode is maintained during dumping/emitting just for 206 // CurrentNode is maintained during dumping/emitting just for
206 // validating Variable::DefNode. Normally, a traversal over 207 // validating Variable::DefNode. Normally, a traversal over
207 // CfgNodes maintains this, but before global operations like 208 // CfgNodes maintains this, but before global operations like
208 // register allocation, resetCurrentNode() should be called to avoid 209 // register allocation, resetCurrentNode() should be called to avoid
209 // spurious validation failures. 210 // spurious validation failures.
210 const CfgNode *CurrentNode; 211 const CfgNode *CurrentNode;
212
213 // Maintain a pointer in TLS to the current Cfg being translated.
214 // This is primarily for accessing its allocator statelessly, but
215 // other uses are possible.
216 thread_local static const Cfg *CurrentCfg;
211 }; 217 };
212 218
213 } // end of namespace Ice 219 } // end of namespace Ice
214 220
215 #endif // SUBZERO_SRC_ICECFG_H 221 #endif // SUBZERO_SRC_ICECFG_H
OLDNEW
« no previous file with comments | « ALLOCATION.rst ('k') | src/IceCfg.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698