New transformation to allocate scratch registers
Any kind of instrumentation using values which don't already
exist in the original code need to allocate (or reuse) registers.
Even though the .dex bytecode uses an unlimited number of "virtual
registers", the calling convention prevents a simple increase of the
total number of registers per method (since the param regs are always
the last registers)
A full register allcator is the most generic solution, but also the
most complex one. Fortunatelly we can allocate scratch registers without
doing a full register allocation:
1. if there are not params, increase the method regs count and we're done
2. if the method uses less than 16 registers, we can renumber the existing registers
3. if we still have registers to allocate, increase the method registers count,
and generate prologue code to shift the param regs into their original registers
While this is obviously less optimal than a good register allocator, the majority
of the methods use less than 16 registers, making options #1 or #2 viable, when no
extra instructions are generated.
Also included is an option to build the register usage histogram:
(dexter -x regs_histogram ...)
The histogram format is: <number of methods> [ <reg count> ] ***...***
For example, the following histogram shows 347 methods use 1 register and 1098 methods use 2 registers, ...
Histogram: Method registers [max_count=1098]
347 [ 1 ] ********************************
1098 [ 2 ] *****************************************************************************************************
788 [ 3 ] ************************************************************************
500 [ 4 ] **********************************************
299 [ 5 ] ****************************
219 [ 6 ] ********************
181 [ 7 ] *****************
126 [ 8 ] ************
103 [ 9 ] **********
113 [ 10 ] ***********
46 [ 11 ] *****
65 [ 12 ] ******
46 [ 13 ] *****
49 [ 14 ] *****
45 [ 15 ] *****
38 [ 16 ] ****
13 [ 17 ] **
10 [ 18 ] *
17 [ 19 ] **
16 [ 20 ] **
11 [ 21 ] **
8 [ 22 ] *
9 [ 23 ] *
14 [ 24 ] **
7 [ 25 ] *
8 [ 26 ] *
8 [ 27 ] *
6 [ 28 ] *
4 [ 29 ] *
6 [ 30 ] *
3 [ 31 ] *
3 [ 32 ] *
3 [ 33 ] *
3 [ 34 ] *
2 [ 35 ] *
3 [ 36 ] *
2 [ 37 ] *
2 [ 38 ] *
1 [ 41 ] *
1 [ 42 ] *
1 [ 43 ] *
1 [ 44 ] *
1 [ 45 ] *
1 [ 46 ] *
1 [ 51 ] *
1 [ 52 ] *
1 [ 54 ] *
1 [ 55 ] *
1 [ 58 ] *
1 [ 68 ] *
1 [ 73 ] *
Histogram: Method argument registers [max_count=1494]
155 [ 0 ] ***********
1482 [ 1 ] ****************************************************************************************************
1494 [ 2 ] *****************************************************************************************************
605 [ 3 ] *****************************************
259 [ 4 ] ******************
100 [ 5 ] *******
52 [ 6 ] ****
35 [ 7 ] ***
15 [ 8 ] **
13 [ 9 ] *
4 [ 10 ] *
3 [ 11 ] *
4 [ 12 ] *
6 [ 13 ] *
4 [ 14 ] *
2 [ 16 ] *
1 [ 19 ] *
Histogram: Method extra registers (total - arguments) [max_count=1098]
347 [ 1 ] ********************************
1098 [ 2 ] *****************************************************************************************************
788 [ 3 ] ************************************************************************
500 [ 4 ] **********************************************
299 [ 5 ] ****************************
219 [ 6 ] ********************
181 [ 7 ] *****************
126 [ 8 ] ************
103 [ 9 ] **********
113 [ 10 ] ***********
46 [ 11 ] *****
65 [ 12 ] ******
46 [ 13 ] *****
49 [ 14 ] *****
45 [ 15 ] *****
38 [ 16 ] ****
13 [ 17 ] **
10 [ 18 ] *
17 [ 19 ] **
16 [ 20 ] **
11 [ 21 ] **
8 [ 22 ] *
9 [ 23 ] *
14 [ 24 ] **
7 [ 25 ] *
8 [ 26 ] *
8 [ 27 ] *
6 [ 28 ] *
4 [ 29 ] *
6 [ 30 ] *
3 [ 31 ] *
3 [ 32 ] *
3 [ 33 ] *
3 [ 34 ] *
2 [ 35 ] *
3 [ 36 ] *
2 [ 37 ] *
2 [ 38 ] *
1 [ 41 ] *
1 [ 42 ] *
1 [ 43 ] *
1 [ 44 ] *
1 [ 45 ] *
1 [ 46 ] *
1 [ 51 ] *
1 [ 52 ] *
1 [ 54 ] *
1 [ 55 ] *
1 [ 58 ] *
1 [ 68 ] *
1 [ 73 ] *
Test: bazel test :dexter_tests
Change-Id: I6d2762d7a56e1d8efff0ecb9756f8b757aa0c26f
Loading
Please sign in to comment