Mercurial > octave-nkf
annotate src/pt-jit.h @ 14960:c959136f8c3e
Rename jit_check_error to jit_error_check
* src/pt-jit.h (JIT_VISIT_IR_NOTEMPLATE, jit_check_error):
Replace check_error with error_check.
* src/pt-jit.cc (jit_convert::visit_binary_expression,
jit_convert::visit_if_command_list, jit_convert::remove_dead,
jit_convert::convert_llvm::visit): Replace check_error with error_check.
author | Max Brister <max@2bass.com> |
---|---|
date | Tue, 19 Jun 2012 12:36:53 -0500 |
parents | 12fd4a62d633 |
children | 903a5ee2cdde |
rev | line source |
---|---|
14899 | 1 /* |
2 | |
14901
516b4a15b775
doc: Copyright fix in pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14899
diff
changeset
|
3 Copyright (C) 2012 Max Brister <max@2bass.com> |
14899 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 3 of the License, or (at your | |
10 option) any later version. | |
11 | |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with Octave; see the file COPYING. If not, see | |
19 <http://www.gnu.org/licenses/>. | |
20 | |
21 */ | |
22 | |
23 #if !defined (octave_tree_jit_h) | |
24 #define octave_tree_jit_h 1 | |
25 | |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
26 #ifdef HAVE_LLVM |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
27 |
14903 | 28 #include <list> |
14899 | 29 #include <map> |
14903 | 30 #include <set> |
14899 | 31 #include <stdexcept> |
32 #include <vector> | |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
33 #include <stack> |
14899 | 34 |
14903 | 35 #include "Array.h" |
14906 | 36 #include "Range.h" |
14899 | 37 #include "pt-walk.h" |
14913
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
38 #include "symtab.h" |
14899 | 39 |
14903 | 40 // -------------------- Current status -------------------- |
41 // Simple binary operations (+-*/) on octave_scalar's (doubles) are optimized. | |
42 // However, there is no warning emitted on divide by 0. For example, | |
43 // a = 5; | |
44 // b = a * 5 + a; | |
45 // | |
46 // For other types all binary operations are compiled but not optimized. For | |
47 // example, | |
48 // a = [1 2 3] | |
49 // b = a + a; | |
50 // will compile to do_binary_op (a, a). | |
14906 | 51 // |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
52 // For loops are compiled again! |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
53 // if, elseif, and else statements compile again! |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
54 // break and continue now work! |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
55 // Additionally, make check passes using jit. |
14906 | 56 // |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
57 // The octave low level IR is a linear IR, it works by converting everything to |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
58 // calls to jit_functions. This turns expressions like c = a + b into |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
59 // c = call binary+ (a, b) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
60 // The jit_functions contain information about overloads for differnt types. For |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
61 // example, if we know a and b are scalars, then c must also be a scalar. |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
62 // |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
63 // |
14906 | 64 // TODO: |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
65 // 1. Support some simple matrix case (and cleanup Octave low level IR) |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
66 // 2. Function calls |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
67 // 3. Cleanup/documentation |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
68 // 4. ... |
14903 | 69 // --------------------------------------------------------- |
14899 | 70 |
14903 | 71 |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
72 // we don't want to include llvm headers here, as they require |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
73 // __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS be defined in the entire |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
74 // compilation unit |
14899 | 75 namespace llvm |
76 { | |
77 class Value; | |
78 class Module; | |
79 class FunctionPassManager; | |
14903 | 80 class PassManager; |
14899 | 81 class ExecutionEngine; |
82 class Function; | |
83 class BasicBlock; | |
84 class LLVMContext; | |
14903 | 85 class Type; |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
86 class Twine; |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
87 class GlobalVariable; |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
88 class TerminatorInst; |
14899 | 89 } |
90 | |
14903 | 91 class octave_base_value; |
92 class octave_value; | |
14899 | 93 class tree; |
94 | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
95 template <typename HOLDER_T, typename SUB_T> |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
96 class jit_internal_node; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
97 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
98 // jit_internal_list and jit_internal_node implement generic embedded doubly |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
99 // linked lists. List items extend from jit_internal_list, and can be placed |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
100 // in nodes of type jit_internal_node. We use CRTP twice. |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
101 template <typename LIST_T, typename NODE_T> |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
102 class |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
103 jit_internal_list |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
104 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
105 friend class jit_internal_node<LIST_T, NODE_T>; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
106 public: |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
107 jit_internal_list (void) : use_head (0), use_tail (0), muse_count (0) {} |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
108 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
109 virtual ~jit_internal_list (void) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
110 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
111 while (use_head) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
112 use_head->stash_value (0); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
113 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
114 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
115 NODE_T *first_use (void) const { return use_head; } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
116 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
117 size_t use_count (void) const { return muse_count; } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
118 private: |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
119 NODE_T *use_head; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
120 NODE_T *use_tail; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
121 size_t muse_count; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
122 }; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
123 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
124 // a node for internal linked lists |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
125 template <typename LIST_T, typename NODE_T> |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
126 class |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
127 jit_internal_node |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
128 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
129 public: |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
130 typedef jit_internal_list<LIST_T, NODE_T> jit_ilist; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
131 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
132 jit_internal_node (void) : mvalue (0), mnext (0), mprev (0) {} |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
133 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
134 ~jit_internal_node (void) { remove (); } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
135 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
136 LIST_T *value (void) const { return mvalue; } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
137 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
138 void stash_value (LIST_T *avalue) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
139 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
140 remove (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
141 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
142 mvalue = avalue; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
143 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
144 if (mvalue) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
145 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
146 jit_ilist *ilist = mvalue; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
147 NODE_T *sthis = static_cast<NODE_T *> (this); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
148 if (ilist->use_head) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
149 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
150 ilist->use_tail->mnext = sthis; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
151 mprev = ilist->use_tail; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
152 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
153 else |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
154 ilist->use_head = sthis; |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
155 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
156 ilist->use_tail = sthis; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
157 ++ilist->muse_count; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
158 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
159 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
160 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
161 NODE_T *next (void) const { return mnext; } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
162 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
163 NODE_T *prev (void) const { return mprev; } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
164 private: |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
165 void remove () |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
166 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
167 if (mvalue) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
168 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
169 jit_ilist *ilist = mvalue; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
170 if (mprev) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
171 mprev->mnext = mnext; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
172 else |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
173 // we are the use_head |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
174 ilist->use_head = mnext; |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
175 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
176 if (mnext) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
177 mnext->mprev = mprev; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
178 else |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
179 // we are the use tail |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
180 ilist->use_tail = mprev; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
181 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
182 mnext = mprev = 0; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
183 --ilist->muse_count; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
184 mvalue = 0; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
185 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
186 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
187 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
188 LIST_T *mvalue; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
189 NODE_T *mnext; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
190 NODE_T *mprev; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
191 }; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
192 |
14937
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
193 // Use like: isa<jit_phi> (value) |
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
194 // basically just a short cut type typing dyanmic_cast. |
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
195 template <typename T, typename U> |
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
196 bool isa (U *value) |
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
197 { |
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
198 return dynamic_cast<T *> (value); |
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
199 } |
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
200 |
14906 | 201 // jit_range is compatable with the llvm range structure |
202 struct | |
203 jit_range | |
204 { | |
205 jit_range (const Range& from) : base (from.base ()), limit (from.limit ()), | |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
206 inc (from.inc ()), nelem (from.nelem ()) |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
207 {} |
14906 | 208 |
209 operator Range () const | |
210 { | |
211 return Range (base, limit, inc); | |
212 } | |
213 | |
214 double base; | |
215 double limit; | |
216 double inc; | |
217 octave_idx_type nelem; | |
218 }; | |
14903 | 219 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
220 std::ostream& operator<< (std::ostream& os, const jit_range& rng); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
221 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
222 // jit_array is compatable with the llvm array/matrix structures |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
223 template <typename T, typename U> |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
224 struct |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
225 jit_array |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
226 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
227 jit_array (T& from) : ref_count (from.jit_ref_count ()), |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
228 slice_data (from.jit_slice_data () - 1), |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
229 slice_len (from.capacity ()), |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
230 dimensions (from.jit_dimensions ()), |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
231 array_rep (from.jit_array_rep ()) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
232 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
233 grab_dimensions (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
234 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
235 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
236 void grab_dimensions (void) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
237 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
238 ++(dimensions[-2]); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
239 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
240 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
241 operator T () const |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
242 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
243 return T (slice_data + 1, slice_len, dimensions, array_rep); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
244 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
245 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
246 int *ref_count; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
247 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
248 U *slice_data; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
249 octave_idx_type slice_len; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
250 octave_idx_type *dimensions; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
251 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
252 void *array_rep; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
253 }; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
254 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
255 typedef jit_array<NDArray, double> jit_matrix; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
256 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
257 std::ostream& operator<< (std::ostream& os, const jit_matrix& mat); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
258 |
14903 | 259 // Used to keep track of estimated (infered) types during JIT. This is a |
260 // hierarchical type system which includes both concrete and abstract types. | |
261 // | |
262 // Current, we only support any and scalar types. If we can't figure out what | |
263 // type a variable is, we assign it the any type. This allows us to generate | |
264 // code even for the case of poor type inference. | |
265 class | |
266 jit_type | |
267 { | |
268 public: | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
269 jit_type (const std::string& aname, jit_type *aparent, llvm::Type *allvm_type, |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
270 int aid) : |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
271 mname (aname), mparent (aparent), llvm_type (allvm_type), mid (aid), |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
272 mdepth (aparent ? aparent->mdepth + 1 : 0) |
14903 | 273 {} |
274 | |
275 // a user readable type name | |
276 const std::string& name (void) const { return mname; } | |
277 | |
278 // a unique id for the type | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
279 int type_id (void) const { return mid; } |
14903 | 280 |
281 // An abstract base type, may be null | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
282 jit_type *parent (void) const { return mparent; } |
14903 | 283 |
284 // convert to an llvm type | |
285 llvm::Type *to_llvm (void) const { return llvm_type; } | |
286 | |
287 // how this type gets passed as a function argument | |
288 llvm::Type *to_llvm_arg (void) const; | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
289 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
290 size_t depth (void) const { return mdepth; } |
14903 | 291 private: |
292 std::string mname; | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
293 jit_type *mparent; |
14903 | 294 llvm::Type *llvm_type; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
295 int mid; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
296 size_t mdepth; |
14903 | 297 }; |
298 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
299 // seperate print function to allow easy printing if type is null |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
300 std::ostream& jit_print (std::ostream& os, jit_type *atype); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
301 |
14903 | 302 // Keeps track of overloads for a builtin function. Used for both type inference |
303 // and code generation. | |
304 class | |
305 jit_function | |
306 { | |
307 public: | |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
308 struct |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
309 overload |
14903 | 310 { |
14945 | 311 overload (void) : function (0), can_error (false), result (0) {} |
14903 | 312 |
14945 | 313 overload (llvm::Function *f, bool e, jit_type *r, jit_type *arg0) : |
314 function (f), can_error (e), result (r), arguments (1) | |
14903 | 315 { |
316 arguments[0] = arg0; | |
317 } | |
318 | |
14945 | 319 overload (llvm::Function *f, bool e, jit_type *r, jit_type *arg0, |
320 jit_type *arg1) : function (f), can_error (e), | |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
321 result (r), arguments (2) |
14903 | 322 { |
323 arguments[0] = arg0; | |
324 arguments[1] = arg1; | |
325 } | |
326 | |
14945 | 327 overload (llvm::Function *f, bool e, jit_type *r, jit_type *arg0, |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
328 jit_type *arg1, jit_type *arg2) : function (f), can_error (e), |
14945 | 329 result (r), arguments (3) |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
330 { |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
331 arguments[0] = arg0; |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
332 arguments[1] = arg1; |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
333 arguments[2] = arg2; |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
334 } |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
335 |
14903 | 336 llvm::Function *function; |
337 bool can_error; | |
338 jit_type *result; | |
339 std::vector<jit_type*> arguments; | |
340 }; | |
341 | |
342 void add_overload (const overload& func) | |
343 { | |
344 add_overload (func, func.arguments); | |
345 } | |
346 | |
14945 | 347 void add_overload (llvm::Function *f, bool e, jit_type *r, jit_type *arg0) |
14906 | 348 { |
14945 | 349 overload ol (f, e, r, arg0); |
14906 | 350 add_overload (ol); |
351 } | |
352 | |
14945 | 353 void add_overload (llvm::Function *f, bool e, jit_type *r, jit_type *arg0, |
14903 | 354 jit_type *arg1) |
355 { | |
14945 | 356 overload ol (f, e, r, arg0, arg1); |
14903 | 357 add_overload (ol); |
358 } | |
359 | |
14945 | 360 void add_overload (llvm::Function *f, bool e, jit_type *r, jit_type *arg0, |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
361 jit_type *arg1, jit_type *arg2) |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
362 { |
14945 | 363 overload ol (f, e, r, arg0, arg1, arg2); |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
364 add_overload (ol); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
365 } |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
366 |
14903 | 367 void add_overload (const overload& func, |
368 const std::vector<jit_type*>& args); | |
369 | |
370 const overload& get_overload (const std::vector<jit_type *>& types) const; | |
371 | |
372 const overload& get_overload (jit_type *arg0) const | |
373 { | |
374 std::vector<jit_type *> types (1); | |
375 types[0] = arg0; | |
376 return get_overload (types); | |
377 } | |
378 | |
379 const overload& get_overload (jit_type *arg0, jit_type *arg1) const | |
380 { | |
381 std::vector<jit_type *> types (2); | |
382 types[0] = arg0; | |
383 types[1] = arg1; | |
384 return get_overload (types); | |
385 } | |
386 | |
387 jit_type *get_result (const std::vector<jit_type *>& types) const | |
388 { | |
389 const overload& temp = get_overload (types); | |
390 return temp.result; | |
391 } | |
392 | |
393 jit_type *get_result (jit_type *arg0, jit_type *arg1) const | |
394 { | |
395 const overload& temp = get_overload (arg0, arg1); | |
396 return temp.result; | |
397 } | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
398 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
399 const std::string& name (void) const { return mname; } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
400 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
401 void stash_name (const std::string& aname) { mname = aname; } |
14903 | 402 private: |
403 Array<octave_idx_type> to_idx (const std::vector<jit_type*>& types) const; | |
404 | |
405 std::vector<Array<overload> > overloads; | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
406 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
407 std::string mname; |
14903 | 408 }; |
409 | |
410 // Get information and manipulate jit types. | |
411 class | |
412 jit_typeinfo | |
413 { | |
414 public: | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
415 static void initialize (llvm::Module *m, llvm::ExecutionEngine *e); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
416 |
14922
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
417 static jit_type *join (jit_type *lhs, jit_type *rhs) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
418 { |
14922
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
419 return instance->do_join (lhs, rhs); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
420 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
421 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
422 static jit_type *get_any (void) { return instance->any; } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
423 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
424 static jit_type *get_matrix (void) { return instance->matrix; } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
425 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
426 static jit_type *get_scalar (void) { return instance->scalar; } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
427 |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
428 static llvm::Type *get_scalar_llvm (void) |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
429 { return instance->scalar->to_llvm (); } |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
430 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
431 static jit_type *get_range (void) { return instance->range; } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
432 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
433 static jit_type *get_string (void) { return instance->string; } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
434 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
435 static jit_type *get_bool (void) { return instance->boolean; } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
436 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
437 static jit_type *get_index (void) { return instance->index; } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
438 |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
439 static llvm::Type *get_index_llvm (void) |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
440 { return instance->index->to_llvm (); } |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
441 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
442 static jit_type *type_of (const octave_value& ov) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
443 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
444 return instance->do_type_of (ov); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
445 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
446 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
447 static const jit_function& binary_op (int op) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
448 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
449 return instance->do_binary_op (op); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
450 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
451 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
452 static const jit_function& grab (void) { return instance->grab_fn; } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
453 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
454 static const jit_function& release (void) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
455 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
456 return instance->release_fn; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
457 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
458 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
459 static const jit_function::overload& get_release (jit_type *type) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
460 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
461 return instance->release_fn.get_overload (type); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
462 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
463 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
464 static const jit_function& print_value (void) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
465 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
466 return instance->print_fn; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
467 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
468 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
469 static const jit_function& for_init (void) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
470 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
471 return instance->for_init_fn; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
472 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
473 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
474 static const jit_function& for_check (void) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
475 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
476 return instance->for_check_fn; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
477 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
478 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
479 static const jit_function& for_index (void) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
480 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
481 return instance->for_index_fn; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
482 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
483 |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
484 static const jit_function& make_range (void) |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
485 { |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
486 return instance->make_range_fn; |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
487 } |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
488 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
489 static const jit_function& paren_subsref (void) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
490 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
491 return instance->paren_subsref_fn; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
492 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
493 |
14943
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14942
diff
changeset
|
494 static const jit_function& logically_true (void) |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14942
diff
changeset
|
495 { |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14942
diff
changeset
|
496 return instance->logically_true_fn; |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14942
diff
changeset
|
497 } |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14942
diff
changeset
|
498 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
499 static const jit_function& cast (jit_type *result) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
500 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
501 return instance->do_cast (result); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
502 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
503 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
504 static const jit_function::overload& cast (jit_type *to, jit_type *from) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
505 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
506 return instance->do_cast (to, from); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
507 } |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
508 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
509 static llvm::Value *insert_error_check (void) |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
510 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
511 return instance->do_insert_error_check (); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
512 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
513 private: |
14906 | 514 jit_typeinfo (llvm::Module *m, llvm::ExecutionEngine *e); |
14903 | 515 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
516 // FIXME: Do these methods really need to be in jit_typeinfo? |
14922
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
517 jit_type *do_join (jit_type *lhs, jit_type *rhs) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
518 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
519 // empty case |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
520 if (! lhs) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
521 return rhs; |
14906 | 522 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
523 if (! rhs) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
524 return lhs; |
14903 | 525 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
526 // check for a shared parent |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
527 while (lhs != rhs) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
528 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
529 if (lhs->depth () > rhs->depth ()) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
530 lhs = lhs->parent (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
531 else if (lhs->depth () < rhs->depth ()) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
532 rhs = rhs->parent (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
533 else |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
534 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
535 // we MUST have depth > 0 as any is the base type of everything |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
536 do |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
537 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
538 lhs = lhs->parent (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
539 rhs = rhs->parent (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
540 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
541 while (lhs != rhs); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
542 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
543 } |
14903 | 544 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
545 return lhs; |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
546 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
547 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
548 jit_type *do_difference (jit_type *lhs, jit_type *) |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
549 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
550 // FIXME: Maybe we can do something smarter? |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
551 return lhs; |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
552 } |
14903 | 553 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
554 jit_type *do_type_of (const octave_value &ov) const; |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
555 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
556 const jit_function& do_binary_op (int op) const |
14906 | 557 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
558 assert (static_cast<size_t>(op) < binary_ops.size ()); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
559 return binary_ops[op]; |
14906 | 560 } |
561 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
562 const jit_function& do_cast (jit_type *to) |
14906 | 563 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
564 static jit_function null_function; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
565 if (! to) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
566 return null_function; |
14906 | 567 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
568 size_t id = to->type_id (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
569 if (id >= casts.size ()) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
570 return null_function; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
571 return casts[id]; |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
572 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
573 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
574 const jit_function::overload& do_cast (jit_type *to, jit_type *from) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
575 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
576 return do_cast (to).get_overload (from); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
577 } |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
578 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
579 jit_type *new_type (const std::string& name, jit_type *parent, |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
580 llvm::Type *llvm_type); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
581 |
14903 | 582 |
583 void add_print (jit_type *ty, void *call); | |
584 | |
585 void add_binary_op (jit_type *ty, int op, int llvm_op); | |
586 | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
587 void add_binary_icmp (jit_type *ty, int op, int llvm_op); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
588 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
589 void add_binary_fcmp (jit_type *ty, int op, int llvm_op); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
590 |
14941 | 591 llvm::Function *create_function (const llvm::Twine& name, llvm::Type *ret) |
592 { | |
593 std::vector<llvm::Type *> args; | |
594 return create_function (name, ret, args); | |
595 } | |
596 | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
597 llvm::Function *create_function (const llvm::Twine& name, llvm::Type *ret, |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
598 llvm::Type *arg0) |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
599 { |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
600 std::vector<llvm::Type *> args (1, arg0); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
601 return create_function (name, ret, args); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
602 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
603 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
604 llvm::Function *create_function (const llvm::Twine& name, jit_type *ret, |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
605 jit_type *arg0) |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
606 { |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
607 return create_function (name, ret->to_llvm (), arg0->to_llvm ()); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
608 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
609 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
610 llvm::Function *create_function (const llvm::Twine& name, llvm::Type *ret, |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
611 llvm::Type *arg0, llvm::Type *arg1) |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
612 { |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
613 std::vector<llvm::Type *> args (2); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
614 args[0] = arg0; |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
615 args[1] = arg1; |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
616 return create_function (name, ret, args); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
617 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
618 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
619 llvm::Function *create_function (const llvm::Twine& name, jit_type *ret, |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
620 jit_type *arg0, jit_type *arg1) |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
621 { |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
622 return create_function (name, ret->to_llvm (), arg0->to_llvm (), |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
623 arg1->to_llvm ()); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
624 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
625 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
626 llvm::Function *create_function (const llvm::Twine& name, llvm::Type *ret, |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
627 llvm::Type *arg0, llvm::Type *arg1, |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
628 llvm::Type *arg2) |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
629 { |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
630 std::vector<llvm::Type *> args (3); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
631 args[0] = arg0; |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
632 args[1] = arg1; |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
633 args[2] = arg2; |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
634 return create_function (name, ret, args); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
635 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
636 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
637 llvm::Function *create_function (const llvm::Twine& name, jit_type *ret, |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
638 jit_type *arg0, jit_type *arg1, |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
639 jit_type *arg2) |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
640 { |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
641 return create_function (name, ret->to_llvm (), arg0->to_llvm (), |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
642 arg1->to_llvm (), arg2->to_llvm ()); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
643 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
644 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
645 llvm::Function *create_function (const llvm::Twine& name, llvm::Type *ret, |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
646 llvm::Type *arg0, llvm::Type *arg1, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
647 llvm::Type *arg2, llvm::Type *arg3) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
648 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
649 std::vector<llvm::Type *> args (4); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
650 args[0] = arg0; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
651 args[1] = arg1; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
652 args[2] = arg2; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
653 args[3] = arg3; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
654 return create_function (name, ret, args); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
655 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
656 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
657 llvm::Function *create_function (const llvm::Twine& name, llvm::Type *ret, |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
658 const std::vector<llvm::Type *>& args); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
659 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
660 llvm::Function *create_identity (jit_type *type); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
661 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
662 llvm::Value *do_insert_error_check (void); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
663 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
664 static jit_typeinfo *instance; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
665 |
14903 | 666 llvm::Module *module; |
667 llvm::ExecutionEngine *engine; | |
668 int next_id; | |
669 | |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
670 llvm::GlobalVariable *lerror_state; |
14903 | 671 |
672 std::vector<jit_type*> id_to_type; | |
673 jit_type *any; | |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
674 jit_type *matrix; |
14903 | 675 jit_type *scalar; |
14906 | 676 jit_type *range; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
677 jit_type *string; |
14906 | 678 jit_type *boolean; |
679 jit_type *index; | |
14903 | 680 |
681 std::vector<jit_function> binary_ops; | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
682 jit_function grab_fn; |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
683 jit_function release_fn; |
14903 | 684 jit_function print_fn; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
685 jit_function for_init_fn; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
686 jit_function for_check_fn; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
687 jit_function for_index_fn; |
14943
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14942
diff
changeset
|
688 jit_function logically_true_fn; |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
689 jit_function make_range_fn; |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
690 jit_function paren_subsref_fn; |
14903 | 691 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
692 // type id -> cast function TO that type |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
693 std::vector<jit_function> casts; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
694 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
695 // type id -> identity function |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
696 std::vector<llvm::Function *> identities; |
14906 | 697 }; |
698 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
699 // The low level octave jit ir |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
700 // this ir is close to llvm, but contains information for doing type inference. |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
701 // We convert the octave parse tree to this IR directly. |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
702 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
703 #define JIT_VISIT_IR_NOTEMPLATE \ |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
704 JIT_METH(block); \ |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14957
diff
changeset
|
705 JIT_METH(branch); \ |
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14957
diff
changeset
|
706 JIT_METH(cond_branch); \ |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
707 JIT_METH(call); \ |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
708 JIT_METH(extract_argument); \ |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
709 JIT_METH(store_argument); \ |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
710 JIT_METH(phi); \ |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
711 JIT_METH(variable); \ |
14960
c959136f8c3e
Rename jit_check_error to jit_error_check
Max Brister <max@2bass.com>
parents:
14959
diff
changeset
|
712 JIT_METH(error_check); \ |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
713 JIT_METH(assign) \ |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
714 JIT_METH(argument) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
715 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
716 #define JIT_VISIT_IR_CONST \ |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
717 JIT_METH(const_scalar); \ |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
718 JIT_METH(const_index); \ |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
719 JIT_METH(const_string); \ |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
720 JIT_METH(const_range) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
721 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
722 #define JIT_VISIT_IR_CLASSES \ |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
723 JIT_VISIT_IR_NOTEMPLATE \ |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
724 JIT_VISIT_IR_CONST |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
725 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
726 // forward declare all ir classes |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
727 #define JIT_METH(cname) \ |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
728 class jit_ ## cname; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
729 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
730 JIT_VISIT_IR_NOTEMPLATE |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
731 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
732 #undef JIT_METH |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
733 |
14937
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
734 // ABCs which aren't included in JIT_VISIT_IR_ALL |
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
735 class jit_instruction; |
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
736 class jit_terminator; |
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
737 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
738 template <typename T, jit_type *(*EXTRACT_T)(void), typename PASS_T = T, |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
739 bool QUOTE=false> |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
740 class jit_const; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
741 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
742 typedef jit_const<double, jit_typeinfo::get_scalar> jit_const_scalar; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
743 typedef jit_const<octave_idx_type, jit_typeinfo::get_index> jit_const_index; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
744 |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
745 typedef jit_const<std::string, jit_typeinfo::get_string, const std::string&, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
746 true> jit_const_string; |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
747 typedef jit_const<jit_range, jit_typeinfo::get_range, const jit_range&> |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
748 jit_const_range; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
749 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
750 class jit_ir_walker; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
751 class jit_use; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
752 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
753 class |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
754 jit_value : public jit_internal_list<jit_value, jit_use> |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
755 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
756 public: |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
757 jit_value (void) : llvm_value (0), ty (0), mlast_use (0), |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
758 min_worklist (false) {} |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
759 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
760 virtual ~jit_value (void); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
761 |
14946
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
762 bool in_worklist (void) const |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
763 { |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
764 return min_worklist; |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
765 } |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
766 |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
767 void stash_in_worklist (bool ain_worklist) |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
768 { |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
769 min_worklist = ain_worklist; |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
770 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
771 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
772 // replace all uses with |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
773 virtual void replace_with (jit_value *value); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
774 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
775 jit_type *type (void) const { return ty; } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
776 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
777 llvm::Type *type_llvm (void) const |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
778 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
779 return ty ? ty->to_llvm () : 0; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
780 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
781 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
782 const std::string& type_name (void) const |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
783 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
784 return ty->name (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
785 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
786 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
787 void stash_type (jit_type *new_ty) { ty = new_ty; } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
788 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
789 std::string print_string (void) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
790 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
791 std::stringstream ss; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
792 print (ss); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
793 return ss.str (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
794 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
795 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
796 jit_instruction *last_use (void) const { return mlast_use; } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
797 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
798 void stash_last_use (jit_instruction *alast_use) |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
799 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
800 mlast_use = alast_use; |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
801 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
802 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
803 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const = 0; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
804 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
805 virtual std::ostream& short_print (std::ostream& os) const |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
806 { return print (os); } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
807 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
808 virtual void accept (jit_ir_walker& walker) = 0; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
809 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
810 bool has_llvm (void) const |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
811 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
812 return llvm_value; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
813 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
814 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
815 llvm::Value *to_llvm (void) const |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
816 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
817 assert (llvm_value); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
818 return llvm_value; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
819 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
820 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
821 void stash_llvm (llvm::Value *compiled) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
822 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
823 llvm_value = compiled; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
824 } |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
825 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
826 protected: |
14945 | 827 std::ostream& print_indent (std::ostream& os, size_t indent = 0) const |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
828 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
829 for (size_t i = 0; i < indent * 8; ++i) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
830 os << " "; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
831 return os; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
832 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
833 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
834 llvm::Value *llvm_value; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
835 private: |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
836 jit_type *ty; |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
837 jit_instruction *mlast_use; |
14946
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
838 bool min_worklist; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
839 }; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
840 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
841 std::ostream& operator<< (std::ostream& os, const jit_value& value); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
842 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
843 class |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
844 jit_use : public jit_internal_node<jit_value, jit_use> |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
845 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
846 public: |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
847 jit_use (void) : muser (0), mindex (0) {} |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
848 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
849 // we should really have a move operator, but not until c++11 :( |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
850 jit_use (const jit_use& use) : muser (0), mindex (0) |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
851 { |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
852 *this = use; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
853 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
854 |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
855 jit_use& operator= (const jit_use& use) |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
856 { |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
857 stash_value (use.value (), use.user (), use.index ()); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
858 return *this; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
859 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
860 |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
861 size_t index (void) const { return mindex; } |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
862 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
863 jit_instruction *user (void) const { return muser; } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
864 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
865 jit_block *user_parent (void) const; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
866 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
867 std::list<jit_block *> user_parent_location (void) const; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
868 |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
869 void stash_value (jit_value *avalue, jit_instruction *auser = 0, |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
870 size_t aindex = -1) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
871 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
872 jit_internal_node::stash_value (avalue); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
873 mindex = aindex; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
874 muser = auser; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
875 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
876 private: |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
877 jit_instruction *muser; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
878 size_t mindex; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
879 }; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
880 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
881 class |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
882 jit_instruction : public jit_value |
14906 | 883 { |
884 public: | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
885 // FIXME: this code could be so much pretier with varadic templates... |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
886 jit_instruction (void) : mid (next_id ()), mparent (0) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
887 {} |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
888 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
889 jit_instruction (size_t nargs) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
890 : already_infered (nargs, reinterpret_cast<jit_type *>(0)), |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
891 mid (next_id ()), mparent (0) |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
892 { |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
893 marguments.reserve (nargs); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
894 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
895 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
896 jit_instruction (jit_value *arg0) |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
897 : already_infered (1, reinterpret_cast<jit_type *>(0)), marguments (1), |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
898 mid (next_id ()), mparent (0) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
899 { |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
900 stash_argument (0, arg0); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
901 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
902 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
903 jit_instruction (jit_value *arg0, jit_value *arg1) |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
904 : already_infered (2, reinterpret_cast<jit_type *>(0)), marguments (2), |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
905 mid (next_id ()), mparent (0) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
906 { |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
907 stash_argument (0, arg0); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
908 stash_argument (1, arg1); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
909 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
910 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
911 jit_instruction (jit_value *arg0, jit_value *arg1, jit_value *arg2) |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
912 : already_infered (3, reinterpret_cast<jit_type *>(0)), marguments (3), |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
913 mid (next_id ()), mparent (0) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
914 { |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
915 stash_argument (0, arg0); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
916 stash_argument (1, arg1); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
917 stash_argument (2, arg2); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
918 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
919 |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
920 jit_instruction (jit_value *arg0, jit_value *arg1, jit_value *arg2, |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
921 jit_value *arg3) |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
922 : already_infered (3, reinterpret_cast<jit_type *>(0)), marguments (4), |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
923 mid (next_id ()), mparent (0) |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
924 { |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
925 stash_argument (0, arg0); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
926 stash_argument (1, arg1); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
927 stash_argument (2, arg2); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
928 stash_argument (3, arg3); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
929 } |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
930 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
931 static void reset_ids (void) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
932 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
933 next_id (true); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
934 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
935 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
936 jit_value *argument (size_t i) const |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
937 { |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
938 return marguments[i].value (); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
939 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
940 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
941 llvm::Value *argument_llvm (size_t i) const |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
942 { |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
943 assert (argument (i)); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
944 return argument (i)->to_llvm (); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
945 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
946 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
947 jit_type *argument_type (size_t i) const |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
948 { |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
949 return argument (i)->type (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
950 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
951 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
952 llvm::Type *argument_type_llvm (size_t i) const |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
953 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
954 assert (argument (i)); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
955 return argument_type (i)->to_llvm (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
956 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
957 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
958 std::ostream& print_argument (std::ostream& os, size_t i) const |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
959 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
960 if (argument (i)) |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
961 return argument (i)->short_print (os); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
962 else |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
963 return os << "NULL"; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
964 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
965 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
966 void stash_argument (size_t i, jit_value *arg) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
967 { |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
968 marguments[i].stash_value (arg, this, i); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
969 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
970 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
971 void push_argument (jit_value *arg) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
972 { |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
973 marguments.push_back (jit_use ()); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
974 stash_argument (marguments.size () - 1, arg); |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
975 already_infered.push_back (0); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
976 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
977 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
978 size_t argument_count (void) const |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
979 { |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
980 return marguments.size (); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
981 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
982 |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
983 void resize_arguments (size_t acount, jit_value *adefault = 0) |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
984 { |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
985 size_t old = marguments.size (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
986 marguments.resize (acount); |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
987 already_infered.resize (acount); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
988 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
989 if (adefault) |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
990 for (size_t i = old; i < acount; ++i) |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
991 stash_argument (i, adefault); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
992 } |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
993 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
994 const std::vector<jit_use>& arguments (void) const { return marguments; } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
995 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
996 // argument types which have been infered already |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
997 const std::vector<jit_type *>& argument_types (void) const |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
998 { return already_infered; } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
999 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1000 virtual void push_variable (void) {} |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1001 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1002 virtual void pop_variable (void) {} |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1003 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1004 virtual bool infer (void) { return false; } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1005 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1006 void remove (void); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1007 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1008 virtual std::ostream& short_print (std::ostream& os) const; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1009 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1010 jit_block *parent (void) const { return mparent; } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1011 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1012 std::list<jit_instruction *>::iterator location (void) const |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1013 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1014 return mlocation; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1015 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1016 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1017 llvm::BasicBlock *parent_llvm (void) const; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1018 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1019 void stash_parent (jit_block *aparent, |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1020 std::list<jit_instruction *>::iterator alocation) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1021 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1022 mparent = aparent; |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1023 mlocation = alocation; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1024 } |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1025 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1026 size_t id (void) const { return mid; } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1027 protected: |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1028 std::vector<jit_type *> already_infered; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1029 private: |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1030 static size_t next_id (bool reset = false) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1031 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1032 static size_t ret = 0; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1033 if (reset) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1034 return ret = 0; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1035 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1036 return ret++; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1037 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1038 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1039 std::vector<jit_use> marguments; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1040 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1041 size_t mid; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1042 jit_block *mparent; |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1043 std::list<jit_instruction *>::iterator mlocation; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1044 }; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1045 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1046 // defnie accept methods for subclasses |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1047 #define JIT_VALUE_ACCEPT \ |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1048 virtual void accept (jit_ir_walker& walker); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1049 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1050 // for use as a dummy argument during conversion to LLVM |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1051 class |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1052 jit_argument : public jit_value |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1053 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1054 public: |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1055 jit_argument (jit_type *atype, llvm::Value *avalue) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1056 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1057 stash_type (atype); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1058 stash_llvm (avalue); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1059 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1060 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1061 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1062 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1063 print_indent (os, indent); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1064 return jit_print (os, type ()) << ": DUMMY"; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1065 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1066 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1067 JIT_VALUE_ACCEPT; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1068 }; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1069 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1070 template <typename T, jit_type *(*EXTRACT_T)(void), typename PASS_T, |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1071 bool QUOTE> |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1072 class |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
1073 jit_const : public jit_value |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1074 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1075 public: |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1076 typedef PASS_T pass_t; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1077 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1078 jit_const (PASS_T avalue) : mvalue (avalue) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1079 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1080 stash_type (EXTRACT_T ()); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1081 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1082 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1083 PASS_T value (void) const { return mvalue; } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1084 |
14945 | 1085 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1086 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1087 print_indent (os, indent); |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
1088 jit_print (os, type ()) << ": "; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1089 if (QUOTE) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1090 os << "\""; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1091 os << mvalue; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1092 if (QUOTE) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1093 os << "\""; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1094 return os; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1095 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1096 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1097 JIT_VALUE_ACCEPT; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1098 private: |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1099 T mvalue; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1100 }; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1101 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1102 class jit_phi_incomming; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1103 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1104 class |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1105 jit_block : public jit_value, public jit_internal_list<jit_block, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1106 jit_phi_incomming> |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1107 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1108 typedef jit_internal_list<jit_block, jit_phi_incomming> ILIST_T; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1109 public: |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1110 typedef std::list<jit_instruction *> instruction_list; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1111 typedef instruction_list::iterator iterator; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1112 typedef instruction_list::const_iterator const_iterator; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1113 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1114 typedef std::set<jit_block *> df_set; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1115 typedef df_set::const_iterator df_iterator; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1116 |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1117 jit_block (const std::string& aname) : mvisit_count (0), mid (NO_ID), |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1118 idom (0), mname (aname), malive (false) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1119 {} |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1120 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1121 virtual void replace_with (jit_value *value); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1122 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1123 // we have a new internal list, but we want to stay compatable with jit_value |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1124 jit_use *first_use (void) const { return jit_value::first_use (); } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1125 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1126 size_t use_count (void) const { return jit_value::use_count (); } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1127 |
14945 | 1128 // if a block is alive, then it might be visited during execution |
1129 bool alive (void) const { return malive; } | |
1130 | |
1131 void mark_alive (void) { malive = true; } | |
1132 | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1133 // If we can merge with a successor, do so and return the now empty block |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1134 jit_block *maybe_merge (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1135 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1136 // merge another block into this block, leaving the merge block empty |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1137 void merge (jit_block& merge); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1138 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1139 const std::string& name (void) const { return mname; } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1140 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1141 jit_instruction *prepend (jit_instruction *instr); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1142 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1143 jit_instruction *prepend_after_phi (jit_instruction *instr); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1144 |
14945 | 1145 template <typename T> |
1146 T *append (T *instr) | |
1147 { | |
1148 internal_append (instr); | |
1149 return instr; | |
1150 } | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1151 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1152 jit_instruction *insert_before (iterator loc, jit_instruction *instr); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1153 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1154 jit_instruction *insert_after (iterator loc, jit_instruction *instr); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1155 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1156 iterator remove (iterator iter) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1157 { |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1158 jit_instruction *instr = *iter; |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1159 iter = instructions.erase (iter); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1160 instr->stash_parent (0, instructions.end ()); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1161 return iter; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1162 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1163 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1164 jit_terminator *terminator (void) const; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1165 |
14945 | 1166 // is the jump from pred alive? |
1167 bool branch_alive (jit_block *asucc) const; | |
1168 | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1169 llvm::BasicBlock *branch_llvm (size_t idx) const; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1170 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1171 llvm::BasicBlock *branch_llvm (jit_block *succ) const; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1172 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1173 jit_block *successor (size_t i) const; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1174 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1175 size_t successor_count (void) const; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1176 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1177 iterator begin (void) { return instructions.begin (); } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1178 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1179 const_iterator begin (void) const { return instructions.begin (); } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1180 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1181 iterator end (void) { return instructions.end (); } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1182 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1183 const_iterator end (void) const { return instructions.end (); } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1184 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1185 iterator phi_begin (void); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1186 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1187 iterator phi_end (void); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1188 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1189 iterator nonphi_begin (void); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1190 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1191 // must label before id is valid |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1192 size_t id (void) const { return mid; } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1193 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1194 // dominance frontier |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1195 const df_set& df (void) const { return mdf; } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1196 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1197 df_iterator df_begin (void) const { return mdf.begin (); } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1198 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1199 df_iterator df_end (void) const { return mdf.end (); } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1200 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1201 // label with a RPO walk |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1202 void label (void) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1203 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1204 size_t number = 0; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1205 label (mvisit_count, number); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1206 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1207 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1208 void label (size_t visit_count, size_t& number) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1209 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1210 if (mvisit_count > visit_count) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1211 return; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1212 ++mvisit_count; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1213 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1214 for (jit_use *use = first_use (); use; use = use->next ()) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1215 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1216 jit_block *pred = use->user_parent (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1217 pred->label (visit_count, number); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1218 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1219 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1220 mid = number++; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1221 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1222 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1223 // See for idom computation algorithm |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1224 // Cooper, Keith D.; Harvey, Timothy J; and Kennedy, Ken (2001). |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1225 // "A Simple, Fast Dominance Algorithm" |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1226 void compute_idom (jit_block *entry_block) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1227 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1228 bool changed; |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1229 entry_block->idom = entry_block; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1230 do |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1231 changed = update_idom (mvisit_count); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1232 while (changed); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1233 } |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1234 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1235 // compute dominance frontier |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1236 void compute_df (void) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1237 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1238 compute_df (mvisit_count); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1239 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1240 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1241 void create_dom_tree (void) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1242 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1243 create_dom_tree (mvisit_count); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1244 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1245 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1246 // visit blocks in the order of the dominator tree |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1247 // inorder - Run on the root first, then children |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1248 // postorder - Run on children first, then the root |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1249 template <typename func_type0, typename func_type1> |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1250 void visit_dom (func_type0 inorder, func_type1 postorder) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1251 { |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1252 do_visit_dom (mvisit_count, inorder, postorder); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1253 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1254 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1255 // call pop_varaible on all instructions |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1256 void pop_all (void); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1257 |
14945 | 1258 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1259 { |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1260 print_indent (os, indent); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1261 short_print (os) << ": %pred = "; |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1262 for (jit_use *use = first_use (); use; use = use->next ()) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1263 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1264 jit_block *pred = use->user_parent (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1265 os << *pred; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1266 if (use->next ()) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1267 os << ", "; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1268 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1269 os << std::endl; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1270 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1271 for (const_iterator iter = begin (); iter != end (); ++iter) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1272 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1273 jit_instruction *instr = *iter; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1274 instr->print (os, indent + 1) << std::endl; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1275 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1276 return os; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1277 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1278 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1279 // print dominator infomration |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1280 std::ostream& print_dom (std::ostream& os) const; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1281 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1282 virtual std::ostream& short_print (std::ostream& os) const |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1283 { |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1284 os << mname; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1285 if (mid != NO_ID) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1286 os << mid; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1287 return os; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1288 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1289 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1290 llvm::BasicBlock *to_llvm (void) const; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1291 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1292 std::list<jit_block *>::iterator location (void) const |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1293 { return mlocation; } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1294 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1295 void stash_location (std::list<jit_block *>::iterator alocation) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1296 { mlocation = alocation; } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1297 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1298 JIT_VALUE_ACCEPT; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1299 private: |
14945 | 1300 void internal_append (jit_instruction *instr); |
1301 | |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1302 void compute_df (size_t visit_count); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1303 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1304 bool update_idom (size_t visit_count); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1305 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1306 void create_dom_tree (size_t visit_count); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1307 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1308 jit_block *idom_intersect (jit_block *b); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1309 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1310 template <typename func_type0, typename func_type1> |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1311 void do_visit_dom (size_t visit_count, func_type0 inorder, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1312 func_type1 postorder); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1313 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1314 static const size_t NO_ID = static_cast<size_t> (-1); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1315 size_t mvisit_count; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1316 size_t mid; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1317 jit_block *idom; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1318 df_set mdf; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1319 std::vector<jit_block *> dom_succ; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1320 std::string mname; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1321 instruction_list instructions; |
14945 | 1322 bool malive; |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1323 std::list<jit_block *>::iterator mlocation; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1324 }; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1325 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1326 // keeps track of phi functions that use a block on incomming edges |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1327 class |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1328 jit_phi_incomming : public jit_internal_node<jit_block, jit_phi_incomming> |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1329 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1330 public: |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1331 jit_phi_incomming (void) {} |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1332 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1333 jit_phi_incomming (const jit_phi_incomming& use) : jit_internal_node () |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1334 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1335 *this = use; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1336 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1337 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1338 jit_phi_incomming& operator= (const jit_phi_incomming& use) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1339 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1340 stash_value (use.value ()); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1341 return *this; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1342 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1343 }; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1344 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1345 // allow regular function pointers as well as pointers to members |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1346 template <typename func_type> |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1347 class jit_block_callback |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1348 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1349 public: |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1350 jit_block_callback (func_type afunction) : function (afunction) {} |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1351 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1352 void operator() (jit_block& block) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1353 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1354 function (block); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1355 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1356 private: |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1357 func_type function; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1358 }; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1359 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1360 template <> |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1361 class jit_block_callback<void (jit_block::*)(void)> |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1362 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1363 public: |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1364 typedef void (jit_block::*func_type)(void); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1365 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1366 jit_block_callback (func_type afunction) : function (afunction) {} |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1367 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1368 void operator() (jit_block& ablock) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1369 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1370 (ablock.*function) (); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1371 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1372 private: |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1373 func_type function; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1374 }; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1375 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1376 template <typename func_type0, typename func_type1> |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1377 void |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1378 jit_block::do_visit_dom (size_t visit_count, func_type0 inorder, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1379 func_type1 postorder) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1380 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1381 if (mvisit_count > visit_count) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1382 return; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1383 mvisit_count = visit_count + 1; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1384 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1385 jit_block_callback<func_type0> inorder_cb (inorder); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1386 inorder_cb (*this); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1387 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1388 for (size_t i = 0; i < dom_succ.size (); ++i) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1389 dom_succ[i]->do_visit_dom (visit_count, inorder, postorder); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1390 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1391 jit_block_callback<func_type1> postorder_cb (postorder); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1392 postorder_cb (*this); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1393 } |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1394 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1395 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1396 // A non-ssa variable |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1397 class |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1398 jit_variable : public jit_value |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1399 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1400 public: |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1401 jit_variable (const std::string& aname) : mname (aname), mlast_use (0) {} |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1402 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1403 const std::string &name (void) const { return mname; } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1404 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1405 // manipulate the value_stack, for use during SSA construction. The top of the |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1406 // value stack represents the current value for this variable |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1407 bool has_top (void) const |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1408 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1409 return ! value_stack.empty (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1410 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1411 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1412 jit_value *top (void) const |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1413 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1414 return value_stack.top (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1415 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1416 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1417 void push (jit_instruction *v) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1418 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1419 value_stack.push (v); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1420 mlast_use = v; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1421 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1422 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1423 void pop (void) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1424 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1425 value_stack.pop (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1426 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1427 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1428 jit_instruction *last_use (void) const |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1429 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1430 return mlast_use; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1431 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1432 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1433 void stash_last_use (jit_instruction *instr) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1434 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1435 mlast_use = instr; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1436 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1437 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1438 // blocks in which we are used |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1439 void use_blocks (jit_block::df_set& result) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1440 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1441 jit_use *use = first_use (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1442 while (use) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1443 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1444 result.insert (use->user_parent ()); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1445 use = use->next (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1446 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1447 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1448 |
14945 | 1449 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1450 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1451 return print_indent (os, indent) << mname; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1452 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1453 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1454 JIT_VALUE_ACCEPT; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1455 private: |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1456 std::string mname; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1457 std::stack<jit_value *> value_stack; |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1458 jit_instruction *mlast_use; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1459 }; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1460 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1461 class |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1462 jit_assign_base : public jit_instruction |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1463 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1464 public: |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1465 jit_assign_base (jit_variable *adest) : jit_instruction (), mdest (adest) {} |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1466 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1467 jit_assign_base (jit_variable *adest, size_t npred) : jit_instruction (npred), |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1468 mdest (adest) {} |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1469 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1470 jit_assign_base (jit_variable *adest, jit_value *arg0, jit_value *arg1) |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1471 : jit_instruction (arg0, arg1), mdest (adest) {} |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1472 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1473 jit_variable *dest (void) const { return mdest; } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1474 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1475 virtual void push_variable (void) |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1476 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1477 mdest->push (this); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1478 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1479 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1480 virtual void pop_variable (void) |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1481 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1482 mdest->pop (); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1483 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1484 private: |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1485 jit_variable *mdest; |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1486 }; |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1487 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1488 class |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1489 jit_assign : public jit_assign_base |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1490 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1491 public: |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
1492 jit_assign (jit_variable *adest, jit_value *asrc) |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1493 : jit_assign_base (adest, adest, asrc) {} |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1494 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1495 jit_instruction *src (void) const |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1496 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1497 return static_cast<jit_instruction *> (argument (1)); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1498 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1499 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1500 virtual void push_variable (void) |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1501 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1502 dest ()->push (src ()); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1503 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1504 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1505 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1506 { |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1507 return print_indent (os, indent) << *dest () << " = " << *src (); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1508 } |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1509 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1510 JIT_VALUE_ACCEPT; |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1511 private: |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1512 jit_variable *mdest; |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1513 }; |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1514 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1515 class |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1516 jit_phi : public jit_assign_base |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1517 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1518 public: |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1519 jit_phi (jit_variable *adest, size_t npred) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1520 : jit_assign_base (adest, npred) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1521 { |
14945 | 1522 mincomming.reserve (npred); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1523 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1524 |
14945 | 1525 // removes arguments form dead incomming jumps |
1526 bool prune (void); | |
1527 | |
1528 void add_incomming (jit_block *from, jit_value *value) | |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1529 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1530 push_argument (value); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1531 mincomming.push_back (jit_phi_incomming ()); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1532 mincomming[mincomming.size () - 1].stash_value (from); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1533 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1534 |
14945 | 1535 jit_block *incomming (size_t i) const |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1536 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1537 return mincomming[i].value (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1538 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1539 |
14945 | 1540 llvm::BasicBlock *incomming_llvm (size_t i) const |
1541 { | |
1542 jit_block *inc = incomming (i); | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1543 return inc->branch_llvm (parent ()); |
14945 | 1544 } |
1545 | |
1546 virtual bool infer (void); | |
1547 | |
1548 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1549 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1550 std::stringstream ss; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1551 print_indent (ss, indent); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1552 short_print (ss) << " phi "; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1553 std::string ss_str = ss.str (); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1554 std::string indent_str (ss_str.size (), ' '); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1555 os << ss_str; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1556 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1557 for (size_t i = 0; i < argument_count (); ++i) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1558 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1559 if (i > 0) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1560 os << indent_str; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1561 os << "| "; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1562 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1563 os << *incomming (i) << " -> "; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1564 os << *argument (i); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1565 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1566 if (i + 1 < argument_count ()) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1567 os << std::endl; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1568 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1569 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1570 return os; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1571 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1572 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1573 virtual std::ostream& short_print (std::ostream& os) const |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1574 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1575 if (type ()) |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1576 jit_print (os, type ()) << ": "; |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1577 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1578 dest ()->short_print (os); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1579 return os << "#" << id (); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1580 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1581 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1582 JIT_VALUE_ACCEPT; |
14945 | 1583 private: |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1584 std::vector<jit_phi_incomming> mincomming; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1585 }; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1586 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1587 class |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1588 jit_terminator : public jit_instruction |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1589 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1590 public: |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1591 jit_terminator (size_t asuccessor_count, jit_value *arg0) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1592 : jit_instruction (arg0), malive (asuccessor_count, false), |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1593 mbranch_llvm (asuccessor_count, 0) {} |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1594 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1595 jit_terminator (size_t asuccessor_count, jit_value *arg0, jit_value *arg1) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1596 : jit_instruction (arg0, arg1), malive (asuccessor_count, false), |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1597 mbranch_llvm (asuccessor_count, 0) {} |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1598 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1599 jit_terminator (size_t asuccessor_count, jit_value *arg0, jit_value *arg1, |
14945 | 1600 jit_value *arg2) |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1601 : jit_instruction (arg0, arg1, arg2), malive (asuccessor_count, false), |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1602 mbranch_llvm (asuccessor_count, 0) {} |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1603 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1604 jit_block *successor (size_t idx = 0) const |
14945 | 1605 { |
1606 return static_cast<jit_block *> (argument (idx)); | |
1607 } | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1608 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1609 // the llvm block between our parent and the given successor |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1610 llvm::BasicBlock *branch_llvm (size_t idx = 0) const |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1611 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1612 return mbranch_llvm[idx] ? mbranch_llvm[idx] : parent ()->to_llvm (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1613 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1614 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1615 llvm::BasicBlock *branch_llvm (int idx) const |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1616 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1617 return branch_llvm (static_cast<size_t> (idx)); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1618 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1619 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1620 llvm::BasicBlock *branch_llvm (const jit_block *asuccessor) const |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1621 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1622 return branch_llvm (successor_index (asuccessor)); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1623 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1624 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1625 llvm::BasicBlock *successor_llvm (size_t idx = 0) const |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1626 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1627 return mbranch_llvm[idx] ? mbranch_llvm[idx] : successor (idx)->to_llvm (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1628 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1629 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1630 size_t successor_index (const jit_block *asuccessor) const; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1631 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1632 // create a merge block along the given edge |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1633 void create_merge (llvm::Function *function, jit_block *asuccessor); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1634 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1635 std::ostream& print_successor (std::ostream& os, size_t idx = 0) const |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1636 { |
14945 | 1637 if (alive (idx)) |
1638 os << "[live] "; | |
1639 else | |
1640 os << "[dead] "; | |
1641 | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1642 return successor (idx)->short_print (os); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1643 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1644 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1645 // Check if the jump to successor is live |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1646 bool alive (const jit_block *asuccessor) const |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1647 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1648 return alive (successor_index (asuccessor)); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1649 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1650 |
14945 | 1651 bool alive (size_t idx) const { return malive[idx]; } |
1652 | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1653 bool alive (int idx) const { return malive[idx]; } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1654 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1655 size_t successor_count (void) const { return malive.size (); } |
14945 | 1656 |
1657 virtual bool infer (void); | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1658 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1659 llvm::TerminatorInst *to_llvm (void) const; |
14945 | 1660 protected: |
1661 virtual bool check_alive (size_t) const { return true; } | |
1662 private: | |
1663 std::vector<bool> malive; | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1664 std::vector<llvm::BasicBlock *> mbranch_llvm; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1665 }; |
14913
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
1666 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1667 class |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14957
diff
changeset
|
1668 jit_branch : public jit_terminator |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1669 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1670 public: |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14957
diff
changeset
|
1671 jit_branch (jit_block *succ) : jit_terminator (1, succ) {} |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1672 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1673 virtual size_t successor_count (void) const { return 1; } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1674 |
14945 | 1675 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1676 { |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14957
diff
changeset
|
1677 print_indent (os, indent) << "branch: "; |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1678 return print_successor (os); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1679 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1680 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1681 JIT_VALUE_ACCEPT; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1682 }; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1683 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1684 class |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14957
diff
changeset
|
1685 jit_cond_branch : public jit_terminator |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1686 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1687 public: |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14957
diff
changeset
|
1688 jit_cond_branch (jit_value *c, jit_block *ctrue, jit_block *cfalse) |
14945 | 1689 : jit_terminator (2, ctrue, cfalse, c) {} |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1690 |
14945 | 1691 jit_value *cond (void) const { return argument (2); } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1692 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1693 std::ostream& print_cond (std::ostream& os) const |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1694 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1695 return cond ()->short_print (os); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1696 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1697 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1698 llvm::Value *cond_llvm (void) const |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1699 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1700 return cond ()->to_llvm (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1701 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1702 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1703 virtual size_t successor_count (void) const { return 2; } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1704 |
14945 | 1705 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1706 { |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14957
diff
changeset
|
1707 print_indent (os, indent) << "cond_branch: "; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1708 print_cond (os) << ", "; |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1709 print_successor (os, 0) << ", "; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1710 return print_successor (os, 1); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1711 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1712 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1713 JIT_VALUE_ACCEPT; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1714 }; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1715 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1716 class |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1717 jit_call : public jit_instruction |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1718 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1719 public: |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1720 jit_call (const jit_function& afunction, |
14945 | 1721 jit_value *arg0) : jit_instruction (arg0), mfunction (afunction) |
1722 {} | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1723 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1724 jit_call (const jit_function& (*afunction) (void), |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1725 jit_value *arg0) : jit_instruction (arg0), |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1726 mfunction (afunction ()) {} |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1727 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1728 jit_call (const jit_function& afunction, |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1729 jit_value *arg0, jit_value *arg1) : jit_instruction (arg0, arg1), |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1730 mfunction (afunction) {} |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1731 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1732 jit_call (const jit_function& (*afunction) (void), |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1733 jit_value *arg0, jit_value *arg1) : jit_instruction (arg0, arg1), |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1734 mfunction (afunction ()) {} |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1735 |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1736 jit_call (const jit_function& (*afunction) (void), |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1737 jit_value *arg0, jit_value *arg1, jit_value *arg2) |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1738 : jit_instruction (arg0, arg1, arg2), mfunction (afunction ()) {} |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1739 |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1740 jit_call (const jit_function& (*afunction) (void), |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1741 jit_value *arg0, jit_value *arg1, jit_value *arg2, jit_value *arg3) |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1742 : jit_instruction (arg0, arg1, arg2, arg3), mfunction (afunction ()) {} |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1743 |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1744 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1745 const jit_function& function (void) const { return mfunction; } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1746 |
14945 | 1747 bool can_error (void) const |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1748 { |
14945 | 1749 return overload ().can_error; |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1750 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1751 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1752 const jit_function::overload& overload (void) const |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1753 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1754 return mfunction.get_overload (argument_types ()); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1755 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1756 |
14945 | 1757 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1758 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1759 print_indent (os, indent); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1760 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1761 if (use_count ()) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1762 short_print (os) << " = "; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1763 os << "call " << mfunction.name () << " ("; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1764 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1765 for (size_t i = 0; i < argument_count (); ++i) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1766 { |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1767 print_argument (os, i); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1768 if (i + 1 < argument_count ()) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1769 os << ", "; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1770 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1771 return os << ")"; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1772 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1773 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1774 virtual bool infer (void); |
14906 | 1775 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1776 JIT_VALUE_ACCEPT; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1777 private: |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1778 const jit_function& mfunction; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1779 }; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1780 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1781 // FIXME: This is just ugly... |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1782 // checks error_state, if error_state is false then goto the normal branche, |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1783 // otherwise goto the error branch |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1784 class |
14960
c959136f8c3e
Rename jit_check_error to jit_error_check
Max Brister <max@2bass.com>
parents:
14959
diff
changeset
|
1785 jit_error_check : public jit_terminator |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1786 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1787 public: |
14960
c959136f8c3e
Rename jit_check_error to jit_error_check
Max Brister <max@2bass.com>
parents:
14959
diff
changeset
|
1788 jit_error_check (jit_call *acheck_for, jit_block *normal, jit_block *error) |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1789 : jit_terminator (2, error, normal, acheck_for) {} |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1790 |
14945 | 1791 jit_call *check_for (void) const |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1792 { |
14945 | 1793 return static_cast<jit_call *> (argument (2)); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1794 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1795 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1796 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1797 { |
14945 | 1798 print_indent (os, indent) << "error_check " << *check_for () << ", "; |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1799 print_successor (os, 1) << ", "; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1800 return print_successor (os, 0); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1801 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1802 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1803 JIT_VALUE_ACCEPT; |
14945 | 1804 protected: |
1805 virtual bool check_alive (size_t idx) const | |
1806 { | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1807 return idx == 1 ? true : check_for ()->can_error (); |
14945 | 1808 } |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1809 }; |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1810 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1811 class |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1812 jit_extract_argument : public jit_assign_base |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1813 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1814 public: |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1815 jit_extract_argument (jit_type *atype, jit_variable *adest) |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1816 : jit_assign_base (adest) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1817 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1818 stash_type (atype); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1819 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1820 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1821 const std::string& name (void) const |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1822 { |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1823 return dest ()->name (); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1824 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1825 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1826 const jit_function::overload& overload (void) const |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1827 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1828 return jit_typeinfo::cast (type (), jit_typeinfo::get_any ()); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1829 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1830 |
14945 | 1831 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1832 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1833 print_indent (os, indent); |
14942
e8487d98561c
Improve printing of jit_extract_argument
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
1834 |
e8487d98561c
Improve printing of jit_extract_argument
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
1835 return short_print (os) << " = extract " << name (); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1836 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1837 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1838 JIT_VALUE_ACCEPT; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1839 }; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1840 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1841 class |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1842 jit_store_argument : public jit_instruction |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1843 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1844 public: |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1845 jit_store_argument (jit_variable *var) |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1846 : jit_instruction (var), dest (var) |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1847 {} |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1848 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1849 const std::string& name (void) const |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1850 { |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1851 return dest->name (); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1852 } |
14906 | 1853 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1854 const jit_function::overload& overload (void) const |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1855 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1856 return jit_typeinfo::cast (jit_typeinfo::get_any (), result_type ()); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1857 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1858 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1859 jit_value *result (void) const |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1860 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1861 return argument (0); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1862 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1863 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1864 jit_type *result_type (void) const |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1865 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1866 return result ()->type (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1867 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1868 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1869 llvm::Value *result_llvm (void) const |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1870 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1871 return result ()->to_llvm (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1872 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1873 |
14945 | 1874 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1875 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1876 jit_value *res = result (); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
1877 print_indent (os, indent) << "store "; |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1878 dest->short_print (os); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1879 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1880 if (! isa<jit_variable> (res)) |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1881 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1882 os << " = "; |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1883 res->short_print (os); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1884 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1885 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1886 return os; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1887 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1888 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
1889 JIT_VALUE_ACCEPT; |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1890 private: |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1891 jit_variable *dest; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1892 }; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1893 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1894 class |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1895 jit_ir_walker |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1896 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1897 public: |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1898 virtual ~jit_ir_walker () {} |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1899 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1900 #define JIT_METH(clname) \ |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1901 virtual void visit (jit_ ## clname&) = 0; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1902 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1903 JIT_VISIT_IR_CLASSES; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1904 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1905 #undef JIT_METH |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1906 }; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1907 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1908 template <typename T, jit_type *(*EXTRACT_T)(void), typename PASS_T, bool QUOTE> |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1909 void |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1910 jit_const<T, EXTRACT_T, PASS_T, QUOTE>::accept (jit_ir_walker& walker) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1911 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1912 walker.visit (*this); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1913 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1914 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1915 // convert between IRs |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1916 // FIXME: Class relationships are messy from here on down. They need to be |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1917 // cleaned up. |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1918 class |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1919 jit_convert : public tree_walker |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1920 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1921 public: |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1922 typedef std::pair<jit_type *, std::string> type_bound; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1923 typedef std::vector<type_bound> type_bound_vector; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1924 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1925 jit_convert (llvm::Module *module, tree &tee); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1926 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
1927 ~jit_convert (void); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
1928 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1929 llvm::Function *get_function (void) const { return function; } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1930 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1931 const std::vector<std::pair<std::string, bool> >& get_arguments(void) const |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1932 { return arguments; } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1933 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1934 const type_bound_vector& get_bounds (void) const { return bounds; } |
14906 | 1935 |
1936 void visit_anon_fcn_handle (tree_anon_fcn_handle&); | |
1937 | |
1938 void visit_argument_list (tree_argument_list&); | |
1939 | |
1940 void visit_binary_expression (tree_binary_expression&); | |
1941 | |
1942 void visit_break_command (tree_break_command&); | |
1943 | |
1944 void visit_colon_expression (tree_colon_expression&); | |
1945 | |
1946 void visit_continue_command (tree_continue_command&); | |
1947 | |
1948 void visit_global_command (tree_global_command&); | |
1949 | |
1950 void visit_persistent_command (tree_persistent_command&); | |
1951 | |
1952 void visit_decl_elt (tree_decl_elt&); | |
1953 | |
1954 void visit_decl_init_list (tree_decl_init_list&); | |
1955 | |
1956 void visit_simple_for_command (tree_simple_for_command&); | |
1957 | |
1958 void visit_complex_for_command (tree_complex_for_command&); | |
1959 | |
1960 void visit_octave_user_script (octave_user_script&); | |
1961 | |
1962 void visit_octave_user_function (octave_user_function&); | |
1963 | |
1964 void visit_octave_user_function_header (octave_user_function&); | |
1965 | |
1966 void visit_octave_user_function_trailer (octave_user_function&); | |
1967 | |
1968 void visit_function_def (tree_function_def&); | |
1969 | |
1970 void visit_identifier (tree_identifier&); | |
1971 | |
1972 void visit_if_clause (tree_if_clause&); | |
1973 | |
1974 void visit_if_command (tree_if_command&); | |
1975 | |
1976 void visit_if_command_list (tree_if_command_list&); | |
1977 | |
1978 void visit_index_expression (tree_index_expression&); | |
1979 | |
1980 void visit_matrix (tree_matrix&); | |
1981 | |
1982 void visit_cell (tree_cell&); | |
1983 | |
1984 void visit_multi_assignment (tree_multi_assignment&); | |
1985 | |
1986 void visit_no_op_command (tree_no_op_command&); | |
1987 | |
1988 void visit_constant (tree_constant&); | |
1989 | |
1990 void visit_fcn_handle (tree_fcn_handle&); | |
1991 | |
1992 void visit_parameter_list (tree_parameter_list&); | |
1993 | |
1994 void visit_postfix_expression (tree_postfix_expression&); | |
1995 | |
1996 void visit_prefix_expression (tree_prefix_expression&); | |
1997 | |
1998 void visit_return_command (tree_return_command&); | |
1999 | |
2000 void visit_return_list (tree_return_list&); | |
2001 | |
2002 void visit_simple_assignment (tree_simple_assignment&); | |
2003 | |
2004 void visit_statement (tree_statement&); | |
2005 | |
2006 void visit_statement_list (tree_statement_list&); | |
2007 | |
2008 void visit_switch_case (tree_switch_case&); | |
2009 | |
2010 void visit_switch_case_list (tree_switch_case_list&); | |
2011 | |
2012 void visit_switch_command (tree_switch_command&); | |
2013 | |
2014 void visit_try_catch_command (tree_try_catch_command&); | |
2015 | |
2016 void visit_unwind_protect_command (tree_unwind_protect_command&); | |
2017 | |
2018 void visit_while_command (tree_while_command&); | |
2019 | |
2020 void visit_do_until_command (tree_do_until_command&); | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
2021 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2022 // this would be easier with variadic templates |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2023 template <typename T> |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2024 T *create (void) |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2025 { |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2026 T *ret = new T(); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2027 track_value (ret); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2028 return ret; |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2029 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2030 |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2031 template <typename T, typename ARG0> |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2032 T *create (const ARG0& arg0) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2033 { |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2034 T *ret = new T(arg0); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2035 track_value (ret); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2036 return ret; |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2037 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2038 |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2039 template <typename T, typename ARG0, typename ARG1> |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2040 T *create (const ARG0& arg0, const ARG1& arg1) |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2041 { |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2042 T *ret = new T(arg0, arg1); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2043 track_value (ret); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2044 return ret; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2045 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2046 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2047 template <typename T, typename ARG0, typename ARG1, typename ARG2> |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2048 T *create (const ARG0& arg0, const ARG1& arg1, const ARG2& arg2) |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2049 { |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2050 T *ret = new T(arg0, arg1, arg2); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2051 track_value (ret); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2052 return ret; |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2053 } |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2054 |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2055 template <typename T, typename ARG0, typename ARG1, typename ARG2, |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2056 typename ARG3> |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2057 T *create (const ARG0& arg0, const ARG1& arg1, const ARG2& arg2, |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2058 const ARG3& arg3) |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2059 { |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2060 T *ret = new T(arg0, arg1, arg2, arg3); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2061 track_value (ret); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2062 return ret; |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2063 } |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2064 private: |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2065 typedef std::list<jit_block *> block_list; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2066 typedef block_list::iterator block_iterator; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2067 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2068 std::vector<std::pair<std::string, bool> > arguments; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2069 type_bound_vector bounds; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2070 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2071 // used instead of return values from visit_* functions |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2072 jit_value *result; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2073 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2074 jit_block *entry_block; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2075 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2076 jit_block *final_block; |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2077 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2078 jit_block *block; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2079 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2080 llvm::Function *function; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2081 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2082 std::list<jit_block *> blocks; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2083 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2084 std::list<jit_instruction *> worklist; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2085 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2086 std::list<jit_value *> constants; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2087 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2088 std::list<jit_value *> all_values; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2089 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2090 size_t iterator_count; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2091 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2092 typedef std::map<std::string, jit_variable *> vmap_t; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2093 vmap_t vmap; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2094 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2095 void add_block (jit_block *ablock) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2096 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2097 blocks.push_back (ablock); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2098 ablock->stash_location (--blocks.end ()); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2099 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2100 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2101 jit_variable *get_variable (const std::string& vname); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2102 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2103 jit_value *do_assign (const std::string& lhs, jit_value *rhs, bool print); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2104 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2105 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2106 jit_value *visit (tree *tee) { return visit (*tee); } |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2107 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2108 jit_value *visit (tree& tee); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2109 |
14946
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
2110 void push_worklist (jit_instruction *instr) |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
2111 { |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
2112 if (! instr->in_worklist ()) |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
2113 { |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2114 instr->stash_in_worklist (true); |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2115 worklist.push_back (instr); |
14946
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
2116 } |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
2117 } |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
2118 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2119 void append_users (jit_value *v) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2120 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2121 for (jit_use *use = v->first_use (); use; use = use->next ()) |
14946
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
2122 push_worklist (use->user ()); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2123 } |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2124 |
14945 | 2125 void append_users_term (jit_terminator *term); |
2126 | |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2127 void track_value (jit_value *value) |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2128 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2129 if (value->type ()) |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2130 constants.push_back (value); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2131 all_values.push_back (value); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2132 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
2133 |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2134 void merge_blocks (void); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2135 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2136 void construct_ssa (void); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2137 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2138 static void do_construct_ssa (jit_block& block); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2139 |
14945 | 2140 void remove_dead (); |
2141 | |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2142 void place_releases (void); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2143 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2144 void print_blocks (const std::string& header) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2145 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2146 std::cout << "-------------------- " << header << " --------------------\n"; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2147 for (std::list<jit_block *>::iterator iter = blocks.begin (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2148 iter != blocks.end (); ++iter) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2149 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2150 assert (*iter); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2151 (*iter)->print (std::cout, 0); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2152 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2153 std::cout << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2154 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2155 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2156 void print_dom (void) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2157 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2158 std::cout << "-------------------- dom info --------------------\n"; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2159 for (std::list<jit_block *>::iterator iter = blocks.begin (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2160 iter != blocks.end (); ++iter) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2161 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2162 assert (*iter); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2163 (*iter)->print_dom (std::cout); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2164 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2165 std::cout << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2166 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2167 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2168 bool breaking; // true if we are breaking OR continuing |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2169 block_list breaks; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2170 block_list continues; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2171 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2172 void finish_breaks (jit_block *dest, const block_list& lst); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2173 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2174 struct release_placer |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2175 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2176 release_placer (jit_convert& aconvert) : convert (aconvert) {} |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
2177 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2178 jit_convert& convert; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2179 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2180 void operator() (jit_block& block); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2181 }; |
14906 | 2182 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2183 // this case is much simpler, just convert from the jit ir to llvm |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2184 class |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2185 convert_llvm : public jit_ir_walker |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2186 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2187 public: |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2188 convert_llvm (jit_convert& jc) : jthis (jc) {} |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2189 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2190 llvm::Function *convert (llvm::Module *module, |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2191 const std::vector<std::pair<std::string, bool> >& args, |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2192 const std::list<jit_block *>& blocks, |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2193 const std::list<jit_value *>& constants); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2194 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2195 #define JIT_METH(clname) \ |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2196 virtual void visit (jit_ ## clname&); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2197 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2198 JIT_VISIT_IR_CLASSES; |
14906 | 2199 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2200 #undef JIT_METH |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2201 private: |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2202 // name -> llvm argument |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2203 std::map<std::string, llvm::Value *> arguments; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2204 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2205 void finish_phi (jit_instruction *phi); |
14906 | 2206 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2207 void visit (jit_value *jvalue) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2208 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2209 return visit (*jvalue); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2210 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2211 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2212 void visit (jit_value &jvalue) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2213 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2214 jvalue.accept (*this); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2215 } |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2216 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2217 llvm::Value *create_call (const jit_function::overload& ol, jit_value *arg0) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2218 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2219 std::vector<jit_value *> args (1, arg0); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2220 return create_call (ol, args); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2221 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2222 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2223 llvm::Value *create_call (const jit_function::overload& ol, jit_value *arg0, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2224 jit_value *arg1) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2225 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2226 std::vector<jit_value *> args (2); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2227 args[0] = arg0; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2228 args[1] = arg1; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2229 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2230 return create_call (ol, args); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2231 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2232 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2233 llvm::Value *create_call (const jit_function::overload& ol, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2234 const std::vector<jit_value *>& jargs); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2235 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2236 llvm::Value *create_call (const jit_function::overload& ol, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2237 const std::vector<jit_use>& uses); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2238 private: |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
2239 jit_convert &jthis; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2240 llvm::Function *function; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2241 }; |
14906 | 2242 }; |
2243 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2244 class jit_info; |
14903 | 2245 |
14899 | 2246 class |
14903 | 2247 tree_jit |
14899 | 2248 { |
2249 public: | |
2250 tree_jit (void); | |
2251 | |
2252 ~tree_jit (void); | |
2253 | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2254 bool execute (tree_simple_for_command& cmd); |
14903 | 2255 |
14906 | 2256 llvm::ExecutionEngine *get_engine (void) const { return engine; } |
14903 | 2257 |
14906 | 2258 llvm::Module *get_module (void) const { return module; } |
14903 | 2259 |
14906 | 2260 void optimize (llvm::Function *fn); |
2261 private: | |
2262 bool initialize (void); | |
14899 | 2263 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2264 // FIXME: Temorary hack to test |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2265 typedef std::map<tree *, jit_info *> compiled_map; |
14899 | 2266 llvm::Module *module; |
14903 | 2267 llvm::PassManager *module_pass_manager; |
14899 | 2268 llvm::FunctionPassManager *pass_manager; |
2269 llvm::ExecutionEngine *engine; | |
14906 | 2270 }; |
14903 | 2271 |
14906 | 2272 class |
2273 jit_info | |
2274 { | |
2275 public: | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2276 jit_info (tree_jit& tjit, tree& tee); |
14913
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
2277 |
14955
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14951
diff
changeset
|
2278 ~jit_info (void); |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14951
diff
changeset
|
2279 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2280 bool execute (void) const; |
14906 | 2281 |
2282 bool match (void) const; | |
2283 private: | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2284 typedef jit_convert::type_bound type_bound; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2285 typedef jit_convert::type_bound_vector type_bound_vector; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2286 typedef void (*jited_function)(octave_base_value**); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2287 |
14906 | 2288 llvm::ExecutionEngine *engine; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2289 jited_function function; |
14955
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14951
diff
changeset
|
2290 llvm::Function *llvm_function; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2291 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2292 std::vector<std::pair<std::string, bool> > arguments; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2293 type_bound_vector bounds; |
14899 | 2294 }; |
14937
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
2295 |
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
2296 // some #defines we use in the header, but not the cc file |
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
2297 #undef JIT_VISIT_IR_CLASSES |
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
2298 #undef JIT_VISIT_IR_CONST |
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
2299 #undef JIT_VALUE_ACCEPT |
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
2300 |
14899 | 2301 #endif |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2302 #endif |