annotate src/pt-jit.h @ 14944:c0a5ab3b9278

jit_const no longer inherits from jit_instruction
author Max Brister <max@2bass.com>
date Fri, 08 Jun 2012 15:30:07 -0500
parents 8efcaf5aa233
children 591aeec5c520
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 // However, there is no warning emitted on divide by 0. For example,
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
43 // a = 5;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
44 // b = a * 5 + a;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
45 //
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
46 // For other types all binary operations are compiled but not optimized. For
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
47 // example,
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
48 // a = [1 2 3]
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
49 // b = a + a;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
50 // will compile to do_binary_op (a, a).
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
51 //
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
52 // For loops are compiled again!
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
53 // if, elseif, and else statements compile again!
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
54 // break and continue now work!
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
55 // Additionally, make check passes using jit.
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
56 //
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
57 // 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
58 // 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
59 // c = call binary+ (a, b)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
60 // The jit_functions contain information about overloads for differnt types. For
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
61 // example, if we know a and b are scalars, then c must also be a scalar.
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
62 //
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
63 //
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
64 // TODO:
14937
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
65 // 1. Support error cases
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
66 // 2. Support some simple matrix case (and cleanup Octave low level IR)
14937
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
67 // 3. Fix memory leaks in JIT
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
68 // 4. Cleanup/documentation
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
69 // 5. ...
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
70 // ---------------------------------------------------------
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
71
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
72
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
73 // we don't want to include llvm headers here, as they require __STDC_LIMIT_MACROS
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
74 // and __STDC_CONSTANT_MACROS be defined in the entire compilation unit
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
75 namespace llvm
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
76 {
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
77 class Value;
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
78 class Module;
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
79 class FunctionPassManager;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
80 class PassManager;
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
81 class ExecutionEngine;
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
82 class Function;
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
83 class BasicBlock;
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
84 class LLVMContext;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
85 class Type;
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
86 class Twine;
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
87 class GlobalVariable;
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
88 }
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
89
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
90 class octave_base_value;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
91 class octave_value;
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
92 class tree;
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
93
14937
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
94 // 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
95 // 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
96 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
97 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
98 {
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
99 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
100 }
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
101
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
102 // jit_range is compatable with the llvm range structure
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
103 struct
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
104 jit_range
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
105 {
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
106 jit_range (const Range& from) : base (from.base ()), limit (from.limit ()),
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
107 inc (from.inc ()), nelem (from.nelem ())
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
108 {}
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
109
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
110 operator Range () const
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
111 {
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
112 return Range (base, limit, inc);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
113 }
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
114
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
115 double base;
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
116 double limit;
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
117 double inc;
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
118 octave_idx_type nelem;
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
119 };
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
120
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
121 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
122
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
123 // 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
124 // hierarchical type system which includes both concrete and abstract types.
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
125 //
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
126 // 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
127 // 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
128 // code even for the case of poor type inference.
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
129 class
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
130 jit_type
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
131 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
132 public:
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
133 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
134 int aid) :
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
135 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
136 mdepth (aparent ? aparent->mdepth + 1 : 0)
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
137 {}
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
138
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
139 // a user readable type name
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
140 const std::string& name (void) const { return mname; }
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
141
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
142 // 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
143 int type_id (void) const { return mid; }
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
144
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
145 // 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
146 jit_type *parent (void) const { return mparent; }
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
147
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
148 // convert to an llvm type
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
149 llvm::Type *to_llvm (void) const { return llvm_type; }
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
150
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
151 // how this type gets passed as a function argument
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
152 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
153
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
154 size_t depth (void) const { return mdepth; }
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
155 private:
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
156 std::string mname;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
157 jit_type *mparent;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
158 llvm::Type *llvm_type;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
159 int mid;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
160 size_t mdepth;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
161 };
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
162
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
163 // 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
164 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
165
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
166 // 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
167 // and code generation.
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
168 class
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
169 jit_function
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
170 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
171 public:
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
172 struct
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
173 overload
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
174 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
175 overload (void) : function (0), can_error (true), result (0) {}
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
176
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
177 overload (llvm::Function *f, bool e, bool s, jit_type *r, jit_type *arg0) :
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
178 function (f), can_error (e), side_effects (s), result (r), arguments (1)
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
179 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
180 arguments[0] = arg0;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
181 }
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
182
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
183 overload (llvm::Function *f, bool e, bool s, jit_type *r, jit_type *arg0,
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
184 jit_type *arg1) : function (f), can_error (e), side_effects (s),
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
185 result (r), arguments (2)
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
186 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
187 arguments[0] = arg0;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
188 arguments[1] = arg1;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
189 }
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
190
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
191 overload (llvm::Function *f, bool e, bool s, jit_type *r, jit_type *arg0,
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
192 jit_type *arg1, jit_type *arg2) : function (f), can_error (e),
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
193 side_effects (s), result (r),
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
194 arguments (3)
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
195 {
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
196 arguments[0] = arg0;
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
197 arguments[1] = arg1;
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
198 arguments[2] = arg2;
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
199 }
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
200
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
201 llvm::Function *function;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
202 bool can_error;
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
203 bool side_effects;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
204 jit_type *result;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
205 std::vector<jit_type*> arguments;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
206 };
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
207
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
208 void add_overload (const overload& func)
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
209 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
210 add_overload (func, func.arguments);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
211 }
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
212
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
213 void add_overload (llvm::Function *f, bool e, bool s, jit_type *r, jit_type *arg0)
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
214 {
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
215 overload ol (f, e, s, r, arg0);
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
216 add_overload (ol);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
217 }
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
218
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
219 void add_overload (llvm::Function *f, bool e, bool s, jit_type *r, jit_type *arg0,
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
220 jit_type *arg1)
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
221 {
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
222 overload ol (f, e, s, r, arg0, arg1);
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
223 add_overload (ol);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
224 }
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
225
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
226 void add_overload (llvm::Function *f, bool e, bool s, jit_type *r, jit_type *arg0,
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
227 jit_type *arg1, jit_type *arg2)
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
228 {
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
229 overload ol (f, e, s, r, arg0, arg1, arg2);
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
230 add_overload (ol);
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
231 }
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
232
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
233 void add_overload (const overload& func,
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
234 const std::vector<jit_type*>& args);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
235
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
236 const overload& get_overload (const std::vector<jit_type *>& types) const;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
237
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
238 const overload& get_overload (jit_type *arg0) const
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
239 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
240 std::vector<jit_type *> types (1);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
241 types[0] = arg0;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
242 return get_overload (types);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
243 }
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
244
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
245 const overload& get_overload (jit_type *arg0, jit_type *arg1) const
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
246 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
247 std::vector<jit_type *> types (2);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
248 types[0] = arg0;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
249 types[1] = arg1;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
250 return get_overload (types);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
251 }
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
252
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
253 jit_type *get_result (const std::vector<jit_type *>& types) const
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
254 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
255 const overload& temp = get_overload (types);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
256 return temp.result;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
257 }
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
258
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
259 jit_type *get_result (jit_type *arg0, jit_type *arg1) const
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
260 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
261 const overload& temp = get_overload (arg0, arg1);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
262 return temp.result;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
263 }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
264
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
265 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
266
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
267 void stash_name (const std::string& aname) { mname = aname; }
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
268 private:
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
269 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
270
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
271 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
272
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
273 std::string mname;
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
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
276 // Get information and manipulate jit types.
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
277 class
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
278 jit_typeinfo
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
279 {
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
280 public:
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
281 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
282
14922
2e6f83b2f2b9 Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents: 14920
diff changeset
283 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
284 {
14922
2e6f83b2f2b9 Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents: 14920
diff changeset
285 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
286 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
287
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
288 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
289
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
290 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
291
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
292 static llvm::Type *get_scalar_llvm (void) { return instance->scalar->to_llvm (); }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
293
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
294 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
295
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
296 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
297
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
298 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
299
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
300 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
301
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
302 static llvm::Type *get_index_llvm (void) { return instance->index->to_llvm (); }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
303
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
304 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
305 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
306 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
307 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
308
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
309 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
310 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
311 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
312 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
313
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
314 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
315
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
316 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
317 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
318 return instance->release_fn;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
319 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
320
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
321 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
322 {
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
323 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
324 }
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
325
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
326 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
327 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
328 return instance->print_fn;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
329 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
330
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
331 static const jit_function& for_init (void)
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
332 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
333 return instance->for_init_fn;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
334 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
335
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
336 static const jit_function& for_check (void)
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
337 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
338 return instance->for_check_fn;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
339 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
340
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
341 static const jit_function& for_index (void)
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
342 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
343 return instance->for_index_fn;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
344 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
345
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
346 static const jit_function& make_range (void)
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
347 {
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
348 return instance->make_range_fn;
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
349 }
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
350
14943
8efcaf5aa233 Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents: 14942
diff changeset
351 static const jit_function& logically_true (void)
8efcaf5aa233 Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents: 14942
diff changeset
352 {
8efcaf5aa233 Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents: 14942
diff changeset
353 return instance->logically_true_fn;
8efcaf5aa233 Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents: 14942
diff changeset
354 }
8efcaf5aa233 Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents: 14942
diff changeset
355
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
356 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
357 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
358 return instance->do_cast (result);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
359 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
360
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
361 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
362 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
363 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
364 }
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
365
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
366 static llvm::Value *insert_error_check (void)
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
367 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
368 return instance->do_insert_error_check ();
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
369 }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
370 private:
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
371 jit_typeinfo (llvm::Module *m, llvm::ExecutionEngine *e);
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
372
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
373 // 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
374 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
375 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
376 // empty case
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
377 if (! lhs)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
378 return rhs;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
379
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
380 if (! rhs)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
381 return lhs;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
382
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
383 // check for a shared parent
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
384 while (lhs != rhs)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
385 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
386 if (lhs->depth () > rhs->depth ())
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
387 lhs = lhs->parent ();
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
388 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
389 rhs = rhs->parent ();
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
390 else
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
391 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
392 // 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
393 do
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 lhs = lhs->parent ();
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
396 rhs = rhs->parent ();
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
397 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
398 while (lhs != rhs);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
399 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
400 }
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
401
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
402 return lhs;
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
403 }
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
404
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
405 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
406 {
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
407 // 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
408 return lhs;
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
409 }
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
410
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
411 jit_type *do_type_of (const octave_value &ov) const;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
412
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
413 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
414 {
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
415 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
416 return binary_ops[op];
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
417 }
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
418
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
419 const jit_function& do_cast (jit_type *to)
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
420 {
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
421 static jit_function null_function;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
422 if (! to)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
423 return null_function;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
424
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
425 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
426 if (id >= casts.size ())
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
427 return null_function;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
428 return casts[id];
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
429 }
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
430
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
431 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
432 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
433 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
434 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
435
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
436 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
437 llvm::Type *llvm_type);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
438
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
439
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
440 void add_print (jit_type *ty, void *call);
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
441
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
442 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
443
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
444 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
445
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
446 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
447
14941
1e3d0366ac8b warn on divide by zero
Max Brister <max@2bass.com>
parents: 14939
diff changeset
448 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
449 {
1e3d0366ac8b warn on divide by zero
Max Brister <max@2bass.com>
parents: 14939
diff changeset
450 std::vector<llvm::Type *> args;
1e3d0366ac8b warn on divide by zero
Max Brister <max@2bass.com>
parents: 14939
diff changeset
451 return create_function (name, ret, args);
1e3d0366ac8b warn on divide by zero
Max Brister <max@2bass.com>
parents: 14939
diff changeset
452 }
1e3d0366ac8b warn on divide by zero
Max Brister <max@2bass.com>
parents: 14939
diff changeset
453
14915
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
454 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
455 llvm::Type *arg0)
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
456 {
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
457 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
458 return create_function (name, ret, args);
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
459 }
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
460
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
461 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
462 jit_type *arg0)
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
463 {
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
464 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
465 }
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
466
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
467 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
468 llvm::Type *arg0, llvm::Type *arg1)
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
469 {
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
470 std::vector<llvm::Type *> args (2);
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
471 args[0] = arg0;
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
472 args[1] = arg1;
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
473 return create_function (name, ret, args);
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
474 }
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
475
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
476 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
477 jit_type *arg0, jit_type *arg1)
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
478 {
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
479 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
480 arg1->to_llvm ());
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
481 }
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
482
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
483 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
484 llvm::Type *arg0, llvm::Type *arg1,
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
485 llvm::Type *arg2)
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
486 {
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
487 std::vector<llvm::Type *> args (3);
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
488 args[0] = arg0;
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
489 args[1] = arg1;
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
490 args[2] = arg2;
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
491 return create_function (name, ret, args);
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
492 }
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
493
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
494 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
495 jit_type *arg0, jit_type *arg1,
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
496 jit_type *arg2)
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
497 {
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
498 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
499 arg1->to_llvm (), arg2->to_llvm ());
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
500 }
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
501
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
502 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
503 const std::vector<llvm::Type *>& args);
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
504
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
505 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
506
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
507 llvm::Value *do_insert_error_check (void);
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
508
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
509 static jit_typeinfo *instance;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
510
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
511 llvm::Module *module;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
512 llvm::ExecutionEngine *engine;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
513 int next_id;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
514
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
515 llvm::Type *ov_t;
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
516 llvm::GlobalVariable *lerror_state;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
517
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
518 std::vector<jit_type*> id_to_type;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
519 jit_type *any;
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
520 jit_type *scalar;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
521 jit_type *range;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
522 jit_type *string;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
523 jit_type *boolean;
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
524 jit_type *index;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
525
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
526 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
527 jit_function grab_fn;
cba58541954c Add if support and fix leak with any
Max Brister <max@2bass.com>
parents: 14914
diff changeset
528 jit_function release_fn;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
529 jit_function print_fn;
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
530 jit_function for_init_fn;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
531 jit_function for_check_fn;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
532 jit_function for_index_fn;
14943
8efcaf5aa233 Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents: 14942
diff changeset
533 jit_function logically_true_fn;
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
534 jit_function make_range_fn;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
535
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
536 // 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
537 std::vector<jit_function> casts;
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 // type id -> identity function
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
540 std::vector<llvm::Function *> identities;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
541 };
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
542
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
543 // 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
544 // 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
545 // 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
546
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
547 #define JIT_VISIT_IR_NOTEMPLATE \
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
548 JIT_METH(block); \
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
549 JIT_METH(break); \
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
550 JIT_METH(cond_break); \
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
551 JIT_METH(call); \
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
552 JIT_METH(extract_argument); \
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
553 JIT_METH(store_argument); \
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
554 JIT_METH(phi); \
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
555 JIT_METH(variable); \
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
556 JIT_METH(check_error); \
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
557 JIT_METH(assign)
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
558
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
559 #define JIT_VISIT_IR_CONST \
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
560 JIT_METH(const_scalar); \
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
561 JIT_METH(const_index); \
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
562 JIT_METH(const_string); \
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
563 JIT_METH(const_range)
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
564
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
565 #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
566 JIT_VISIT_IR_NOTEMPLATE \
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
567 JIT_VISIT_IR_CONST
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
568
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
569 // forward declare all ir classes
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
570 #define JIT_METH(cname) \
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
571 class jit_ ## cname;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
572
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
573 JIT_VISIT_IR_NOTEMPLATE
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
574
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
575 #undef JIT_METH
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
576
14937
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
577 // 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
578 class jit_instruction;
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
579 class jit_terminator;
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
580
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
581 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
582 bool QUOTE=false>
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
583 class jit_const;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
584
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
585 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
586 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
587
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
588 typedef jit_const<std::string, jit_typeinfo::get_string, const std::string&, true>
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
589 jit_const_string;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
590 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
591 jit_const_range;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
592
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
593 class jit_ir_walker;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
594 class jit_use;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
595
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
596 class
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
597 jit_value
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
598 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
599 friend class jit_use;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
600 public:
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
601 jit_value (void) : llvm_value (0), ty (0), use_head (0), myuse_count (0),
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
602 mlast_use (0) {}
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
603
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
604 virtual ~jit_value (void);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
605
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
606 // replace all uses with
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
607 void replace_with (jit_value *value);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
608
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
609 jit_type *type (void) const { return ty; }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
610
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
611 llvm::Type *type_llvm (void) const
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
612 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
613 return ty ? ty->to_llvm () : 0;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
614 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
615
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
616 const std::string& type_name (void) const
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
617 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
618 return ty->name ();
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
619 }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
620
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
621 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
622
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
623 jit_use *first_use (void) const { return use_head; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
624
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
625 size_t use_count (void) const { return myuse_count; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
626
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
627 std::string print_string (void)
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
628 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
629 std::stringstream ss;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
630 print (ss);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
631 return ss.str ();
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
632 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
633
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
634 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
635
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
636 void stash_last_use (jit_instruction *alast_use)
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
637 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
638 mlast_use = alast_use;
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
639 }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
640
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
641 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
642
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
643 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
644 { return print (os); }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
645
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
646 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
647
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
648 bool has_llvm (void) const
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
649 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
650 return llvm_value;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
651 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
652
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
653 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
654 {
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
655 assert (llvm_value);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
656 return llvm_value;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
657 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
658
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
659 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
660 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
661 llvm_value = compiled;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
662 }
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
663
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
664 protected:
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
665 std::ostream& print_indent (std::ostream& os, size_t indent) const
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
666 {
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
667 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
668 os << " ";
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
669 return os;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
670 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
671
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
672 llvm::Value *llvm_value;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
673 private:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
674 jit_type *ty;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
675 jit_use *use_head;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
676 size_t myuse_count;
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
677 jit_instruction *mlast_use;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
678 };
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
679
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
680 std::ostream& operator<< (std::ostream& os, const jit_value& value);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
681
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
682 class
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
683 jit_use
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
684 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
685 public:
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
686 jit_use (void) : mvalue (0), mnext (0), mprev (0), muser (0), mindex (0) {}
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
687
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
688 // we should really have a move operator, but not until c++11 :(
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
689 jit_use (const jit_use& use) : mvalue (0), mnext (0), mprev (0), muser (0),
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
690 mindex (0)
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
691 {
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
692 *this = use;
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
693 }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
694
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
695 ~jit_use (void) { remove (); }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
696
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
697 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
698 {
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
699 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
700 return *this;
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
701 }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
702
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
703 jit_value *value (void) const { return mvalue; }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
704
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
705 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
706
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
707 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
708
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
709 jit_block *user_parent (void) const;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
710
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
711 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
712
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
713 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
714 size_t aindex = -1)
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
715 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
716 remove ();
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
717
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
718 mvalue = avalue;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
719
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
720 if (mvalue)
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
721 {
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
722 if (mvalue->use_head)
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
723 {
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
724 mvalue->use_head->mprev = this;
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
725 mnext = mvalue->use_head;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
726 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
727
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
728 mvalue->use_head = this;
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
729 ++mvalue->myuse_count;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
730 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
731
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
732 mindex = aindex;
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
733 muser = auser;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
734 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
735
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
736 jit_use *next (void) const { return mnext; }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
737
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
738 jit_use *prev (void) const { return mprev; }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
739 private:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
740 void remove (void)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
741 {
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
742 if (mvalue)
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
743 {
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
744 if (this == mvalue->use_head)
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
745 mvalue->use_head = mnext;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
746
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
747 if (mprev)
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
748 mprev->mnext = mnext;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
749
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
750 if (mnext)
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
751 mnext->mprev = mprev;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
752
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
753 mnext = mprev = 0;
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
754 --mvalue->myuse_count;
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
755 mvalue = 0;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
756 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
757 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
758
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
759 jit_value *mvalue;
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
760 jit_use *mnext;
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
761 jit_use *mprev;
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
762 jit_instruction *muser;
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
763 size_t mindex;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
764 };
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
765
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
766 class
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
767 jit_instruction : public jit_value
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
768 {
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
769 public:
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
770 // 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
771 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
772 {}
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
773
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
774 jit_instruction (size_t nargs, jit_value *adefault = 0)
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
775 : already_infered (nargs, reinterpret_cast<jit_type *>(0)), arguments (nargs),
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
776 mid (next_id ()), mparent (0)
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
777 {
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
778 if (adefault)
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
779 for (size_t i = 0; i < nargs; ++i)
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
780 stash_argument (i, adefault);
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
781 }
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
782
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
783 jit_instruction (jit_value *arg0)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
784 : already_infered (1, reinterpret_cast<jit_type *>(0)), arguments (1),
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
785 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
786 {
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
787 stash_argument (0, arg0);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
788 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
789
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
790 jit_instruction (jit_value *arg0, jit_value *arg1)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
791 : already_infered (2, reinterpret_cast<jit_type *>(0)), arguments (2),
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
792 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
793 {
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
794 stash_argument (0, arg0);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
795 stash_argument (1, arg1);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
796 }
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 jit_instruction (jit_value *arg0, jit_value *arg1, jit_value *arg2)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
799 : already_infered (3, reinterpret_cast<jit_type *>(0)), arguments (3),
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
800 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
801 {
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
802 stash_argument (0, arg0);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
803 stash_argument (1, arg1);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
804 stash_argument (2, arg2);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
805 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
806
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
807 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
808 jit_value *arg3)
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
809 : already_infered (3, reinterpret_cast<jit_type *>(0)), arguments (4),
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
810 mid (next_id ()), mparent (0)
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
811 {
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
812 stash_argument (0, arg0);
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
813 stash_argument (1, arg1);
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
814 stash_argument (2, arg2);
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
815 stash_argument (3, arg3);
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
816 }
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
817
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
818 static void reset_ids (void)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
819 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
820 next_id (true);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
821 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
822
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
823 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
824 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
825 return arguments[i].value ();
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
826 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
827
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
828 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
829 {
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
830 assert (argument (i));
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
831 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
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 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
835 {
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
836 return argument (i)->type ();
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
837 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
838
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
839 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
840 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
841 assert (argument (i));
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
842 return argument_type (i)->to_llvm ();
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
843 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
844
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
845 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
846 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
847 if (argument (i))
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
848 return argument (i)->short_print (os);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
849 else
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
850 return os << "NULL";
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
851 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
852
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
853 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
854 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
855 arguments[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
856 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
857
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
858 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
859 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
860 return arguments.size ();
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
861 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
862
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
863 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
864 {
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
865 size_t old = arguments.size ();
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
866 arguments.resize (acount);
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
867
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
868 if (adefault)
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
869 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
870 stash_argument (i, adefault);
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
871 }
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
872
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
873 // 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
874 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
875 { return already_infered; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
876
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
877 virtual bool dead (void) const { return false; }
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
878
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
879 virtual bool almost_dead (void) const { return false; }
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
880
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
881 virtual void push_variable (void) {}
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
882
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
883 virtual void pop_variable (void) {}
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
884
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
885 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
886
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
887 void remove (void);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
888
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
889 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
890
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
891 jit_block *parent (void) const { return mparent; }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
892
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
893 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
894 {
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
895 return mlocation;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
896 }
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
897
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
898 llvm::BasicBlock *parent_llvm (void) const;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
899
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
900 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
901 std::list<jit_instruction *>::iterator alocation)
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
902 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
903 mparent = aparent;
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
904 mlocation = alocation;
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
905 }
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
906
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
907 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
908 protected:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
909 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
910 private:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
911 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
912 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
913 static size_t ret = 0;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
914 if (reset)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
915 return ret = 0;
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 return ret++;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
918 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
919
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
920 std::vector<jit_use> arguments;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
921
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
922 size_t mid;
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
923 jit_block *mparent;
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
924 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
925 };
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
926
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
927 // defnie accept methods for subclasses
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
928 #define JIT_VALUE_ACCEPT(clname) \
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
929 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
930
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
931 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
932 bool QUOTE>
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
933 class
14944
c0a5ab3b9278 jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents: 14943
diff changeset
934 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
935 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
936 public:
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
937 typedef PASS_T pass_t;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
938
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
939 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
940 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
941 stash_type (EXTRACT_T ());
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
942 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
943
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
944 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
945
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
946 virtual std::ostream& print (std::ostream& os, size_t indent) const
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
947 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
948 print_indent (os, indent);
14944
c0a5ab3b9278 jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents: 14943
diff changeset
949 jit_print (os, type ()) << ": ";
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
950 if (QUOTE)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
951 os << "\"";
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
952 os << mvalue;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
953 if (QUOTE)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
954 os << "\"";
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
955 return os;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
956 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
957
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
958 JIT_VALUE_ACCEPT (jit_const);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
959 private:
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
960 T mvalue;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
961 };
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
962
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
963 class
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
964 jit_block : public jit_value
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
965 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
966 public:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
967 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
968 typedef instruction_list::iterator iterator;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
969 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
970
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
971 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
972 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
973
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
974 jit_block (const std::string& aname) : mvisit_count (0), mid (NO_ID), idom (0),
14939
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
975 mname (aname), mdead (false)
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
976 {}
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
977
14939
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
978 virtual bool dead (void) const { return mdead; }
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
979
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
980 void mark_dead (void) { mdead = true; }
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
981
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
982 // If we can merge with a sucessor, do so and return the now empty block
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
983 jit_block *maybe_merge ();
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
984
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
985 // 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
986 void merge (jit_block& merge);
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
987
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
988 const std::string& name (void) const { return mname; }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
989
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
990 jit_instruction *prepend (jit_instruction *instr);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
991
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
992 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
993
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
994 jit_instruction *append (jit_instruction *instr);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
995
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
996 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
997
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
998 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
999
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1000 iterator remove (iterator iter)
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1001 {
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1002 jit_instruction *instr = *iter;
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1003 iter = instructions.erase (iter);
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1004 instr->stash_parent (0, instructions.end ());
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1005 return iter;
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1006 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1007
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1008 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
1009
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
1010 jit_block *pred (size_t idx) const;
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1011
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1012 jit_terminator *pred_terminator (size_t idx) const
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1013 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1014 return pred (idx)->terminator ();
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1015 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1016
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1017 std::ostream& print_pred (std::ostream& os, size_t idx) const
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1018 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1019 return pred (idx)->short_print (os);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1020 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1021
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1022 // takes into account for the addition of phi merges
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1023 llvm::BasicBlock *pred_llvm (size_t idx) const
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1024 {
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
1025 if (mpred_llvm.size () < pred_count ())
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1026 mpred_llvm.resize (pred_count ());
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1027
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1028 return mpred_llvm[idx] ? mpred_llvm[idx] : pred (idx)->to_llvm ();
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1029 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1030
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1031 llvm::BasicBlock *pred_llvm (jit_block *apred) const
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1032 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1033 return pred_llvm (pred_index (apred));
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1034 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1035
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
1036 size_t pred_index (jit_block *apred) const;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1037
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1038 // create llvm phi merge blocks for all predecessors (if required)
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1039 void create_merge (llvm::Function *inside, size_t pred_idx);
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 size_t pred_count (void) const { return use_count (); }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1042
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1043 jit_block *succ (size_t i) const;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1044
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1045 size_t succ_count (void) const;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1046
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1047 iterator begin (void) { return instructions.begin (); }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1048
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1049 const_iterator begin (void) const { return instructions.begin (); }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1050
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1051 iterator end (void) { return instructions.end (); }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1052
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1053 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
1054
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1055 iterator phi_begin (void);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1056
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1057 iterator phi_end (void);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1058
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1059 iterator nonphi_begin (void);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1060
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1061 // 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
1062 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
1063
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1064 // dominance frontier
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1065 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
1066
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1067 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
1068
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1069 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
1070
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1071 // label with a RPO walk
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1072 void label (void)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1073 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1074 size_t number = 0;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1075 label (mvisit_count, number);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1076 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1077
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1078 void label (size_t visit_count, size_t& number)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1079 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1080 if (mvisit_count > visit_count)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1081 return;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1082 ++mvisit_count;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1083
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1084 for (size_t i = 0; i < pred_count (); ++i)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1085 pred (i)->label (visit_count, number);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1086
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1087 mid = number++;
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1088 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1089
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1090 // See for idom computation algorithm
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1091 // 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
1092 // "A Simple, Fast Dominance Algorithm"
14939
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1093 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
1094 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1095 bool changed;
14939
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1096 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
1097 do
14939
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1098 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
1099 while (changed);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1100 }
14923
168cb10bb9c5 If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents: 14922
diff changeset
1101
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1102 // compute dominance frontier
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1103 void compute_df (void)
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 compute_df (mvisit_count);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1106 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1107
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1108 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
1109 {
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1110 create_dom_tree (mvisit_count);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1111 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1112
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1113 // visit blocks in the order of the dominator tree
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1114 // inorder - Run on the root first, then children
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1115 // postorder - Run on children first, then the root
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1116 template <typename func_type0, typename func_type1>
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1117 void visit_dom (func_type0 inorder, func_type1 postorder)
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1118 {
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1119 do_visit_dom (mvisit_count, inorder, postorder);
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1120 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1121
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1122 // 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
1123 void pop_all (void);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1124
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1125 virtual std::ostream& print (std::ostream& os, size_t indent) const
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1126 {
14939
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1127 print_indent (os, indent);
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1128 short_print (os) << ": %pred = ";
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1129 for (size_t i = 0; i < pred_count (); ++i)
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1130 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1131 print_pred (os, i);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1132 if (i + 1 < pred_count ())
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1133 os << ", ";
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1134 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1135 os << std::endl;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1136
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1137 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
1138 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1139 jit_instruction *instr = *iter;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1140 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
1141 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1142 return os;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1143 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1144
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1145 // print dominator infomration
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1146 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
1147
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1148 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
1149 {
14939
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1150 os << mname;
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1151 if (mid != NO_ID)
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1152 os << mid;
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1153 return os;
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1154 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1155
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1156 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
1157
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1158 JIT_VALUE_ACCEPT (block)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1159 private:
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1160 void compute_df (size_t visit_count);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1161
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1162 bool update_idom (size_t visit_count);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1163
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1164 void create_dom_tree (size_t visit_count);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1165
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1166 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
1167
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1168 template <typename func_type0, typename func_type1>
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1169 void do_visit_dom (size_t visit_count, func_type0 inorder, func_type1 postorder);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1170
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1171 static const size_t NO_ID = static_cast<size_t> (-1);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1172 size_t mvisit_count;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1173 size_t mid;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1174 jit_block *idom;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1175 df_set mdf;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1176 std::vector<jit_block *> dom_succ;
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1177 std::string mname;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1178 instruction_list instructions;
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1179 mutable std::vector<llvm::BasicBlock *> mpred_llvm;
14939
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1180 bool mdead;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1181 };
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1182
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1183 // allow regular function pointers as well as pointers to members
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1184 template <typename func_type>
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1185 class jit_block_callback
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1186 {
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1187 public:
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1188 jit_block_callback (func_type afunction) : function (afunction) {}
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1189
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1190 void operator() (jit_block& block)
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1191 {
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1192 function (block);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1193 }
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1194 private:
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1195 func_type function;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1196 };
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1197
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1198 template <>
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1199 class jit_block_callback<void (jit_block::*)(void)>
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1200 {
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1201 public:
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1202 typedef void (jit_block::*func_type)(void);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1203
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1204 jit_block_callback (func_type afunction) : function (afunction) {}
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1205
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1206 void operator() (jit_block& ablock)
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1207 {
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1208 (ablock.*function) ();
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1209 }
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1210 private:
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1211 func_type function;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1212 };
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1213
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1214 template <typename func_type0, typename func_type1>
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1215 void
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1216 jit_block::do_visit_dom (size_t visit_count, func_type0 inorder, func_type1 postorder)
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1217 {
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1218 if (mvisit_count > visit_count)
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1219 return;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1220 mvisit_count = visit_count + 1;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1221
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1222 jit_block_callback<func_type0> inorder_cb (inorder);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1223 inorder_cb (*this);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1224
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1225 for (size_t i = 0; i < dom_succ.size (); ++i)
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1226 dom_succ[i]->do_visit_dom (visit_count, inorder, postorder);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1227
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1228 jit_block_callback<func_type1> postorder_cb (postorder);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1229 postorder_cb (*this);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1230 }
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1231
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 // A non-ssa variable
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1234 class
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1235 jit_variable : public jit_value
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1236 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1237 public:
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1238 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
1239
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1240 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
1241
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1242 // 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
1243 // 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
1244 bool has_top (void) const
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1245 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1246 return ! value_stack.empty ();
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1247 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1248
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1249 jit_value *top (void) const
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1250 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1251 return value_stack.top ();
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1252 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1253
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1254 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
1255 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1256 value_stack.push (v);
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1257 mlast_use = v;
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1258 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1259
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1260 void pop (void)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1261 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1262 value_stack.pop ();
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1263 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1264
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1265 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
1266 {
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1267 return mlast_use;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1268 }
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1269
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1270 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
1271 {
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1272 mlast_use = instr;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1273 }
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1274
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1275 // 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
1276 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
1277 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1278 jit_use *use = first_use ();
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1279 while (use)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1280 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1281 result.insert (use->user_parent ());
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1282 use = use->next ();
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1283 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1284 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1285
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1286 virtual std::ostream& print (std::ostream& os, size_t indent) const
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 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
1289 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1290
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1291 JIT_VALUE_ACCEPT (variable)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1292 private:
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1293 std::string mname;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1294 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
1295 jit_instruction *mlast_use;
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1296 };
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1297
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1298 class
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1299 jit_assign_base : public jit_instruction
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1300 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1301 public:
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1302 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
1303
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1304 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
1305 mdest (adest) {}
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1306
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1307 jit_assign_base (jit_variable *adest, jit_value *arg0, jit_value *arg1)
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1308 : jit_instruction (arg0, arg1), mdest (adest) {}
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1309
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1310 jit_variable *dest (void) const { return mdest; }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1311
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1312 virtual void push_variable (void)
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1313 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1314 mdest->push (this);
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1315 }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1316
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1317 virtual void pop_variable (void)
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1318 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1319 mdest->pop ();
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1320 }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1321 private:
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1322 jit_variable *mdest;
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1323 };
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1324
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1325 class
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1326 jit_assign : public jit_assign_base
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1327 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1328 public:
14944
c0a5ab3b9278 jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents: 14943
diff changeset
1329 jit_assign (jit_variable *adest, jit_value *asrc)
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1330 : jit_assign_base (adest, adest, asrc) {}
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1331
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1332 jit_instruction *src (void) const
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1333 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1334 return static_cast<jit_instruction *> (argument (1));
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1335 }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1336
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1337 virtual void push_variable (void)
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1338 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1339 dest ()->push (src ());
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1340 }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1341
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1342 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
1343 {
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1344 return print_indent (os, indent) << *dest () << " = " << *src ();
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1345 }
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1346
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1347 JIT_VALUE_ACCEPT (assign);
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1348 private:
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1349 jit_variable *mdest;
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1350 };
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1351
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1352 class
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1353 jit_phi : public jit_assign_base
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1354 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1355 public:
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1356 jit_phi (jit_variable *adest, size_t npred) : jit_assign_base (adest, npred)
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1357 {}
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1358
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1359 virtual bool dead (void) const
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1360 {
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1361 return use_count () == 0;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1362 }
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1363
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1364 virtual bool almost_dead (void) const
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1365 {
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1366 return use_count () <= 1;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1367 }
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1368
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1369 virtual bool infer (void)
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1370 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1371 jit_type *infered = 0;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1372 for (size_t i = 0; i < argument_count (); ++i)
14922
2e6f83b2f2b9 Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents: 14920
diff changeset
1373 infered = jit_typeinfo::join (infered, argument_type (i));
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1374
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1375 if (infered != type ())
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1376 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1377 stash_type (infered);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1378 return true;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1379 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1380
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1381 return false;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1382 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1383
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1384 virtual std::ostream& print (std::ostream& os, size_t indent) const
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1385 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1386 std::stringstream ss;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1387 print_indent (ss, indent);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1388 short_print (ss) << " phi ";
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1389 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
1390 std::string indent_str (ss_str.size (), ' ');
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1391 os << ss_str;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1392
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1393 jit_block *pblock = parent ();
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1394 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
1395 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1396 if (i > 0)
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1397 os << indent_str;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1398 os << "| ";
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1399
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1400 pblock->print_pred (os, i) << " -> ";
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1401 print_argument (os, i);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1402
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1403 if (i + 1 < argument_count ())
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1404 os << std::endl;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1405 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1406
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1407 return os;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1408 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1409
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1410 virtual std::ostream& short_print (std::ostream& os) const
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1411 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1412 if (type ())
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1413 jit_print (os, type ()) << ": ";
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1414
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1415 dest ()->short_print (os);
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1416 return os << "#" << id ();
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1417 }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1418
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1419 JIT_VALUE_ACCEPT (phi);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1420 };
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1421
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1422 class
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1423 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
1424 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1425 public:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1426 jit_terminator (jit_value *arg0) : jit_instruction (arg0) {}
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1427
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1428 jit_terminator (jit_value *arg0, jit_value *arg1)
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1429 : jit_instruction (arg0, arg1) {}
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1430
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1431 jit_terminator (jit_value *arg0, jit_value *arg1, jit_value *arg2)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1432 : jit_instruction (arg0, arg1, arg2) {}
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1433
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1434 virtual jit_block *sucessor (size_t idx = 0) const = 0;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1435
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1436 // return either our sucessors block directly, or the phi merge block
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1437 // between us and our sucessor
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1438 llvm::BasicBlock *sucessor_llvm (size_t idx = 0) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1439 {
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1440 jit_block *succ = sucessor (idx);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1441 llvm::BasicBlock *pllvm = parent_llvm ();
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1442 llvm::BasicBlock *spred_llvm = succ->pred_llvm (parent ());
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1443 llvm::BasicBlock *succ_llvm = succ->to_llvm ();
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1444 return pllvm == spred_llvm ? succ_llvm : spred_llvm;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1445 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1446
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1447 std::ostream& print_sucessor (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
1448 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1449 return sucessor (idx)->short_print (os);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1450 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1451
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1452 virtual size_t sucessor_count (void) const = 0;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1453 };
14913
c7071907a641 Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents: 14911
diff changeset
1454
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1455 class
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1456 jit_break : public jit_terminator
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1457 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1458 public:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1459 jit_break (jit_block *succ) : jit_terminator (succ) {}
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1460
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1461 jit_block *sucessor (size_t idx = 0) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1462 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1463 jit_value *arg = argument (idx);
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1464 return static_cast<jit_block *> (arg);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1465 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1466
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1467 size_t sucessor_count (void) const { return 1; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1468
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1469 virtual std::ostream& print (std::ostream& os, size_t indent) const
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1470 {
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1471 print_indent (os, indent) << "break: ";
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1472 return print_sucessor (os);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1473 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1474
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1475 JIT_VALUE_ACCEPT (break)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1476 };
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1477
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1478 class
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1479 jit_cond_break : public jit_terminator
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1480 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1481 public:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1482 jit_cond_break (jit_value *c, jit_block *ctrue, jit_block *cfalse)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1483 : jit_terminator (c, ctrue, cfalse) {}
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1484
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1485 jit_value *cond (void) const { return argument (0); }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1486
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1487 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
1488 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1489 return cond ()->short_print (os);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1490 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1491
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1492 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
1493 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1494 return cond ()->to_llvm ();
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1495 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1496
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1497 jit_block *sucessor (size_t idx) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1498 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1499 jit_value *arg = argument (idx + 1);
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1500 return static_cast<jit_block *> (arg);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1501 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1502
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1503 size_t sucessor_count (void) const { return 2; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1504
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1505 virtual std::ostream& print (std::ostream& os, size_t indent) const
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1506 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1507 print_indent (os, indent) << "cond_break: ";
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1508 print_cond (os) << ", ";
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1509 print_sucessor (os, 0) << ", ";
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1510 return print_sucessor (os, 1);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1511 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1512
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1513 JIT_VALUE_ACCEPT (cond_break)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1514 };
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1515
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1516 class
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1517 jit_call : public jit_instruction
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1518 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1519 public:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1520 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
1521 jit_value *arg0) : jit_instruction (arg0), mfunction (afunction) {}
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1522
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1523 jit_call (const jit_function& (*afunction) (void),
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1524 jit_value *arg0) : jit_instruction (arg0), mfunction (afunction ()) {}
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1525
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1526 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
1527 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
1528 mfunction (afunction) {}
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1529
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1530 jit_call (const jit_function& (*afunction) (void),
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1531 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
1532 mfunction (afunction ()) {}
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1533
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1534 jit_call (const jit_function& (*afunction) (void),
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1535 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
1536 : jit_instruction (arg0, arg1, arg2), mfunction (afunction ()) {}
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1537
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1538 jit_call (const jit_function& (*afunction) (void),
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1539 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
1540 : jit_instruction (arg0, arg1, arg2, arg3), mfunction (afunction ()) {}
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1541
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1542
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1543 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
1544
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1545 bool has_side_effects (void) const
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1546 {
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1547 return overload ().side_effects;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1548 }
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1549
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1550 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
1551 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1552 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
1553 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1554
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1555 virtual std::ostream& print (std::ostream& os, size_t indent) const
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1556 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1557 print_indent (os, indent);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1558
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1559 if (use_count ())
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1560 short_print (os) << " = ";
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1561 os << "call " << mfunction.name () << " (";
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1562
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1563 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
1564 {
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1565 print_argument (os, i);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1566 if (i + 1 < argument_count ())
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1567 os << ", ";
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1568 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1569 return os << ")";
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1570 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1571
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1572 virtual bool dead (void) const;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1573
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1574 virtual bool almost_dead (void) const;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1575
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1576 virtual bool infer (void);
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1577
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1578 JIT_VALUE_ACCEPT (call)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1579 private:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1580 const jit_function& mfunction;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1581 };
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1582
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1583 // FIXME: This is just ugly...
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1584 // 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
1585 // 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
1586 class
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1587 jit_check_error : public jit_terminator
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1588 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1589 public:
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1590 jit_check_error (jit_block *normal, jit_block *error)
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1591 : jit_terminator (normal, error) {}
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1592
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1593 jit_block *sucessor (size_t idx) const
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1594 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1595 return static_cast<jit_block *> (argument (idx));
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1596 }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1597
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1598 size_t sucessor_count (void) const { return 2; }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1599
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1600 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
1601 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1602 print_indent (os, indent) << "check_error: normal: ";
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1603 print_sucessor (os, 0) << " error: ";
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1604 return print_sucessor (os, 1);
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1605 }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1606
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1607 JIT_VALUE_ACCEPT (jit_check_error)
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1608 };
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1609
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1610 class
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1611 jit_extract_argument : public jit_assign_base
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1612 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1613 public:
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1614 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
1615 : jit_assign_base (adest)
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1616 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1617 stash_type (atype);
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1618 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1619
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1620 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
1621 {
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1622 return dest ()->name ();
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1623 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1624
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1625 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
1626 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1627 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
1628 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1629
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1630 virtual std::ostream& print (std::ostream& os, size_t indent) const
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1631 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1632 print_indent (os, indent);
14942
e8487d98561c Improve printing of jit_extract_argument
Max Brister <max@2bass.com>
parents: 14941
diff changeset
1633
e8487d98561c Improve printing of jit_extract_argument
Max Brister <max@2bass.com>
parents: 14941
diff changeset
1634 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
1635 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1636
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1637 JIT_VALUE_ACCEPT (extract_argument)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1638 };
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1639
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1640 class
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1641 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
1642 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1643 public:
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1644 jit_store_argument (jit_variable *var)
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1645 : jit_instruction (var), dest (var)
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1646 {}
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1647
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1648 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
1649 {
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1650 return dest->name ();
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1651 }
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1652
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1653 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
1654 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1655 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
1656 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1657
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1658 jit_value *result (void) const
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1659 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1660 return argument (0);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1661 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1662
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1663 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
1664 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1665 return result ()->type ();
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1666 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1667
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1668 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
1669 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1670 return result ()->to_llvm ();
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1671 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1672
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1673 virtual std::ostream& print (std::ostream& os, size_t indent) const
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1674 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1675 jit_value *res = result ();
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1676 print_indent (os, indent) << "store ";
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1677 dest->short_print (os);
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1678
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1679 if (! isa<jit_variable> (res))
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1680 {
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1681 os << " = ";
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1682 res->short_print (os);
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1683 }
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1684
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1685 return os;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1686 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1687
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1688 JIT_VALUE_ACCEPT (store_argument)
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1689 private:
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1690 jit_variable *dest;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1691 };
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1692
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1693 class
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1694 jit_ir_walker
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1695 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1696 public:
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1697 virtual ~jit_ir_walker () {}
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1698
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1699 #define JIT_METH(clname) \
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1700 virtual void visit (jit_ ## clname&) = 0;
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1701
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1702 JIT_VISIT_IR_CLASSES;
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1703
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1704 #undef JIT_METH
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1705 };
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1706
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1707 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
1708 void
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1709 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
1710 {
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1711 walker.visit (*this);
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1712 }
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1713
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1714 // convert between IRs
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1715 // 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
1716 // cleaned up.
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1717 class
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1718 jit_convert : public tree_walker
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1719 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1720 public:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1721 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
1722 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
1723
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1724 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
1725
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1726 ~jit_convert (void);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1727
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1728 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
1729
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1730 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
1731 { return arguments; }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1732
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1733 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
1734
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1735 void visit_anon_fcn_handle (tree_anon_fcn_handle&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1736
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1737 void visit_argument_list (tree_argument_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1738
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1739 void visit_binary_expression (tree_binary_expression&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1740
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1741 void visit_break_command (tree_break_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1742
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1743 void visit_colon_expression (tree_colon_expression&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1744
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1745 void visit_continue_command (tree_continue_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1746
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1747 void visit_global_command (tree_global_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1748
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1749 void visit_persistent_command (tree_persistent_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1750
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1751 void visit_decl_elt (tree_decl_elt&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1752
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1753 void visit_decl_init_list (tree_decl_init_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1754
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1755 void visit_simple_for_command (tree_simple_for_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1756
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1757 void visit_complex_for_command (tree_complex_for_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1758
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1759 void visit_octave_user_script (octave_user_script&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1760
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1761 void visit_octave_user_function (octave_user_function&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1762
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1763 void visit_octave_user_function_header (octave_user_function&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1764
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1765 void visit_octave_user_function_trailer (octave_user_function&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1766
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1767 void visit_function_def (tree_function_def&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1768
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1769 void visit_identifier (tree_identifier&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1770
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1771 void visit_if_clause (tree_if_clause&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1772
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1773 void visit_if_command (tree_if_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1774
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1775 void visit_if_command_list (tree_if_command_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1776
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1777 void visit_index_expression (tree_index_expression&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1778
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1779 void visit_matrix (tree_matrix&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1780
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1781 void visit_cell (tree_cell&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1782
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1783 void visit_multi_assignment (tree_multi_assignment&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1784
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1785 void visit_no_op_command (tree_no_op_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1786
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1787 void visit_constant (tree_constant&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1788
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1789 void visit_fcn_handle (tree_fcn_handle&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1790
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1791 void visit_parameter_list (tree_parameter_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1792
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1793 void visit_postfix_expression (tree_postfix_expression&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1794
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1795 void visit_prefix_expression (tree_prefix_expression&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1796
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1797 void visit_return_command (tree_return_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1798
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1799 void visit_return_list (tree_return_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1800
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1801 void visit_simple_assignment (tree_simple_assignment&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1802
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1803 void visit_statement (tree_statement&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1804
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1805 void visit_statement_list (tree_statement_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1806
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1807 void visit_switch_case (tree_switch_case&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1808
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1809 void visit_switch_case_list (tree_switch_case_list&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1810
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1811 void visit_switch_command (tree_switch_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1812
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1813 void visit_try_catch_command (tree_try_catch_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1814
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1815 void visit_unwind_protect_command (tree_unwind_protect_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1816
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1817 void visit_while_command (tree_while_command&);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1818
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1819 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
1820
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1821 // this would be easier with variadic templates
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1822 template <typename T>
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1823 T *create (void)
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1824 {
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1825 T *ret = new T();
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1826 track_value (ret);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1827 return ret;
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1828 }
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1829
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1830 template <typename T, typename ARG0>
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1831 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
1832 {
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1833 T *ret = new T(arg0);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1834 track_value (ret);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1835 return ret;
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1836 }
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1837
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1838 template <typename T, typename ARG0, typename ARG1>
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1839 T *create (const ARG0& arg0, const ARG1& arg1)
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1840 {
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1841 T *ret = new T(arg0, arg1);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1842 track_value (ret);
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1843 return ret;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1844 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1845
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1846 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
1847 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
1848 {
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1849 T *ret = new T(arg0, arg1, arg2);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1850 track_value (ret);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1851 return ret;
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1852 }
14936
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1853
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1854 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
1855 typename ARG3>
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1856 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
1857 const ARG3& arg3)
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1858 {
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1859 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
1860 track_value (ret);
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1861 return ret;
32deb562ae77 Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents: 14935
diff changeset
1862 }
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1863 private:
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1864 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
1865 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
1866
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1867 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
1868 type_bound_vector bounds;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1869
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1870 // 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
1871 jit_value *result;
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1872
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1873 jit_block *entry_block;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1874
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1875 jit_block *final_block;
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1876
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1877 jit_block *block;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1878
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1879 llvm::Function *function;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1880
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1881 std::list<jit_block *> blocks;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1882
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1883 std::list<jit_instruction *> worklist;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1884
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1885 std::list<jit_value *> constants;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1886
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1887 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
1888
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1889 size_t iterator_count;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1890
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1891 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
1892 vmap_t vmap;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1893
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1894 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
1895
14944
c0a5ab3b9278 jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents: 14943
diff changeset
1896 jit_value *do_assign (const std::string& lhs, jit_value *rhs, bool print);
c0a5ab3b9278 jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents: 14943
diff changeset
1897
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1898
14944
c0a5ab3b9278 jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents: 14943
diff changeset
1899 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
1900
14944
c0a5ab3b9278 jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents: 14943
diff changeset
1901 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
1902
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1903 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
1904 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1905 for (jit_use *use = v->first_use (); use; use = use->next ())
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1906 worklist.push_back (use->user ());
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1907 }
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1908
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1909 void track_value (jit_value *value)
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1910 {
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1911 if (value->type ())
14925
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1912 constants.push_back (value);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1913 all_values.push_back (value);
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1914 }
8697e3e9d77a Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents: 14923
diff changeset
1915
14939
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1916 void merge_blocks (void);
4488022820c9 No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents: 14938
diff changeset
1917
14938
bab44e3ee291 Adding basic error support to JIT
Max Brister <max@2bass.com>
parents: 14937
diff changeset
1918 void construct_ssa (void);
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1919
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1920 static void do_construct_ssa (jit_block& block);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1921
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1922 void place_releases (void);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1923
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1924 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
1925 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1926 std::cout << "-------------------- " << header << " --------------------\n";
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1927 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
1928 iter != blocks.end (); ++iter)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1929 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1930 assert (*iter);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1931 (*iter)->print (std::cout, 0);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1932 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1933 std::cout << std::endl;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1934 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1935
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1936 void print_dom (void)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1937 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1938 std::cout << "-------------------- dom info --------------------\n";
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1939 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
1940 iter != blocks.end (); ++iter)
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1941 {
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1942 assert (*iter);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1943 (*iter)->print_dom (std::cout);
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1944 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1945 std::cout << std::endl;
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1946 }
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1947
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1948 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
1949 block_list breaks;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1950 block_list continues;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1951
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1952 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
1953
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1954 struct release_placer
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1955 {
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1956 release_placer (jit_convert& aconvert) : convert (aconvert) {}
14928
39d52aa37a08 Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents: 14926
diff changeset
1957
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1958 jit_convert& convert;
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1959
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1960 void operator() (jit_block& block);
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1961 };
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1962
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1963 // 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
1964 class
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1965 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
1966 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1967 public:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1968 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
1969 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
1970 const std::list<jit_block *>& blocks,
c0a5ab3b9278 jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents: 14943
diff changeset
1971 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
1972
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1973 #define JIT_METH(clname) \
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1974 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
1975
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1976 JIT_VISIT_IR_CLASSES;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1977
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1978 #undef JIT_METH
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1979 private:
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1980 // name -> llvm argument
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1981 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
1982
14935
5801e031a3b5 Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents: 14932
diff changeset
1983 void finish_phi (jit_instruction *phi);
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
1984
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1985 void visit (jit_value *jvalue)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1986 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1987 return visit (*jvalue);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1988 }
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1989
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1990 void visit (jit_value &jvalue)
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1991 {
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1992 jvalue.accept (*this);
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1993 }
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1994 private:
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
1995 llvm::Function *function;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1996 };
14906
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
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
1999 class jit_info;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
2000
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2001 class
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
2002 tree_jit
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2003 {
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2004 public:
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2005 tree_jit (void);
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2006
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2007 ~tree_jit (void);
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2008
14920
51d4b1018efb For loops compile with new IR
Max Brister <max@2bass.com>
parents: 14918
diff changeset
2009 bool execute (tree_simple_for_command& cmd);
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
2010
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2011 llvm::ExecutionEngine *get_engine (void) const { return engine; }
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
2012
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2013 llvm::Module *get_module (void) const { return module; }
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
2014
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2015 void optimize (llvm::Function *fn);
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2016 private:
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2017 bool initialize (void);
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2018
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2019 // FIXME: Temorary hack to test
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2020 typedef std::map<tree *, jit_info *> compiled_map;
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2021 llvm::Module *module;
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
2022 llvm::PassManager *module_pass_manager;
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2023 llvm::FunctionPassManager *pass_manager;
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2024 llvm::ExecutionEngine *engine;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2025 };
14903
54ea692b8ab5 Reworking JIT implementation
Max Brister <max@2bass.com>
parents: 14901
diff changeset
2026
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2027 class
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2028 jit_info
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 public:
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2031 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
2032
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2033 bool execute (void) const;
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2034
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2035 bool match (void) const;
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2036 private:
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2037 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
2038 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
2039 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
2040
14906
3f81e8b42955 JIT for loops over ranges
Max Brister <max@2bass.com>
parents: 14903
diff changeset
2041 llvm::ExecutionEngine *engine;
14917
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2042 jited_function function;
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2043
232d8ab07932 Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents: 14915
diff changeset
2044 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
2045 type_bound_vector bounds;
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2046 };
14937
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
2047
78e1457c5bf5 Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents: 14936
diff changeset
2048 // 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
2049 #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
2050 #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
2051 #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
2052
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents:
diff changeset
2053 #endif
14932
1f914446157d Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents: 14928
diff changeset
2054 #endif