Commit 53ebd00
committed
Reverse switches on the stored condition instead of a control-flow tape
Reverse-mode differentiation of a switch statement recorded, in a second
control-flow tape, which case a `break` exited from, then re-dispatched the
reverse sweep by popping that tape. The information is redundant: the switch
condition is already stored (`_cond`), and every case guard already compares
against it (`if (v == _cond) break`). The extra tape -- and the
BreakContStmtHandler state backing it -- only duplicated what the condition
carries.
Drop the control-flow tape for switches and re-switch on the stored condition
directly. Each fall-through group's reverse entry is now labelled with its
original case values rather than a synthesized counter, and the trailing
group (closed by the switch end rather than a break) is labelled in
VisitSwitchStmt. The per-case guards are unchanged. Loops keep their
control-flow tape, where a break's iteration genuinely cannot be recovered
from a condition.
This is behaviour-preserving: all Switch.C/SwitchInit.C execution results are
unchanged; only the generated code -- forward (the counter pushes are gone)
and reverse -- and its FileCheck baselines change, with one fewer tape. A
switch whose cases return rather than break is added to Switch.C to cover the
returning-case shape.
SwitchInit.C no longer needs its Valgrind XFAIL: the control-flow tape it
tripped on under memcheck is gone.1 parent cf64927 commit 53ebd00
4 files changed
Lines changed: 343 additions & 217 deletions
File tree
- include/clad/Differentiator
- lib/Differentiator
- test/Gradient
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
703 | 703 | | |
704 | 704 | | |
705 | 705 | | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
717 | 718 | | |
718 | 719 | | |
719 | 720 | | |
| |||
760 | 761 | | |
761 | 762 | | |
762 | 763 | | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
763 | 767 | | |
764 | 768 | | |
765 | 769 | | |
| |||
835 | 839 | | |
836 | 840 | | |
837 | 841 | | |
| 842 | + | |
838 | 843 | | |
| 844 | + | |
| 845 | + | |
839 | 846 | | |
840 | 847 | | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
841 | 854 | | |
842 | 855 | | |
843 | 856 | | |
| |||
854 | 867 | | |
855 | 868 | | |
856 | 869 | | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
857 | 876 | | |
858 | 877 | | |
859 | 878 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4412 | 4412 | | |
4413 | 4413 | | |
4414 | 4414 | | |
| 4415 | + | |
| 4416 | + | |
4415 | 4417 | | |
4416 | 4418 | | |
4417 | 4419 | | |
| |||
4421 | 4423 | | |
4422 | 4424 | | |
4423 | 4425 | | |
4424 | | - | |
4425 | | - | |
4426 | | - | |
4427 | 4426 | | |
4428 | 4427 | | |
4429 | | - | |
4430 | 4428 | | |
4431 | 4429 | | |
4432 | 4430 | | |
4433 | 4431 | | |
| 4432 | + | |
| 4433 | + | |
| 4434 | + | |
| 4435 | + | |
| 4436 | + | |
| 4437 | + | |
| 4438 | + | |
| 4439 | + | |
| 4440 | + | |
| 4441 | + | |
| 4442 | + | |
| 4443 | + | |
| 4444 | + | |
| 4445 | + | |
| 4446 | + | |
| 4447 | + | |
| 4448 | + | |
| 4449 | + | |
| 4450 | + | |
| 4451 | + | |
| 4452 | + | |
| 4453 | + | |
| 4454 | + | |
| 4455 | + | |
| 4456 | + | |
| 4457 | + | |
4434 | 4458 | | |
4435 | | - | |
| 4459 | + | |
4436 | 4460 | | |
4437 | 4461 | | |
4438 | 4462 | | |
| |||
4492 | 4516 | | |
4493 | 4517 | | |
4494 | 4518 | | |
| 4519 | + | |
| 4520 | + | |
| 4521 | + | |
| 4522 | + | |
| 4523 | + | |
| 4524 | + | |
| 4525 | + | |
| 4526 | + | |
| 4527 | + | |
| 4528 | + | |
| 4529 | + | |
| 4530 | + | |
| 4531 | + | |
| 4532 | + | |
| 4533 | + | |
| 4534 | + | |
| 4535 | + | |
| 4536 | + | |
| 4537 | + | |
| 4538 | + | |
| 4539 | + | |
| 4540 | + | |
| 4541 | + | |
| 4542 | + | |
| 4543 | + | |
| 4544 | + | |
| 4545 | + | |
| 4546 | + | |
| 4547 | + | |
| 4548 | + | |
4495 | 4549 | | |
4496 | 4550 | | |
4497 | 4551 | | |
| |||
4640 | 4694 | | |
4641 | 4695 | | |
4642 | 4696 | | |
| 4697 | + | |
| 4698 | + | |
| 4699 | + | |
| 4700 | + | |
| 4701 | + | |
| 4702 | + | |
| 4703 | + | |
| 4704 | + | |
4643 | 4705 | | |
4644 | 4706 | | |
4645 | 4707 | | |
4646 | | - | |
| 4708 | + | |
4647 | 4709 | | |
4648 | 4710 | | |
4649 | 4711 | | |
| |||
4733 | 4795 | | |
4734 | 4796 | | |
4735 | 4797 | | |
4736 | | - | |
| 4798 | + | |
| 4799 | + | |
| 4800 | + | |
4737 | 4801 | | |
4738 | 4802 | | |
4739 | 4803 | | |
| |||
0 commit comments