Mercurial > octave-nkf
annotate libinterp/corefcn/jit-util.h @ 18600:67445219aee2 draft
-Werror at JIT related files
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 21 Mar 2014 14:59:39 -0400 |
parents | 175b392e91fe |
children |
rev | line source |
---|---|
18600 | 1 #pragma GCC diagnostic push |
2 #pragma GCC diagnostic error "-Werror" | |
15016 | 3 /* |
4 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17164
diff
changeset
|
5 Copyright (C) 2012-2013 Max Brister |
15016 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
11 Free Software Foundation; either version 3 of the License, or (at your | |
12 option) any later version. | |
13 | |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
20 along with Octave; see the file COPYING. If not, see | |
21 <http://www.gnu.org/licenses/>. | |
22 | |
23 */ | |
24 | |
16768 | 25 // Author: Max Brister <max@2bass.com> |
26 | |
15016 | 27 // Some utility classes and functions used throughout jit |
28 | |
29 #if !defined (octave_jit_util_h) | |
30 #define octave_jit_util_h 1 | |
31 | |
32 #ifdef HAVE_LLVM | |
33 | |
34 #include <stdexcept> | |
35 | |
17164 | 36 #if defined(HAVE_LLVM_IR_DATALAYOUT_H) || defined(HAVE_LLVM_DATALAYOUT_H) |
37 #define HAVE_LLVM_DATALAYOUT | |
38 #endif | |
39 | |
15016 | 40 // we don't want to include llvm headers here, as they require |
41 // __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS be defined in the entire | |
42 // compilation unit | |
43 namespace llvm | |
44 { | |
45 class Value; | |
46 class Module; | |
47 class FunctionPassManager; | |
48 class PassManager; | |
49 class ExecutionEngine; | |
50 class Function; | |
51 class BasicBlock; | |
52 class LLVMContext; | |
53 class Type; | |
54 class StructType; | |
55 class Twine; | |
56 class GlobalVariable; | |
57 class TerminatorInst; | |
58 class PHINode; | |
59 | |
60 class ConstantFolder; | |
61 | |
62 template <bool preserveNames> | |
63 class IRBuilderDefaultInserter; | |
64 | |
65 template <bool preserveNames, typename T, typename Inserter> | |
66 class IRBuilder; | |
67 | |
68 typedef IRBuilder<true, ConstantFolder, IRBuilderDefaultInserter<true> > | |
69 IRBuilderD; | |
70 } | |
71 | |
72 class octave_base_value; | |
73 class octave_builtin; | |
74 class octave_value; | |
75 class tree; | |
76 class tree_expression; | |
77 | |
78 // thrown when we should give up on JIT and interpret | |
79 class jit_fail_exception : public std::runtime_error | |
80 { | |
81 public: | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
82 jit_fail_exception (void) : std::runtime_error ("unknown"), mknown (false) { } |
15016 | 83 jit_fail_exception (const std::string& reason) : std::runtime_error (reason), |
84 mknown (true) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
85 { } |
15016 | 86 |
87 bool known (void) const { return mknown; } | |
88 private: | |
89 bool mknown; | |
90 }; | |
91 | |
92 // llvm doesn't provide this, and it's really useful for debugging | |
93 std::ostream& operator<< (std::ostream& os, const llvm::Value& v); | |
94 | |
95 template <typename HOLDER_T, typename SUB_T> | |
96 class jit_internal_node; | |
97 | |
98 // jit_internal_list and jit_internal_node implement generic embedded doubly | |
99 // linked lists. List items extend from jit_internal_list, and can be placed | |
100 // in nodes of type jit_internal_node. We use CRTP twice. | |
101 template <typename LIST_T, typename NODE_T> | |
102 class | |
103 jit_internal_list | |
104 { | |
105 friend class jit_internal_node<LIST_T, NODE_T>; | |
106 public: | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
107 jit_internal_list (void) : use_head (0), use_tail (0), muse_count (0) { } |
15016 | 108 |
109 virtual ~jit_internal_list (void) | |
110 { | |
111 while (use_head) | |
112 use_head->stash_value (0); | |
113 } | |
114 | |
115 NODE_T *first_use (void) const { return use_head; } | |
116 | |
117 size_t use_count (void) const { return muse_count; } | |
118 private: | |
119 NODE_T *use_head; | |
120 NODE_T *use_tail; | |
121 size_t muse_count; | |
122 }; | |
123 | |
124 // a node for internal linked lists | |
125 template <typename LIST_T, typename NODE_T> | |
126 class | |
127 jit_internal_node | |
128 { | |
129 public: | |
130 typedef jit_internal_list<LIST_T, NODE_T> jit_ilist; | |
131 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
132 jit_internal_node (void) : mvalue (0), mnext (0), mprev (0) { } |
15016 | 133 |
134 ~jit_internal_node (void) { remove (); } | |
135 | |
136 LIST_T *value (void) const { return mvalue; } | |
137 | |
138 void stash_value (LIST_T *avalue) | |
139 { | |
140 remove (); | |
141 | |
142 mvalue = avalue; | |
143 | |
144 if (mvalue) | |
145 { | |
146 jit_ilist *ilist = mvalue; | |
147 NODE_T *sthis = static_cast<NODE_T *> (this); | |
148 if (ilist->use_head) | |
149 { | |
150 ilist->use_tail->mnext = sthis; | |
151 mprev = ilist->use_tail; | |
152 } | |
153 else | |
154 ilist->use_head = sthis; | |
155 | |
156 ilist->use_tail = sthis; | |
157 ++ilist->muse_count; | |
158 } | |
159 } | |
160 | |
161 NODE_T *next (void) const { return mnext; } | |
162 | |
163 NODE_T *prev (void) const { return mprev; } | |
164 private: | |
165 void remove () | |
166 { | |
167 if (mvalue) | |
168 { | |
169 jit_ilist *ilist = mvalue; | |
170 if (mprev) | |
171 mprev->mnext = mnext; | |
172 else | |
173 // we are the use_head | |
174 ilist->use_head = mnext; | |
175 | |
176 if (mnext) | |
177 mnext->mprev = mprev; | |
178 else | |
179 // we are the use tail | |
180 ilist->use_tail = mprev; | |
181 | |
182 mnext = mprev = 0; | |
183 --ilist->muse_count; | |
184 mvalue = 0; | |
185 } | |
186 } | |
187 | |
188 LIST_T *mvalue; | |
189 NODE_T *mnext; | |
190 NODE_T *mprev; | |
191 }; | |
192 | |
193 // Use like: isa<jit_phi> (value) | |
194 // basically just a short cut type typing dyanmic_cast. | |
195 template <typename T, typename U> | |
196 bool isa (U *value) | |
197 { | |
198 return dynamic_cast<T *> (value); | |
199 } | |
200 | |
201 #define JIT_ASSIGN_ARG(i) the_args[i] = arg ## i; | |
202 #define JIT_EXPAND(ret, fname, type, isconst, N) \ | |
203 ret fname (JIT_PARAM_ARGS OCT_MAKE_DECL_LIST (type, arg, N)) isconst \ | |
204 { \ | |
205 std::vector<type> the_args (N); \ | |
206 OCT_ITERATE_MACRO (JIT_ASSIGN_ARG, N); \ | |
207 return fname (JIT_PARAMS the_args); \ | |
208 } | |
209 | |
210 #endif | |
211 #endif | |
18600 | 212 |
213 #pragma GCC diagnostic pop |