annotate src/pt-jit.h @ 14936:32deb562ae77

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