Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Start writing discussion of callframe management |
---|---|
Timelines: | family | ancestors | descendants | both | kbk-refactor-callframe |
Files: | files | file ages | folders |
SHA3-256: |
50af9aa069345e22c57c8d4313159d4a |
User & Date: | kbk 2019-02-16 21:40:16.969 |
Context
2019-02-16
| ||
21:43 | Fix some Markdown typos check-in: a0fc4f2102 user: kbk tags: kbk-refactor-callframe | |
21:40 | Start writing discussion of callframe management check-in: 50af9aa069 user: kbk tags: kbk-refactor-callframe | |
2019-01-29
| ||
13:19 | Fix misorderered scalar check/copy to result check-in: 36e8177510 user: kbk tags: notworking, kbk-refactor-callframe | |
Changes
Changes to demos/perftest/tester.tcl.
︙ | ︙ | |||
2646 2647 2648 2649 2650 2651 2652 | regsubtest # Failure handling, [subst], [try] wideretest substtest substtest2 switchfail trimtest | > > | | 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 | regsubtest # Failure handling, [subst], [try] wideretest substtest substtest2 switchfail trimtest # See email chain at # https://sourceforge.net/p/tcl/mailman/message/36579552/ # magicreturn BUG returntest errortest1 errortest2 errortest2-caller errortest3 errortest4 errortest4a errortest4b errortest5 errortest6 |
︙ | ︙ | |||
2694 2695 2696 2697 2698 2699 2700 | wordcounter3 wordcounter4 # Calls of uncompiled code calltest calltest2 calltest3 # Callframe tests | > > | | | | | | | | | | 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 | wordcounter3 wordcounter4 # Calls of uncompiled code calltest calltest2 calltest3 # Callframe tests # Direct operations are not yet implemented in the # callframe-refactor branch # callframe::test1 TEMP direct ops BUG # callframe::test2 TEMP direct ops BUG # callframe::test3 TEMP direct ops BUG # callframe::test4 TEMP direct ops BUG # The interprocedural tests mrtest::* coscaller1 coscaller2 xsum xsum2 # Namespace tests # nstestaux::pts TEMP depends on direct ops BUG nstest::nstest0 nstest::nstest1 # nstest::nstest2 fails with command not found BUG nstest::nstest3 nstest::nstest4 # nstest::nstest5 fails with invalid command name BUG nstest::nstest6 nstest::nstest7 nstest::nstest8 nstest9 upvartest::* # Miscellaneous other tests bctest asmtest # List expansion tests expandtest::joinsp expandtest::join/ expandtest::join, expandtest::fixed expandtest::fixedUp expandtest::test1 expandtest::test2 expandtest::test3 # expandtest::test4 Needs support for return -code continue BUG # expandtest::test5 Needs support for loop exception ranges BUG expandtest::test6 expandtest::test7 expandtest::test8 expandtest::test9 expandtest::test10 expandtest::test11 expandtest::test12 |
︙ | ︙ | |||
2753 2754 2755 2756 2757 2758 2759 | linesearch::colinear linesearch::sameline linesearch::getAllLines1 linesearch::getAllLines2 regexptest::* vartest::* nsvartest::* | | | 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 | linesearch::colinear linesearch::sameline linesearch::getAllLines1 linesearch::getAllLines2 regexptest::* vartest::* nsvartest::* # directtest::* TEMP direct ops BUG upvar0 upvar0a upvartest0::* upvartest1::* upvartest2::* flightawarebench::* hash::* |
︙ | ︙ |
Added doc/20190216callframe/callframe.md.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | # Optimizing data motion into and out of callframes in Tcl Kevin B Kenny 16 February 2019 ## Introduction As of the current version ([0718166269]), the handling of variables in the callframe reflects some fairly fundamental oversights in the effect of Tcl operations on variables. Essentially, what it does is to introduce `moveToCallFrame` and `moveToCallFrame` operations around a partial subset of operations that might change or refer to a variable in a callframe. This subset includes command invocations that are known to access caller variables, assignments to potentially-aliased variables, some direct operations, and very little else. It fails to account for all the operations, while simultaneously introducing unnecessary data motion. It also forecloses on optimizations such as deferring writes to non-local variables to loop exits. This discussion is written at least partly for the benefit of its author, to help with understanding what optimizations are safe and profitable, and how to compute them. It will, however, hopefully aid those who come after in understanding how the the decisions that were made. ## Back to basics - the code generation strategy One general strategy has been overwhelmingly successful in other areas of quadcode manipulation. Rather than attempting to add operations that handle the awkward cases when they are detected, it has been much easier to generate code for the worst case always, and then optimize it away. The code for variable accesses, for instance, is truly horrific when initially generated: + test that a variable exists, and throw an error otherwise + test that the variable is not an array, and throw an error otherwise. + test that the value is of an admissible type for the operation that will use it, and throw an error otherwise. + downcast the value to an instance of the correct type. + if the value is used in an arithmetic operation, purify the value, that is, extract the machine-native representation. Nevertheless, all of these tests become redundant if a second access to the variable is dominated by the first. In that case, partial redundancy elimination will eliminate all five of these steps and simply use the pure value in the arithmetic operation. The partial redundancy elimination is based largely on the value-based algorithms developed in (LT Simpson's PhD thesis)[https://www.clear.rice.edu/comp512/Lectures/Papers/SimpsonThesis.pdf]. We therefore assume here that we will take the brutally simple approach of generating code that: + whenever a local variable (whether potentially aliased or not) is loaded, generate a `moveFromCallFrame` instruction transferring a Tcl value into an SSA value. + whenever a local variable (whether potientially aliased or not) is stored, generate a `moveToCallFrame` instruction transferring an SSA value into a Tcl value. + whenever an operation (an invocation, a direct operation, etc.) may potentially refer to a local variable or an alias thereof. make sure that it has the callframe as one of its inputs. + whenever an operation (an invocation, a direct operation, etc.) may potentially modify a local variable or an alias thereof, make sure that it has the callframe as both an input and an output. + upon procedure exit (normal or abnormal) make sure that any potentially aliased local variables are actually returned to the callframe. The last three items in the list ensure that we can track antidependencies correctly; they become dependencies on the callframe value. This, in turn, will require that we modify the `directSet`, `directGet`, `directIncr`, etc. instructions, to include callframe references. (This change will also address a set of issues marked with **TODO** in `quadcode/translate.tcl` where it is assumed that the `existStk`, `loadStk`, `storeStk`, etc. bytecode instructions refer only to qualified names.) Simpson mentions fairly briefly how memory load operations (he uses the example of array accesses, but our `moveFromCallFrame` fits the scheme) can also be eliminated by his techniques. The treatment is considerly less well developed than that for simple values. Moreover, he calls out that memory store operations are not amenable to his technique owing to anti-dependencies (a STORE operation may not be hoisted above a LOAD operation that might refer to the same memory). His technique also does not contemplate downward code motion, where a STORE operation that does not affect a loop's operation might be moved to after the loop exit. To address these deficiencies, it falls to us to develop a better theory of Tcl variable accesses. |
Changes to quadcode/callframe.tcl.
︙ | ︙ | |||
30 31 32 33 34 35 36 | if {[lsearch -exact -index 0 $bb upvar] >= 0} { return 1 } } return 0 } | | < < < < < < < < < < < < < < < | < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | if {[lsearch -exact -index 0 $bb upvar] >= 0} { return 1 } } return 0 } # quadcode::transformer method cfRedundancy -- # # Removes various partial redundancies among callframe operations # # Results: # Returns 1 if anything changed, 0 otherwise. # # Side effects: # Removes many redundant operations. # quadcode::transformer method cfConsumer -- # # Determines what 'invoke' or other operation consumes a callframe # that appears in a 'moveToCallframe' operation # # Parameters: |
︙ | ︙ |