Mercurial > octave
comparison libinterp/parse-tree/jit-ir.cc @ 29654:d13d090cb03a stable
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
Files affected: make_int.cc, file-editor-tab.cc, octave-qscintilla.cc,
Cell.cc, Cell.h, call-stack.cc, call-stack.h, cellfun.cc, data.cc,
debug.cc, dlmread.cc, error.cc, event-queue.h, fcn-info.cc,
fcn-info.h, file-io.cc, ft-text-renderer.cc, gl2ps-print.cc,
graphics.cc, graphics.in.h, help.cc, hex2num.cc, input.cc,
latex-text-renderer.cc, load-path.cc, load-save.cc, load-save.h,
ls-hdf5.cc, ls-mat-ascii.cc, ls-mat5.cc, ls-oct-text.cc, mex.cc,
mexproto.h, mxarray.h, oct-map.cc, oct-stream.cc, oct-stream.h,
pager.cc, pager.h, pr-output.cc, regexp.cc, settings.h,
stack-frame.cc, stack-frame.h, strfns.cc, syminfo.cc, symrec.h,
symscope.cc, symscope.h, symtab.cc, sysdep.cc, toplev.cc, utils.cc,
utils.h, variables.cc, __fltk_uigetfile__.cc, __init_fltk__.cc,
audioread.cc, gzip.cc, cdef-class.cc, cdef-manager.cc, cdef-method.cc,
cdef-object.cc, cdef-object.h, ov-base-diag.cc, ov-base-diag.h,
ov-base-mat.cc, ov-base-mat.h, ov-base-scalar.cc, ov-base-scalar.h,
ov-base-sparse.h, ov-base.cc, ov-base.h, ov-cell.cc, ov-cell.h,
ov-ch-mat.cc, ov-class.cc, ov-class.h, ov-classdef.cc,
ov-fcn-handle.cc, ov-java.cc, ov-lazy-idx.h, ov-perm.cc, ov-perm.h,
ov-range.h, ov-str-mat.cc, ov-struct.cc, ov-struct.h, ov-usr-fcn.cc,
ov-usr-fcn.h, ov.cc, ov.h, ovl.cc, octave.cc, bp-table.cc, jit-ir.cc,
jit-ir.h, jit-typeinfo.cc, jit-typeinfo.h, jit-util.h, lex.h, lex.ll,
oct-lvalue.cc, oct-parse.yy, parse.h, profiler.h, pt-eval.cc,
pt-eval.h, pt-jit.cc, pt-jit.h, pt-pr-code.cc, pt-tm-const.cc,
pt-tm-const.h, Array.h, CMatrix.cc, DiagArray2.h, PermMatrix.h,
Sparse.h, dMatrix.cc, fCMatrix.cc, fMatrix.cc, bsxfun-defs.cc,
oct-fftw.cc, oct-fftw.h, randpoisson.cc, sparse-chol.cc,
mx-inlines.cc, file-ops.cc, lo-sysdep.cc, oct-env.cc, oct-time.cc,
action-container.cc, action-container.h, base-list.h, caseless-str.h,
cmd-edit.cc, cmd-hist.cc, data-conv.cc, data-conv.h, f77-fcn.h,
file-info.cc, file-info.h, kpse.cc, kpse.h, lo-cutils.h, lo-hash.h,
lo-regexp.cc, oct-base64.cc, oct-base64.h, oct-binmap.h, oct-glob.cc,
oct-shlib.cc, oct-shlib.h, oct-sort.cc, oct-sparse.h, oct-string.cc,
quit.cc, unwind-prot.h, url-transfer.cc, main.in.cc, mkoctfile.in.cc,
and shared-fcns.h.
(grafted from aef11bb4e6d1f303ad9de5688fcb7244ef48867e)
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 28 Apr 2021 22:57:42 -0400 |
parents | 0a5b15007766 |
children |
comparison
equal
deleted
inserted
replaced
29652:5068a97f0f39 | 29654:d13d090cb03a |
---|---|
171 jit_value::replace_with (jit_value *value) | 171 jit_value::replace_with (jit_value *value) |
172 { | 172 { |
173 while (first_use ()) | 173 while (first_use ()) |
174 { | 174 { |
175 jit_instruction *user = first_use ()->user (); | 175 jit_instruction *user = first_use ()->user (); |
176 size_t idx = first_use ()->index (); | 176 std::size_t idx = first_use ()->index (); |
177 user->stash_argument (idx, value); | 177 user->stash_argument (idx, value); |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 #define JIT_METH(clname) \ | 181 #define JIT_METH(clname) \ |
224 jit_print (os, type ()) << ": "; | 224 jit_print (os, type ()) << ": "; |
225 return os << '#' << m_id; | 225 return os << '#' << m_id; |
226 } | 226 } |
227 | 227 |
228 void | 228 void |
229 jit_instruction::do_construct_ssa (size_t start, size_t end) | 229 jit_instruction::do_construct_ssa (std::size_t start, std::size_t end) |
230 { | 230 { |
231 for (size_t i = start; i < end; ++i) | 231 for (std::size_t i = start; i < end; ++i) |
232 { | 232 { |
233 jit_value *arg = argument (i); | 233 jit_value *arg = argument (i); |
234 jit_variable *var = dynamic_cast<jit_variable *> (arg); | 234 jit_variable *var = dynamic_cast<jit_variable *> (arg); |
235 if (var && var->has_top ()) | 235 if (var && var->has_top ()) |
236 stash_argument (i, var->top ()); | 236 stash_argument (i, var->top ()); |
375 { | 375 { |
376 return terminator ()->alive (asucc); | 376 return terminator ()->alive (asucc); |
377 } | 377 } |
378 | 378 |
379 jit_block * | 379 jit_block * |
380 jit_block::successor (size_t i) const | 380 jit_block::successor (std::size_t i) const |
381 { | 381 { |
382 jit_terminator *term = terminator (); | 382 jit_terminator *term = terminator (); |
383 return term->successor (i); | 383 return term->successor (i); |
384 } | 384 } |
385 | 385 |
386 size_t | 386 std::size_t |
387 jit_block::successor_count (void) const | 387 jit_block::successor_count (void) const |
388 { | 388 { |
389 jit_terminator *term = terminator (); | 389 jit_terminator *term = terminator (); |
390 return term ? term->successor_count () : 0; | 390 return term ? term->successor_count () : 0; |
391 } | 391 } |
406 for (jit_use *use = first_use (); use; use = use->next ()) | 406 for (jit_use *use = first_use (); use; use = use->next ()) |
407 os << *use->user_parent () << ' '; | 407 os << *use->user_parent () << ' '; |
408 os << std::endl; | 408 os << std::endl; |
409 | 409 |
410 os << " successors: "; | 410 os << " successors: "; |
411 for (size_t i = 0; i < successor_count (); ++i) | 411 for (std::size_t i = 0; i < successor_count (); ++i) |
412 os << *successor (i) << ' '; | 412 os << *successor (i) << ' '; |
413 os << std::endl; | 413 os << std::endl; |
414 | 414 |
415 os << " m_idom: "; | 415 os << " m_idom: "; |
416 if (m_idom) | 416 if (m_idom) |
422 for (auto iter = df_begin (); iter != df_end (); ++iter) | 422 for (auto iter = df_begin (); iter != df_end (); ++iter) |
423 os << **iter << ' '; | 423 os << **iter << ' '; |
424 os << std::endl; | 424 os << std::endl; |
425 | 425 |
426 os << " m_dom_succ: "; | 426 os << " m_dom_succ: "; |
427 for (size_t i = 0; i < m_dom_succ.size (); ++i) | 427 for (std::size_t i = 0; i < m_dom_succ.size (); ++i) |
428 os << *m_dom_succ[i] << ' '; | 428 os << *m_dom_succ[i] << ' '; |
429 | 429 |
430 return os << std::endl; | 430 return os << std::endl; |
431 } | 431 } |
432 | 432 |
433 void | 433 void |
434 jit_block::compute_df (size_t avisit_count) | 434 jit_block::compute_df (std::size_t avisit_count) |
435 { | 435 { |
436 if (visited (avisit_count)) | 436 if (visited (avisit_count)) |
437 return; | 437 return; |
438 | 438 |
439 if (use_count () >= 2) | 439 if (use_count () >= 2) |
447 runner = runner->m_idom; | 447 runner = runner->m_idom; |
448 } | 448 } |
449 } | 449 } |
450 } | 450 } |
451 | 451 |
452 for (size_t i = 0; i < successor_count (); ++i) | 452 for (std::size_t i = 0; i < successor_count (); ++i) |
453 successor (i)->compute_df (avisit_count); | 453 successor (i)->compute_df (avisit_count); |
454 } | 454 } |
455 | 455 |
456 bool | 456 bool |
457 jit_block::update_idom (size_t avisit_count) | 457 jit_block::update_idom (std::size_t avisit_count) |
458 { | 458 { |
459 if (visited (avisit_count) || ! use_count ()) | 459 if (visited (avisit_count) || ! use_count ()) |
460 return false; | 460 return false; |
461 | 461 |
462 bool changed = false; | 462 bool changed = false; |
486 | 486 |
487 return changed; | 487 return changed; |
488 } | 488 } |
489 | 489 |
490 void | 490 void |
491 jit_block::label (size_t avisit_count, size_t& number) | 491 jit_block::label (std::size_t avisit_count, std::size_t& number) |
492 { | 492 { |
493 if (visited (avisit_count)) | 493 if (visited (avisit_count)) |
494 return; | 494 return; |
495 | 495 |
496 for (jit_use *use = first_use (); use; use = use->next ()) | 496 for (jit_use *use = first_use (); use; use = use->next ()) |
511 instr->pop_variable (); | 511 instr->pop_variable (); |
512 } | 512 } |
513 } | 513 } |
514 | 514 |
515 std::ostream& | 515 std::ostream& |
516 jit_block::print (std::ostream& os, size_t indent) const | 516 jit_block::print (std::ostream& os, std::size_t indent) const |
517 { | 517 { |
518 print_indent (os, indent); | 518 print_indent (os, indent); |
519 short_print (os) << ": %pred = "; | 519 short_print (os) << ": %pred = "; |
520 for (jit_use *use = first_use (); use; use = use->next ()) | 520 for (jit_use *use = first_use (); use; use = use->next ()) |
521 { | 521 { |
539 jit_block *asuccessor) | 539 jit_block *asuccessor) |
540 { | 540 { |
541 if (successor_count () > 1) | 541 if (successor_count () > 1) |
542 { | 542 { |
543 jit_terminator *term = terminator (); | 543 jit_terminator *term = terminator (); |
544 size_t idx = term->successor_index (asuccessor); | 544 std::size_t idx = term->successor_index (asuccessor); |
545 jit_block *split = factory.create<jit_block> ("phi_split", m_visit_count); | 545 jit_block *split = factory.create<jit_block> ("phi_split", m_visit_count); |
546 | 546 |
547 // place after this to ensure define before use in the blocks list | 547 // place after this to ensure define before use in the blocks list |
548 blocks.insert_after (this, split); | 548 blocks.insert_after (this, split); |
549 | 549 |
562 | 562 |
563 return this; | 563 return this; |
564 } | 564 } |
565 | 565 |
566 void | 566 void |
567 jit_block::create_dom_tree (size_t avisit_count) | 567 jit_block::create_dom_tree (std::size_t avisit_count) |
568 { | 568 { |
569 if (visited (avisit_count)) | 569 if (visited (avisit_count)) |
570 return; | 570 return; |
571 | 571 |
572 if (m_idom != this) | 572 if (m_idom != this) |
573 m_idom->m_dom_succ.push_back (this); | 573 m_idom->m_dom_succ.push_back (this); |
574 | 574 |
575 for (size_t i = 0; i < successor_count (); ++i) | 575 for (std::size_t i = 0; i < successor_count (); ++i) |
576 successor (i)->create_dom_tree (avisit_count); | 576 successor (i)->create_dom_tree (avisit_count); |
577 } | 577 } |
578 | 578 |
579 jit_block * | 579 jit_block * |
580 jit_block::idom_intersect (jit_block *i, jit_block *j) | 580 jit_block::idom_intersect (jit_block *i, jit_block *j) |
600 // -------------------- jit_phi -------------------- | 600 // -------------------- jit_phi -------------------- |
601 bool | 601 bool |
602 jit_phi::prune (void) | 602 jit_phi::prune (void) |
603 { | 603 { |
604 jit_block *p = parent (); | 604 jit_block *p = parent (); |
605 size_t new_idx = 0; | 605 std::size_t new_idx = 0; |
606 jit_value *unique = argument (1); | 606 jit_value *unique = argument (1); |
607 | 607 |
608 for (size_t i = 0; i < argument_count (); ++i) | 608 for (std::size_t i = 0; i < argument_count (); ++i) |
609 { | 609 { |
610 jit_block *inc = incoming (i); | 610 jit_block *inc = incoming (i); |
611 if (inc->branch_alive (p)) | 611 if (inc->branch_alive (p)) |
612 { | 612 { |
613 if (unique != argument (i)) | 613 if (unique != argument (i)) |
645 jit_block *p = parent (); | 645 jit_block *p = parent (); |
646 if (! p->alive ()) | 646 if (! p->alive ()) |
647 return false; | 647 return false; |
648 | 648 |
649 jit_type *infered = nullptr; | 649 jit_type *infered = nullptr; |
650 for (size_t i = 0; i < argument_count (); ++i) | 650 for (std::size_t i = 0; i < argument_count (); ++i) |
651 { | 651 { |
652 jit_block *inc = incoming (i); | 652 jit_block *inc = incoming (i); |
653 if (inc->branch_alive (p)) | 653 if (inc->branch_alive (p)) |
654 infered = jit_type_join (infered, argument_type (i)); | 654 infered = jit_type_join (infered, argument_type (i)); |
655 } | 655 } |
668 { | 668 { |
669 return llvm::cast<llvm::PHINode> (jit_value::to_llvm ()); | 669 return llvm::cast<llvm::PHINode> (jit_value::to_llvm ()); |
670 } | 670 } |
671 | 671 |
672 // -------------------- jit_terminator -------------------- | 672 // -------------------- jit_terminator -------------------- |
673 size_t | 673 std::size_t |
674 jit_terminator::successor_index (const jit_block *asuccessor) const | 674 jit_terminator::successor_index (const jit_block *asuccessor) const |
675 { | 675 { |
676 size_t scount = successor_count (); | 676 std::size_t scount = successor_count (); |
677 for (size_t i = 0; i < scount; ++i) | 677 for (std::size_t i = 0; i < scount; ++i) |
678 if (successor (i) == asuccessor) | 678 if (successor (i) == asuccessor) |
679 return i; | 679 return i; |
680 | 680 |
681 panic_impossible (); | 681 panic_impossible (); |
682 } | 682 } |
686 { | 686 { |
687 if (! parent ()->alive ()) | 687 if (! parent ()->alive ()) |
688 return false; | 688 return false; |
689 | 689 |
690 bool changed = false; | 690 bool changed = false; |
691 for (size_t i = 0; i < m_alive.size (); ++i) | 691 for (std::size_t i = 0; i < m_alive.size (); ++i) |
692 if (! m_alive[i] && check_alive (i)) | 692 if (! m_alive[i] && check_alive (i)) |
693 { | 693 { |
694 changed = true; | 694 changed = true; |
695 m_alive[i] = true; | 695 m_alive[i] = true; |
696 successor (i)->mark_alive (); | 696 successor (i)->mark_alive (); |
725 | 725 |
726 bool | 726 bool |
727 jit_call::infer (void) | 727 jit_call::infer (void) |
728 { | 728 { |
729 // FIXME: explain algorithm | 729 // FIXME: explain algorithm |
730 for (size_t i = 0; i < argument_count (); ++i) | 730 for (std::size_t i = 0; i < argument_count (); ++i) |
731 { | 731 { |
732 m_already_infered[i] = argument_type (i); | 732 m_already_infered[i] = argument_type (i); |
733 if (! m_already_infered[i]) | 733 if (! m_already_infered[i]) |
734 return false; | 734 return false; |
735 } | 735 } |
766 panic_impossible (); | 766 panic_impossible (); |
767 } | 767 } |
768 } | 768 } |
769 | 769 |
770 std::ostream& | 770 std::ostream& |
771 jit_error_check::print (std::ostream& os, size_t indent) const | 771 jit_error_check::print (std::ostream& os, std::size_t indent) const |
772 { | 772 { |
773 print_indent (os, indent) << "error_check " << variable_to_string (m_variable) | 773 print_indent (os, indent) << "error_check " << variable_to_string (m_variable) |
774 << ", "; | 774 << ", "; |
775 | 775 |
776 if (has_check_for ()) | 776 if (has_check_for ()) |
779 return print_successor (os << "<error> ", 0); | 779 return print_successor (os << "<error> ", 0); |
780 } | 780 } |
781 | 781 |
782 // -------------------- jit_magic_end -------------------- | 782 // -------------------- jit_magic_end -------------------- |
783 jit_magic_end::context::context (jit_factory& factory, jit_value *avalue, | 783 jit_magic_end::context::context (jit_factory& factory, jit_value *avalue, |
784 size_t aindex, size_t acount) | 784 std::size_t aindex, std::size_t acount) |
785 : m_value (avalue), m_index (factory.create<jit_const_index> (aindex)), | 785 : m_value (avalue), m_index (factory.create<jit_const_index> (aindex)), |
786 m_count (factory.create<jit_const_index> (acount)) | 786 m_count (factory.create<jit_const_index> (acount)) |
787 { } | 787 { } |
788 | 788 |
789 jit_magic_end::jit_magic_end (const std::vector<context>& full_context) | 789 jit_magic_end::jit_magic_end (const std::vector<context>& full_context) |
790 : m_contexts (full_context) | 790 : m_contexts (full_context) |
791 { | 791 { |
792 resize_arguments (m_contexts.size ()); | 792 resize_arguments (m_contexts.size ()); |
793 | 793 |
794 size_t i; | 794 std::size_t i; |
795 std::vector<context>::const_iterator iter; | 795 std::vector<context>::const_iterator iter; |
796 for (iter = m_contexts.begin (), i = 0; iter != m_contexts.end (); ++iter, ++i) | 796 for (iter = m_contexts.begin (), i = 0; iter != m_contexts.end (); ++iter, ++i) |
797 stash_argument (i, iter->m_value); | 797 stash_argument (i, iter->m_value); |
798 } | 798 } |
799 | 799 |
800 jit_magic_end::context | 800 jit_magic_end::context |
801 jit_magic_end::resolve_context (void) const | 801 jit_magic_end::resolve_context (void) const |
802 { | 802 { |
803 size_t idx; | 803 std::size_t idx; |
804 for (idx = 0; idx < m_contexts.size (); ++idx) | 804 for (idx = 0; idx < m_contexts.size (); ++idx) |
805 { | 805 { |
806 jit_type *ctx_type = m_contexts[idx].m_value->type (); | 806 jit_type *ctx_type = m_contexts[idx].m_value->type (); |
807 if (! ctx_type || ctx_type->skip_paren ()) | 807 if (! ctx_type || ctx_type->skip_paren ()) |
808 break; | 808 break; |
828 | 828 |
829 return false; | 829 return false; |
830 } | 830 } |
831 | 831 |
832 std::ostream& | 832 std::ostream& |
833 jit_magic_end::print (std::ostream& os, size_t indent) const | 833 jit_magic_end::print (std::ostream& os, std::size_t indent) const |
834 { | 834 { |
835 context ctx = resolve_context (); | 835 context ctx = resolve_context (); |
836 short_print (print_indent (os, indent)) << " (" << *ctx.m_value << ", "; | 836 short_print (print_indent (os, indent)) << " (" << *ctx.m_value << ", "; |
837 return os << *ctx.m_index << ", " << *ctx.m_count << ')'; | 837 return os << *ctx.m_index << ", " << *ctx.m_count << ')'; |
838 } | 838 } |