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