Mercurial > octave-nkf
comparison src/jit-typeinfo.h @ 15078:fe4752f772e2
Generate ND indexing functions on demand in JIT.
* src/jit-typeinfo.cc (jit_operation::~jit_operation,
jit_operation::do_generate, jit_operation::generate,
jit_operation::signature_cmp::operator()): New function.
(jit_operation::overload): Call do_generate when lookup fails.
(jit_index_operation, jit_paren_subsref, jit_paren_subsasgn): New class.
(jit_typeinfo::jit_typeinfo): Update to use jit_paren_subsref and
jit_paren_subsasgn.
(jit_typeinfo::gen_subsref, jit_typeinfo::gen_subsasgn): Removed functions.
* src/jit-typeinfo.h (jit_operation::~jit_operation, jit_operation::generate,
jit_operation::do_generate): New declaration.
(jit_operation::add_overload, jit_operation::overload, jit_operation::result,
jit_operation::to_idx): Use signature_vec typedef.
(jit_operation::singature_cmp): New class.
(jit_index_operation, jit_paren_subsref, jit_paren_subsasgn): New class.
(jit_typeinfo::get_scalar_ptr): Nwe function.
(jit_typeinfo::gen_subsref, jit_typeinfo::gen_subsasgn): Removed declaration.
* src/pt-jit.cc: New test.
author | Max Brister <max@2bass.com> |
---|---|
date | Wed, 01 Aug 2012 17:00:12 -0500 |
parents | f57d7578c1a6 |
children |
comparison
equal
deleted
inserted
replaced
15077:f0b04a20d7cf | 15078:fe4752f772e2 |
---|---|
312 // and their resulting types. | 312 // and their resulting types. |
313 class | 313 class |
314 jit_operation | 314 jit_operation |
315 { | 315 { |
316 public: | 316 public: |
317 // type signature vector | |
318 typedef std::vector<jit_type *> signature_vec; | |
319 | |
320 virtual ~jit_operation (void); | |
321 | |
317 void add_overload (const jit_function& func) | 322 void add_overload (const jit_function& func) |
318 { | 323 { |
319 add_overload (func, func.arguments ()); | 324 add_overload (func, func.arguments ()); |
320 } | 325 } |
321 | 326 |
322 void add_overload (const jit_function& func, | 327 void add_overload (const jit_function& func, |
323 const std::vector<jit_type*>& args); | 328 const signature_vec& args); |
324 | 329 |
325 const jit_function& overload (const std::vector<jit_type *>& types) const; | 330 const jit_function& overload (const signature_vec& types) const; |
326 | 331 |
327 jit_type *result (const std::vector<jit_type *>& types) const | 332 jit_type *result (const signature_vec& types) const |
328 { | 333 { |
329 const jit_function& temp = overload (types); | 334 const jit_function& temp = overload (types); |
330 return temp.result (); | 335 return temp.result (); |
331 } | 336 } |
332 | 337 |
344 #undef JIT_PARAM_ARGS | 349 #undef JIT_PARAM_ARGS |
345 | 350 |
346 const std::string& name (void) const { return mname; } | 351 const std::string& name (void) const { return mname; } |
347 | 352 |
348 void stash_name (const std::string& aname) { mname = aname; } | 353 void stash_name (const std::string& aname) { mname = aname; } |
354 protected: | |
355 virtual jit_function *generate (const signature_vec& types) const; | |
349 private: | 356 private: |
350 Array<octave_idx_type> to_idx (const std::vector<jit_type*>& types) const; | 357 Array<octave_idx_type> to_idx (const signature_vec& types) const; |
358 | |
359 const jit_function& do_generate (const signature_vec& types) const; | |
360 | |
361 struct signature_cmp | |
362 { | |
363 bool operator() (const signature_vec *lhs, const signature_vec *rhs); | |
364 }; | |
365 | |
366 typedef std::map<const signature_vec *, jit_function *, signature_cmp> | |
367 generated_map; | |
368 | |
369 mutable generated_map generated; | |
351 | 370 |
352 std::vector<Array<jit_function> > overloads; | 371 std::vector<Array<jit_function> > overloads; |
353 | 372 |
354 std::string mname; | 373 std::string mname; |
374 }; | |
375 | |
376 class | |
377 jit_index_operation : public jit_operation | |
378 { | |
379 public: | |
380 jit_index_operation (void) : module (0), engine (0) {} | |
381 | |
382 void initialize (llvm::Module *amodule, llvm::ExecutionEngine *aengine) | |
383 { | |
384 module = amodule; | |
385 engine = aengine; | |
386 do_initialize (); | |
387 } | |
388 protected: | |
389 virtual jit_function *generate (const signature_vec& types) const; | |
390 | |
391 virtual jit_function *generate_matrix (const signature_vec& types) const = 0; | |
392 | |
393 virtual void do_initialize (void) = 0; | |
394 | |
395 // helper functions | |
396 // [start_idx, end_idx). | |
397 llvm::Value *create_arg_array (llvm::IRBuilderD& builder, | |
398 const jit_function &fn, size_t start_idx, | |
399 size_t end_idx) const; | |
400 | |
401 llvm::Module *module; | |
402 llvm::ExecutionEngine *engine; | |
403 }; | |
404 | |
405 class | |
406 jit_paren_subsref : public jit_index_operation | |
407 { | |
408 protected: | |
409 virtual jit_function *generate_matrix (const signature_vec& types) const; | |
410 | |
411 virtual void do_initialize (void); | |
412 private: | |
413 jit_function paren_scalar; | |
414 }; | |
415 | |
416 class | |
417 jit_paren_subsasgn : public jit_index_operation | |
418 { | |
419 protected: | |
420 jit_function *generate_matrix (const signature_vec& types) const; | |
421 | |
422 virtual void do_initialize (void); | |
423 private: | |
424 jit_function paren_scalar; | |
355 }; | 425 }; |
356 | 426 |
357 // A singleton class which handles the construction of jit_types and | 427 // A singleton class which handles the construction of jit_types and |
358 // jit_operations. | 428 // jit_operations. |
359 class | 429 class |
373 | 443 |
374 static jit_type *get_scalar (void) { return instance->scalar; } | 444 static jit_type *get_scalar (void) { return instance->scalar; } |
375 | 445 |
376 static llvm::Type *get_scalar_llvm (void) | 446 static llvm::Type *get_scalar_llvm (void) |
377 { return instance->scalar->to_llvm (); } | 447 { return instance->scalar->to_llvm (); } |
448 | |
449 static jit_type *get_scalar_ptr (void) { return instance->scalar_ptr; } | |
378 | 450 |
379 static jit_type *get_range (void) { return instance->range; } | 451 static jit_type *get_range (void) { return instance->range; } |
380 | 452 |
381 static jit_type *get_string (void) { return instance->string; } | 453 static jit_type *get_string (void) { return instance->string; } |
382 | 454 |
629 | 701 |
630 void create_int (size_t nbits); | 702 void create_int (size_t nbits); |
631 | 703 |
632 jit_type *intN (size_t nbits) const; | 704 jit_type *intN (size_t nbits) const; |
633 | 705 |
634 void gen_subsref (const jit_function& paren_scalar, size_t n); | |
635 | |
636 void gen_subsasgn (const jit_function& paren_scalar, size_t n); | |
637 | |
638 static jit_typeinfo *instance; | 706 static jit_typeinfo *instance; |
639 | 707 |
640 llvm::Module *module; | 708 llvm::Module *module; |
641 llvm::ExecutionEngine *engine; | 709 llvm::ExecutionEngine *engine; |
642 int next_id; | 710 int next_id; |
645 | 713 |
646 std::vector<jit_type*> id_to_type; | 714 std::vector<jit_type*> id_to_type; |
647 jit_type *any; | 715 jit_type *any; |
648 jit_type *matrix; | 716 jit_type *matrix; |
649 jit_type *scalar; | 717 jit_type *scalar; |
718 jit_type *scalar_ptr; // a fake type for interfacing with C++ | |
650 jit_type *range; | 719 jit_type *range; |
651 jit_type *string; | 720 jit_type *string; |
652 jit_type *boolean; | 721 jit_type *boolean; |
653 jit_type *index; | 722 jit_type *index; |
654 jit_type *complex; | 723 jit_type *complex; |
665 jit_operation for_init_fn; | 734 jit_operation for_init_fn; |
666 jit_operation for_check_fn; | 735 jit_operation for_check_fn; |
667 jit_operation for_index_fn; | 736 jit_operation for_index_fn; |
668 jit_operation logically_true_fn; | 737 jit_operation logically_true_fn; |
669 jit_operation make_range_fn; | 738 jit_operation make_range_fn; |
670 jit_operation paren_subsref_fn; | 739 jit_paren_subsref paren_subsref_fn; |
671 jit_operation paren_subsasgn_fn; | 740 jit_paren_subsasgn paren_subsasgn_fn; |
672 jit_operation end_fn; | 741 jit_operation end_fn; |
673 | 742 |
674 // type id -> cast function TO that type | 743 // type id -> cast function TO that type |
675 std::vector<jit_operation> casts; | 744 std::vector<jit_operation> casts; |
676 | 745 |