annotate src/pt-jit.h @ 14971:b23a98ca0e43

Remove jit_block::visit_dom and simplify release placement * src/pt-jit.cc (octave_jit_paren_subsasgn_impl): Remove debug print. (jit_value::first_use_block): New function. (jit_block::compute_df, jit_block::update_idom, jit_block::create_dom_tree): Use visited function. (jit_convert::construct_ssa): Call do_construct_ssa with visit count. (jit_convert::do_construct_ssa): Use dominator graph directly. (jit_convert::place_releases, jit_convert::release_temp): Track temporaries instead of using compute_temp. (jit_convert::compute_temp::compute_temp, jit_convert::compute_temp::operator ()): Removed function. * src/pt-jit.cc (jit_value::fire_use_block): New declaration. (jit_block::label): Use visited function. (jit_block::dom_successor, jit_block::dom_successor_count, jit_block::visited, jit_block::visit_count): New functions. (jit_block::visit_dom, jit_block::do_visit_dom): Removed function. (jit_block_callback): Removed class. (jit_convert::do_construct_ssa, jit_convert::rleease_temp): Change function signature. (jit_convert::instr_set): Remove typedef. (jit_convert::compute_temp): Remove class declaration.
author Max Brister <max@2bass.com>
date Mon, 25 Jun 2012 16:26:00 -0500
parents bbeef7b8ea2e
children 2960f1b2d6ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
1 /*
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2
14901
516b4a15b775 doc: Copyright fix in pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14899
diff changeset
3 Copyright (C) 2012 Max Brister <max@2bass.com>
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
4
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
5 This file is part of Octave.
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
6
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
10 option) any later version.
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
11
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
15 for more details.
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
16
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
20
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
21 */
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
22
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
23 #if !defined (octave_tree_jit_h)
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
24 #define octave_tree_jit_h 1
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
25
14932
1f914446157d Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents: 14928
diff changeset
26 #ifdef HAVE_LLVM
1f914446157d Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents: 14928
diff changeset
27
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
28 #include <list>
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
29 #include <map>
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
30 #include <set>
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
31 #include <stdexcept>
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
32 #include <vector>
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
33 #include <stack>
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
34
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
35 #include "Array.h"
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
36 #include "Range.h"
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
37 #include "pt-walk.h"
14913
c7071907a641 Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents: 14911
diff changeset
38 #include "symtab.h"
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
39
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
40 // -------------------- Current status --------------------
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
41 // Simple binary operations (+-*/) on octave_scalar's (doubles) are optimized.
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
42 // a = 5;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
43 // b = a * 5 + a;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
44 //
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
45 // Indexing matrices with scalars works.
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
46 //
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
47 // if, elseif, else, break, continue, and for compile. Compilation is triggered
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
48 // at the start of a simple for loop.
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
49 //
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
50 // The octave low level IR is a linear IR, it works by converting everything to
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
51 // calls to jit_functions. This turns expressions like c = a + b into
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
52 // c = call binary+ (a, b)
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
53 // The jit_functions contain information about overloads for different types.
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
54 // For, example, if we know a and b are scalars, then c must also be a scalar.
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
55 //
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
56 //
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
57 // TODO:
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
58 // 1. Function calls
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
59 // 2. Cleanup/documentation
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
60 // 3. ...
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
61 // ---------------------------------------------------------
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
62
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
63
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
64 // we don't want to include llvm headers here, as they require
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
65 // __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS be defined in the entire
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
66 // compilation unit
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
67 namespace llvm
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
68 {
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
69 class Value;
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
70 class Module;
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
71 class FunctionPassManager;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
72 class PassManager;
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
73 class ExecutionEngine;
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
74 class Function;
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
75 class BasicBlock;
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
76 class LLVMContext;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
77 class Type;
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
78 class Twine;
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
79 class GlobalVariable;
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
80 class TerminatorInst;
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
81 class PHINode;
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
82 }
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
83
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
84 class octave_base_value;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
85 class octave_value;
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
86 class tree;
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
87 class tree_expression;
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
88
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
89 template <typename HOLDER_T, typename SUB_T>
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
90 class jit_internal_node;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
91
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
92 // jit_internal_list and jit_internal_node implement generic embedded doubly
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
93 // linked lists. List items extend from jit_internal_list, and can be placed
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
94 // in nodes of type jit_internal_node. We use CRTP twice.
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
95 template <typename LIST_T, typename NODE_T>
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
96 class
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
97 jit_internal_list
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
98 {
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
99 friend class jit_internal_node<LIST_T, NODE_T>;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
100 public:
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
101 jit_internal_list (void) : use_head (0), use_tail (0), muse_count (0) {}
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
102
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
103 virtual ~jit_internal_list (void)
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
104 {
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
105 while (use_head)
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
106 use_head->stash_value (0);
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
107 }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
108
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
109 NODE_T *first_use (void) const { return use_head; }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
110
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
111 size_t use_count (void) const { return muse_count; }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
112 private:
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
113 NODE_T *use_head;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
114 NODE_T *use_tail;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
115 size_t muse_count;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
116 };
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
117
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
118 // a node for internal linked lists
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
119 template <typename LIST_T, typename NODE_T>
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
120 class
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
121 jit_internal_node
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
122 {
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
123 public:
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
124 typedef jit_internal_list<LIST_T, NODE_T> jit_ilist;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
125
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
126 jit_internal_node (void) : mvalue (0), mnext (0), mprev (0) {}
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
127
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
128 ~jit_internal_node (void) { remove (); }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
129
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
130 LIST_T *value (void) const { return mvalue; }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
131
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
132 void stash_value (LIST_T *avalue)
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
133 {
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
134 remove ();
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
135
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
136 mvalue = avalue;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
137
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
138 if (mvalue)
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
139 {
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
140 jit_ilist *ilist = mvalue;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
141 NODE_T *sthis = static_cast<NODE_T *> (this);
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
142 if (ilist->use_head)
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
143 {
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
144 ilist->use_tail->mnext = sthis;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
145 mprev = ilist->use_tail;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
146 }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
147 else
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
148 ilist->use_head = sthis;
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
149
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
150 ilist->use_tail = sthis;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
151 ++ilist->muse_count;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
152 }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
153 }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
154
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
155 NODE_T *next (void) const { return mnext; }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
156
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
157 NODE_T *prev (void) const { return mprev; }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
158 private:
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
159 void remove ()
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
160 {
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
161 if (mvalue)
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
162 {
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
163 jit_ilist *ilist = mvalue;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
164 if (mprev)
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
165 mprev->mnext = mnext;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
166 else
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
167 // we are the use_head
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
168 ilist->use_head = mnext;
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
169
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
170 if (mnext)
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
171 mnext->mprev = mprev;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
172 else
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
173 // we are the use tail
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
174 ilist->use_tail = mprev;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
175
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
176 mnext = mprev = 0;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
177 --ilist->muse_count;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
178 mvalue = 0;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
179 }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
180 }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
181
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
182 LIST_T *mvalue;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
183 NODE_T *mnext;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
184 NODE_T *mprev;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
185 };
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
186
14937
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
187 // Use like: isa<jit_phi> (value)
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
188 // basically just a short cut type typing dyanmic_cast.
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
189 template <typename T, typename U>
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
190 bool isa (U *value)
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
191 {
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
192 return dynamic_cast<T *> (value);
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
193 }
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
194
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
195 // jit_range is compatable with the llvm range structure
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
196 struct
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
197 jit_range
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
198 {
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
199 jit_range (const Range& from) : base (from.base ()), limit (from.limit ()),
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
200 inc (from.inc ()), nelem (from.nelem ())
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
201 {}
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
202
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
203 operator Range () const
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
204 {
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
205 return Range (base, limit, inc);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
206 }
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
207
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
208 double base;
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
209 double limit;
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
210 double inc;
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
211 octave_idx_type nelem;
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
212 };
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
213
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
214 std::ostream& operator<< (std::ostream& os, const jit_range& rng);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
215
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
216 // jit_array is compatable with the llvm array/matrix structures
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
217 template <typename T, typename U>
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
218 struct
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
219 jit_array
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
220 {
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
221 jit_array (T& from) : ref_count (from.jit_ref_count ()),
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
222 slice_data (from.jit_slice_data () - 1),
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
223 slice_len (from.capacity ()),
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
224 dimensions (from.jit_dimensions ()),
14967
0cfe0cf55a02 Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents: 14966
diff changeset
225 array (new T (from))
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
226 {
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
227 grab_dimensions ();
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
228 }
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
229
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
230 void grab_dimensions (void)
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
231 {
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
232 ++(dimensions[-2]);
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
233 }
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
234
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
235 operator T () const
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
236 {
14967
0cfe0cf55a02 Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents: 14966
diff changeset
237 return *array;
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
238 }
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
239
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
240 int *ref_count;
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
241
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
242 U *slice_data;
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
243 octave_idx_type slice_len;
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
244 octave_idx_type *dimensions;
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
245
14967
0cfe0cf55a02 Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents: 14966
diff changeset
246 T *array;
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
247 };
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
248
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
249 typedef jit_array<NDArray, double> jit_matrix;
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
250
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
251 std::ostream& operator<< (std::ostream& os, const jit_matrix& mat);
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
252
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
253 // Used to keep track of estimated (infered) types during JIT. This is a
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
254 // hierarchical type system which includes both concrete and abstract types.
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
255 //
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
256 // Current, we only support any and scalar types. If we can't figure out what
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
257 // type a variable is, we assign it the any type. This allows us to generate
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
258 // code even for the case of poor type inference.
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
259 class
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
260 jit_type
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
261 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
262 public:
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
263 jit_type (const std::string& aname, jit_type *aparent, llvm::Type *allvm_type,
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
264 int aid) :
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
265 mname (aname), mparent (aparent), llvm_type (allvm_type), mid (aid),
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
266 mdepth (aparent ? aparent->mdepth + 1 : 0)
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
267 {}
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
268
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
269 // a user readable type name
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
270 const std::string& name (void) const { return mname; }
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 // a unique id for the type
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
273 int type_id (void) const { return mid; }
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
274
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
275 // An abstract base type, may be null
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
276 jit_type *parent (void) const { return mparent; }
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 // convert to an llvm type
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
279 llvm::Type *to_llvm (void) const { return llvm_type; }
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
280
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
281 // how this type gets passed as a function argument
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
282 llvm::Type *to_llvm_arg (void) const;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
283
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
284 size_t depth (void) const { return mdepth; }
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
285 private:
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
286 std::string mname;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
287 jit_type *mparent;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
288 llvm::Type *llvm_type;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
289 int mid;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
290 size_t mdepth;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
291 };
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
292
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
293 // seperate print function to allow easy printing if type is null
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
294 std::ostream& jit_print (std::ostream& os, jit_type *atype);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
295
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
296 // Keeps track of overloads for a builtin function. Used for both type inference
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
297 // and code generation.
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
298 class
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
299 jit_function
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
300 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
301 public:
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
302 struct
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
303 overload
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
304 {
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
305 overload (void) : function (0), can_error (false), result (0) {}
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
306
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
307 overload (llvm::Function *f, bool e, jit_type *r, jit_type *arg0) :
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
308 function (f), can_error (e), result (r), arguments (1)
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
309 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
310 arguments[0] = arg0;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
311 }
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
312
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
313 overload (llvm::Function *f, bool e, jit_type *r, jit_type *arg0,
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
314 jit_type *arg1) : function (f), can_error (e),
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
315 result (r), arguments (2)
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
316 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
317 arguments[0] = arg0;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
318 arguments[1] = arg1;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
319 }
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
320
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
321 overload (llvm::Function *f, bool e, jit_type *r, jit_type *arg0,
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
322 jit_type *arg1, jit_type *arg2) : function (f), can_error (e),
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
323 result (r), arguments (3)
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
324 {
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
325 arguments[0] = arg0;
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
326 arguments[1] = arg1;
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
327 arguments[2] = arg2;
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
328 }
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
329
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
330 llvm::Function *function;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
331 bool can_error;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
332 jit_type *result;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
333 std::vector<jit_type*> arguments;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
334 };
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
335
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
336 void add_overload (const overload& func)
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
337 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
338 add_overload (func, func.arguments);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
339 }
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
340
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
341 void add_overload (llvm::Function *f, bool e, jit_type *r, jit_type *arg0)
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
342 {
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
343 overload ol (f, e, r, arg0);
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
344 add_overload (ol);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
345 }
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
346
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
347 void add_overload (llvm::Function *f, bool e, jit_type *r, jit_type *arg0,
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
348 jit_type *arg1)
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
349 {
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
350 overload ol (f, e, r, arg0, arg1);
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
351 add_overload (ol);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
352 }
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
353
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
354 void add_overload (llvm::Function *f, bool e, jit_type *r, jit_type *arg0,
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
355 jit_type *arg1, jit_type *arg2)
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
356 {
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
357 overload ol (f, e, r, arg0, arg1, arg2);
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
358 add_overload (ol);
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
359 }
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
360
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
361 void add_overload (const overload& func,
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
362 const std::vector<jit_type*>& args);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
363
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
364 const overload& get_overload (const std::vector<jit_type *>& types) const;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
365
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
366 const overload& get_overload (jit_type *arg0) const
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
367 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
368 std::vector<jit_type *> types (1);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
369 types[0] = arg0;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
370 return get_overload (types);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
371 }
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
372
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
373 const overload& get_overload (jit_type *arg0, jit_type *arg1) const
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 std::vector<jit_type *> types (2);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
376 types[0] = arg0;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
377 types[1] = arg1;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
378 return get_overload (types);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
379 }
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 jit_type *get_result (const std::vector<jit_type *>& types) const
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
382 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
383 const overload& temp = get_overload (types);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
384 return temp.result;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
385 }
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 jit_type *get_result (jit_type *arg0, jit_type *arg1) const
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
388 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
389 const overload& temp = get_overload (arg0, arg1);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
390 return temp.result;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
391 }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
392
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
393 const std::string& name (void) const { return mname; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
394
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
395 void stash_name (const std::string& aname) { mname = aname; }
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
396 private:
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
397 Array<octave_idx_type> to_idx (const std::vector<jit_type*>& types) const;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
398
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
399 std::vector<Array<overload> > overloads;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
400
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
401 std::string mname;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
402 };
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
403
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
404 // Get information and manipulate jit types.
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
405 class
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
406 jit_typeinfo
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
407 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
408 public:
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
409 static void initialize (llvm::Module *m, llvm::ExecutionEngine *e);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
410
14922
2e6f83b2f2b9 Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents: 14920
diff changeset
411 static jit_type *join (jit_type *lhs, jit_type *rhs)
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
412 {
14922
2e6f83b2f2b9 Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents: 14920
diff changeset
413 return instance->do_join (lhs, rhs);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
414 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
415
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
416 static jit_type *get_any (void) { return instance->any; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
417
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
418 static jit_type *get_matrix (void) { return instance->matrix; }
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
419
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
420 static jit_type *get_scalar (void) { return instance->scalar; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
421
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
422 static llvm::Type *get_scalar_llvm (void)
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
423 { return instance->scalar->to_llvm (); }
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
424
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
425 static jit_type *get_range (void) { return instance->range; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
426
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
427 static jit_type *get_string (void) { return instance->string; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
428
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
429 static jit_type *get_bool (void) { return instance->boolean; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
430
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
431 static jit_type *get_index (void) { return instance->index; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
432
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
433 static llvm::Type *get_index_llvm (void)
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
434 { return instance->index->to_llvm (); }
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
435
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
436 static jit_type *type_of (const octave_value& ov)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
437 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
438 return instance->do_type_of (ov);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
439 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
440
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
441 static const jit_function& binary_op (int op)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
442 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
443 return instance->do_binary_op (op);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
444 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
445
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
446 static const jit_function& grab (void) { return instance->grab_fn; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
447
14965
f2117a963c54 Place grab/release for assignments
Max Brister <max@2bass.com>
parents: 14963
diff changeset
448 static const jit_function::overload& get_grab (jit_type *type)
f2117a963c54 Place grab/release for assignments
Max Brister <max@2bass.com>
parents: 14963
diff changeset
449 {
f2117a963c54 Place grab/release for assignments
Max Brister <max@2bass.com>
parents: 14963
diff changeset
450 return instance->grab_fn.get_overload (type);
f2117a963c54 Place grab/release for assignments
Max Brister <max@2bass.com>
parents: 14963
diff changeset
451 }
f2117a963c54 Place grab/release for assignments
Max Brister <max@2bass.com>
parents: 14963
diff changeset
452
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
453 static const jit_function& release (void)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
454 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
455 return instance->release_fn;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
456 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
457
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
458 static const jit_function::overload& get_release (jit_type *type)
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
459 {
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
460 return instance->release_fn.get_overload (type);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
461 }
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
462
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
463 static const jit_function& print_value (void)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
464 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
465 return instance->print_fn;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
466 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
467
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
468 static const jit_function& for_init (void)
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
469 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
470 return instance->for_init_fn;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
471 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
472
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
473 static const jit_function& for_check (void)
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
474 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
475 return instance->for_check_fn;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
476 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
477
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
478 static const jit_function& for_index (void)
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
479 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
480 return instance->for_index_fn;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
481 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
482
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
483 static const jit_function& make_range (void)
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
484 {
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
485 return instance->make_range_fn;
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
486 }
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
487
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
488 static const jit_function& paren_subsref (void)
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
489 {
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
490 return instance->paren_subsref_fn;
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
491 }
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
492
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
493 static const jit_function& paren_subsasgn (void)
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
494 {
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
495 return instance->paren_subsasgn_fn;
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
496 }
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
497
14943
8efcaf5aa233 Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents: 14942
diff changeset
498 static const jit_function& logically_true (void)
8efcaf5aa233 Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents: 14942
diff changeset
499 {
8efcaf5aa233 Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents: 14942
diff changeset
500 return instance->logically_true_fn;
8efcaf5aa233 Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents: 14942
diff changeset
501 }
8efcaf5aa233 Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents: 14942
diff changeset
502
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
503 static const jit_function& cast (jit_type *result)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
504 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
505 return instance->do_cast (result);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
506 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
507
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
508 static const jit_function::overload& cast (jit_type *to, jit_type *from)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
509 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
510 return instance->do_cast (to, from);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
511 }
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
512
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
513 static llvm::Value *insert_error_check (void)
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
514 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
515 return instance->do_insert_error_check ();
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
516 }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
517 private:
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
518 jit_typeinfo (llvm::Module *m, llvm::ExecutionEngine *e);
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
519
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
520 // FIXME: Do these methods really need to be in jit_typeinfo?
14922
2e6f83b2f2b9 Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents: 14920
diff changeset
521 jit_type *do_join (jit_type *lhs, jit_type *rhs)
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
522 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
523 // empty case
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
524 if (! lhs)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
525 return rhs;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
526
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
527 if (! rhs)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
528 return lhs;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
529
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
530 // check for a shared parent
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
531 while (lhs != rhs)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
532 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
533 if (lhs->depth () > rhs->depth ())
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
534 lhs = lhs->parent ();
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
535 else if (lhs->depth () < rhs->depth ())
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
536 rhs = rhs->parent ();
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
537 else
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
538 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
539 // we MUST have depth > 0 as any is the base type of everything
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
540 do
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
541 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
542 lhs = lhs->parent ();
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
543 rhs = rhs->parent ();
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
544 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
545 while (lhs != rhs);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
546 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
547 }
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
548
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
549 return lhs;
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
550 }
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
551
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
552 jit_type *do_difference (jit_type *lhs, jit_type *)
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
553 {
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
554 // FIXME: Maybe we can do something smarter?
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
555 return lhs;
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
556 }
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
557
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
558 jit_type *do_type_of (const octave_value &ov) const;
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
559
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
560 const jit_function& do_binary_op (int op) const
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
561 {
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
562 assert (static_cast<size_t>(op) < binary_ops.size ());
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
563 return binary_ops[op];
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
564 }
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
565
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
566 const jit_function& do_cast (jit_type *to)
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
567 {
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
568 static jit_function null_function;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
569 if (! to)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
570 return null_function;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
571
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
572 size_t id = to->type_id ();
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
573 if (id >= casts.size ())
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
574 return null_function;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
575 return casts[id];
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
576 }
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
577
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
578 const jit_function::overload& do_cast (jit_type *to, jit_type *from)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
579 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
580 return do_cast (to).get_overload (from);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
581 }
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
582
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
583 jit_type *new_type (const std::string& name, jit_type *parent,
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
584 llvm::Type *llvm_type);
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
585
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
586
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
587 void add_print (jit_type *ty, void *call);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
588
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
589 void add_binary_op (jit_type *ty, int op, int llvm_op);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
590
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
591 void add_binary_icmp (jit_type *ty, int op, int llvm_op);
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
592
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
593 void add_binary_fcmp (jit_type *ty, int op, int llvm_op);
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
594
14941
1e3d0366ac8b warn on divide by zero
Max Brister <max@2bass.com>
parents: 14939
diff changeset
595 llvm::Function *create_function (const llvm::Twine& name, llvm::Type *ret)
1e3d0366ac8b warn on divide by zero
Max Brister <max@2bass.com>
parents: 14939
diff changeset
596 {
1e3d0366ac8b warn on divide by zero
Max Brister <max@2bass.com>
parents: 14939
diff changeset
597 std::vector<llvm::Type *> args;
1e3d0366ac8b warn on divide by zero
Max Brister <max@2bass.com>
parents: 14939
diff changeset
598 return create_function (name, ret, args);
1e3d0366ac8b warn on divide by zero
Max Brister <max@2bass.com>
parents: 14939
diff changeset
599 }
1e3d0366ac8b warn on divide by zero
Max Brister <max@2bass.com>
parents: 14939
diff changeset
600
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
601 llvm::Function *create_function (const llvm::Twine& name, llvm::Type *ret,
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
602 llvm::Type *arg0)
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
603 {
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
604 std::vector<llvm::Type *> args (1, arg0);
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
605 return create_function (name, ret, args);
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
606 }
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
607
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
608 llvm::Function *create_function (const llvm::Twine& name, jit_type *ret,
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
609 jit_type *arg0)
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
610 {
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
611 return create_function (name, ret->to_llvm (), arg0->to_llvm ());
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
612 }
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
613
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
614 llvm::Function *create_function (const llvm::Twine& name, llvm::Type *ret,
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
615 llvm::Type *arg0, llvm::Type *arg1)
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
616 {
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
617 std::vector<llvm::Type *> args (2);
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
618 args[0] = arg0;
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
619 args[1] = arg1;
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
620 return create_function (name, ret, args);
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
621 }
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
622
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
623 llvm::Function *create_function (const llvm::Twine& name, jit_type *ret,
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
624 jit_type *arg0, jit_type *arg1)
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
625 {
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
626 return create_function (name, ret->to_llvm (), arg0->to_llvm (),
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
627 arg1->to_llvm ());
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
628 }
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
629
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
630 llvm::Function *create_function (const llvm::Twine& name, llvm::Type *ret,
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
631 llvm::Type *arg0, llvm::Type *arg1,
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
632 llvm::Type *arg2)
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
633 {
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
634 std::vector<llvm::Type *> args (3);
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
635 args[0] = arg0;
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
636 args[1] = arg1;
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
637 args[2] = arg2;
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
638 return create_function (name, ret, args);
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
639 }
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
640
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
641 llvm::Function *create_function (const llvm::Twine& name, jit_type *ret,
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
642 jit_type *arg0, jit_type *arg1,
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
643 jit_type *arg2)
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
644 {
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
645 return create_function (name, ret->to_llvm (), arg0->to_llvm (),
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
646 arg1->to_llvm (), arg2->to_llvm ());
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
647 }
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
648
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
649 llvm::Function *create_function (const llvm::Twine& name, llvm::Type *ret,
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
650 llvm::Type *arg0, llvm::Type *arg1,
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
651 llvm::Type *arg2, llvm::Type *arg3)
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
652 {
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
653 std::vector<llvm::Type *> args (4);
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
654 args[0] = arg0;
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
655 args[1] = arg1;
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
656 args[2] = arg2;
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
657 args[3] = arg3;
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
658 return create_function (name, ret, args);
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
659 }
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
660
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
661 llvm::Function *create_function (const llvm::Twine& name, llvm::Type *ret,
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
662 const std::vector<llvm::Type *>& args);
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
663
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
664 llvm::Function *create_identity (jit_type *type);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
665
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
666 llvm::Value *do_insert_error_check (void);
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
667
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
668 static jit_typeinfo *instance;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
669
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
670 llvm::Module *module;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
671 llvm::ExecutionEngine *engine;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
672 int next_id;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
673
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
674 llvm::GlobalVariable *lerror_state;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
675
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
676 std::vector<jit_type*> id_to_type;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
677 jit_type *any;
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
678 jit_type *matrix;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
679 jit_type *scalar;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
680 jit_type *range;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
681 jit_type *string;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
682 jit_type *boolean;
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
683 jit_type *index;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
684
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
685 std::vector<jit_function> binary_ops;
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
686 jit_function grab_fn;
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
687 jit_function release_fn;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
688 jit_function print_fn;
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
689 jit_function for_init_fn;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
690 jit_function for_check_fn;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
691 jit_function for_index_fn;
14943
8efcaf5aa233 Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents: 14942
diff changeset
692 jit_function logically_true_fn;
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
693 jit_function make_range_fn;
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
694 jit_function paren_subsref_fn;
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
695 jit_function paren_subsasgn_fn;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
696
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
697 // type id -> cast function TO that type
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
698 std::vector<jit_function> casts;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
699
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
700 // type id -> identity function
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
701 std::vector<llvm::Function *> identities;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
702 };
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
703
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
704 // The low level octave jit ir
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
705 // this ir is close to llvm, but contains information for doing type inference.
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
706 // We convert the octave parse tree to this IR directly.
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
707
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
708 #define JIT_VISIT_IR_NOTEMPLATE \
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
709 JIT_METH(block); \
14958
4b98b3f66e46 Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents: 14957
diff changeset
710 JIT_METH(branch); \
4b98b3f66e46 Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents: 14957
diff changeset
711 JIT_METH(cond_branch); \
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
712 JIT_METH(call); \
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
713 JIT_METH(extract_argument); \
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
714 JIT_METH(store_argument); \
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
715 JIT_METH(phi); \
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
716 JIT_METH(variable); \
14960
c959136f8c3e Rename jit_check_error to jit_error_check
Max Brister <max@2bass.com>
parents: 14959
diff changeset
717 JIT_METH(error_check); \
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
718 JIT_METH(assign) \
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
719 JIT_METH(argument)
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
720
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
721 #define JIT_VISIT_IR_CONST \
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
722 JIT_METH(const_scalar); \
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
723 JIT_METH(const_index); \
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
724 JIT_METH(const_string); \
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
725 JIT_METH(const_range)
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
726
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
727 #define JIT_VISIT_IR_CLASSES \
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
728 JIT_VISIT_IR_NOTEMPLATE \
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
729 JIT_VISIT_IR_CONST
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
730
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
731 // forward declare all ir classes
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
732 #define JIT_METH(cname) \
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
733 class jit_ ## cname;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
734
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
735 JIT_VISIT_IR_NOTEMPLATE
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
736
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
737 #undef JIT_METH
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
738
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
739 class jit_convert;
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
740
14937
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
741 // ABCs which aren't included in JIT_VISIT_IR_ALL
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
742 class jit_instruction;
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
743 class jit_terminator;
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
744
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
745 template <typename T, jit_type *(*EXTRACT_T)(void), typename PASS_T = T,
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
746 bool QUOTE=false>
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
747 class jit_const;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
748
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
749 typedef jit_const<double, jit_typeinfo::get_scalar> jit_const_scalar;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
750 typedef jit_const<octave_idx_type, jit_typeinfo::get_index> jit_const_index;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
751
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
752 typedef jit_const<std::string, jit_typeinfo::get_string, const std::string&,
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
753 true> jit_const_string;
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
754 typedef jit_const<jit_range, jit_typeinfo::get_range, const jit_range&>
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
755 jit_const_range;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
756
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
757 class jit_ir_walker;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
758 class jit_use;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
759
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
760 class
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
761 jit_value : public jit_internal_list<jit_value, jit_use>
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
762 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
763 public:
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
764 jit_value (void) : llvm_value (0), ty (0), mlast_use (0),
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
765 min_worklist (false) {}
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
766
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
767 virtual ~jit_value (void);
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
768
14946
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
769 bool in_worklist (void) const
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
770 {
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
771 return min_worklist;
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
772 }
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
773
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
774 void stash_in_worklist (bool ain_worklist)
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
775 {
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
776 min_worklist = ain_worklist;
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
777 }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
778
14971
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
779 // The block of the first use which is not a jit_error_check
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
780 // So this is not necessarily first_use ()->parent ().
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
781 jit_block *first_use_block (void);
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
782
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
783 // replace all uses with
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
784 virtual void replace_with (jit_value *value);
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
785
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
786 jit_type *type (void) const { return ty; }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
787
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
788 llvm::Type *type_llvm (void) const
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
789 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
790 return ty ? ty->to_llvm () : 0;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
791 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
792
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
793 const std::string& type_name (void) const
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
794 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
795 return ty->name ();
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
796 }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
797
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
798 void stash_type (jit_type *new_ty) { ty = new_ty; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
799
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
800 std::string print_string (void)
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
801 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
802 std::stringstream ss;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
803 print (ss);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
804 return ss.str ();
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
805 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
806
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
807 jit_instruction *last_use (void) const { return mlast_use; }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
808
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
809 void stash_last_use (jit_instruction *alast_use)
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
810 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
811 mlast_use = alast_use;
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
812 }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
813
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
814 virtual bool needs_release (void) const { return false; }
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
815
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
816 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const = 0;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
817
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
818 virtual std::ostream& short_print (std::ostream& os) const
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
819 { return print (os); }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
820
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
821 virtual void accept (jit_ir_walker& walker) = 0;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
822
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
823 bool has_llvm (void) const
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
824 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
825 return llvm_value;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
826 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
827
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
828 llvm::Value *to_llvm (void) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
829 {
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
830 assert (llvm_value);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
831 return llvm_value;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
832 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
833
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
834 void stash_llvm (llvm::Value *compiled)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
835 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
836 llvm_value = compiled;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
837 }
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
838
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
839 protected:
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
840 std::ostream& print_indent (std::ostream& os, size_t indent = 0) const
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
841 {
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
842 for (size_t i = 0; i < indent * 8; ++i)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
843 os << " ";
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
844 return os;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
845 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
846
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
847 llvm::Value *llvm_value;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
848 private:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
849 jit_type *ty;
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
850 jit_instruction *mlast_use;
14946
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
851 bool min_worklist;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
852 };
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
853
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
854 std::ostream& operator<< (std::ostream& os, const jit_value& value);
14966
b7b647bc4b90 Place releases for temporaries on error
Max Brister <max@2bass.com>
parents: 14965
diff changeset
855 std::ostream& jit_print (std::ostream& os, jit_value *avalue);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
856
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
857 class
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
858 jit_use : public jit_internal_node<jit_value, jit_use>
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
859 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
860 public:
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
861 jit_use (void) : muser (0), mindex (0) {}
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
862
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
863 // we should really have a move operator, but not until c++11 :(
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
864 jit_use (const jit_use& use) : muser (0), mindex (0)
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
865 {
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
866 *this = use;
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
867 }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
868
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
869 jit_use& operator= (const jit_use& use)
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
870 {
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
871 stash_value (use.value (), use.user (), use.index ());
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
872 return *this;
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
873 }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
874
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
875 size_t index (void) const { return mindex; }
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
876
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
877 jit_instruction *user (void) const { return muser; }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
878
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
879 jit_block *user_parent (void) const;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
880
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
881 std::list<jit_block *> user_parent_location (void) const;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
882
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
883 void stash_value (jit_value *avalue, jit_instruction *auser = 0,
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
884 size_t aindex = -1)
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
885 {
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
886 jit_internal_node::stash_value (avalue);
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
887 mindex = aindex;
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
888 muser = auser;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
889 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
890 private:
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
891 jit_instruction *muser;
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
892 size_t mindex;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
893 };
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
894
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
895 class
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
896 jit_instruction : public jit_value
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
897 {
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
898 public:
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
899 // FIXME: this code could be so much pretier with varadic templates...
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
900 jit_instruction (void) : mid (next_id ()), mparent (0)
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
901 {}
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
902
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
903 jit_instruction (size_t nargs)
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
904 : already_infered (nargs, reinterpret_cast<jit_type *>(0)),
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
905 mid (next_id ()), mparent (0)
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
906 {
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
907 marguments.reserve (nargs);
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
908 }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
909
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
910 jit_instruction (jit_value *arg0)
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
911 : already_infered (1, reinterpret_cast<jit_type *>(0)), marguments (1),
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
912 mid (next_id ()), mparent (0)
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
913 {
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
914 stash_argument (0, arg0);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
915 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
916
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
917 jit_instruction (jit_value *arg0, jit_value *arg1)
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
918 : already_infered (2, reinterpret_cast<jit_type *>(0)), marguments (2),
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
919 mid (next_id ()), mparent (0)
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
920 {
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
921 stash_argument (0, arg0);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
922 stash_argument (1, arg1);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
923 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
924
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
925 jit_instruction (jit_value *arg0, jit_value *arg1, jit_value *arg2)
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
926 : already_infered (3, reinterpret_cast<jit_type *>(0)), marguments (3),
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
927 mid (next_id ()), mparent (0)
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
928 {
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
929 stash_argument (0, arg0);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
930 stash_argument (1, arg1);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
931 stash_argument (2, arg2);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
932 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
933
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
934 jit_instruction (jit_value *arg0, jit_value *arg1, jit_value *arg2,
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
935 jit_value *arg3)
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
936 : already_infered (3, reinterpret_cast<jit_type *>(0)), marguments (4),
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
937 mid (next_id ()), mparent (0)
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
938 {
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
939 stash_argument (0, arg0);
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
940 stash_argument (1, arg1);
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
941 stash_argument (2, arg2);
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
942 stash_argument (3, arg3);
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
943 }
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
944
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
945 static void reset_ids (void)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
946 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
947 next_id (true);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
948 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
949
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
950 jit_value *argument (size_t i) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
951 {
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
952 return marguments[i].value ();
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
953 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
954
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
955 llvm::Value *argument_llvm (size_t i) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
956 {
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
957 assert (argument (i));
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
958 return argument (i)->to_llvm ();
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
959 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
960
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
961 jit_type *argument_type (size_t i) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
962 {
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
963 return argument (i)->type ();
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
964 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
965
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
966 llvm::Type *argument_type_llvm (size_t i) const
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
967 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
968 assert (argument (i));
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
969 return argument_type (i)->to_llvm ();
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
970 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
971
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
972 std::ostream& print_argument (std::ostream& os, size_t i) const
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
973 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
974 if (argument (i))
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
975 return argument (i)->short_print (os);
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
976 else
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
977 return os << "NULL";
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
978 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
979
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
980 void stash_argument (size_t i, jit_value *arg)
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
981 {
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
982 marguments[i].stash_value (arg, this, i);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
983 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
984
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
985 void push_argument (jit_value *arg)
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
986 {
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
987 marguments.push_back (jit_use ());
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
988 stash_argument (marguments.size () - 1, arg);
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
989 already_infered.push_back (0);
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
990 }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
991
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
992 size_t argument_count (void) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
993 {
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
994 return marguments.size ();
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
995 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
996
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
997 void resize_arguments (size_t acount, jit_value *adefault = 0)
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
998 {
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
999 size_t old = marguments.size ();
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1000 marguments.resize (acount);
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1001 already_infered.resize (acount);
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
1002
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
1003 if (adefault)
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
1004 for (size_t i = old; i < acount; ++i)
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
1005 stash_argument (i, adefault);
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
1006 }
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
1007
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1008 const std::vector<jit_use>& arguments (void) const { return marguments; }
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1009
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1010 // argument types which have been infered already
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1011 const std::vector<jit_type *>& argument_types (void) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1012 { return already_infered; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1013
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1014 virtual void push_variable (void) {}
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1015
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1016 virtual void pop_variable (void) {}
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1017
14962
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1018 virtual void construct_ssa (void)
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1019 {
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1020 do_construct_ssa (0, argument_count ());
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1021 }
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1022
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1023 virtual bool infer (void) { return false; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1024
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1025 void remove (void);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1026
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1027 virtual std::ostream& short_print (std::ostream& os) const;
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1028
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1029 jit_block *parent (void) const { return mparent; }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1030
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1031 std::list<jit_instruction *>::iterator location (void) const
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1032 {
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1033 return mlocation;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1034 }
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1035
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1036 llvm::BasicBlock *parent_llvm (void) const;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1037
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1038 void stash_parent (jit_block *aparent,
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1039 std::list<jit_instruction *>::iterator alocation)
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1040 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1041 mparent = aparent;
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1042 mlocation = alocation;
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1043 }
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1044
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1045 size_t id (void) const { return mid; }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1046 protected:
14962
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1047
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1048 // Do SSA replacement on arguments in [start, end)
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1049 void do_construct_ssa (size_t start, size_t end);
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1050
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1051 std::vector<jit_type *> already_infered;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1052 private:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1053 static size_t next_id (bool reset = false)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1054 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1055 static size_t ret = 0;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1056 if (reset)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1057 return ret = 0;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1058
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1059 return ret++;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1060 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1061
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1062 std::vector<jit_use> marguments;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1063
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1064 size_t mid;
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1065 jit_block *mparent;
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1066 std::list<jit_instruction *>::iterator mlocation;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1067 };
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1068
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1069 // defnie accept methods for subclasses
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1070 #define JIT_VALUE_ACCEPT \
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1071 virtual void accept (jit_ir_walker& walker);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1072
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1073 // for use as a dummy argument during conversion to LLVM
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1074 class
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1075 jit_argument : public jit_value
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1076 {
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1077 public:
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1078 jit_argument (jit_type *atype, llvm::Value *avalue)
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1079 {
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1080 stash_type (atype);
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1081 stash_llvm (avalue);
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1082 }
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1083
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1084 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1085 {
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1086 print_indent (os, indent);
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1087 return jit_print (os, type ()) << ": DUMMY";
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1088 }
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1089
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1090 JIT_VALUE_ACCEPT;
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1091 };
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1092
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1093 template <typename T, jit_type *(*EXTRACT_T)(void), typename PASS_T,
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1094 bool QUOTE>
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1095 class
14944
c0a5ab3b9278 jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents: 14943
diff changeset
1096 jit_const : public jit_value
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1097 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1098 public:
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1099 typedef PASS_T pass_t;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1100
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1101 jit_const (PASS_T avalue) : mvalue (avalue)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1102 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1103 stash_type (EXTRACT_T ());
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1104 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1105
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1106 PASS_T value (void) const { return mvalue; }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1107
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1108 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1109 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1110 print_indent (os, indent);
14944
c0a5ab3b9278 jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents: 14943
diff changeset
1111 jit_print (os, type ()) << ": ";
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1112 if (QUOTE)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1113 os << "\"";
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1114 os << mvalue;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1115 if (QUOTE)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1116 os << "\"";
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1117 return os;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1118 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1119
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1120 JIT_VALUE_ACCEPT;
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1121 private:
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1122 T mvalue;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1123 };
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1124
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1125 class jit_phi_incomming;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1126
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1127 class
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
1128 jit_block : public jit_value, public jit_internal_list<jit_block,
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
1129 jit_phi_incomming>
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1130 {
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1131 typedef jit_internal_list<jit_block, jit_phi_incomming> ILIST_T;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1132 public:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1133 typedef std::list<jit_instruction *> instruction_list;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1134 typedef instruction_list::iterator iterator;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1135 typedef instruction_list::const_iterator const_iterator;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1136
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1137 typedef std::set<jit_block *> df_set;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1138 typedef df_set::const_iterator df_iterator;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1139
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1140 static const size_t NO_ID = static_cast<size_t> (-1);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1141
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1142 jit_block (const std::string& aname, size_t avisit_count = 0)
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1143 : mvisit_count (avisit_count), mid (NO_ID), idom (0), mname (aname),
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1144 malive (false)
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1145 {}
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1146
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1147 virtual void replace_with (jit_value *value);
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1148
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1149 void replace_in_phi (jit_block *ablock, jit_block *with);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1150
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1151 // we have a new internal list, but we want to stay compatable with jit_value
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1152 jit_use *first_use (void) const { return jit_value::first_use (); }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1153
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1154 size_t use_count (void) const { return jit_value::use_count (); }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1155
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1156 // if a block is alive, then it might be visited during execution
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1157 bool alive (void) const { return malive; }
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1158
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1159 void mark_alive (void) { malive = true; }
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1160
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1161 // If we can merge with a successor, do so and return the now empty block
14939
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1162 jit_block *maybe_merge ();
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1163
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1164 // merge another block into this block, leaving the merge block empty
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1165 void merge (jit_block& merge);
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1166
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1167 const std::string& name (void) const { return mname; }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1168
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1169 jit_instruction *prepend (jit_instruction *instr);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1170
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1171 jit_instruction *prepend_after_phi (jit_instruction *instr);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1172
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1173 template <typename T>
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1174 T *append (T *instr)
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1175 {
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1176 internal_append (instr);
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1177 return instr;
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1178 }
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1179
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1180 jit_instruction *insert_before (iterator loc, jit_instruction *instr);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1181
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1182 jit_instruction *insert_before (jit_instruction *loc, jit_instruction *instr)
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1183 {
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1184 return insert_before (loc->location (), instr);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1185 }
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1186
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1187 jit_instruction *insert_after (iterator loc, jit_instruction *instr);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1188
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1189 jit_instruction *insert_after (jit_instruction *loc, jit_instruction *instr)
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1190 {
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1191 return insert_after (loc->location (), instr);
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
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1194 iterator remove (iterator iter)
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1195 {
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1196 jit_instruction *instr = *iter;
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1197 iter = instructions.erase (iter);
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1198 instr->stash_parent (0, instructions.end ());
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1199 return iter;
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1200 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1201
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1202 jit_terminator *terminator (void) const;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1203
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1204 // is the jump from pred alive?
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1205 bool branch_alive (jit_block *asucc) const;
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1206
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1207 jit_block *successor (size_t i) const;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1208
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1209 size_t successor_count (void) const;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1210
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1211 iterator begin (void) { return instructions.begin (); }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1212
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1213 const_iterator begin (void) const { return instructions.begin (); }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1214
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1215 iterator end (void) { return instructions.end (); }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1216
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1217 const_iterator end (void) const { return instructions.end (); }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1218
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1219 iterator phi_begin (void);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1220
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1221 iterator phi_end (void);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1222
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1223 iterator nonphi_begin (void);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1224
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1225 // must label before id is valid
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1226 size_t id (void) const { return mid; }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1227
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1228 // dominance frontier
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1229 const df_set& df (void) const { return mdf; }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1230
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1231 df_iterator df_begin (void) const { return mdf.begin (); }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1232
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1233 df_iterator df_end (void) const { return mdf.end (); }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1234
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1235 // label with a RPO walk
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1236 void label (void)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1237 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1238 size_t number = 0;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1239 label (mvisit_count, number);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1240 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1241
14971
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1242 void label (size_t avisit_count, size_t& number)
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1243 {
14971
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1244 if (visited (avisit_count))
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1245 return;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1246
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1247 for (jit_use *use = first_use (); use; use = use->next ())
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1248 {
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1249 jit_block *pred = use->user_parent ();
14971
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1250 pred->label (avisit_count, number);
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1251 }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1252
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1253 mid = number++;
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1254 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1255
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1256 // See for idom computation algorithm
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1257 // Cooper, Keith D.; Harvey, Timothy J; and Kennedy, Ken (2001).
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1258 // "A Simple, Fast Dominance Algorithm"
14939
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1259 void compute_idom (jit_block *entry_block)
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1260 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1261 bool changed;
14939
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1262 entry_block->idom = entry_block;
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1263 do
14939
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1264 changed = update_idom (mvisit_count);
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1265 while (changed);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1266 }
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
1267
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1268 // compute dominance frontier
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1269 void compute_df (void)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1270 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1271 compute_df (mvisit_count);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1272 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1273
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1274 void create_dom_tree (void)
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1275 {
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1276 create_dom_tree (mvisit_count);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1277 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1278
14971
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1279 jit_block *dom_successor (size_t idx) const
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1280 {
14971
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1281 return dom_succ[idx];
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1282 }
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1283
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1284 size_t dom_successor_count (void) const
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1285 {
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1286 return dom_succ.size ();
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1287 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1288
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1289 // call pop_varaible on all instructions
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1290 void pop_all (void);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1291
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1292 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1293 {
14939
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1294 print_indent (os, indent);
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1295 short_print (os) << ": %pred = ";
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1296 for (jit_use *use = first_use (); use; use = use->next ())
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1297 {
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1298 jit_block *pred = use->user_parent ();
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1299 os << *pred;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1300 if (use->next ())
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1301 os << ", ";
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 os << std::endl;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1304
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1305 for (const_iterator iter = begin (); iter != end (); ++iter)
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1306 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1307 jit_instruction *instr = *iter;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1308 instr->print (os, indent + 1) << std::endl;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1309 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1310 return os;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1311 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1312
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1313 // ...
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1314 jit_block *maybe_split (jit_convert& convert, jit_block *asuccessor);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1315
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1316 jit_block *maybe_split (jit_convert& convert, jit_block& asuccessor)
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1317 {
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1318 return maybe_split (convert, &asuccessor);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1319 }
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1320
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1321 // print dominator infomration
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1322 std::ostream& print_dom (std::ostream& os) const;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1323
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1324 virtual std::ostream& short_print (std::ostream& os) const
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1325 {
14939
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1326 os << mname;
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1327 if (mid != NO_ID)
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1328 os << mid;
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1329 return os;
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1330 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1331
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1332 llvm::BasicBlock *to_llvm (void) const;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1333
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1334 std::list<jit_block *>::iterator location (void) const
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1335 { return mlocation; }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1336
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1337 void stash_location (std::list<jit_block *>::iterator alocation)
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1338 { mlocation = alocation; }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1339
14971
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1340 // used to prevent visiting the same node twice in the graph
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1341 size_t visit_count (void) const { return mvisit_count; }
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1342
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1343 // check if this node has been visited yet at the given visit count. If we
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1344 // have not been visited yet, mark us as visited.
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1345 bool visited (size_t avisit_count)
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1346 {
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1347 if (mvisit_count <= avisit_count)
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1348 {
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1349 mvisit_count = avisit_count + 1;
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1350 return false;
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1351 }
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1352
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1353 return true;
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1354 }
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1355
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1356 JIT_VALUE_ACCEPT;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1357 private:
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1358 void internal_append (jit_instruction *instr);
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1359
14971
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1360 void compute_df (size_t avisit_count);
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1361
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1362 bool update_idom (size_t avisit_count);
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1363
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
1364 void create_dom_tree (size_t avisit_count);
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1365
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1366 jit_block *idom_intersect (jit_block *b);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1367
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1368 size_t mvisit_count;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1369 size_t mid;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1370 jit_block *idom;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1371 df_set mdf;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1372 std::vector<jit_block *> dom_succ;
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1373 std::string mname;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1374 instruction_list instructions;
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1375 bool malive;
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1376 std::list<jit_block *>::iterator mlocation;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1377 };
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1378
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1379 // keeps track of phi functions that use a block on incomming edges
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1380 class
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1381 jit_phi_incomming : public jit_internal_node<jit_block, jit_phi_incomming>
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1382 {
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1383 public:
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1384 jit_phi_incomming (void) : muser (0) {}
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1385
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1386 jit_phi_incomming (jit_phi *auser) : muser (auser) {}
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1387
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1388 jit_phi_incomming (const jit_phi_incomming& use) : jit_internal_node ()
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1389 {
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1390 *this = use;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1391 }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1392
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1393 jit_phi_incomming& operator= (const jit_phi_incomming& use)
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1394 {
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1395 stash_value (use.value ());
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1396 muser = use.muser;
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1397 return *this;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1398 }
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1399
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1400 jit_phi *user (void) const { return muser; }
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1401
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1402 jit_block *user_parent (void) const;
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1403 private:
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1404 jit_phi *muser;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1405 };
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1406
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1407 // A non-ssa variable
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1408 class
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1409 jit_variable : public jit_value
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1410 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1411 public:
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1412 jit_variable (const std::string& aname) : mname (aname), mlast_use (0) {}
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1413
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1414 const std::string &name (void) const { return mname; }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1415
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1416 // manipulate the value_stack, for use during SSA construction. The top of the
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1417 // value stack represents the current value for this variable
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1418 bool has_top (void) const
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1419 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1420 return ! value_stack.empty ();
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1421 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1422
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1423 jit_value *top (void) const
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1424 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1425 return value_stack.top ();
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1426 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1427
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1428 void push (jit_instruction *v)
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1429 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1430 value_stack.push (v);
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1431 mlast_use = v;
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1432 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1433
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1434 void pop (void)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1435 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1436 value_stack.pop ();
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1437 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1438
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1439 jit_instruction *last_use (void) const
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1440 {
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1441 return mlast_use;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1442 }
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1443
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1444 void stash_last_use (jit_instruction *instr)
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1445 {
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1446 mlast_use = instr;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1447 }
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1448
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1449 // blocks in which we are used
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1450 void use_blocks (jit_block::df_set& result)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1451 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1452 jit_use *use = first_use ();
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1453 while (use)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1454 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1455 result.insert (use->user_parent ());
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1456 use = use->next ();
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1457 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1458 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1459
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1460 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1461 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1462 return print_indent (os, indent) << mname;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1463 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1464
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1465 JIT_VALUE_ACCEPT;
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1466 private:
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1467 std::string mname;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1468 std::stack<jit_value *> value_stack;
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1469 jit_instruction *mlast_use;
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1470 };
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1471
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1472 class
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1473 jit_assign_base : public jit_instruction
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1474 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1475 public:
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1476 jit_assign_base (jit_variable *adest) : jit_instruction (), mdest (adest) {}
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1477
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1478 jit_assign_base (jit_variable *adest, size_t npred) : jit_instruction (npred),
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1479 mdest (adest) {}
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1480
14965
f2117a963c54 Place grab/release for assignments
Max Brister <max@2bass.com>
parents: 14963
diff changeset
1481 jit_assign_base (jit_variable *adest, jit_value *arg0, jit_value *arg1)
f2117a963c54 Place grab/release for assignments
Max Brister <max@2bass.com>
parents: 14963
diff changeset
1482 : jit_instruction (arg0, arg1), mdest (adest) {}
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1483
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1484 jit_variable *dest (void) const { return mdest; }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1485
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1486 virtual void push_variable (void)
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1487 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1488 mdest->push (this);
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1489 }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1490
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1491 virtual void pop_variable (void)
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1492 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1493 mdest->pop ();
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1494 }
14962
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1495
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1496 virtual std::ostream& short_print (std::ostream& os) const
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1497 {
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1498 if (type ())
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1499 jit_print (os, type ()) << ": ";
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1500
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1501 dest ()->short_print (os);
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1502 return os << "#" << id ();
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1503 }
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1504 private:
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1505 jit_variable *mdest;
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1506 };
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1507
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1508 class
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1509 jit_assign : public jit_assign_base
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1510 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1511 public:
14944
c0a5ab3b9278 jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents: 14943
diff changeset
1512 jit_assign (jit_variable *adest, jit_value *asrc)
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
1513 : jit_assign_base (adest, adest, asrc), martificial (false) {}
14965
f2117a963c54 Place grab/release for assignments
Max Brister <max@2bass.com>
parents: 14963
diff changeset
1514
f2117a963c54 Place grab/release for assignments
Max Brister <max@2bass.com>
parents: 14963
diff changeset
1515 jit_value *overwrite (void) const
f2117a963c54 Place grab/release for assignments
Max Brister <max@2bass.com>
parents: 14963
diff changeset
1516 {
f2117a963c54 Place grab/release for assignments
Max Brister <max@2bass.com>
parents: 14963
diff changeset
1517 return argument (0);
f2117a963c54 Place grab/release for assignments
Max Brister <max@2bass.com>
parents: 14963
diff changeset
1518 }
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1519
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1520 jit_value *src (void) const
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1521 {
14965
f2117a963c54 Place grab/release for assignments
Max Brister <max@2bass.com>
parents: 14963
diff changeset
1522 return argument (1);
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1523 }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1524
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
1525 // variables don't get modified in an SSA, but COW requires we modify
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
1526 // variables. An artificial assign is for when a variable gets modified. We
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
1527 // need an assign in the SSA, but the reference counts shouldn't be updated.
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
1528 bool artificial (void) const { return martificial; }
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
1529
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
1530 void mark_artificial (void) { martificial = true; }
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
1531
14962
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1532 virtual bool infer (void)
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1533 {
14962
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1534 jit_type *stype = src ()->type ();
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1535 if (stype != type())
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1536 {
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1537 stash_type (stype);
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1538 return true;
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1539 }
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1540
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1541 return false;
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1542 }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1543
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1544 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1545 {
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
1546 print_indent (os, indent) << *this << " = " << *src ();
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
1547
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
1548 if (artificial ())
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
1549 os << " [artificial]";
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
1550
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
1551 return os;
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1552 }
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1553
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1554 JIT_VALUE_ACCEPT;
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
1555 private:
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
1556 bool martificial;
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1557 };
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1558
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1559 class
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1560 jit_phi : public jit_assign_base
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1561 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1562 public:
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1563 jit_phi (jit_variable *adest, size_t npred)
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1564 : jit_assign_base (adest, npred)
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1565 {
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1566 mincomming.reserve (npred);
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1567 }
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1568
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1569 // removes arguments form dead incomming jumps
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1570 bool prune (void);
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1571
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1572 void add_incomming (jit_block *from, jit_value *value)
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1573 {
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1574 push_argument (value);
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1575 mincomming.push_back (jit_phi_incomming (this));
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1576 mincomming[mincomming.size () - 1].stash_value (from);
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1577 }
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1578
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1579 jit_block *incomming (size_t i) const
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1580 {
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1581 return mincomming[i].value ();
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1582 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1583
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1584 llvm::BasicBlock *incomming_llvm (size_t i) const
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1585 {
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1586 return incomming (i)->to_llvm ();
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1587 }
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1588
14962
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1589 virtual void construct_ssa (void) {}
90a7a2af2cd5 Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents: 14961
diff changeset
1590
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1591 virtual bool infer (void);
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1592
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1593 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1594 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1595 std::stringstream ss;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1596 print_indent (ss, indent);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1597 short_print (ss) << " phi ";
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1598 std::string ss_str = ss.str ();
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1599 std::string indent_str (ss_str.size (), ' ');
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1600 os << ss_str;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1601
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1602 for (size_t i = 0; i < argument_count (); ++i)
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1603 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1604 if (i > 0)
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1605 os << indent_str;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1606 os << "| ";
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1607
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1608 os << *incomming (i) << " -> ";
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1609 os << *argument (i);
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1610
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1611 if (i + 1 < argument_count ())
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1612 os << std::endl;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1613 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1614
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1615 return os;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1616 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1617
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1618 llvm::PHINode *to_llvm (void) const;
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1619
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1620 JIT_VALUE_ACCEPT;
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1621 private:
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1622 std::vector<jit_phi_incomming> mincomming;
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1623 };
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1624
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1625 class
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1626 jit_terminator : public jit_instruction
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1627 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1628 public:
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1629 jit_terminator (size_t asuccessor_count, jit_value *arg0)
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1630 : jit_instruction (arg0), malive (asuccessor_count, false),
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1631 mbranch_llvm (asuccessor_count, 0) {}
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1632
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1633 jit_terminator (size_t asuccessor_count, jit_value *arg0, jit_value *arg1)
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1634 : jit_instruction (arg0, arg1), malive (asuccessor_count, false),
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1635 mbranch_llvm (asuccessor_count, 0) {}
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1636
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1637 jit_terminator (size_t asuccessor_count, jit_value *arg0, jit_value *arg1,
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1638 jit_value *arg2)
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1639 : jit_instruction (arg0, arg1, arg2), malive (asuccessor_count, false),
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1640 mbranch_llvm (asuccessor_count, 0) {}
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1641
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1642 jit_block *successor (size_t idx = 0) const
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1643 {
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1644 return static_cast<jit_block *> (argument (idx));
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1645 }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1646
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1647 // the llvm block between our parent and the given successor
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1648 llvm::BasicBlock *branch_llvm (size_t idx = 0) const
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1649 {
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1650 return mbranch_llvm[idx] ? mbranch_llvm[idx] : parent ()->to_llvm ();
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1651 }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1652
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1653 llvm::BasicBlock *branch_llvm (int idx) const
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1654 {
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1655 return branch_llvm (static_cast<size_t> (idx));
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1656 }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1657
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1658 llvm::BasicBlock *branch_llvm (const jit_block *asuccessor) const
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1659 {
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1660 return branch_llvm (successor_index (asuccessor));
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1661 }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1662
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1663 llvm::BasicBlock *successor_llvm (size_t idx = 0) const
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1664 {
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1665 return mbranch_llvm[idx] ? mbranch_llvm[idx] : successor (idx)->to_llvm ();
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1666 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1667
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1668 size_t successor_index (const jit_block *asuccessor) const;
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1669
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1670 std::ostream& print_successor (std::ostream& os, size_t idx = 0) const
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1671 {
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1672 if (alive (idx))
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1673 os << "[live] ";
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1674 else
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1675 os << "[dead] ";
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1676
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1677 return successor (idx)->short_print (os);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1678 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1679
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1680 // Check if the jump to successor is live
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1681 bool alive (const jit_block *asuccessor) const
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1682 {
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1683 return alive (successor_index (asuccessor));
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1684 }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1685
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1686 bool alive (size_t idx) const { return malive[idx]; }
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1687
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1688 bool alive (int idx) const { return malive[idx]; }
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1689
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1690 size_t successor_count (void) const { return malive.size (); }
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1691
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1692 virtual bool infer (void);
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1693
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1694 llvm::TerminatorInst *to_llvm (void) const;
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1695 protected:
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1696 virtual bool check_alive (size_t) const { return true; }
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1697 private:
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1698 std::vector<bool> malive;
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1699 std::vector<llvm::BasicBlock *> mbranch_llvm;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1700 };
14913
c7071907a641 Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents: 14911
diff changeset
1701
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1702 class
14958
4b98b3f66e46 Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents: 14957
diff changeset
1703 jit_branch : public jit_terminator
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1704 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1705 public:
14958
4b98b3f66e46 Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents: 14957
diff changeset
1706 jit_branch (jit_block *succ) : jit_terminator (1, succ) {}
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1707
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1708 virtual size_t successor_count (void) const { return 1; }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1709
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1710 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1711 {
14958
4b98b3f66e46 Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents: 14957
diff changeset
1712 print_indent (os, indent) << "branch: ";
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1713 return print_successor (os);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1714 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1715
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1716 JIT_VALUE_ACCEPT;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1717 };
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1718
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1719 class
14958
4b98b3f66e46 Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents: 14957
diff changeset
1720 jit_cond_branch : public jit_terminator
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1721 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1722 public:
14958
4b98b3f66e46 Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents: 14957
diff changeset
1723 jit_cond_branch (jit_value *c, jit_block *ctrue, jit_block *cfalse)
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1724 : jit_terminator (2, ctrue, cfalse, c) {}
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1725
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1726 jit_value *cond (void) const { return argument (2); }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1727
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1728 std::ostream& print_cond (std::ostream& os) const
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1729 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1730 return cond ()->short_print (os);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1731 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1732
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1733 llvm::Value *cond_llvm (void) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1734 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1735 return cond ()->to_llvm ();
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1736 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1737
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1738 virtual size_t successor_count (void) const { return 2; }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1739
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1740 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1741 {
14958
4b98b3f66e46 Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents: 14957
diff changeset
1742 print_indent (os, indent) << "cond_branch: ";
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1743 print_cond (os) << ", ";
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1744 print_successor (os, 0) << ", ";
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1745 return print_successor (os, 1);
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1746 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1747
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1748 JIT_VALUE_ACCEPT;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1749 };
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1750
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1751 class
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1752 jit_call : public jit_instruction
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1753 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1754 public:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1755 jit_call (const jit_function& afunction,
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1756 jit_value *arg0) : jit_instruction (arg0), mfunction (afunction)
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1757 {}
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1758
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1759 jit_call (const jit_function& (*afunction) (void),
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
1760 jit_value *arg0) : jit_instruction (arg0),
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
1761 mfunction (afunction ()) {}
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1762
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1763 jit_call (const jit_function& afunction,
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1764 jit_value *arg0, jit_value *arg1) : jit_instruction (arg0, arg1),
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1765 mfunction (afunction) {}
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1766
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1767 jit_call (const jit_function& (*afunction) (void),
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1768 jit_value *arg0, jit_value *arg1) : jit_instruction (arg0, arg1),
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1769 mfunction (afunction ()) {}
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1770
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1771 jit_call (const jit_function& (*afunction) (void),
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1772 jit_value *arg0, jit_value *arg1, jit_value *arg2)
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1773 : jit_instruction (arg0, arg1, arg2), mfunction (afunction ()) {}
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1774
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1775 jit_call (const jit_function& (*afunction) (void),
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1776 jit_value *arg0, jit_value *arg1, jit_value *arg2, jit_value *arg3)
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1777 : jit_instruction (arg0, arg1, arg2, arg3), mfunction (afunction ()) {}
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
1778
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1779
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1780 const jit_function& function (void) const { return mfunction; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1781
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1782 bool can_error (void) const
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1783 {
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1784 return overload ().can_error;
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1785 }
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1786
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1787 const jit_function::overload& overload (void) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1788 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1789 return mfunction.get_overload (argument_types ());
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1790 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1791
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1792 virtual bool needs_release (void) const
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1793 {
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1794 return type () && jit_typeinfo::get_release (type ()).function;
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1795 }
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
1796
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1797 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1798 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1799 print_indent (os, indent);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1800
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1801 if (use_count ())
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1802 short_print (os) << " = ";
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1803 os << "call " << mfunction.name () << " (";
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1804
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1805 for (size_t i = 0; i < argument_count (); ++i)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1806 {
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1807 print_argument (os, i);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1808 if (i + 1 < argument_count ())
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1809 os << ", ";
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1810 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1811 return os << ")";
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1812 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1813
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1814 virtual bool infer (void);
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1815
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1816 JIT_VALUE_ACCEPT;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1817 private:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1818 const jit_function& mfunction;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1819 };
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1820
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1821 // FIXME: This is just ugly...
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1822 // checks error_state, if error_state is false then goto the normal branche,
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1823 // otherwise goto the error branch
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1824 class
14960
c959136f8c3e Rename jit_check_error to jit_error_check
Max Brister <max@2bass.com>
parents: 14959
diff changeset
1825 jit_error_check : public jit_terminator
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1826 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1827 public:
14960
c959136f8c3e Rename jit_check_error to jit_error_check
Max Brister <max@2bass.com>
parents: 14959
diff changeset
1828 jit_error_check (jit_call *acheck_for, jit_block *normal, jit_block *error)
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1829 : jit_terminator (2, error, normal, acheck_for) {}
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1830
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1831 jit_call *check_for (void) const
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1832 {
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1833 return static_cast<jit_call *> (argument (2));
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1834 }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1835
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1836 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1837 {
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1838 print_indent (os, indent) << "error_check " << *check_for () << ", ";
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1839 print_successor (os, 1) << ", ";
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1840 return print_successor (os, 0);
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1841 }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1842
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1843 JIT_VALUE_ACCEPT;
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1844 protected:
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1845 virtual bool check_alive (size_t idx) const
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1846 {
14948
006570a76b90 Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents: 14946
diff changeset
1847 return idx == 1 ? true : check_for ()->can_error ();
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1848 }
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1849 };
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1850
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1851 class
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1852 jit_extract_argument : public jit_assign_base
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1853 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1854 public:
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1855 jit_extract_argument (jit_type *atype, jit_variable *adest)
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1856 : jit_assign_base (adest)
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1857 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1858 stash_type (atype);
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1859 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1860
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1861 const std::string& name (void) const
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1862 {
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1863 return dest ()->name ();
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1864 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1865
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1866 const jit_function::overload& overload (void) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1867 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1868 return jit_typeinfo::cast (type (), jit_typeinfo::get_any ());
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1869 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1870
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1871 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1872 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1873 print_indent (os, indent);
14942
e8487d98561c Improve printing of jit_extract_argument
Max Brister <max@2bass.com>
parents: 14941
diff changeset
1874
e8487d98561c Improve printing of jit_extract_argument
Max Brister <max@2bass.com>
parents: 14941
diff changeset
1875 return short_print (os) << " = extract " << name ();
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1876 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1877
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1878 JIT_VALUE_ACCEPT;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1879 };
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1880
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1881 class
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1882 jit_store_argument : public jit_instruction
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1883 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1884 public:
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1885 jit_store_argument (jit_variable *var)
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1886 : jit_instruction (var), dest (var)
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1887 {}
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1888
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1889 const std::string& name (void) const
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1890 {
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1891 return dest->name ();
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1892 }
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1893
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1894 const jit_function::overload& overload (void) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1895 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1896 return jit_typeinfo::cast (jit_typeinfo::get_any (), result_type ());
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1897 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1898
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1899 jit_value *result (void) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1900 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1901 return argument (0);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1902 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1903
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1904 jit_type *result_type (void) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1905 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1906 return result ()->type ();
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1907 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1908
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1909 llvm::Value *result_llvm (void) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1910 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1911 return result ()->to_llvm ();
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1912 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1913
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
1914 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1915 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1916 jit_value *res = result ();
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1917 print_indent (os, indent) << "store ";
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1918 dest->short_print (os);
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1919
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1920 if (! isa<jit_variable> (res))
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1921 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1922 os << " = ";
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1923 res->short_print (os);
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1924 }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1925
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1926 return os;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1927 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1928
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
1929 JIT_VALUE_ACCEPT;
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1930 private:
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1931 jit_variable *dest;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1932 };
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1933
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1934 class
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1935 jit_ir_walker
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1936 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1937 public:
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1938 virtual ~jit_ir_walker () {}
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1939
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1940 #define JIT_METH(clname) \
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1941 virtual void visit (jit_ ## clname&) = 0;
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1942
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1943 JIT_VISIT_IR_CLASSES;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1944
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1945 #undef JIT_METH
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1946 };
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1947
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1948 template <typename T, jit_type *(*EXTRACT_T)(void), typename PASS_T, bool QUOTE>
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1949 void
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1950 jit_const<T, EXTRACT_T, PASS_T, QUOTE>::accept (jit_ir_walker& walker)
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1951 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1952 walker.visit (*this);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1953 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1954
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1955 // convert between IRs
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1956 // FIXME: Class relationships are messy from here on down. They need to be
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1957 // cleaned up.
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1958 class
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1959 jit_convert : public tree_walker
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1960 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1961 public:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1962 typedef std::pair<jit_type *, std::string> type_bound;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1963 typedef std::vector<type_bound> type_bound_vector;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1964
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1965 jit_convert (llvm::Module *module, tree &tee);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1966
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1967 ~jit_convert (void);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1968
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1969 llvm::Function *get_function (void) const { return function; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1970
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1971 const std::vector<std::pair<std::string, bool> >& get_arguments(void) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1972 { return arguments; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1973
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1974 const type_bound_vector& get_bounds (void) const { return bounds; }
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1975
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1976 void visit_anon_fcn_handle (tree_anon_fcn_handle&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1977
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1978 void visit_argument_list (tree_argument_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1979
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1980 void visit_binary_expression (tree_binary_expression&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1981
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1982 void visit_break_command (tree_break_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1983
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1984 void visit_colon_expression (tree_colon_expression&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1985
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1986 void visit_continue_command (tree_continue_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1987
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1988 void visit_global_command (tree_global_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1989
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1990 void visit_persistent_command (tree_persistent_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1991
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1992 void visit_decl_elt (tree_decl_elt&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1993
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1994 void visit_decl_init_list (tree_decl_init_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1995
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1996 void visit_simple_for_command (tree_simple_for_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1997
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1998 void visit_complex_for_command (tree_complex_for_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1999
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2000 void visit_octave_user_script (octave_user_script&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2001
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2002 void visit_octave_user_function (octave_user_function&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2003
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2004 void visit_octave_user_function_header (octave_user_function&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2005
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2006 void visit_octave_user_function_trailer (octave_user_function&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2007
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2008 void visit_function_def (tree_function_def&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2009
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2010 void visit_identifier (tree_identifier&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2011
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2012 void visit_if_clause (tree_if_clause&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2013
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2014 void visit_if_command (tree_if_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2015
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2016 void visit_if_command_list (tree_if_command_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2017
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2018 void visit_index_expression (tree_index_expression&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2019
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2020 void visit_matrix (tree_matrix&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2021
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2022 void visit_cell (tree_cell&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2023
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2024 void visit_multi_assignment (tree_multi_assignment&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2025
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2026 void visit_no_op_command (tree_no_op_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2027
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2028 void visit_constant (tree_constant&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2029
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2030 void visit_fcn_handle (tree_fcn_handle&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2031
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2032 void visit_parameter_list (tree_parameter_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2033
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2034 void visit_postfix_expression (tree_postfix_expression&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2035
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2036 void visit_prefix_expression (tree_prefix_expression&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2037
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2038 void visit_return_command (tree_return_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2039
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2040 void visit_return_list (tree_return_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2041
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2042 void visit_simple_assignment (tree_simple_assignment&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2043
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2044 void visit_statement (tree_statement&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2045
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2046 void visit_statement_list (tree_statement_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2047
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2048 void visit_switch_case (tree_switch_case&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2049
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2050 void visit_switch_case_list (tree_switch_case_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2051
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2052 void visit_switch_command (tree_switch_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2053
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2054 void visit_try_catch_command (tree_try_catch_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2055
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2056 void visit_unwind_protect_command (tree_unwind_protect_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2057
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2058 void visit_while_command (tree_while_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2059
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2060 void visit_do_until_command (tree_do_until_command&);
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
2061
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2062 // this would be easier with variadic templates
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2063 template <typename T>
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2064 T *create (void)
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2065 {
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2066 T *ret = new T();
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2067 track_value (ret);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2068 return ret;
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2069 }
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2070
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2071 template <typename T, typename ARG0>
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2072 T *create (const ARG0& arg0)
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2073 {
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2074 T *ret = new T(arg0);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2075 track_value (ret);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2076 return ret;
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2077 }
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2078
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2079 template <typename T, typename ARG0, typename ARG1>
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2080 T *create (const ARG0& arg0, const ARG1& arg1)
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2081 {
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2082 T *ret = new T(arg0, arg1);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2083 track_value (ret);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2084 return ret;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2085 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2086
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2087 template <typename T, typename ARG0, typename ARG1, typename ARG2>
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2088 T *create (const ARG0& arg0, const ARG1& arg1, const ARG2& arg2)
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2089 {
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2090 T *ret = new T(arg0, arg1, arg2);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2091 track_value (ret);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2092 return ret;
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2093 }
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
2094
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
2095 template <typename T, typename ARG0, typename ARG1, typename ARG2,
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
2096 typename ARG3>
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
2097 T *create (const ARG0& arg0, const ARG1& arg1, const ARG2& arg2,
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
2098 const ARG3& arg3)
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
2099 {
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
2100 T *ret = new T(arg0, arg1, arg2, arg3);
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
2101 track_value (ret);
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
2102 return ret;
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
2103 }
14961
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2104
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2105 template <typename ARG0, typename ARG1>
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2106 jit_call *create_checked (const ARG0& arg0, const ARG1& arg1)
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2107 {
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2108 jit_call *ret = create<jit_call> (arg0, arg1);
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2109 return create_checked_impl (ret);
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2110 }
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2111
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2112 template <typename ARG0, typename ARG1, typename ARG2>
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2113 jit_call *create_checked (const ARG0& arg0, const ARG1& arg1,
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2114 const ARG2& arg2)
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2115 {
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2116 jit_call *ret = create<jit_call> (arg0, arg1, arg2);
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2117 return create_checked_impl (ret);
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2118 }
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2119
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2120 template <typename ARG0, typename ARG1, typename ARG2, typename ARG3>
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2121 jit_call *create_checked (const ARG0& arg0, const ARG1& arg1,
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2122 const ARG2& arg2, const ARG3& arg3)
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2123 {
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2124 jit_call *ret = create<jit_call> (arg0, arg1, arg2, arg3);
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2125 return create_checked_impl (ret);
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2126 }
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2127
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
2128 typedef std::list<jit_block *> block_list;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
2129 typedef block_list::iterator block_iterator;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
2130
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2131 void append (jit_block *ablock);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2132
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2133 void insert_before (block_iterator iter, jit_block *ablock);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2134
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2135 void insert_before (jit_block *loc, jit_block *ablock)
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2136 {
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2137 insert_before (loc->location (), ablock);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2138 }
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2139
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2140 void insert_after (block_iterator iter, jit_block *ablock);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2141
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2142 void insert_after (jit_block *loc, jit_block *ablock)
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2143 {
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2144 insert_after (loc->location (), ablock);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2145 }
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2146 private:
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2147 std::vector<std::pair<std::string, bool> > arguments;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2148 type_bound_vector bounds;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2149
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2150 // used instead of return values from visit_* functions
14944
c0a5ab3b9278 jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents: 14943
diff changeset
2151 jit_value *result;
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2152
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2153 jit_block *entry_block;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2154
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
2155 jit_block *final_block;
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
2156
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2157 jit_block *block;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2158
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2159 llvm::Function *function;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2160
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2161 std::list<jit_block *> blocks;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2162
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2163 std::list<jit_instruction *> worklist;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2164
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2165 std::list<jit_value *> constants;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2166
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2167 std::list<jit_value *> all_values;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2168
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2169 size_t iterator_count;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2170
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2171 typedef std::map<std::string, jit_variable *> vmap_t;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2172 vmap_t vmap;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2173
14961
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2174 jit_call *create_checked_impl (jit_call *ret)
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2175 {
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2176 block->append (ret);
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2177 create_check (ret);
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2178 return ret;
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2179 }
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2180
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2181 jit_error_check *create_check (jit_call *call)
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2182 {
14961
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2183 jit_block *normal = create<jit_block> (block->name ());
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2184 jit_error_check *ret
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2185 = block->append (create<jit_error_check> (call, normal, final_block));
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2186 append (normal);
14961
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2187 block = normal;
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2188
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2189 return ret;
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2190 }
903a5ee2cdde Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents: 14960
diff changeset
2191
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2192 jit_variable *get_variable (const std::string& vname);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2193
14969
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2194 std::pair<jit_value *, jit_value *> resolve (tree_index_expression& exp);
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2195
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2196 jit_value *do_assign (tree_expression *exp, jit_value *rhs,
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2197 bool artificial = false);
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2198
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2199 jit_value *do_assign (const std::string& lhs, jit_value *rhs, bool print,
bbeef7b8ea2e Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents: 14968
diff changeset
2200 bool artificial = false);
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2201
14944
c0a5ab3b9278 jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents: 14943
diff changeset
2202 jit_value *visit (tree *tee) { return visit (*tee); }
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2203
14944
c0a5ab3b9278 jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents: 14943
diff changeset
2204 jit_value *visit (tree& tee);
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2205
14946
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
2206 void push_worklist (jit_instruction *instr)
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
2207 {
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
2208 if (! instr->in_worklist ())
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
2209 {
14959
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
2210 instr->stash_in_worklist (true);
12fd4a62d633 Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents: 14958
diff changeset
2211 worklist.push_back (instr);
14946
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
2212 }
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
2213 }
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
2214
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2215 void append_users (jit_value *v)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2216 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2217 for (jit_use *use = v->first_use (); use; use = use->next ())
14946
3564bb141396 Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents: 14945
diff changeset
2218 push_worklist (use->user ());
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2219 }
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2220
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
2221 void append_users_term (jit_terminator *term);
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
2222
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2223 void track_value (jit_value *value)
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2224 {
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2225 if (value->type ())
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2226 constants.push_back (value);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2227 all_values.push_back (value);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2228 }
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
2229
14939
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
2230 void merge_blocks (void);
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
2231
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
2232 void construct_ssa (void);
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2233
14971
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
2234 void do_construct_ssa (jit_block& block, size_t avisit_count);
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
2235
14945
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
2236 void remove_dead ();
591aeec5c520 Remove uneeded error checks
Max Brister <max@2bass.com>
parents: 14944
diff changeset
2237
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
2238 void place_releases (void);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
2239
14971
b23a98ca0e43 Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents: 14969
diff changeset
2240 void release_temp (jit_block& ablock, std::set<jit_value *>& temp);
14966
b7b647bc4b90 Place releases for temporaries on error
Max Brister <max@2bass.com>
parents: 14965
diff changeset
2241
b7b647bc4b90 Place releases for temporaries on error
Max Brister <max@2bass.com>
parents: 14965
diff changeset
2242 void release_dead_phi (jit_block& ablock);
b7b647bc4b90 Place releases for temporaries on error
Max Brister <max@2bass.com>
parents: 14965
diff changeset
2243
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2244 void simplify_phi (void);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2245
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2246 void simplify_phi (jit_phi& phi);
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2247
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2248 void print_blocks (const std::string& header)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2249 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2250 std::cout << "-------------------- " << header << " --------------------\n";
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2251 for (std::list<jit_block *>::iterator iter = blocks.begin ();
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2252 iter != blocks.end (); ++iter)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2253 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2254 assert (*iter);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2255 (*iter)->print (std::cout, 0);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2256 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2257 std::cout << std::endl;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2258 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2259
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2260 void print_dom (void)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2261 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2262 std::cout << "-------------------- dom info --------------------\n";
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2263 for (std::list<jit_block *>::iterator iter = blocks.begin ();
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2264 iter != blocks.end (); ++iter)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2265 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2266 assert (*iter);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2267 (*iter)->print_dom (std::cout);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2268 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2269 std::cout << std::endl;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2270 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2271
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
2272 bool breaking; // true if we are breaking OR continuing
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
2273 block_list breaks;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
2274 block_list continues;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
2275
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
2276 void finish_breaks (jit_block *dest, const block_list& lst);
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
2277
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2278 // this case is much simpler, just convert from the jit ir to llvm
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2279 class
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2280 convert_llvm : public jit_ir_walker
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2281 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2282 public:
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2283 convert_llvm (jit_convert& jc) : jthis (jc) {}
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2284
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2285 llvm::Function *convert (llvm::Module *module,
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2286 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
2287 const std::list<jit_block *>& blocks,
c0a5ab3b9278 jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents: 14943
diff changeset
2288 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
2289
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2290 #define JIT_METH(clname) \
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
2291 virtual void visit (jit_ ## clname&);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2292
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2293 JIT_VISIT_IR_CLASSES;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2294
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2295 #undef JIT_METH
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2296 private:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2297 // name -> llvm argument
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2298 std::map<std::string, llvm::Value *> arguments;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2299
14963
709f50069722 Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents: 14962
diff changeset
2300 void finish_phi (jit_phi *phi);
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2301
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2302 void visit (jit_value *jvalue)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2303 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2304 return visit (*jvalue);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2305 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2306
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2307 void visit (jit_value &jvalue)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2308 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2309 jvalue.accept (*this);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2310 }
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2311
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2312 llvm::Value *create_call (const jit_function::overload& ol, jit_value *arg0)
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2313 {
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2314 std::vector<jit_value *> args (1, arg0);
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2315 return create_call (ol, args);
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2316 }
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2317
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2318 llvm::Value *create_call (const jit_function::overload& ol, jit_value *arg0,
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2319 jit_value *arg1)
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2320 {
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2321 std::vector<jit_value *> args (2);
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2322 args[0] = arg0;
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2323 args[1] = arg1;
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2324
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2325 return create_call (ol, args);
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2326 }
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2327
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2328 llvm::Value *create_call (const jit_function::overload& ol,
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2329 const std::vector<jit_value *>& jargs);
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2330
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2331 llvm::Value *create_call (const jit_function::overload& ol,
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2332 const std::vector<jit_use>& uses);
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
2333 private:
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14948
diff changeset
2334 jit_convert &jthis;
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
2335 llvm::Function *function;
14968
7f60cdfcc0e5 Do not smash stack when passing structures in JIT
Max Brister <max@2bass.com>
parents: 14967
diff changeset
2336 llvm::BasicBlock *prelude;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2337 };
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2338 };
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2339
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2340 class jit_info;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
2341
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2342 class
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
2343 tree_jit
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2344 {
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2345 public:
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2346 tree_jit (void);
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2347
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2348 ~tree_jit (void);
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2349
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
2350 bool execute (tree_simple_for_command& cmd);
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
2351
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2352 llvm::ExecutionEngine *get_engine (void) const { return engine; }
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
2353
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2354 llvm::Module *get_module (void) const { return module; }
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
2355
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2356 void optimize (llvm::Function *fn);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2357 private:
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2358 bool initialize (void);
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2359
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2360 // FIXME: Temorary hack to test
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2361 typedef std::map<tree *, jit_info *> compiled_map;
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2362 llvm::Module *module;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
2363 llvm::PassManager *module_pass_manager;
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2364 llvm::FunctionPassManager *pass_manager;
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2365 llvm::ExecutionEngine *engine;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2366 };
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
2367
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2368 class
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2369 jit_info
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2370 {
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2371 public:
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2372 jit_info (tree_jit& tjit, tree& tee);
14913
c7071907a641 Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents: 14911
diff changeset
2373
14955
609dcc297db5 src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents: 14951
diff changeset
2374 ~jit_info (void);
609dcc297db5 src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents: 14951
diff changeset
2375
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2376 bool execute (void) const;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2377
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2378 bool match (void) const;
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2379 private:
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2380 typedef jit_convert::type_bound type_bound;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2381 typedef jit_convert::type_bound_vector type_bound_vector;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2382 typedef void (*jited_function)(octave_base_value**);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2383
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2384 llvm::ExecutionEngine *engine;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2385 jited_function function;
14955
609dcc297db5 src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents: 14951
diff changeset
2386 llvm::Function *llvm_function;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2387
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2388 std::vector<std::pair<std::string, bool> > arguments;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2389 type_bound_vector bounds;
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2390 };
14937
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
2391
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
2392 // some #defines we use in the header, but not the cc file
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
2393 #undef JIT_VISIT_IR_CLASSES
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
2394 #undef JIT_VISIT_IR_CONST
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
2395 #undef JIT_VALUE_ACCEPT
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
2396
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2397 #endif
14932
1f914446157d Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents: 14928
diff changeset
2398 #endif