annotate src/pt-jit.cc @ 15016:005cb78e1dd1

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