Mercurial > octave-nkf
annotate src/interp-core/pt-jit.cc @ 15147:98a65d9e426f
Remove uneeded release overloads
* jit-typeinfo.cc (jit_typeinfo::jit_typeinfo): Remove overloads for scalar,
complex, and index release.
* pt-jit.cc (jit_convert::release_temp, jit_convert::release_dead_phi,
jit_convert::convert_llvm::visit): Only release when required.
author | Max Brister <max@2bass.com> |
---|---|
date | Fri, 10 Aug 2012 16:19:27 -0500 |
parents | 709e8928e68c |
children | 1b2fbc30e4e7 |
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 #define __STDC_LIMIT_MACROS | |
24 #define __STDC_CONSTANT_MACROS | |
25 | |
26 #ifdef HAVE_CONFIG_H | |
27 #include <config.h> | |
28 #endif | |
29 | |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
30 #ifdef HAVE_LLVM |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
31 |
14899 | 32 #include "pt-jit.h" |
33 | |
14903 | 34 #include <llvm/Analysis/CallGraph.h> |
14899 | 35 #include <llvm/Analysis/Passes.h> |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
36 #include <llvm/Analysis/Verifier.h> |
15030
86a95d6ada0d
src/pt-jit.cc: Fix JIT build with LLVM 3.0.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
37 #include <llvm/LLVMContext.h> |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
38 #include <llvm/ExecutionEngine/ExecutionEngine.h> |
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
39 #include <llvm/ExecutionEngine/JIT.h> |
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
40 #include <llvm/Module.h> |
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
41 #include <llvm/PassManager.h> |
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
42 #include <llvm/Support/IRBuilder.h> |
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
43 #include <llvm/Support/raw_os_ostream.h> |
14899 | 44 #include <llvm/Support/TargetSelect.h> |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
45 #include <llvm/Target/TargetData.h> |
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
46 #include <llvm/Transforms/IPO.h> |
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
47 #include <llvm/Transforms/Scalar.h> |
14899 | 48 |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
49 #ifdef OCTAVE_JIT_DEBUG |
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
50 #include <llvm/Bitcode/ReaderWriter.h> |
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
51 #endif |
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
52 |
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
53 #include "symtab.h" |
14899 | 54 #include "pt-all.h" |
55 | |
14903 | 56 static llvm::IRBuilder<> builder (llvm::getGlobalContext ()); |
57 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
58 static llvm::LLVMContext& context = llvm::getGlobalContext (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
59 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
60 // -------------------- jit_convert -------------------- |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
61 jit_convert::jit_convert (llvm::Module *module, tree &tee, |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
62 jit_type *for_bounds) |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
63 : iterator_count (0), for_bounds_count (0), short_count (0), breaking (false) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
64 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
65 jit_instruction::reset_ids (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
66 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
67 entry_block = create<jit_block> ("body"); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
68 final_block = create<jit_block> ("final"); |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
69 append (entry_block); |
14945 | 70 entry_block->mark_alive (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
71 block = entry_block; |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
72 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
73 if (for_bounds) |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
74 create_variable (next_for_bounds (false), for_bounds); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
75 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
76 visit (tee); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
77 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
78 // FIXME: Remove if we no longer only compile loops |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
79 assert (! breaking); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
80 assert (breaks.empty ()); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
81 assert (continues.empty ()); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
82 |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
83 block->append (create<jit_branch> (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
|
84 append (final_block); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
85 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
86 for (vmap_t::iterator iter = vmap.begin (); iter != vmap.end (); ++iter) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
87 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
88 jit_variable *var = iter->second; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
89 const std::string& name = var->name (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
90 if (name.size () && name[0] != '#') |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
91 final_block->append (create<jit_store_argument> (var)); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
92 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
93 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
94 construct_ssa (); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
95 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
96 // initialize the worklist to instructions derived from constants |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
97 for (std::list<jit_value *>::iterator iter = constants.begin (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
98 iter != constants.end (); ++iter) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
99 append_users (*iter); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
100 |
15023
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
101 // the entry block terminator may be a regular branch statement |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
102 if (entry_block->terminator ()) |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
103 push_worklist (entry_block->terminator ()); |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
104 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
105 // FIXME: Describe algorithm here |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
106 while (worklist.size ()) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
107 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
108 jit_instruction *next = worklist.front (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
109 worklist.pop_front (); |
14946
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
110 next->stash_in_worklist (false); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
111 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
112 if (next->infer ()) |
14945 | 113 { |
114 // terminators need to be handles specially | |
115 if (jit_terminator *term = dynamic_cast<jit_terminator *> (next)) | |
116 append_users_term (term); | |
117 else | |
118 append_users (next); | |
119 } | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
120 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
121 |
14945 | 122 remove_dead (); |
14946
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
123 merge_blocks (); |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
124 final_block->label (); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
125 place_releases (); |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
126 simplify_phi (); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
127 |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
128 #ifdef OCTAVE_JIT_DEBUG |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
129 final_block->label (); |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
130 std::cout << "-------------------- Compiling tree --------------------\n"; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
131 std::cout << tee.str_print_code () << std::endl; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
132 print_blocks ("octave jit ir"); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
133 #endif |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
134 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
135 // for now just init arguments from entry, later we will have to do something |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
136 // more interesting |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
137 for (jit_block::iterator iter = entry_block->begin (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
138 iter != entry_block->end (); ++iter) |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
139 if (jit_extract_argument *extract |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
140 = dynamic_cast<jit_extract_argument *> (*iter)) |
14937
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
141 arguments.push_back (std::make_pair (extract->name (), true)); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
142 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
143 convert_llvm to_llvm (*this); |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
144 function = to_llvm.convert (module, arguments, blocks, constants); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
145 |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
146 #ifdef OCTAVE_JIT_DEBUG |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
147 std::cout << "-------------------- llvm ir --------------------"; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
148 llvm::raw_os_ostream llvm_cout (std::cout); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
149 function->print (llvm_cout); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
150 std::cout << std::endl; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
151 llvm::verifyFunction (*function); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
152 #endif |
14906 | 153 } |
154 | |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
155 jit_convert::~jit_convert (void) |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
156 { |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
157 for (std::list<jit_value *>::iterator iter = all_values.begin (); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
158 iter != all_values.end (); ++iter) |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
159 delete *iter; |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
160 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
161 |
14906 | 162 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
163 jit_convert::visit_anon_fcn_handle (tree_anon_fcn_handle&) |
14903 | 164 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
165 throw jit_fail_exception (); |
14903 | 166 } |
167 | |
168 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
169 jit_convert::visit_argument_list (tree_argument_list&) |
14903 | 170 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
171 throw jit_fail_exception (); |
14903 | 172 } |
173 | |
174 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
175 jit_convert::visit_binary_expression (tree_binary_expression& be) |
14903 | 176 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
177 if (be.op_type () >= octave_value::num_binary_ops) |
14978
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
178 { |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
179 tree_boolean_expression *boole; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
180 boole = dynamic_cast<tree_boolean_expression *> (&be); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
181 assert (boole); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
182 bool is_and = boole->op_type () == tree_boolean_expression::bool_and; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
183 |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
184 std::string short_name = next_shortcircut_result (); |
14978
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
185 jit_variable *short_result = create<jit_variable> (short_name); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
186 vmap[short_name] = short_result; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
187 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
188 jit_block *done = create<jit_block> (block->name ()); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
189 tree_expression *lhs = be.lhs (); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
190 jit_value *lhsv = visit (lhs); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
191 lhsv = create_checked (&jit_typeinfo::logically_true, lhsv); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
192 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
193 jit_block *short_early = create<jit_block> ("short_early"); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
194 append (short_early); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
195 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
196 jit_block *short_cont = create<jit_block> ("short_cont"); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
197 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
198 if (is_and) |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
199 block->append (create<jit_cond_branch> (lhsv, short_cont, short_early)); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
200 else |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
201 block->append (create<jit_cond_branch> (lhsv, short_early, short_cont)); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
202 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
203 block = short_early; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
204 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
205 jit_value *early_result = create<jit_const_bool> (! is_and); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
206 block->append (create<jit_assign> (short_result, early_result)); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
207 block->append (create<jit_branch> (done)); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
208 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
209 append (short_cont); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
210 block = short_cont; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
211 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
212 tree_expression *rhs = be.rhs (); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
213 jit_value *rhsv = visit (rhs); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
214 rhsv = create_checked (&jit_typeinfo::logically_true, rhsv); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
215 block->append (create<jit_assign> (short_result, rhsv)); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
216 block->append (create<jit_branch> (done)); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
217 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
218 append (done); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
219 block = done; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
220 result = short_result; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
221 } |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
222 else |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
223 { |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
224 tree_expression *lhs = be.lhs (); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
225 jit_value *lhsv = visit (lhs); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
226 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
227 tree_expression *rhs = be.rhs (); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
228 jit_value *rhsv = visit (rhs); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
229 |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
230 const jit_operation& fn = jit_typeinfo::binary_op (be.op_type ()); |
14978
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
231 result = create_checked (fn, lhsv, rhsv); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
232 } |
14903 | 233 } |
234 | |
235 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
236 jit_convert::visit_break_command (tree_break_command&) |
14903 | 237 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
238 breaks.push_back (block); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
239 breaking = true; |
14903 | 240 } |
241 | |
242 void | |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
243 jit_convert::visit_colon_expression (tree_colon_expression& expr) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
244 { |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
245 // in the futher we need to add support for classes and deal with rvalues |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
246 jit_value *base = visit (expr.base ()); |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
247 jit_value *limit = visit (expr.limit ()); |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
248 jit_value *increment; |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
249 tree_expression *tinc = expr.increment (); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
250 |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
251 if (tinc) |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
252 increment = visit (tinc); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
253 else |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
254 increment = create<jit_const_scalar> (1); |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
255 |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
256 result = block->append (create<jit_call> (jit_typeinfo::make_range, base, |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
257 limit, increment)); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
258 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
259 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
260 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
261 jit_convert::visit_continue_command (tree_continue_command&) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
262 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
263 continues.push_back (block); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
264 breaking = true; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
265 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
266 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
267 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
268 jit_convert::visit_global_command (tree_global_command&) |
14903 | 269 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
270 throw jit_fail_exception (); |
14903 | 271 } |
272 | |
273 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
274 jit_convert::visit_persistent_command (tree_persistent_command&) |
14903 | 275 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
276 throw jit_fail_exception (); |
14903 | 277 } |
278 | |
279 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
280 jit_convert::visit_decl_elt (tree_decl_elt&) |
14903 | 281 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
282 throw jit_fail_exception (); |
14903 | 283 } |
284 | |
285 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
286 jit_convert::visit_decl_init_list (tree_decl_init_list&) |
14903 | 287 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
288 throw jit_fail_exception (); |
14903 | 289 } |
290 | |
291 void | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
292 jit_convert::visit_simple_for_command (tree_simple_for_command& cmd) |
14903 | 293 { |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
294 // Note we do an initial check to see if the loop will run atleast once. |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
295 // This allows us to get better type inference bounds on variables defined |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
296 // and used only inside the for loop (e.g. the index variable) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
297 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
298 // If we are a nested for loop we need to store the previous breaks |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
299 assert (! breaking); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
300 unwind_protect prot; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
301 prot.protect_var (breaks); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
302 prot.protect_var (continues); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
303 prot.protect_var (breaking); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
304 breaks.clear (); |
14989 | 305 continues.clear (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
306 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
307 // we need a variable for our iterator, because it is used in multiple blocks |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
308 std::string iter_name = next_iterator (); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
309 jit_variable *iterator = create<jit_variable> (iter_name); |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
310 create<jit_variable> (iter_name); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
311 vmap[iter_name] = iterator; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
312 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
313 jit_block *body = create<jit_block> ("for_body"); |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
314 append (body); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
315 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
316 jit_block *tail = create<jit_block> ("for_tail"); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
317 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
318 // do control expression, iter init, and condition check in prev_block (block) |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
319 // if we are the top level for loop, the bounds is an input argument. |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
320 jit_value *control = find_variable (next_for_bounds ()); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
321 if (! control) |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
322 control = visit (cmd.control_expr ()); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
323 jit_call *init_iter = create<jit_call> (jit_typeinfo::for_init, control); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
324 block->append (init_iter); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
325 block->append (create<jit_assign> (iterator, init_iter)); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
326 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
327 jit_value *check = block->append (create<jit_call> (jit_typeinfo::for_check, |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
328 control, iterator)); |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
329 block->append (create<jit_cond_branch> (check, body, tail)); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
330 block = body; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
331 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
332 // compute the syntactical iterator |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
333 jit_call *idx_rhs = create<jit_call> (jit_typeinfo::for_index, control, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
334 iterator); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
335 block->append (idx_rhs); |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
336 do_assign (cmd.left_hand_side (), idx_rhs); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
337 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
338 // do loop |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
339 tree_statement_list *pt_body = cmd.body (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
340 pt_body->accept (*this); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
341 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
342 if (breaking && continues.empty ()) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
343 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
344 // WTF are you doing user? Every branch was a continue, why did you have |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
345 // a loop??? Users are silly people... |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
346 finish_breaks (tail, breaks); |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
347 append (tail); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
348 block = tail; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
349 return; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
350 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
351 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
352 // check our condition, continues jump to this block |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
353 jit_block *check_block = create<jit_block> ("for_check"); |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
354 append (check_block); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
355 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
356 if (! breaking) |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
357 block->append (create<jit_branch> (check_block)); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
358 finish_breaks (check_block, continues); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
359 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
360 block = check_block; |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
361 const jit_operation& add_fn = jit_typeinfo::binary_op (octave_value::op_add); |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
362 jit_value *one = create<jit_const_index> (1); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
363 jit_call *iter_inc = create<jit_call> (add_fn, iterator, one); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
364 block->append (iter_inc); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
365 block->append (create<jit_assign> (iterator, iter_inc)); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
366 check = block->append (create<jit_call> (jit_typeinfo::for_check, control, |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
367 iterator)); |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
368 block->append (create<jit_cond_branch> (check, body, tail)); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
369 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
370 // breaks will go to our tail |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
371 append (tail); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
372 finish_breaks (tail, breaks); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
373 block = tail; |
14903 | 374 } |
375 | |
376 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
377 jit_convert::visit_complex_for_command (tree_complex_for_command&) |
14903 | 378 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
379 throw jit_fail_exception (); |
14903 | 380 } |
381 | |
382 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
383 jit_convert::visit_octave_user_script (octave_user_script&) |
14903 | 384 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
385 throw jit_fail_exception (); |
14903 | 386 } |
387 | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
388 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
389 jit_convert::visit_octave_user_function (octave_user_function&) |
14903 | 390 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
391 throw jit_fail_exception (); |
14899 | 392 } |
393 | |
14903 | 394 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
395 jit_convert::visit_octave_user_function_header (octave_user_function&) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
396 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
397 throw jit_fail_exception (); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
398 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
399 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
400 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
401 jit_convert::visit_octave_user_function_trailer (octave_user_function&) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
402 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
403 throw jit_fail_exception (); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
404 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
405 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
406 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
407 jit_convert::visit_function_def (tree_function_def&) |
14899 | 408 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
409 throw jit_fail_exception (); |
14903 | 410 } |
14899 | 411 |
14903 | 412 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
413 jit_convert::visit_identifier (tree_identifier& ti) |
14903 | 414 { |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
415 if (ti.has_magic_end ()) |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
416 { |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
417 if (!end_context.size ()) |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
418 throw jit_fail_exception ("Illegal end"); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
419 result = block->append (create<jit_magic_end> (end_context)); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
420 } |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
421 else |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
422 result = get_variable (ti.name ()); |
14899 | 423 } |
424 | |
425 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
426 jit_convert::visit_if_clause (tree_if_clause&) |
14903 | 427 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
428 throw jit_fail_exception (); |
14899 | 429 } |
430 | |
431 void | |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
432 jit_convert::visit_if_command (tree_if_command& cmd) |
14903 | 433 { |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
434 tree_if_command_list *lst = cmd.cmd_list (); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
435 assert (lst); // jwe: Can this be null? |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
436 lst->accept (*this); |
14903 | 437 } |
438 | |
439 void | |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
440 jit_convert::visit_if_command_list (tree_if_command_list& lst) |
14903 | 441 { |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
442 tree_if_clause *last = lst.back (); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
443 size_t last_else = static_cast<size_t> (last->is_else_clause ()); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
444 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
445 // entry_blocks represents the block you need to enter in order to execute |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
446 // the condition check for the ith clause. For the else, it is simple the |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
447 // else body. If there is no else body, then it is padded with the tail |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
448 std::vector<jit_block *> entry_blocks (lst.size () + 1 - last_else); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
449 std::vector<jit_block *> branch_blocks (lst.size (), 0); // final blocks |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
450 entry_blocks[0] = block; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
451 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
452 // we need to construct blocks first, because they have jumps to eachother |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
453 tree_if_command_list::iterator iter = lst.begin (); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
454 ++iter; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
455 for (size_t i = 1; iter != lst.end (); ++iter, ++i) |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
456 { |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
457 tree_if_clause *tic = *iter; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
458 if (tic->is_else_clause ()) |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
459 entry_blocks[i] = create<jit_block> ("else"); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
460 else |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
461 entry_blocks[i] = create<jit_block> ("ifelse_cond"); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
462 } |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
463 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
464 jit_block *tail = create<jit_block> ("if_tail"); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
465 if (! last_else) |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
466 entry_blocks[entry_blocks.size () - 1] = tail; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
467 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
468 size_t num_incomming = 0; // number of incomming blocks to our tail |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
469 iter = lst.begin (); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
470 for (size_t i = 0; iter != lst.end (); ++iter, ++i) |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
471 { |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
472 tree_if_clause *tic = *iter; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
473 block = entry_blocks[i]; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
474 assert (block); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
475 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
476 if (i) // the first block is prev_block, so it has already been added |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
477 append (entry_blocks[i]); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
478 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
479 if (! tic->is_else_clause ()) |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
480 { |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
481 tree_expression *expr = tic->condition (); |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
482 jit_value *cond = visit (expr); |
14961
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
483 jit_call *check = create_checked (&jit_typeinfo::logically_true, |
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
484 cond); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
485 jit_block *body = create<jit_block> (i == 0 ? "if_body" |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
486 : "ifelse_body"); |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
487 append (body); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
488 |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
489 jit_instruction *br = create<jit_cond_branch> (check, body, |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
490 entry_blocks[i + 1]); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
491 block->append (br); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
492 block = body; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
493 } |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
494 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
495 tree_statement_list *stmt_lst = tic->commands (); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
496 assert (stmt_lst); // jwe: Can this be null? |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
497 stmt_lst->accept (*this); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
498 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
499 if (breaking) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
500 breaking = false; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
501 else |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
502 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
503 ++num_incomming; |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
504 block->append (create<jit_branch> (tail)); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
505 } |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
506 } |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
507 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
508 if (num_incomming || ! last_else) |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
509 { |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
510 append (tail); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
511 block = tail; |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
512 } |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
513 else |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
514 // every branch broke, so we don't have a tail |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
515 breaking = true; |
14903 | 516 } |
517 | |
518 void | |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
519 jit_convert::visit_index_expression (tree_index_expression& exp) |
14903 | 520 { |
15067 | 521 result = resolve (jit_typeinfo::paren_subsref (), exp); |
14903 | 522 } |
523 | |
524 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
525 jit_convert::visit_matrix (tree_matrix&) |
14899 | 526 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
527 throw jit_fail_exception (); |
14899 | 528 } |
529 | |
530 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
531 jit_convert::visit_cell (tree_cell&) |
14906 | 532 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
533 throw jit_fail_exception (); |
14906 | 534 } |
535 | |
536 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
537 jit_convert::visit_multi_assignment (tree_multi_assignment&) |
14899 | 538 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
539 throw jit_fail_exception (); |
14903 | 540 } |
541 | |
542 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
543 jit_convert::visit_no_op_command (tree_no_op_command&) |
14906 | 544 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
545 throw jit_fail_exception (); |
14906 | 546 } |
547 | |
548 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
549 jit_convert::visit_constant (tree_constant& tc) |
14903 | 550 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
551 octave_value v = tc.rvalue1 (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
552 if (v.is_real_scalar () && v.is_double_type ()) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
553 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
554 double dv = v.double_value (); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
555 result = create<jit_const_scalar> (dv); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
556 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
557 else if (v.is_range ()) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
558 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
559 Range rv = v.range_value (); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
560 result = create<jit_const_range> (rv); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
561 } |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
562 else if (v.is_complex_scalar ()) |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
563 { |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
564 Complex cv = v.complex_value (); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
565 result = create<jit_const_complex> (cv); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
566 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
567 else |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
568 throw jit_fail_exception ("Unknown constant"); |
14903 | 569 } |
14899 | 570 |
14903 | 571 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
572 jit_convert::visit_fcn_handle (tree_fcn_handle&) |
14903 | 573 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
574 throw jit_fail_exception (); |
14903 | 575 } |
14899 | 576 |
14903 | 577 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
578 jit_convert::visit_parameter_list (tree_parameter_list&) |
14906 | 579 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
580 throw jit_fail_exception (); |
14906 | 581 } |
582 | |
583 void | |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
584 jit_convert::visit_postfix_expression (tree_postfix_expression& tpe) |
14903 | 585 { |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
586 octave_value::unary_op etype = tpe.op_type (); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
587 tree_expression *operand = tpe.operand (); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
588 jit_value *operandv = visit (operand); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
589 |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
590 const jit_operation& fn = jit_typeinfo::unary_op (etype); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
591 result = create_checked (fn, operandv); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
592 |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
593 if (etype == octave_value::op_incr || etype == octave_value::op_decr) |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
594 { |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
595 // FIXME: Somehow copy operandv |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
596 // do_assign (operand, operandv); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
597 throw jit_fail_exception ("Postfix ++ and -- not yet supported"); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
598 } |
14903 | 599 } |
14899 | 600 |
14903 | 601 void |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
602 jit_convert::visit_prefix_expression (tree_prefix_expression& tpe) |
14899 | 603 { |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
604 octave_value::unary_op etype = tpe.op_type (); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
605 tree_expression *operand = tpe.operand (); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
606 const jit_operation& fn = jit_typeinfo::unary_op (etype); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
607 result = create_checked (fn, visit (operand)); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
608 |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
609 if (etype == octave_value::op_incr || etype == octave_value::op_decr) |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
610 do_assign (operand, result); |
14899 | 611 } |
612 | |
613 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
614 jit_convert::visit_return_command (tree_return_command&) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
615 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
616 throw jit_fail_exception (); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
617 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
618 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
619 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
620 jit_convert::visit_return_list (tree_return_list&) |
14899 | 621 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
622 throw jit_fail_exception (); |
14899 | 623 } |
624 | |
625 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
626 jit_convert::visit_simple_assignment (tree_simple_assignment& tsa) |
14899 | 627 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
628 tree_expression *rhs = tsa.right_hand_side (); |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
629 jit_value *rhsv = visit (rhs); |
15140
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
630 octave_value::assign_op op = tsa.op_type (); |
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
631 |
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
632 if (op != octave_value::op_asn_eq) |
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
633 { |
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
634 // do the equivlent binary operation, then assign. This is always correct, |
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
635 // but isn't always optimal. |
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
636 tree_expression *lhs = tsa.left_hand_side (); |
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
637 jit_value *lhsv = visit (lhs); |
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
638 octave_value::binary_op bop = octave_value::assign_op_to_binary_op (op); |
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
639 const jit_operation& fn = jit_typeinfo::binary_op (bop); |
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
640 rhsv = create_checked (fn, lhsv, rhsv); |
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
641 } |
14899 | 642 |
14978
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
643 result = do_assign (tsa.left_hand_side (), rhsv); |
14899 | 644 } |
645 | |
646 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
647 jit_convert::visit_statement (tree_statement& stmt) |
14899 | 648 { |
649 tree_command *cmd = stmt.command (); | |
650 tree_expression *expr = stmt.expression (); | |
651 | |
652 if (cmd) | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
653 visit (cmd); |
14899 | 654 else |
655 { | |
656 // stolen from tree_evaluator::visit_statement | |
657 bool do_bind_ans = false; | |
658 | |
659 if (expr->is_identifier ()) | |
660 { | |
661 tree_identifier *id = dynamic_cast<tree_identifier *> (expr); | |
662 | |
663 do_bind_ans = (! id->is_variable ()); | |
664 } | |
665 else | |
666 do_bind_ans = (! expr->is_assignment_expression ()); | |
667 | |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
668 jit_value *expr_result = visit (expr); |
14899 | 669 |
670 if (do_bind_ans) | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
671 do_assign ("ans", expr_result, expr->print_result ()); |
14899 | 672 else if (expr->is_identifier () && expr->print_result ()) |
673 { | |
674 // FIXME: ugly hack, we need to come up with a way to pass | |
675 // nargout to visit_identifier | |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
676 const jit_operation& fn = jit_typeinfo::print_value (); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
677 jit_const_string *name = create<jit_const_string> (expr->name ()); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
678 block->append (create<jit_call> (fn, name, expr_result)); |
14899 | 679 } |
680 } | |
681 } | |
682 | |
683 void | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
684 jit_convert::visit_statement_list (tree_statement_list& lst) |
14906 | 685 { |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
686 for (tree_statement_list::iterator iter = lst.begin (); iter != lst.end(); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
687 ++iter) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
688 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
689 tree_statement *elt = *iter; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
690 // jwe: Can this ever be null? |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
691 assert (elt); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
692 elt->accept (*this); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
693 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
694 if (breaking) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
695 break; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
696 } |
14906 | 697 } |
698 | |
699 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
700 jit_convert::visit_switch_case (tree_switch_case&) |
14906 | 701 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
702 throw jit_fail_exception (); |
14906 | 703 } |
704 | |
705 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
706 jit_convert::visit_switch_case_list (tree_switch_case_list&) |
14899 | 707 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
708 throw jit_fail_exception (); |
14899 | 709 } |
710 | |
711 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
712 jit_convert::visit_switch_command (tree_switch_command&) |
14906 | 713 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
714 throw jit_fail_exception (); |
14906 | 715 } |
716 | |
717 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
718 jit_convert::visit_try_catch_command (tree_try_catch_command&) |
14899 | 719 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
720 throw jit_fail_exception (); |
14899 | 721 } |
722 | |
723 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
724 jit_convert::visit_unwind_protect_command (tree_unwind_protect_command&) |
14899 | 725 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
726 throw jit_fail_exception (); |
14899 | 727 } |
728 | |
729 void | |
14989 | 730 jit_convert::visit_while_command (tree_while_command& wc) |
14906 | 731 { |
14989 | 732 assert (! breaking); |
733 unwind_protect prot; | |
734 prot.protect_var (breaks); | |
735 prot.protect_var (continues); | |
736 prot.protect_var (breaking); | |
737 breaks.clear (); | |
738 continues.clear (); | |
739 | |
740 jit_block *cond_check = create<jit_block> ("while_cond_check"); | |
741 block->append (create<jit_branch> (cond_check)); | |
742 append (cond_check); | |
743 block = cond_check; | |
744 | |
745 tree_expression *expr = wc.condition (); | |
746 assert (expr && "While expression can not be null"); | |
747 jit_value *check = visit (expr); | |
748 check = create_checked (&jit_typeinfo::logically_true, check); | |
749 | |
750 jit_block *body = create<jit_block> ("while_body"); | |
751 append (body); | |
752 | |
753 jit_block *tail = create<jit_block> ("while_tail"); | |
754 block->append (create<jit_cond_branch> (check, body, tail)); | |
755 block = body; | |
756 | |
757 tree_statement_list *loop_body = wc.body (); | |
758 if (loop_body) | |
759 loop_body->accept (*this); | |
760 | |
761 finish_breaks (tail, breaks); | |
762 finish_breaks (cond_check, continues); | |
763 | |
764 if (! breaking) | |
765 block->append (create<jit_branch> (cond_check)); | |
766 | |
767 append (tail); | |
768 block = tail; | |
14906 | 769 } |
770 | |
771 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
772 jit_convert::visit_do_until_command (tree_do_until_command&) |
14899 | 773 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
774 throw jit_fail_exception (); |
14899 | 775 } |
776 | |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
777 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
778 jit_convert::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
|
779 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
780 blocks.push_back (ablock); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
781 ablock->stash_location (--blocks.end ()); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
782 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
783 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
784 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
785 jit_convert::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
|
786 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
787 iter = blocks.insert (iter, ablock); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
788 ablock->stash_location (iter); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
789 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
790 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
791 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
792 jit_convert::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
|
793 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
794 ++iter; |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
795 insert_before (iter, ablock); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
796 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
797 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
798 jit_variable * |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
799 jit_convert::find_variable (const std::string& vname) const |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
800 { |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
801 vmap_t::const_iterator iter; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
802 iter = vmap.find (vname); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
803 return iter != vmap.end () ? iter->second : 0; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
804 } |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
805 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
806 jit_variable * |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
807 jit_convert::get_variable (const std::string& vname) |
14899 | 808 { |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
809 jit_variable *ret = find_variable (vname); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
810 if (ret) |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
811 return ret; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
812 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
813 octave_value val = symbol_table::find (vname); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
814 jit_type *type = jit_typeinfo::type_of (val); |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
815 return create_variable (vname, type); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
816 } |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
817 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
818 jit_variable * |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
819 jit_convert::create_variable (const std::string& vname, jit_type *type) |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
820 { |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
821 jit_variable *var = create<jit_variable> (vname); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
822 jit_extract_argument *extract; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
823 extract = create<jit_extract_argument> (type, var); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
824 entry_block->prepend (extract); |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
825 return vmap[vname] = var; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
826 } |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
827 |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
828 std::string |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
829 jit_convert::next_name (const char *prefix, size_t& count, bool inc) |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
830 { |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
831 std::stringstream ss; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
832 ss << prefix << count; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
833 if (inc) |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
834 ++count; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
835 return ss.str (); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
836 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
837 |
15067 | 838 jit_instruction * |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
839 jit_convert::resolve (const jit_operation& fres, tree_index_expression& exp, |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
840 jit_value *extra_arg) |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
841 { |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
842 std::string type = exp.type_tags (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
843 if (! (type.size () == 1 && type[0] == '(')) |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
844 throw jit_fail_exception ("Unsupported index operation"); |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
845 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
846 std::list<tree_argument_list *> args = exp.arg_lists (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
847 if (args.size () != 1) |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
848 throw jit_fail_exception ("Bad number of arguments in tree_index_expression"); |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
849 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
850 tree_argument_list *arg_list = args.front (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
851 if (! arg_list) |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
852 throw jit_fail_exception ("null argument list"); |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
853 |
15067 | 854 if (arg_list->size () < 1) |
855 throw jit_fail_exception ("Empty arg_list"); | |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
856 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
857 tree_expression *tree_object = exp.expression (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
858 jit_value *object = visit (tree_object); |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
859 |
15067 | 860 size_t narg = arg_list->size (); |
861 tree_argument_list::iterator iter = arg_list->begin (); | |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
862 bool have_extra = extra_arg; |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
863 std::vector<jit_value *> call_args (narg + 1 + have_extra); |
15067 | 864 call_args[0] = object; |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
865 |
15067 | 866 for (size_t idx = 0; iter != arg_list->end (); ++idx, ++iter) |
867 { | |
868 unwind_protect prot; | |
869 prot.add_method (&end_context, | |
870 &std::vector<jit_magic_end::context>::pop_back); | |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
871 end_context.push_back (jit_magic_end::context (*this, object, idx, narg)); |
15067 | 872 call_args[idx + 1] = visit (*iter); |
873 } | |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
874 |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
875 if (extra_arg) |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
876 call_args[call_args.size () - 1] = extra_arg; |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
877 |
15067 | 878 return create_checked (fres, call_args); |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
879 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
880 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
881 jit_value * |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
882 jit_convert::do_assign (tree_expression *exp, jit_value *rhs, bool artificial) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
883 { |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
884 if (! exp) |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
885 throw jit_fail_exception ("NULL lhs in assign"); |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
886 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
887 if (isa<tree_identifier> (exp)) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
888 return do_assign (exp->name (), rhs, exp->print_result (), artificial); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
889 else if (tree_index_expression *idx |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
890 = dynamic_cast<tree_index_expression *> (exp)) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
891 { |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
892 jit_value *new_object = resolve (jit_typeinfo::paren_subsasgn (), *idx, |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
893 rhs); |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
894 do_assign (idx->expression (), new_object, true); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
895 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
896 // FIXME: Will not work for values that must be release/grabed |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
897 return rhs; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
898 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
899 else |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
900 throw jit_fail_exception ("Unsupported assignment"); |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
901 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
902 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
903 jit_value * |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
904 jit_convert::do_assign (const std::string& lhs, jit_value *rhs, |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
905 bool print, bool artificial) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
906 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
907 jit_variable *var = get_variable (lhs); |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
908 jit_assign *assign = block->append (create<jit_assign> (var, rhs)); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
909 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
910 if (artificial) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
911 assign->mark_artificial (); |
14906 | 912 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
913 if (print) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
914 { |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
915 const jit_operation& print_fn = jit_typeinfo::print_value (); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
916 jit_const_string *name = create<jit_const_string> (lhs); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
917 block->append (create<jit_call> (print_fn, name, var)); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
918 } |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
919 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
920 return var; |
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 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
923 jit_value * |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
924 jit_convert::visit (tree& tee) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
925 { |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
926 unwind_protect prot; |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
927 prot.protect_var (result); |
14906 | 928 |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
929 tee.accept (*this); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
930 return result; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
931 } |
14906 | 932 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
933 void |
14945 | 934 jit_convert::append_users_term (jit_terminator *term) |
935 { | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
936 for (size_t i = 0; i < term->successor_count (); ++i) |
14945 | 937 { |
938 if (term->alive (i)) | |
939 { | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
940 jit_block *succ = term->successor (i); |
14945 | 941 for (jit_block::iterator iter = succ->begin (); iter != succ->end () |
942 && isa<jit_phi> (*iter); ++iter) | |
14946
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
943 push_worklist (*iter); |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
944 |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
945 jit_terminator *sterm = succ->terminator (); |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
946 if (sterm) |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
947 push_worklist (sterm); |
14945 | 948 } |
949 } | |
950 } | |
951 | |
952 void | |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
953 jit_convert::merge_blocks (void) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
954 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
955 std::vector<jit_block *> dead; |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
956 for (block_list::iterator iter = blocks.begin (); iter != blocks.end (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
957 ++iter) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
958 { |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
959 jit_block *b = *iter; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
960 jit_block *merged = b->maybe_merge (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
961 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
962 if (merged) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
963 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
964 if (merged == final_block) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
965 final_block = b; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
966 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
967 if (merged == entry_block) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
968 entry_block = b; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
969 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
970 dead.push_back (merged); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
971 } |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
972 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
973 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
974 for (size_t i = 0; i < dead.size (); ++i) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
975 blocks.erase (dead[i]->location ()); |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
976 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
977 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
978 void |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
979 jit_convert::construct_ssa (void) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
980 { |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
981 merge_blocks (); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
982 final_block->label (); |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
983 final_block->compute_idom (entry_block); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
984 entry_block->compute_df (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
985 entry_block->create_dom_tree (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
986 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
987 // insert phi nodes where needed, this is done on a per variable basis |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
988 for (vmap_t::iterator iter = vmap.begin (); iter != vmap.end (); ++iter) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
989 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
990 jit_block::df_set visited, added_phi; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
991 std::list<jit_block *> ssa_worklist; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
992 iter->second->use_blocks (visited); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
993 ssa_worklist.insert (ssa_worklist.begin (), visited.begin (), |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
994 visited.end ()); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
995 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
996 while (ssa_worklist.size ()) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
997 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
998 jit_block *b = ssa_worklist.front (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
999 ssa_worklist.pop_front (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1000 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1001 for (jit_block::df_iterator diter = b->df_begin (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1002 diter != b->df_end (); ++diter) |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1003 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1004 jit_block *dblock = *diter; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1005 if (! added_phi.count (dblock)) |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1006 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1007 jit_phi *phi = create<jit_phi> (iter->second, |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1008 dblock->use_count ()); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1009 dblock->prepend (phi); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1010 added_phi.insert (dblock); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1011 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1012 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1013 if (! visited.count (dblock)) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1014 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1015 ssa_worklist.push_back (dblock); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1016 visited.insert (dblock); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1017 } |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1018 } |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1019 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1020 } |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1021 |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1022 do_construct_ssa (*entry_block, entry_block->visit_count ()); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1023 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1024 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1025 void |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1026 jit_convert::do_construct_ssa (jit_block& ablock, size_t avisit_count) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1027 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1028 if (ablock.visited (avisit_count)) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1029 return; |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1030 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1031 // replace variables with their current SSA value |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1032 for (jit_block::iterator iter = ablock.begin (); iter != ablock.end (); ++iter) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1033 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1034 jit_instruction *instr = *iter; |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1035 instr->construct_ssa (); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1036 instr->push_variable (); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1037 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1038 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1039 // finish phi nodes of successors |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1040 for (size_t i = 0; i < ablock.successor_count (); ++i) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1041 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1042 jit_block *finish = ablock.successor (i); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1043 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1044 for (jit_block::iterator iter = finish->begin (); iter != finish->end () |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1045 && isa<jit_phi> (*iter);) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1046 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1047 jit_phi *phi = static_cast<jit_phi *> (*iter); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1048 jit_variable *var = phi->dest (); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1049 if (var->has_top ()) |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1050 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1051 phi->add_incomming (&ablock, var->top ()); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1052 ++iter; |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1053 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1054 else |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1055 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1056 // temporaries may have extranious phi nodes which can be removed |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1057 assert (! phi->use_count ()); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1058 assert (var->name ().size () && var->name ()[0] == '#'); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1059 iter = finish->remove (iter); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1060 } |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1061 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1062 } |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1063 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1064 for (size_t i = 0; i < ablock.dom_successor_count (); ++i) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1065 do_construct_ssa (*ablock.dom_successor (i), avisit_count); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1066 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1067 ablock.pop_all (); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1068 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1069 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1070 void |
14945 | 1071 jit_convert::remove_dead () |
1072 { | |
1073 block_list::iterator biter; | |
1074 for (biter = blocks.begin (); biter != blocks.end (); ++biter) | |
1075 { | |
1076 jit_block *b = *biter; | |
1077 if (b->alive ()) | |
1078 { | |
1079 for (jit_block::iterator iter = b->begin (); iter != b->end () | |
1080 && isa<jit_phi> (*iter);) | |
1081 { | |
1082 jit_phi *phi = static_cast<jit_phi *> (*iter); | |
1083 if (phi->prune ()) | |
1084 iter = b->remove (iter); | |
1085 else | |
1086 ++iter; | |
1087 } | |
1088 } | |
1089 } | |
1090 | |
1091 for (biter = blocks.begin (); biter != blocks.end ();) | |
1092 { | |
1093 jit_block *b = *biter; | |
1094 if (b->alive ()) | |
1095 { | |
14960
c959136f8c3e
Rename jit_check_error to jit_error_check
Max Brister <max@2bass.com>
parents:
14959
diff
changeset
|
1096 // FIXME: A special case for jit_error_check, if we generalize to |
14945 | 1097 // we will need to change! |
1098 jit_terminator *term = b->terminator (); | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1099 if (term && term->successor_count () == 2 && ! term->alive (0)) |
14945 | 1100 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1101 jit_block *succ = term->successor (1); |
14945 | 1102 term->remove (); |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
1103 jit_branch *abreak = b->append (create<jit_branch> (succ)); |
14945 | 1104 abreak->infer (); |
1105 } | |
1106 | |
1107 ++biter; | |
1108 } | |
1109 else | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1110 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1111 jit_terminator *term = b->terminator (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1112 if (term) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1113 term->remove (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1114 biter = blocks.erase (biter); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1115 } |
14945 | 1116 } |
1117 } | |
1118 | |
1119 void | |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1120 jit_convert::place_releases (void) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1121 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1122 std::set<jit_value *> temporaries; |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1123 for (block_list::iterator iter = blocks.begin (); iter != blocks.end (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1124 ++iter) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1125 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1126 jit_block& ablock = **iter; |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1127 if (ablock.id () != jit_block::NO_ID) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1128 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1129 release_temp (ablock, temporaries); |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1130 release_dead_phi (ablock); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1131 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1132 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1133 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1134 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1135 void |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1136 jit_convert::release_temp (jit_block& ablock, std::set<jit_value *>& temp) |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1137 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1138 for (jit_block::iterator iter = ablock.begin (); iter != ablock.end (); |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1139 ++iter) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1140 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1141 jit_instruction *instr = *iter; |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1142 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1143 // check for temporaries that require release and live across |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1144 // multiple blocks |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1145 if (instr->needs_release ()) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1146 { |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1147 jit_block *fu_block = instr->first_use_block (); |
15147
98a65d9e426f
Remove uneeded release overloads
Max Brister <max@2bass.com>
parents:
15146
diff
changeset
|
1148 if (fu_block && fu_block != &ablock && instr->needs_release ()) |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1149 temp.insert (instr); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1150 } |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1151 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1152 if (isa<jit_call> (instr)) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1153 { |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1154 // place releases for temporary arguments |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1155 for (size_t i = 0; i < instr->argument_count (); ++i) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1156 { |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1157 jit_value *arg = instr->argument (i); |
15147
98a65d9e426f
Remove uneeded release overloads
Max Brister <max@2bass.com>
parents:
15146
diff
changeset
|
1158 if (! arg->needs_release ()) |
98a65d9e426f
Remove uneeded release overloads
Max Brister <max@2bass.com>
parents:
15146
diff
changeset
|
1159 continue; |
98a65d9e426f
Remove uneeded release overloads
Max Brister <max@2bass.com>
parents:
15146
diff
changeset
|
1160 |
98a65d9e426f
Remove uneeded release overloads
Max Brister <max@2bass.com>
parents:
15146
diff
changeset
|
1161 jit_call *release = create<jit_call> (&jit_typeinfo::release, |
98a65d9e426f
Remove uneeded release overloads
Max Brister <max@2bass.com>
parents:
15146
diff
changeset
|
1162 arg); |
98a65d9e426f
Remove uneeded release overloads
Max Brister <max@2bass.com>
parents:
15146
diff
changeset
|
1163 release->infer (); |
98a65d9e426f
Remove uneeded release overloads
Max Brister <max@2bass.com>
parents:
15146
diff
changeset
|
1164 ablock.insert_after (iter, release); |
98a65d9e426f
Remove uneeded release overloads
Max Brister <max@2bass.com>
parents:
15146
diff
changeset
|
1165 ++iter; |
98a65d9e426f
Remove uneeded release overloads
Max Brister <max@2bass.com>
parents:
15146
diff
changeset
|
1166 temp.erase (arg); |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1167 } |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1168 } |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1169 } |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1170 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1171 if (! temp.size () || ! isa<jit_error_check> (ablock.terminator ())) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1172 return; |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1173 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1174 // FIXME: If we support try/catch or unwind_protect final_block may not be the |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1175 // destination |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1176 jit_block *split = ablock.maybe_split (*this, final_block); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1177 jit_terminator *term = split->terminator (); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1178 for (std::set<jit_value *>::const_iterator iter = temp.begin (); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1179 iter != temp.end (); ++iter) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1180 { |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1181 jit_value *value = *iter; |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1182 jit_call *release = create<jit_call> (&jit_typeinfo::release, value); |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1183 split->insert_before (term, release); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1184 release->infer (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1185 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1186 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1187 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1188 void |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1189 jit_convert::release_dead_phi (jit_block& ablock) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1190 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1191 jit_block::iterator iter = ablock.begin (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1192 while (iter != ablock.end () && isa<jit_phi> (*iter)) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1193 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1194 jit_phi *phi = static_cast<jit_phi *> (*iter); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1195 ++iter; |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1196 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1197 jit_use *use = phi->first_use (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1198 if (phi->use_count () == 1 && isa<jit_assign> (use->user ())) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1199 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1200 // instead of releasing on assign, release on all incomming branches, |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1201 // this can get rid of casts inside loops |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1202 for (size_t i = 0; i < phi->argument_count (); ++i) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1203 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1204 jit_value *arg = phi->argument (i); |
15147
98a65d9e426f
Remove uneeded release overloads
Max Brister <max@2bass.com>
parents:
15146
diff
changeset
|
1205 if (! arg->needs_release ()) |
98a65d9e426f
Remove uneeded release overloads
Max Brister <max@2bass.com>
parents:
15146
diff
changeset
|
1206 continue; |
98a65d9e426f
Remove uneeded release overloads
Max Brister <max@2bass.com>
parents:
15146
diff
changeset
|
1207 |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1208 jit_block *inc = phi->incomming (i); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1209 jit_block *split = inc->maybe_split (*this, ablock); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1210 jit_terminator *term = split->terminator (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1211 jit_call *release = create<jit_call> (jit_typeinfo::release, arg); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1212 release->infer (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1213 split->insert_before (term, release); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1214 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1215 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1216 phi->replace_with (0); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1217 phi->remove (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1218 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1219 } |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1220 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1221 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1222 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1223 jit_convert::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
|
1224 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1225 for (block_list::iterator biter = blocks.begin (); biter != blocks.end (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1226 ++biter) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1227 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1228 jit_block &ablock = **biter; |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1229 for (jit_block::iterator iter = ablock.begin (); iter != ablock.end () |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1230 && isa<jit_phi> (*iter); ++iter) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1231 simplify_phi (*static_cast<jit_phi *> (*iter)); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1232 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1233 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1234 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1235 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1236 jit_convert::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
|
1237 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1238 jit_block& pblock = *phi.parent (); |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
1239 const jit_operation& cast_fn = jit_typeinfo::cast (phi.type ()); |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1240 jit_variable *dest = phi.dest (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1241 for (size_t i = 0; i < phi.argument_count (); ++i) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1242 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1243 jit_value *arg = phi.argument (i); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1244 if (arg->type () != phi.type ()) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1245 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1246 jit_block *pred = phi.incomming (i); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1247 jit_block *split = pred->maybe_split (*this, pblock); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1248 jit_terminator *term = split->terminator (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1249 jit_instruction *cast = create<jit_call> (cast_fn, arg); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1250 jit_assign *assign = create<jit_assign> (dest, cast); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1251 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1252 split->insert_before (term, cast); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1253 split->insert_before (term, assign); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1254 cast->infer (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1255 assign->infer (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1256 phi.stash_argument (i, assign); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1257 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1258 } |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1259 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1260 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1261 void |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1262 jit_convert::finish_breaks (jit_block *dest, const block_list& lst) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1263 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1264 for (block_list::const_iterator iter = lst.begin (); iter != lst.end (); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1265 ++iter) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1266 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1267 jit_block *b = *iter; |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
1268 b->append (create<jit_branch> (dest)); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1269 } |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1270 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1271 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1272 // -------------------- jit_convert::convert_llvm -------------------- |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1273 llvm::Function * |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1274 jit_convert::convert_llvm::convert (llvm::Module *module, |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1275 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
|
1276 const std::list<jit_block *>& blocks, |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
1277 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
|
1278 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1279 jit_type *any = jit_typeinfo::get_any (); |
14899 | 1280 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1281 // argument is an array of octave_base_value*, or octave_base_value** |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1282 llvm::Type *arg_type = any->to_llvm (); // this is octave_base_value* |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1283 arg_type = arg_type->getPointerTo (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1284 llvm::FunctionType *ft = llvm::FunctionType::get (llvm::Type::getVoidTy (context), |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1285 arg_type, false); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1286 function = llvm::Function::Create (ft, llvm::Function::ExternalLinkage, |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1287 "foobar", module); |
14906 | 1288 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1289 try |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1290 { |
14968
7f60cdfcc0e5
Do not smash stack when passing structures in JIT
Max Brister <max@2bass.com>
parents:
14967
diff
changeset
|
1291 prelude = llvm::BasicBlock::Create (context, "prelude", function); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1292 builder.SetInsertPoint (prelude); |
14906 | 1293 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1294 llvm::Value *arg = function->arg_begin (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1295 for (size_t i = 0; i < args.size (); ++i) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1296 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1297 llvm::Value *loaded_arg = builder.CreateConstInBoundsGEP1_32 (arg, i); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1298 arguments[args[i].first] = loaded_arg; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1299 } |
14906 | 1300 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1301 std::list<jit_block *>::const_iterator biter; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1302 for (biter = blocks.begin (); biter != blocks.end (); ++biter) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1303 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1304 jit_block *jblock = *biter; |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1305 llvm::BasicBlock *block = llvm::BasicBlock::Create (context, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1306 jblock->name (), |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1307 function); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1308 jblock->stash_llvm (block); |
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 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1311 jit_block *first = *blocks.begin (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1312 builder.CreateBr (first->to_llvm ()); |
14906 | 1313 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
1314 // constants aren't in the IR, we visit those first |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
1315 for (std::list<jit_value *>::const_iterator iter = constants.begin (); |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
1316 iter != constants.end (); ++iter) |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
1317 if (! isa<jit_instruction> (*iter)) |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
1318 visit (*iter); |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
1319 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1320 // convert all instructions |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1321 for (biter = blocks.begin (); biter != blocks.end (); ++biter) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1322 visit (*biter); |
14906 | 1323 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1324 // now finish phi nodes |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1325 for (biter = blocks.begin (); biter != blocks.end (); ++biter) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1326 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1327 jit_block& block = **biter; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1328 for (jit_block::iterator piter = block.begin (); |
14937
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
1329 piter != block.end () && isa<jit_phi> (*piter); ++piter) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1330 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1331 jit_instruction *phi = *piter; |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1332 finish_phi (static_cast<jit_phi *> (phi)); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1333 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1334 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1335 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1336 jit_block *last = blocks.back (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1337 builder.SetInsertPoint (last->to_llvm ()); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1338 builder.CreateRetVoid (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1339 } catch (const jit_fail_exception& e) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1340 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1341 function->eraseFromParent (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1342 throw; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1343 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1344 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1345 return function; |
14899 | 1346 } |
1347 | |
1348 void | |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1349 jit_convert::convert_llvm::finish_phi (jit_phi *phi) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1350 { |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1351 llvm::PHINode *llvm_phi = phi->to_llvm (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1352 for (size_t i = 0; i < phi->argument_count (); ++i) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1353 { |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1354 llvm::BasicBlock *pred = phi->incomming_llvm (i); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1355 llvm_phi->addIncoming (phi->argument_llvm (i), pred); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1356 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1357 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1358 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1359 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1360 jit_convert::convert_llvm::visit (jit_const_string& cs) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1361 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1362 cs.stash_llvm (builder.CreateGlobalStringPtr (cs.value ())); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1363 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1364 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1365 void |
14978
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
1366 jit_convert::convert_llvm::visit (jit_const_bool& cb) |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
1367 { |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
1368 cb.stash_llvm (llvm::ConstantInt::get (cb.type_llvm (), cb.value ())); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
1369 } |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
1370 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
1371 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1372 jit_convert::convert_llvm::visit (jit_const_scalar& cs) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1373 { |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1374 cs.stash_llvm (llvm::ConstantFP::get (cs.type_llvm (), cs.value ())); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1375 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1376 |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1377 void |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1378 jit_convert::convert_llvm::visit (jit_const_complex& cc) |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1379 { |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1380 llvm::Type *scalar_t = jit_typeinfo::get_scalar_llvm (); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1381 llvm::Constant *values[2]; |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1382 Complex value = cc.value (); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1383 values[0] = llvm::ConstantFP::get (scalar_t, value.real ()); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1384 values[1] = llvm::ConstantFP::get (scalar_t, value.imag ()); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1385 cc.stash_llvm (llvm::ConstantVector::get (values)); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1386 } |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1387 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1388 void jit_convert::convert_llvm::visit (jit_const_index& ci) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1389 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1390 ci.stash_llvm (llvm::ConstantInt::get (ci.type_llvm (), ci.value ())); |
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 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1393 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1394 jit_convert::convert_llvm::visit (jit_const_range& cr) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1395 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1396 llvm::StructType *stype = llvm::cast<llvm::StructType>(cr.type_llvm ()); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1397 llvm::Type *scalar_t = jit_typeinfo::get_scalar_llvm (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1398 llvm::Type *idx = jit_typeinfo::get_index_llvm (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1399 const jit_range& rng = cr.value (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1400 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1401 llvm::Constant *constants[4]; |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1402 constants[0] = llvm::ConstantFP::get (scalar_t, rng.base); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1403 constants[1] = llvm::ConstantFP::get (scalar_t, rng.limit); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1404 constants[2] = llvm::ConstantFP::get (scalar_t, rng.inc); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1405 constants[3] = llvm::ConstantInt::get (idx, rng.nelem); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1406 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1407 llvm::Value *as_llvm; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1408 as_llvm = llvm::ConstantStruct::get (stype, |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1409 llvm::makeArrayRef (constants, 4)); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1410 cr.stash_llvm (as_llvm); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1411 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1412 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1413 void |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1414 jit_convert::convert_llvm::visit (jit_block& b) |
14899 | 1415 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1416 llvm::BasicBlock *block = b.to_llvm (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1417 builder.SetInsertPoint (block); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1418 for (jit_block::iterator iter = b.begin (); iter != b.end (); ++iter) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1419 visit (*iter); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1420 } |
14903 | 1421 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1422 void |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
1423 jit_convert::convert_llvm::visit (jit_branch& b) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1424 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1425 b.stash_llvm (builder.CreateBr (b.successor_llvm ())); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1426 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1427 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1428 void |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
1429 jit_convert::convert_llvm::visit (jit_cond_branch& cb) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1430 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1431 llvm::Value *cond = cb.cond_llvm (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1432 llvm::Value *br; |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1433 br = builder.CreateCondBr (cond, cb.successor_llvm (0), |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1434 cb.successor_llvm (1)); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1435 cb.stash_llvm (br); |
14899 | 1436 } |
1437 | |
14913
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
1438 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1439 jit_convert::convert_llvm::visit (jit_call& call) |
14913
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
1440 { |
15014
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1441 const jit_function& ol = call.overload (); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1442 |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1443 std::vector<jit_value *> args (call.arguments ().size ()); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1444 for (size_t i = 0; i < args.size (); ++i) |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1445 args[i] = call.argument (i); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1446 |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
1447 llvm::Value *ret = ol.call (builder, args); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1448 call.stash_llvm (ret); |
14913
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
1449 } |
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
1450 |
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
1451 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1452 jit_convert::convert_llvm::visit (jit_extract_argument& extract) |
14913
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
1453 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1454 llvm::Value *arg = arguments[extract.name ()]; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1455 assert (arg); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1456 arg = builder.CreateLoad (arg); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1457 |
15014
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1458 const jit_function& ol = extract.overload (); |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
1459 extract.stash_llvm (ol.call (builder, arg)); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1460 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1461 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1462 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1463 jit_convert::convert_llvm::visit (jit_store_argument& store) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1464 { |
15014
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1465 const jit_function& ol = store.overload (); |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
1466 llvm::Value *arg_value = ol.call (builder, store.result ()); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1467 llvm::Value *arg = arguments[store.name ()]; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1468 store.stash_llvm (builder.CreateStore (arg_value, arg)); |
14913
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
1469 } |
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
1470 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1471 void |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1472 jit_convert::convert_llvm::visit (jit_phi& phi) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1473 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1474 // we might not have converted all incoming branches, so we don't |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1475 // set incomming branches now |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1476 llvm::PHINode *node = llvm::PHINode::Create (phi.type_llvm (), |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1477 phi.argument_count ()); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1478 builder.Insert (node); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1479 phi.stash_llvm (node); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1480 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1481 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1482 void |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1483 jit_convert::convert_llvm::visit (jit_variable&) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1484 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
1485 throw jit_fail_exception ("ERROR: SSA construction should remove all variables"); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1486 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1487 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1488 void |
14960
c959136f8c3e
Rename jit_check_error to jit_error_check
Max Brister <max@2bass.com>
parents:
14959
diff
changeset
|
1489 jit_convert::convert_llvm::visit (jit_error_check& check) |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1490 { |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
1491 llvm::Value *cond = jit_typeinfo::insert_error_check (builder); |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1492 llvm::Value *br = builder.CreateCondBr (cond, check.successor_llvm (0), |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1493 check.successor_llvm (1)); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1494 check.stash_llvm (br); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1495 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1496 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1497 void |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1498 jit_convert::convert_llvm::visit (jit_assign& assign) |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1499 { |
15014
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1500 jit_value *new_value = assign.src (); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1501 assign.stash_llvm (new_value->to_llvm ()); |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
1502 |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1503 if (assign.artificial ()) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1504 return; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1505 |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1506 if (isa<jit_assign_base> (new_value)) |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
1507 { |
15014
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1508 const jit_function& ol = jit_typeinfo::get_grab (new_value->type ()); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1509 if (ol.valid ()) |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
1510 assign.stash_llvm (ol.call (builder, new_value)); |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
1511 } |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
1512 |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
1513 jit_value *overwrite = assign.overwrite (); |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
1514 if (isa<jit_assign_base> (overwrite)) |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
1515 { |
15014
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1516 const jit_function& ol = jit_typeinfo::get_release (overwrite->type ()); |
15147
98a65d9e426f
Remove uneeded release overloads
Max Brister <max@2bass.com>
parents:
15146
diff
changeset
|
1517 if (ol.valid ()) |
98a65d9e426f
Remove uneeded release overloads
Max Brister <max@2bass.com>
parents:
15146
diff
changeset
|
1518 ol.call (builder, overwrite); |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
1519 } |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1520 } |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1521 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1522 void |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1523 jit_convert::convert_llvm::visit (jit_argument&) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1524 {} |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1525 |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
1526 void |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
1527 jit_convert::convert_llvm::visit (jit_magic_end& me) |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
1528 { |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
1529 const jit_function& ol = me.overload (); |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1530 |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1531 jit_magic_end::context ctx = me.resolve_context (); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1532 llvm::Value *ret = ol.call (builder, ctx.value, ctx.index, ctx.count); |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
1533 me.stash_llvm (ret); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
1534 } |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
1535 |
14906 | 1536 // -------------------- tree_jit -------------------- |
1537 | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1538 tree_jit::tree_jit (void) : module (0), engine (0) |
14906 | 1539 { |
1540 } | |
1541 | |
1542 tree_jit::~tree_jit (void) | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1543 {} |
14906 | 1544 |
1545 bool | |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1546 tree_jit::execute (tree_simple_for_command& cmd, const octave_value& bounds) |
14906 | 1547 { |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1548 const size_t MIN_TRIP_COUNT = 1000; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1549 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1550 size_t tc = trip_count (bounds); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1551 if (! tc || ! initialize ()) |
14906 | 1552 return false; |
1553 | |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1554 jit_info::vmap extra_vars; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1555 extra_vars["#for_bounds0"] = &bounds; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1556 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1557 jit_info *info = cmd.get_info (); |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1558 if (! info || ! info->match (extra_vars)) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1559 { |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1560 if (tc < MIN_TRIP_COUNT) |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1561 return false; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1562 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1563 delete info; |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1564 info = new jit_info (*this, cmd, bounds); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1565 cmd.stash_info (info); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1566 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1567 |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1568 return info->execute (extra_vars); |
14906 | 1569 } |
1570 | |
1571 bool | |
15023
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1572 tree_jit::execute (tree_while_command& cmd) |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1573 { |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1574 if (! initialize ()) |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1575 return false; |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1576 |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1577 jit_info *info = cmd.get_info (); |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1578 if (! info || ! info->match ()) |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1579 { |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1580 delete info; |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1581 info = new jit_info (*this, cmd); |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1582 cmd.stash_info (info); |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1583 } |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1584 |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1585 return info->execute (); |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1586 } |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1587 |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1588 bool |
14906 | 1589 tree_jit::initialize (void) |
14903 | 1590 { |
14906 | 1591 if (engine) |
1592 return true; | |
1593 | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1594 if (! module) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1595 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1596 llvm::InitializeNativeTarget (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1597 module = new llvm::Module ("octave", context); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1598 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1599 |
14906 | 1600 // sometimes this fails pre main |
1601 engine = llvm::ExecutionEngine::createJIT (module); | |
1602 | |
1603 if (! engine) | |
1604 return false; | |
1605 | |
1606 module_pass_manager = new llvm::PassManager (); | |
1607 module_pass_manager->add (llvm::createAlwaysInlinerPass ()); | |
1608 | |
1609 pass_manager = new llvm::FunctionPassManager (module); | |
1610 pass_manager->add (new llvm::TargetData(*engine->getTargetData ())); | |
1611 pass_manager->add (llvm::createBasicAliasAnalysisPass ()); | |
1612 pass_manager->add (llvm::createPromoteMemoryToRegisterPass ()); | |
1613 pass_manager->add (llvm::createInstructionCombiningPass ()); | |
1614 pass_manager->add (llvm::createReassociatePass ()); | |
1615 pass_manager->add (llvm::createGVNPass ()); | |
1616 pass_manager->add (llvm::createCFGSimplificationPass ()); | |
1617 pass_manager->doInitialization (); | |
1618 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1619 jit_typeinfo::initialize (module, engine); |
14906 | 1620 |
1621 return true; | |
1622 } | |
1623 | |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1624 size_t |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1625 tree_jit::trip_count (const octave_value& bounds) const |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1626 { |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1627 if (bounds.is_range ()) |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1628 { |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1629 Range rng = bounds.range_value (); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1630 return rng.nelem (); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1631 } |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1632 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1633 // unsupported type |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1634 return 0; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1635 } |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1636 |
14906 | 1637 |
1638 void | |
1639 tree_jit::optimize (llvm::Function *fn) | |
1640 { | |
1641 module_pass_manager->run (*module); | |
1642 pass_manager->run (*fn); | |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1643 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1644 #ifdef OCTAVE_JIT_DEBUG |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1645 std::string error; |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1646 llvm::raw_fd_ostream fout ("test.bc", error, |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1647 llvm::raw_fd_ostream::F_Binary); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1648 llvm::WriteBitcodeToFile (module, fout); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1649 #endif |
14906 | 1650 } |
1651 | |
1652 // -------------------- jit_info -------------------- | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1653 jit_info::jit_info (tree_jit& tjit, tree& tee) |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1654 : engine (tjit.get_engine ()), function (0), llvm_function (0) |
14906 | 1655 { |
14903 | 1656 try |
1657 { | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1658 jit_convert conv (tjit.get_module (), tee); |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1659 initialize (tjit, conv); |
14903 | 1660 } |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1661 catch (const jit_fail_exception& e) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1662 { |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
1663 #ifdef OCTAVE_JIT_DEBUG |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
1664 if (e.known ()) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1665 std::cout << "jit fail: " << e.what () << std::endl; |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
1666 #endif |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1667 } |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1668 } |
14906 | 1669 |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1670 jit_info::jit_info (tree_jit& tjit, tree& tee, const octave_value& for_bounds) |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1671 : engine (tjit.get_engine ()), function (0), llvm_function (0) |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1672 { |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1673 try |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1674 { |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1675 jit_convert conv (tjit.get_module (), tee, |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1676 jit_typeinfo::type_of (for_bounds)); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1677 initialize (tjit, conv); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1678 } |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1679 catch (const jit_fail_exception& e) |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1680 { |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
1681 #ifdef OCTAVE_JIT_DEBUG |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1682 if (e.known ()) |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1683 std::cout << "jit fail: " << e.what () << std::endl; |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
1684 #endif |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1685 } |
14955
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
1686 } |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
1687 |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
1688 jit_info::~jit_info (void) |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
1689 { |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
1690 if (llvm_function) |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
1691 llvm_function->eraseFromParent (); |
14903 | 1692 } |
1693 | |
1694 bool | |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1695 jit_info::execute (const vmap& extra_vars) const |
14899 | 1696 { |
1697 if (! function) | |
1698 return false; | |
1699 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1700 std::vector<octave_base_value *> real_arguments (arguments.size ()); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1701 for (size_t i = 0; i < arguments.size (); ++i) |
14899 | 1702 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1703 if (arguments[i].second) |
14899 | 1704 { |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1705 octave_value current = find (extra_vars, arguments[i].first); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1706 octave_base_value *obv = current.internal_rep (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1707 obv->grab (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1708 real_arguments[i] = obv; |
14899 | 1709 } |
1710 } | |
1711 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1712 function (&real_arguments[0]); |
14899 | 1713 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1714 for (size_t i = 0; i < arguments.size (); ++i) |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1715 { |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1716 const std::string& name = arguments[i].first; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1717 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1718 // do not store for loop bounds temporary |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1719 if (name.size () && name[0] != '#') |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1720 symbol_table::varref (arguments[i].first) = real_arguments[i]; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1721 } |
14910
a8f1e08de8fc
Simplified llvm::GenericValue creation
Max Brister <max@2bass.com>
parents:
14906
diff
changeset
|
1722 |
14899 | 1723 return true; |
1724 } | |
14903 | 1725 |
1726 bool | |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1727 jit_info::match (const vmap& extra_vars) const |
14903 | 1728 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1729 if (! function) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1730 return true; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1731 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1732 for (size_t i = 0; i < bounds.size (); ++i) |
14903 | 1733 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1734 const std::string& arg_name = bounds[i].second; |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1735 octave_value value = find (extra_vars, arg_name); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1736 jit_type *type = jit_typeinfo::type_of (value); |
14906 | 1737 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1738 // FIXME: Check for a parent relationship |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1739 if (type != bounds[i].first) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1740 return false; |
14903 | 1741 } |
1742 | |
1743 return true; | |
1744 } | |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1745 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1746 void |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1747 jit_info::initialize (tree_jit& tjit, jit_convert& conv) |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1748 { |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1749 llvm_function = conv.get_function (); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1750 arguments = conv.get_arguments (); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1751 bounds = conv.get_bounds (); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1752 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1753 if (llvm_function) |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1754 { |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1755 tjit.optimize (llvm_function); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1756 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1757 #ifdef OCTAVE_JIT_DEBUG |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1758 std::cout << "-------------------- optimized llvm ir " |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1759 << "--------------------\n"; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1760 llvm::raw_os_ostream llvm_cout (std::cout); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1761 llvm_function->print (llvm_cout); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1762 llvm_cout.flush (); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1763 std::cout << std::endl; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1764 #endif |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1765 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1766 void *void_fn = engine->getPointerToFunction (llvm_function); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1767 function = reinterpret_cast<jited_function> (void_fn); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1768 } |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1769 } |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1770 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1771 octave_value |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1772 jit_info::find (const vmap& extra_vars, const std::string& vname) const |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1773 { |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1774 vmap::const_iterator iter = extra_vars.find (vname); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1775 return iter == extra_vars.end () ? symbol_table::varval (vname) |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1776 : *iter->second; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1777 } |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15023
diff
changeset
|
1778 |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
1779 #endif |
15014
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1780 |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1781 |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1782 /* |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1783 Test some simple cases that compile. |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1784 |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1785 %!test |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1786 %! inc = 1e-5; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1787 %! result = 0; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1788 %! for ii = 0:inc:1 |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1789 %! result = result + inc * (1/3 * ii * ii); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1790 %! endfor |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1791 %! assert (abs (result - 1/9) < 1e-5); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1792 |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1793 %!test |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1794 %! inc = 1e-5; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1795 %! result = 0; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1796 %! for ii = 0:inc:1 |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1797 %! # the ^ operator's result is complex |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1798 %! result = result + inc * (1/3 * ii ^ 2); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1799 %! endfor |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1800 %! assert (abs (result - 1/9) < 1e-5); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1801 |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1802 %!test |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1803 %! nr = 1001; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1804 %! mat = zeros (1, nr); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1805 %! for i = 1:nr |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1806 %! mat(i) = i; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1807 %! endfor |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1808 %! assert (mat == 1:nr); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1809 |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1810 %!test |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1811 %! nr = 1001; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1812 %! mat = 1:nr; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1813 %! mat(end) = 0; # force mat to a matrix |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1814 %! total = 0; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1815 %! for i = 1:nr |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1816 %! total = mat(i) + total; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1817 %! endfor |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1818 %! assert (sum (mat) == total); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1819 |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1820 %!test |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1821 %! nr = 1001; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1822 %! mat = [3 1 5]; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1823 %! try |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1824 %! for i = 1:nr |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1825 %! if i > 500 |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1826 %! result = mat(100); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1827 %! else |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1828 %! result = i; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1829 %! endif |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1830 %! endfor |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1831 %! catch |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1832 %! end |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1833 %! assert (result == 500); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1834 |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1835 %!function result = gen_test (n) |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1836 %! result = double (rand (1, n) > .01); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1837 %!endfunction |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1838 |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1839 %!function z = vectorized (A, K) |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1840 %! temp = ones (1, K); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1841 %! z = conv (A, temp); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1842 %! z = z > K-1; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1843 %! z = conv (z, temp); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1844 %! z = z(K:end-K+1); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1845 %! z = z >= 1; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1846 %!endfunction |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1847 |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1848 %!function z = loopy (A, K) |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1849 %! z = A; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1850 %! n = numel (A); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1851 %! counter = 0; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1852 %! for ii=1:n |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1853 %! if z(ii) |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1854 %! counter = counter + 1; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1855 %! else |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1856 %! if counter > 0 && counter < K |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1857 %! z(ii-counter:ii-1) = 0; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1858 %! endif |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1859 %! counter = 0; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1860 %! endif |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1861 %! endfor |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1862 %! |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1863 %! if counter > 0 && counter < K |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1864 %! z(end-counter+1:end) = 0; |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1865 %! endif |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1866 %!endfunction |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1867 |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1868 %!test |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1869 %! test_set = gen_test (10000); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1870 %! assert (all (vectorized (test_set, 3) == loopy (test_set, 3))); |
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1871 |
15023
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1872 %!test |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1873 %! niter = 1001; |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1874 %! i = 0; |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1875 %! while (i < niter) |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1876 %! i = i + 1; |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1877 %! endwhile |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1878 %! assert (i == niter); |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1879 |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
1880 %!test |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
1881 %! niter = 1001; |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
1882 %! result = 0; |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
1883 %! m = [5 10]; |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
1884 %! for i=1:niter |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
1885 %! result = result + m(end); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
1886 %! endfor |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
1887 %! assert (result == m(end) * niter); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15030
diff
changeset
|
1888 |
15067 | 1889 %!test |
1890 %! ndim = 100; | |
1891 %! result = 0; | |
1892 %! m = zeros (ndim); | |
1893 %! m(:) = 1:ndim^2; | |
1894 %! i = 1; | |
1895 %! while (i <= ndim) | |
1896 %! for j = 1:ndim | |
1897 %! result = result + m(i, j); | |
1898 %! endfor | |
1899 %! i = i + 1; | |
1900 %! endwhile | |
1901 %! assert (result == sum (sum (m))); | |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
1902 |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
1903 %!test |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
1904 %! ndim = 100; |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
1905 %! m = zeros (ndim); |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
1906 %! i = 1; |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
1907 %! while (i <= ndim) |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
1908 %! for j = 1:ndim |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
1909 %! m(i, j) = (j - 1) * ndim + i; |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
1910 %! endfor |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
1911 %! i = i + 1; |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
1912 %! endwhile |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
1913 %! m2 = zeros (ndim); |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
1914 %! m2(:) = 1:(ndim^2); |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
1915 %! assert (all (m == m2)); |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
1916 |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1917 %!test |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1918 %! ndim = 2; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1919 %! m = zeros (ndim, ndim, ndim, ndim); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1920 %! result = 0; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1921 %! i0 = 1; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1922 %! while (i0 <= ndim) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1923 %! for i1 = 1:ndim |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1924 %! for i2 = 1:ndim |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1925 %! for i3 = 1:ndim |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1926 %! m(i0, i1, i2, i3) = 1; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1927 %! m(i0, i1, i2, i3, 1, 1, 1, 1, 1, 1) = 1; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1928 %! result = result + m(i0, i1, i2, i3); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1929 %! endfor |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1930 %! endfor |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1931 %! endfor |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1932 %! i0 = i0 + 1; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1933 %! endwhile |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1934 %! expected = ones (ndim, ndim, ndim, ndim); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1935 %! assert (all (m == expected)); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1936 %! assert (result == sum (expected (:))); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1937 |
15095
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1938 %!function test_divide () |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1939 %! state = warning ("query", "Octave:divide-by-zero").state; |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1940 %! unwind_protect |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1941 %! warning ("error", "Octave:divide-by-zero"); |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1942 %! for i=1:1e5 |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1943 %! a = 1; |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1944 %! a / 0; |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1945 %! endfor |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1946 %! unwind_protect_cleanup |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1947 %! warning (state, "Octave:divide-by-zero"); |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1948 %! end_unwind_protect |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1949 %!endfunction |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1950 |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1951 %!error <division by zero> test_divide () |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1952 |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1953 %!test |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1954 %! while 1 |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1955 %! a = 0; |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1956 %! result = a / 1; |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1957 %! break; |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1958 %! endwhile |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1959 %! assert (result, 0); |
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1960 |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1961 %!test |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1962 %! m = zeros (2, 1001); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1963 %! for i=1:1001 |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1964 %! m(end, i) = i; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1965 %! m(end - 1, end - i + 1) = i; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1966 %! endfor |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1967 %! m2 = zeros (2, 1001); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1968 %! m2(1, :) = fliplr (1:1001); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1969 %! m2(2, :) = 1:1001; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1970 %! assert (m, m2); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1971 |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
1972 %!test |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
1973 %! m = [1 2 3]; |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
1974 %! for i=1:1001 |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
1975 %! m = sin (m); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
1976 %! break; |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
1977 %! endfor |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
1978 %! assert (m == sin ([1 2 3])); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
1979 |
15140
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
1980 %!test |
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
1981 %! i = 0; |
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
1982 %! while i < 10 |
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
1983 %! i += 1; |
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
1984 %! endwhile |
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
1985 %! assert (i == 10); |
6ea86e1d0f5f
Support +=, -=, *=, ect. in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
1986 |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
1987 %!test |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
1988 %! i = 0; |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
1989 %! while i < 10 |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
1990 %! a = ++i; |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
1991 %! endwhile |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
1992 %! assert (i == 10); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
1993 %! assert (a == 10); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15140
diff
changeset
|
1994 |
15014
094bc0a145a1
Take into account different calling conventions
Max Brister <max@2bass.com>
parents:
14992
diff
changeset
|
1995 */ |