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