OLD | NEW |
---|---|
(Empty) | |
1 // -*- Mode: c++ -*- | |
2 /* Copyright 2014 The Native Client Authors. All rights reserved. | |
Mark Seaborn
2014/03/20 00:09:47
Can you use the LLVM licence and boilerplate style
Jim Stichnoth
2014/03/20 22:58:45
Done. (Waiting for a suitable LICENSE.TXT file fr
| |
3 * Use of this source code is governed by a BSD-style license that can | |
4 * be found in the LICENSE file. | |
5 */ | |
6 | |
Mark Seaborn
2014/03/20 00:09:47
Can you put these files in a src/ or lib/ director
Jim Stichnoth
2014/03/20 22:58:45
Done. I moved *.{h,cpp} into the src/ subdirector
| |
7 #ifndef _IceCfg_h | |
Mark Seaborn
2014/03/20 00:09:47
Can you use the LLVM style? i.e. ICECFG_H
Jim Stichnoth
2014/03/20 22:58:45
Done.
| |
8 #define _IceCfg_h | |
9 | |
10 #include "IceDefs.h" | |
11 #include "IceTypes.h" | |
12 | |
13 #include "llvm/Support/Allocator.h" | |
14 | |
15 class IceCfg { | |
16 public: | |
17 IceCfg(void); | |
Mark Seaborn
2014/03/20 00:09:47
Can you use "()" (C++ style) rather than "(void)"
Jim Stichnoth
2014/03/20 22:58:45
Done.
| |
18 ~IceCfg(); | |
19 | |
20 // Manage the name and return type of the function being translated. | |
21 void setName(const IceString &FunctionName) { Name = FunctionName; } | |
22 IceString getName(void) const { return Name; } | |
23 void setReturnType(IceType ReturnType) { Type = ReturnType; } | |
24 | |
25 // When emitting assembly, we allow a string to be prepended to | |
26 // names of translated functions. This makes it easier to create an | |
27 // execution test against a reference translator like llc, with both | |
28 // translators using the same bitcode as input. | |
29 void setTestPrefix(const IceString &Prefix) { TestPrefix = Prefix; } | |
30 IceString getTestPrefix(void) const { return TestPrefix; } | |
31 IceString mangleName(const IceString &Name) const { | |
32 return getTestPrefix() + Name; | |
33 } | |
34 | |
35 // Manage the "internal" attribute of the function. | |
36 void setInternal(bool Internal) { IsInternal = Internal; } | |
37 bool getInternal(void) const { return IsInternal; } | |
38 | |
39 // Translation error flagging. If support for some construct is | |
40 // known to be missing, instead of an assertion failure, setError() | |
41 // should be called and the error should be propagated back up. | |
42 // This way, we can gracefully fail to translate and let a fallback | |
43 // translator handle the function. | |
44 void setError(const IceString &Message); | |
45 bool hasError(void) const { return HasError; } | |
46 IceString getError(void) const { return ErrorMessage; } | |
47 | |
48 // Manage nodes (a.k.a. basic blocks, IceCfgNodes). | |
49 void setEntryNode(IceCfgNode *EntryNode) { Entry = EntryNode; } | |
50 IceCfgNode *getEntryNode(void) const { return Entry; } | |
51 // Create a node and append it to the end of the linearized list. | |
52 IceCfgNode *makeNode(const IceString &Name = ""); | |
53 uint32_t getNumNodes(void) const { return Nodes.size(); } | |
54 const IceNodeList &getNodes(void) const { return Nodes; } | |
55 | |
56 // Manage instruction numbering. | |
57 int newInstNumber(void) { return NextInstNumber++; } | |
58 | |
59 // Manage IceVariables. | |
60 IceVariable *makeVariable(IceType Type, const IceCfgNode *Node, | |
61 const IceString &Name = ""); | |
62 uint32_t getNumVariables(void) const { return Variables.size(); } | |
63 const IceVarList &getVariables(void) const { return Variables; } | |
64 | |
65 // Manage arguments to the function. | |
66 void addArg(IceVariable *Arg); | |
67 const IceVarList &getArgs(void) const { return Args; } | |
68 | |
69 // Manage IceConstants. | |
70 // getConstant*() functions are not const because they might add | |
71 // something to the constant pool. | |
72 IceConstant *getConstantInt(IceType Type, uint64_t ConstantInt64); | |
73 IceConstant *getConstantFloat(float Value); | |
74 IceConstant *getConstantDouble(double Value); | |
75 // Returns a symbolic constant. Handle is currently unused but is | |
76 // reserved to hold something LLVM-specific to facilitate linking. | |
77 IceConstant *getConstantSym(IceType Type, const void *Handle, int64_t Offset, | |
78 const IceString &Name = "", | |
79 bool SuppressMangling = false); | |
80 | |
81 void registerEdges(void); | |
82 void dump(void) const; | |
83 | |
84 // Allocate an instruction of type T using the per-Cfg instruction allocator. | |
85 template <typename T> T *allocateInst() { return Allocator.Allocate<T>(); } | |
86 | |
87 // Allocate an array of data of type T using the per-Cfg allocator. | |
88 template <typename T> T *allocateArrayOf(size_t NumElems) { | |
89 return Allocator.Allocate<T>(NumElems); | |
90 } | |
91 | |
92 mutable IceOstream Str; | |
93 | |
94 private: | |
95 // TODO: for now, everything is allocated from the same allocator. In the | |
96 // future we may want to split this to several allocators, for example in | |
97 // order to use a "Recycler" to preserve memory. If we keep all allocation | |
98 // requests from the Cfg exposed via methods, we can always switch the | |
99 // implementation over at a later point. | |
100 llvm::BumpPtrAllocator Allocator; | |
101 | |
102 IceString Name; // function name | |
103 IceString TestPrefix; // prepended to all symbol names, for testing | |
104 IceType Type; // return type | |
105 bool IsInternal; // internal linkage | |
106 bool HasError; | |
107 IceString ErrorMessage; | |
108 IceCfgNode *Entry; // entry basic block | |
109 IceNodeList Nodes; // linearized node list; Entry should be first | |
110 int NextInstNumber; | |
111 IceVarList Variables; | |
112 IceVarList Args; // subset of Variables, in argument order | |
113 class IceConstantPool *ConstantPool; | |
114 }; | |
115 | |
116 #endif // _IceCfg_h | |
OLD | NEW |