annotate src/pt-jit.h @ 15014:094bc0a145a1

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