annotate src/interp-core/pt-jit.h @ 15181:ed2b911a2fb3

Rename jit_convert::convert_llvm to jit_convert_llvm * pt-jit.cc (jit_convert::jit_convert): Use jit_convert_llvm. (jit_convert::convert_llvm): Rename to jit_convert_llvm. * pt-jit.h (jit_convert::convert_llvm): Rename to jit_convert_llvm.
author Max Brister <max@2bass.com>
date Wed, 15 Aug 2012 22:36:59 -0500
parents b1b22bc50aed
children a7a56b436de2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
1 /*
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
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
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
4
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
5 This file is part of Octave.
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
6
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
10 option) any later version.
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
11
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
15 for more details.
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
16
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
20
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
21 */
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
22
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
23 #if !defined (octave_tree_jit_h)
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
24 #define octave_tree_jit_h 1
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
25
14932
1f914446157d Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents: 14928
diff changeset
26 #ifdef HAVE_LLVM
1f914446157d Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents: 14928
diff changeset
27
15016
005cb78e1dd1 Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents: 15014
diff changeset
28 #include "jit-ir.h"
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
29
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
30 #include "pt-walk.h"
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
31
15181
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
32 // Convert from the parse tree (AST) to the low level Octave IR.
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
33 class
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
34 jit_convert : public tree_walker
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
35 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
36 public:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
37 typedef std::pair<jit_type *, std::string> type_bound;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
38 typedef std::vector<type_bound> type_bound_vector;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
39
15027
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
40 jit_convert (llvm::Module *module, tree &tee, jit_type *for_bounds = 0);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
41
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
42 ~jit_convert (void);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
43
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
44 llvm::Function *get_function (void) const { return function; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
45
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
46 const std::vector<std::pair<std::string, bool> >& get_arguments(void) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
47 { return arguments; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
48
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
49 const type_bound_vector& get_bounds (void) const { return bounds; }
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
50
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
51 void visit_anon_fcn_handle (tree_anon_fcn_handle&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
52
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
53 void visit_argument_list (tree_argument_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
54
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
55 void visit_binary_expression (tree_binary_expression&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
56
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
57 void visit_break_command (tree_break_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
58
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
59 void visit_colon_expression (tree_colon_expression&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
60
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
61 void visit_continue_command (tree_continue_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
62
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
63 void visit_global_command (tree_global_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
64
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
65 void visit_persistent_command (tree_persistent_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
66
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
67 void visit_decl_elt (tree_decl_elt&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
68
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
69 void visit_decl_init_list (tree_decl_init_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
70
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
71 void visit_simple_for_command (tree_simple_for_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
72
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
73 void visit_complex_for_command (tree_complex_for_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
74
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
75 void visit_octave_user_script (octave_user_script&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
76
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
77 void visit_octave_user_function (octave_user_function&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
78
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
79 void visit_octave_user_function_header (octave_user_function&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
80
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
81 void visit_octave_user_function_trailer (octave_user_function&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
82
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
83 void visit_function_def (tree_function_def&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
84
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
85 void visit_identifier (tree_identifier&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
86
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
87 void visit_if_clause (tree_if_clause&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
88
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
89 void visit_if_command (tree_if_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
90
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
91 void visit_if_command_list (tree_if_command_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
92
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
93 void visit_index_expression (tree_index_expression&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
94
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
95 void visit_matrix (tree_matrix&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
96
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
97 void visit_cell (tree_cell&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
98
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
99 void visit_multi_assignment (tree_multi_assignment&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
100
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
101 void visit_no_op_command (tree_no_op_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
102
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
103 void visit_constant (tree_constant&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
104
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
105 void visit_fcn_handle (tree_fcn_handle&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
106
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
107 void visit_parameter_list (tree_parameter_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
108
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
109 void visit_postfix_expression (tree_postfix_expression&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
110
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
111 void visit_prefix_expression (tree_prefix_expression&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
112
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
113 void visit_return_command (tree_return_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
114
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
115 void visit_return_list (tree_return_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
116
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
117 void visit_simple_assignment (tree_simple_assignment&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
118
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
119 void visit_statement (tree_statement&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
120
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
121 void visit_statement_list (tree_statement_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
122
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
123 void visit_switch_case (tree_switch_case&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
124
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
125 void visit_switch_case_list (tree_switch_case_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
126
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
127 void visit_switch_command (tree_switch_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
128
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
129 void visit_try_catch_command (tree_try_catch_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
130
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
131 void visit_unwind_protect_command (tree_unwind_protect_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
132
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
133 void visit_while_command (tree_while_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
134
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
135 void visit_do_until_command (tree_do_until_command&);
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
136
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
137 // this would be easier with variadic templates
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
138 template <typename T>
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
139 T *create (void)
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
140 {
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
141 T *ret = new T();
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
142 track_value (ret);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
143 return ret;
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
144 }
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
145
14980
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
146 #define DECL_ARG(n) const ARG ## n& arg ## n
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
147 #define JIT_CREATE(N) \
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
148 template <typename T, OCT_MAKE_DECL_LIST (typename, ARG, N)> \
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
149 T *create (OCT_MAKE_LIST (DECL_ARG, N)) \
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
150 { \
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
151 T *ret = new T (OCT_MAKE_ARG_LIST (arg, N)); \
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
152 track_value (ret); \
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
153 return ret; \
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
154 }
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
155
14980
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
156 JIT_CREATE (1)
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
157 JIT_CREATE (2)
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
158 JIT_CREATE (3)
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
159 JIT_CREATE (4)
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
160
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
161 #undef JIT_CREATE
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
162
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
163 #define JIT_CREATE_CHECKED(N) \
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
164 template <OCT_MAKE_DECL_LIST (typename, ARG, N)> \
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
165 jit_call *create_checked (OCT_MAKE_LIST (DECL_ARG, N)) \
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
166 { \
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
167 jit_call *ret = create<jit_call> (OCT_MAKE_ARG_LIST (arg, N)); \
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
168 return create_checked_impl (ret); \
14961
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
169 }
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
170
14980
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
171 JIT_CREATE_CHECKED (1)
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
172 JIT_CREATE_CHECKED (2)
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
173 JIT_CREATE_CHECKED (3)
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
174 JIT_CREATE_CHECKED (4)
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
175
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
176 #undef JIT_CREATE_CHECKED
bb1f3a9bb122 Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents: 14978
diff changeset
177 #undef DECL_ARG
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
178
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
179 typedef std::list<jit_block *> block_list;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
180 typedef block_list::iterator block_iterator;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
181
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
182 void append (jit_block *ablock);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
183
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
184 void insert_before (block_iterator iter, jit_block *ablock);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
185
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
186 void insert_before (jit_block *loc, jit_block *ablock)
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
187 {
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
188 insert_before (loc->location (), ablock);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
189 }
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
190
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
191 void insert_after (block_iterator iter, jit_block *ablock);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
192
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
193 void insert_after (jit_block *loc, jit_block *ablock)
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
194 {
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
195 insert_after (loc->location (), ablock);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
196 }
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
197 private:
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
198 std::vector<std::pair<std::string, bool> > arguments;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
199 type_bound_vector bounds;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
200
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
201 // used instead of return values from visit_* functions
14944
c0a5ab3b9278 jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents: 14943
diff changeset
202 jit_value *result;
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
203
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
204 jit_block *entry_block;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
205
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
206 jit_block *final_block;
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
207
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
208 jit_block *block;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
209
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
210 llvm::Function *function;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
211
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
212 std::list<jit_block *> blocks;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
213
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
214 std::list<jit_instruction *> worklist;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
215
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
216 std::list<jit_value *> constants;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
217
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
218 std::list<jit_value *> all_values;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
219
15067
df4538e3b50b ND scalar indexing in JIT.
Max Brister <max@2bass.com>
parents: 15056
diff changeset
220 std::vector<jit_magic_end::context> end_context;
15056
bc32288f4a42 Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents: 15027
diff changeset
221
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
222 size_t iterator_count;
15027
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
223 size_t for_bounds_count;
14978
f649b66ef1af Add short circult operators to JIT
Max Brister <max@2bass.com>
parents: 14976
diff changeset
224 size_t short_count;
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
225
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
226 typedef std::map<std::string, jit_variable *> vmap_t;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
227 vmap_t vmap;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
228
14961
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
229 jit_call *create_checked_impl (jit_call *ret)
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
230 {
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
231 block->append (ret);
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
232 create_check (ret);
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
233 return ret;
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
234 }
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
235
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
236 jit_error_check *create_check (jit_call *call)
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
237 {
14961
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
238 jit_block *normal = create<jit_block> (block->name ());
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
239 jit_error_check *ret
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
240 = block->append (create<jit_error_check> (call, normal, final_block));
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
241 append (normal);
14961
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
242 block = normal;
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
243
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
244 return ret;
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
245 }
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
246
15027
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
247 // get an existing vairable. If the variable does not exist, it will not be
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
248 // created
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
249 jit_variable *find_variable (const std::string& vname) const;
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
250
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
251 // get a variable, create it if it does not exist. The type will default to
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
252 // the variable's current type in the symbol table.
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
253 jit_variable *get_variable (const std::string& vname);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
254
15027
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
255 // create a variable of the given name and given type. Will also insert an
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
256 // extract statement
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
257 jit_variable *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
258
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
259 // The name of the next for loop iterator. If inc is false, then the iterator
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
260 // counter will not be incremented.
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
261 std::string next_iterator (bool inc = true)
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
262 { return next_name ("#iter", iterator_count, inc); }
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
263
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
264 std::string next_for_bounds (bool inc = true)
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
265 { return next_name ("#for_bounds", for_bounds_count, inc); }
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
266
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
267 std::string next_shortcircut_result (bool inc = true)
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
268 { return next_name ("#shortcircut_result", short_count, inc); }
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
269
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
270 std::string 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
271
15067
df4538e3b50b ND scalar indexing in JIT.
Max Brister <max@2bass.com>
parents: 15056
diff changeset
272 jit_instruction *resolve (const jit_operation& fres,
15068
f57d7578c1a6 Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents: 15067
diff changeset
273 tree_index_expression& exp,
f57d7578c1a6 Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents: 15067
diff changeset
274 jit_value *extra_arg = 0);
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
275
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
276 jit_value *do_assign (tree_expression *exp, jit_value *rhs,
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
277 bool artificial = false);
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
278
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
279 jit_value *do_assign (const std::string& lhs, jit_value *rhs, bool print,
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
280 bool artificial = false);
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
281
14944
c0a5ab3b9278 jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents: 14943
diff changeset
282 jit_value *visit (tree *tee) { return visit (*tee); }
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
283
14944
c0a5ab3b9278 jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents: 14943
diff changeset
284 jit_value *visit (tree& tee);
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
285
14946
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
286 void push_worklist (jit_instruction *instr)
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
287 {
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
288 if (! instr->in_worklist ())
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
289 {
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
290 instr->stash_in_worklist (true);
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
291 worklist.push_back (instr);
14946
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
292 }
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
293 }
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
294
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
295 void append_users (jit_value *v)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
296 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
297 for (jit_use *use = v->first_use (); use; use = use->next ())
14946
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
298 push_worklist (use->user ());
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
299 }
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
300
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
301 void append_users_term (jit_terminator *term);
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
302
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
303 void track_value (jit_value *value)
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
304 {
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
305 if (value->type ())
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
306 constants.push_back (value);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
307 all_values.push_back (value);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
308 }
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
309
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
310 void construct_ssa (void);
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
311
14971
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
312 void do_construct_ssa (jit_block& block, size_t avisit_count);
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
313
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
314 void remove_dead ();
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
315
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
316 void place_releases (void);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
317
14971
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
318 void release_temp (jit_block& ablock, std::set<jit_value *>& temp);
14966
b7b647bc4b90 Place releases for temporaries on error
Max Brister <max@2bass.com>
parents: 14965
diff changeset
319
b7b647bc4b90 Place releases for temporaries on error
Max Brister <max@2bass.com>
parents: 14965
diff changeset
320 void release_dead_phi (jit_block& ablock);
b7b647bc4b90 Place releases for temporaries on error
Max Brister <max@2bass.com>
parents: 14965
diff changeset
321
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
322 void simplify_phi (void);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
323
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
324 void simplify_phi (jit_phi& phi);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
325
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
326 void print_blocks (const std::string& header)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
327 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
328 std::cout << "-------------------- " << header << " --------------------\n";
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
329 for (std::list<jit_block *>::iterator iter = blocks.begin ();
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
330 iter != blocks.end (); ++iter)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
331 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
332 assert (*iter);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
333 (*iter)->print (std::cout, 0);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
334 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
335 std::cout << std::endl;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
336 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
337
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
338 void print_dom (void)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
339 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
340 std::cout << "-------------------- dom info --------------------\n";
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
341 for (std::list<jit_block *>::iterator iter = blocks.begin ();
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
342 iter != blocks.end (); ++iter)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
343 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
344 assert (*iter);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
345 (*iter)->print_dom (std::cout);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
346 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
347 std::cout << std::endl;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
348 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
349
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
350 bool breaking; // true if we are breaking OR continuing
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
351 block_list breaks;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
352 block_list continues;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
353
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
354 void finish_breaks (jit_block *dest, const block_list& lst);
15181
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
355 };
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
356
15181
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
357 // Convert from the low level Octave IR to LLVM
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
358 class
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
359 jit_convert_llvm : public jit_ir_walker
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
360 {
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
361 public:
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
362 jit_convert_llvm (jit_convert& jc) : jthis (jc) {}
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
363
15181
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
364 llvm::Function *convert (llvm::Module *module,
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
365 const std::vector<std::pair<std::string, bool> >& args,
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
366 const std::list<jit_block *>& blocks,
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
367 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
368
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
369 #define JIT_METH(clname) \
15181
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
370 virtual void visit (jit_ ## clname&);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
371
15181
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
372 JIT_VISIT_IR_CLASSES;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
373
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
374 #undef JIT_METH
15181
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
375 private:
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
376 // name -> llvm argument
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
377 std::map<std::string, llvm::Value *> arguments;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
378
15181
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
379 void finish_phi (jit_phi *phi);
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
380
15181
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
381 void visit (jit_value *jvalue)
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
382 {
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
383 return visit (*jvalue);
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
384 }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
385
15181
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
386 void visit (jit_value &jvalue)
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
387 {
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
388 jvalue.accept (*this);
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
389 }
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
390 private:
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
391 jit_convert &jthis;
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
392 llvm::Function *function;
ed2b911a2fb3 Rename jit_convert::convert_llvm to jit_convert_llvm
Max Brister <max@2bass.com>
parents: 15180
diff changeset
393 llvm::BasicBlock *prelude;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
394 };
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
395
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
396 class jit_info;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
397
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
398 class
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
399 tree_jit
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
400 {
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
401 public:
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
402 tree_jit (void);
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
403
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
404 ~tree_jit (void);
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
405
15027
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
406 bool execute (tree_simple_for_command& cmd, const octave_value& bounds);
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
407
15023
75d1bc2fd6d2 Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents: 15016
diff changeset
408 bool execute (tree_while_command& cmd);
75d1bc2fd6d2 Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents: 15016
diff changeset
409
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
410 llvm::ExecutionEngine *get_engine (void) const { return engine; }
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
411
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
412 llvm::Module *get_module (void) const { return module; }
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
413
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
414 void optimize (llvm::Function *fn);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
415 private:
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
416 bool initialize (void);
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
417
15027
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
418 size_t trip_count (const octave_value& bounds) const;
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
419
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
420 // FIXME: Temorary hack to test
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
421 typedef std::map<tree *, jit_info *> compiled_map;
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
422 llvm::Module *module;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
423 llvm::PassManager *module_pass_manager;
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
424 llvm::FunctionPassManager *pass_manager;
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
425 llvm::ExecutionEngine *engine;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
426 };
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
427
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
428 class
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
429 jit_info
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
430 {
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
431 public:
15027
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
432 // we use a pointer here so we don't have to include ov.h
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
433 typedef std::map<std::string, const octave_value *> vmap;
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
434
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
435 jit_info (tree_jit& tjit, tree& tee);
14913
c7071907a641 Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents: 14911
diff changeset
436
15027
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
437 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
438
14955
609dcc297db5 src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents: 14951
diff changeset
439 ~jit_info (void);
609dcc297db5 src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents: 14951
diff changeset
440
15027
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
441 bool execute (const vmap& extra_vars = vmap ()) const;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
442
15027
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
443 bool match (const vmap& extra_vars = vmap ()) const;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
444 private:
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
445 typedef jit_convert::type_bound type_bound;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
446 typedef jit_convert::type_bound_vector type_bound_vector;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
447 typedef void (*jited_function)(octave_base_value**);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
448
15027
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
449 void initialize (tree_jit& tjit, jit_convert& conv);
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
450
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
451 octave_value 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
452
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
453 llvm::ExecutionEngine *engine;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
454 jited_function function;
14955
609dcc297db5 src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents: 14951
diff changeset
455 llvm::Function *llvm_function;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
456
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
457 std::vector<std::pair<std::string, bool> > arguments;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
458 type_bound_vector bounds;
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
459 };
14937
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
460
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
461 #endif
14932
1f914446157d Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents: 14928
diff changeset
462 #endif