Mercurial > octave-nkf
comparison libinterp/corefcn/pt-jit.h @ 20654:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | 4197fc428c7d |
children |
comparison
equal
deleted
inserted
replaced
20653:9cef0a1207e4 | 20654:b65888ec820e |
---|---|
23 // Author: Max Brister <max@2bass.com> | 23 // Author: Max Brister <max@2bass.com> |
24 | 24 |
25 #if !defined (octave_pt_jit_h) | 25 #if !defined (octave_pt_jit_h) |
26 #define octave_pt_jit_h 1 | 26 #define octave_pt_jit_h 1 |
27 | 27 |
28 #ifdef HAVE_LLVM | 28 #ifdef HAVE_JIT |
29 | 29 |
30 #include "jit-ir.h" | 30 #include "jit-ir.h" |
31 #include "pt-walk.h" | 31 #include "pt-walk.h" |
32 #include "symtab.h" | 32 #include "symtab.h" |
33 | |
33 | 34 |
34 class octave_value_list; | 35 class octave_value_list; |
35 | 36 |
36 // Convert from the parse tree (AST) to the low level Octave IR. | 37 // Convert from the parse tree (AST) to the low level Octave IR. |
37 class | 38 class |
67 | 68 |
68 const type_bound_vector& get_bounds (void) const { return bounds; } | 69 const type_bound_vector& get_bounds (void) const { return bounds; } |
69 | 70 |
70 jit_factory& get_factory (void) { return factory; } | 71 jit_factory& get_factory (void) { return factory; } |
71 | 72 |
73 #ifdef HAVE_LLVM | |
72 llvm::Function *get_function (void) const { return function; } | 74 llvm::Function *get_function (void) const { return function; } |
75 #endif | |
73 | 76 |
74 const variable_map &get_variable_map (void) const { return vmap; } | 77 const variable_map &get_variable_map (void) const { return vmap; } |
75 | 78 |
76 void visit_anon_fcn_handle (tree_anon_fcn_handle&); | 79 void visit_anon_fcn_handle (tree_anon_fcn_handle&); |
77 | 80 |
178 | 181 |
179 jit_block *final_block; | 182 jit_block *final_block; |
180 | 183 |
181 jit_block *block; | 184 jit_block *block; |
182 | 185 |
186 #ifdef HAVE_LLVM | |
183 llvm::Function *function; | 187 llvm::Function *function; |
188 #endif | |
184 | 189 |
185 jit_block_list blocks; | 190 jit_block_list blocks; |
186 | 191 |
187 std::vector<jit_magic_end::context> end_context; | 192 std::vector<jit_magic_end::context> end_context; |
188 | 193 |
240 block_list continues; | 245 block_list continues; |
241 | 246 |
242 void finish_breaks (jit_block *dest, const block_list& lst); | 247 void finish_breaks (jit_block *dest, const block_list& lst); |
243 }; | 248 }; |
244 | 249 |
250 // Convert from the low level Octave IR to libgccjit | |
251 #ifdef HAVE_GCCJIT | |
252 class | |
253 jit_convert_gcc : public jit_ir_walker | |
254 { | |
255 public: | |
256 jit_convert_gcc (); | |
257 ~jit_convert_gcc (); | |
258 | |
259 gcc_jit_result *convert_loop (const jit_block_list& blocks, | |
260 const std::list<jit_value *>& constants); | |
261 | |
262 #define JIT_METH(clname) \ | |
263 virtual void visit (jit_ ## clname&); | |
264 | |
265 JIT_VISIT_IR_CLASSES; | |
266 | |
267 private: | |
268 void visit (jit_value *jvalue) | |
269 { | |
270 return visit (*jvalue); | |
271 } | |
272 | |
273 void visit (jit_value &jvalue) | |
274 { | |
275 jvalue.accept (*this); | |
276 } | |
277 | |
278 #if 0 | |
279 gccjit::lvalue as_lvalue (jit_value *); | |
280 #endif | |
281 gccjit::rvalue as_rvalue (jit_value *); | |
282 | |
283 void add_assignment_for_insn (jit_instruction &insn, | |
284 gccjit::rvalue val); | |
285 | |
286 gccjit::block get_block_for_edge (jit_block *src, jit_block *dest); | |
287 | |
288 gccjit::block get_current_block (); | |
289 void push_block (gccjit::block block); | |
290 void pop_block (); | |
291 | |
292 bool converting_function; | |
293 | |
294 // Inputs (used internally by callback): | |
295 const jit_block_list *m_blocks; | |
296 const std::list<jit_value *> *m_constants; | |
297 | |
298 // Internal state: | |
299 gccjit::context m_ctxt; | |
300 gccjit::function m_func; | |
301 | |
302 /* We have a single param, confusingly named "params" (an array). */ | |
303 gccjit::param params; | |
304 | |
305 // name -> argument index (used for compiling functions) | |
306 std::map<std::string, int> m_argument_index; | |
307 std::vector<std::pair<std::string, bool> > m_argument_vec; | |
308 | |
309 std::vector<gccjit::lvalue> m_extracted_params; | |
310 std::map<jit_block *, gccjit::block> m_block_map; | |
311 std::map<std::pair<jit_block *, jit_block *>, gccjit::block> m_blocks_for_edges; | |
312 std::map<jit_instruction *, gccjit::lvalue> m_locals_for_insns; | |
313 | |
314 std::map<jit_value *, gccjit::rvalue> m_rvalues; | |
315 | |
316 std::stack<gccjit::block> m_block_stack; | |
317 | |
318 bool m_with_comments; | |
319 bool m_log_visits; | |
320 }; | |
321 #endif // #ifdef HAVE_GCCJIT | |
322 | |
245 // Convert from the low level Octave IR to LLVM | 323 // Convert from the low level Octave IR to LLVM |
324 #if HAVE_LLVM | |
246 class | 325 class |
247 jit_convert_llvm : public jit_ir_walker | 326 jit_convert_llvm : public jit_ir_walker |
248 { | 327 { |
249 public: | 328 public: |
250 llvm::Function *convert_loop (llvm::Module *module, | 329 llvm::Function *convert_loop (llvm::Module *module, |
297 void visit (jit_value &jvalue) | 376 void visit (jit_value &jvalue) |
298 { | 377 { |
299 jvalue.accept (*this); | 378 jvalue.accept (*this); |
300 } | 379 } |
301 }; | 380 }; |
381 #endif /* HAVE_LLVM */ | |
302 | 382 |
303 // type inference and SSA construction on the low level Octave IR | 383 // type inference and SSA construction on the low level Octave IR |
304 class | 384 class |
305 jit_infer | 385 jit_infer |
306 { | 386 { |
360 static bool execute (tree_while_command& cmd); | 440 static bool execute (tree_while_command& cmd); |
361 | 441 |
362 static bool execute (octave_user_function& fcn, const octave_value_list& args, | 442 static bool execute (octave_user_function& fcn, const octave_value_list& args, |
363 octave_value_list& retval); | 443 octave_value_list& retval); |
364 | 444 |
445 #ifdef HAVE_LLVM | |
365 llvm::ExecutionEngine *get_engine (void) const { return engine; } | 446 llvm::ExecutionEngine *get_engine (void) const { return engine; } |
366 | 447 |
367 llvm::Module *get_module (void) const { return module; } | 448 llvm::Module *get_module (void) const { return module; } |
368 | 449 |
369 void optimize (llvm::Function *fn); | 450 void optimize (llvm::Function *fn); |
451 #endif | |
370 private: | 452 private: |
371 tree_jit (void); | 453 tree_jit (void); |
372 | 454 |
373 static tree_jit& instance (void); | 455 static tree_jit& instance (void); |
374 | 456 |
383 | 465 |
384 bool enabled (void); | 466 bool enabled (void); |
385 | 467 |
386 size_t trip_count (const octave_value& bounds) const; | 468 size_t trip_count (const octave_value& bounds) const; |
387 | 469 |
470 #ifdef HAVE_LLVM | |
388 llvm::Module *module; | 471 llvm::Module *module; |
389 #ifdef LEGACY_PASSMANAGER | 472 #ifdef LEGACY_PASSMANAGER |
390 llvm::legacy::PassManager *module_pass_manager; | 473 llvm::legacy::PassManager *module_pass_manager; |
391 llvm::legacy::FunctionPassManager *pass_manager; | 474 llvm::legacy::FunctionPassManager *pass_manager; |
392 #else | 475 #else |
393 llvm::PassManager *module_pass_manager; | 476 llvm::PassManager *module_pass_manager; |
394 llvm::FunctionPassManager *pass_manager; | 477 llvm::FunctionPassManager *pass_manager; |
395 #endif | 478 #endif |
396 llvm::ExecutionEngine *engine; | 479 llvm::ExecutionEngine *engine; |
480 #endif | |
397 }; | 481 }; |
398 | 482 |
399 class | 483 class |
400 jit_function_info | 484 jit_function_info |
401 { | 485 { |
437 | 521 |
438 void compile (tree_jit& tjit, tree& tee, jit_type *for_bounds = 0); | 522 void compile (tree_jit& tjit, tree& tee, jit_type *for_bounds = 0); |
439 | 523 |
440 octave_value find (const vmap& extra_vars, const std::string& vname) const; | 524 octave_value find (const vmap& extra_vars, const std::string& vname) const; |
441 | 525 |
526 #ifdef HAVE_LLVM | |
442 llvm::ExecutionEngine *engine; | 527 llvm::ExecutionEngine *engine; |
528 #endif | |
443 jited_function function; | 529 jited_function function; |
530 #ifdef HAVE_LLVM | |
444 llvm::Function *llvm_function; | 531 llvm::Function *llvm_function; |
445 | 532 #endif |
533 #ifdef HAVE_GCCJIT | |
534 gcc_jit_result *gccjit_result; | |
535 #endif | |
446 std::vector<std::pair<std::string, bool> > arguments; | 536 std::vector<std::pair<std::string, bool> > arguments; |
447 type_bound_vector bounds; | 537 type_bound_vector bounds; |
448 }; | 538 }; |
449 | 539 |
450 #endif | 540 #endif /* ifdef HAVE_JIT */ |
451 #endif | 541 #endif |