annotate src/pt-jit.cc @ 15068:f57d7578c1a6

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