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