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

Side by Side Diff: src/IceCfg.h

Issue 205613002: Initial skeleton of Subzero. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Address Jan's latest comments Created 6 years, 8 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 | « README.rst ('k') | src/IceCfg.cpp » ('j') | src/IceCfg.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 //===- subzero/src/IceCfg.h - Control flow graph ----------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the IceCfg class, which represents the control
11 // flow graph and the overall per-function compilation context.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef SUBZERO_SRC_ICECFG_H
16 #define SUBZERO_SRC_ICECFG_H
17
18 #include "IceDefs.h"
19 #include "IceTypes.h"
20
21 #include "llvm/Support/Allocator.h"
22
23 class IceCfg {
24 public:
25 IceCfg();
26 ~IceCfg();
27
28 // Manage the name and return type of the function being translated.
29 void setName(const IceString &FunctionName) { Name = FunctionName; }
30 IceString getName() const { return Name; }
31 void setReturnType(IceType ReturnType) { Type = ReturnType; }
JF 2014/04/04 04:05:26 The return type of what? The function associated w
Jim Stichnoth 2014/04/06 02:16:09 Yes, this is in a comment 3 lines above. :)
32
33 // When emitting assembly, we allow a string to be prepended to
34 // names of translated functions. This makes it easier to create an
35 // execution test against a reference translator like llc, with both
36 // translators using the same bitcode as input.
37 void setTestPrefix(const IceString &Prefix) { TestPrefix = Prefix; }
38 IceString getTestPrefix() const { return TestPrefix; }
39 IceString mangleName(const IceString &Name) const {
40 return getTestPrefix() + Name;
41 }
42
43 // Manage the "internal" attribute of the function.
44 void setInternal(bool Internal) { IsInternal = Internal; }
45 bool getInternal() const { return IsInternal; }
46
47 // Translation error flagging. If support for some construct is
48 // known to be missing, instead of an assertion failure, setError()
49 // should be called and the error should be propagated back up.
50 // This way, we can gracefully fail to translate and let a fallback
51 // translator handle the function.
52 void setError(const IceString &Message);
53 bool hasError() const { return HasError; }
54 IceString getError() const { return ErrorMessage; }
55
56 // Manage nodes (a.k.a. basic blocks, IceCfgNodes).
57 void setEntryNode(IceCfgNode *EntryNode) { Entry = EntryNode; }
58 IceCfgNode *getEntryNode() const { return Entry; }
59 // Create a node and append it to the end of the linearized list.
60 IceCfgNode *makeNode(const IceString &Name = "");
61 uint32_t getNumNodes() const { return Nodes.size(); }
62 const IceNodeList &getNodes() const { return Nodes; }
63
64 // Manage instruction numbering.
65 int newInstNumber() { return NextInstNumber++; }
66
67 // Manage IceVariables.
68 IceVariable *makeVariable(IceType Type, const IceCfgNode *Node,
69 const IceString &Name = "");
70 uint32_t getNumVariables() const { return Variables.size(); }
71 const IceVarList &getVariables() const { return Variables; }
72
73 // Manage arguments to the function.
74 void addArg(IceVariable *Arg);
75 const IceVarList &getArgs() const { return Args; }
76
77 // Manage IceConstants.
78 // getConstant*() functions are not const because they might add
79 // something to the constant pool.
80 IceConstant *getConstantInt(IceType Type, uint64_t ConstantInt64);
81 IceConstant *getConstantFloat(float Value);
82 IceConstant *getConstantDouble(double Value);
83 // Returns a symbolic constant. Handle is currently unused but is
84 // reserved to hold something LLVM-specific to facilitate linking.
85 IceConstant *getConstantSym(IceType Type, const void *Handle, int64_t Offset,
86 const IceString &Name = "",
87 bool SuppressMangling = false);
88
89 void registerEdges();
90 void dump() const;
91
92 // Allocate data of type T using the per-Cfg instruction allocator.
93 template <typename T> T *allocate() { return Allocator.Allocate<T>(); }
94
95 // Allocate an instruction of type T using the per-Cfg instruction allocator.
96 template <typename T> T *allocateInst() { return Allocator.Allocate<T>(); }
97
98 // Allocate an array of data of type T using the per-Cfg allocator.
99 template <typename T> T *allocateArrayOf(size_t NumElems) {
100 return Allocator.Allocate<T>(NumElems);
101 }
102
103 mutable IceOstream Str;
JF 2014/04/04 04:05:26 This would be nicer in a separate context object o
Jim Stichnoth 2014/04/06 02:16:09 If you don't mind, I'd love to defer this cleanup
Jim Stichnoth 2014/04/09 05:34:27 Never mind the deferral request. The latest patch
104
105 private:
JF 2014/04/04 04:05:26 Disable copy/assign: http://llvm.org/docs/Coding
Jim Stichnoth 2014/04/06 02:16:09 Done.
106 // TODO: for now, everything is allocated from the same allocator. In the
107 // future we may want to split this to several allocators, for example in
108 // order to use a "Recycler" to preserve memory. If we keep all allocation
109 // requests from the Cfg exposed via methods, we can always switch the
110 // implementation over at a later point.
111 llvm::BumpPtrAllocator Allocator;
112
113 IceString Name; // function name
114 IceString TestPrefix; // prepended to all symbol names, for testing
115 IceType Type; // return type
116 bool IsInternal; // internal linkage
117 bool HasError;
118 IceString ErrorMessage;
119 IceCfgNode *Entry; // entry basic block
120 IceNodeList Nodes; // linearized node list; Entry should be first
121 int NextInstNumber;
122 IceVarList Variables;
123 IceVarList Args; // subset of Variables, in argument order
124 class IceConstantPool *ConstantPool;
JF 2014/04/04 04:05:26 Use a smart pointer here.
Jim Stichnoth 2014/04/06 02:16:09 Done.
125 };
126
127 #endif // SUBZERO_SRC_ICECFG_H
OLDNEW
« no previous file with comments | « README.rst ('k') | src/IceCfg.cpp » ('j') | src/IceCfg.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698