aboutsummaryrefslogtreecommitdiffhomepage
path: root/src-backend/notes/reg_alloc.txt
blob: c8ac057a8c06d358a7513920d09c0318031ab33d (plain)
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

Register allocation
===================

Simple allocation
-----------------
Reserve any special-purpose register registers, e.g:
- ebx for PIC code on x86
- frame pointer register (ebp on x86)

Then allocate a register to all low var-lane indices.
- Assign the var-lane to the register.
  This is a fixed size lookup table (but the size varies per arch).
- Mark the register as used.
- Continue to the following var-lane.


Advanced allocation
-------------------
On some architectures, some registers have a certain intended purpose, and
the machine code might be shorter or more efficient if the optimal registers
are used.

For example, on x86:
- ecx = loop counter
- ebp, e*x = for struct pointers etc.

Caller/calle saving
-------------------
Temporaries should use caller-saved regs.

Variables might be better of with callee-saved regs, unless it is a leaf call.

If "tightcall" is added (less regs are saved by the caller), then such
functions should avoid using the unsaved regs in likely paths, as they
have to be saved before the first use AND before any external calls.

Optimized var-lane allocation
-----------------------------
Variables that...

1. are only used in a single EBB, and
2. whose address is never taken (not passed into a pointer)

...can be allocated in a separate set of low-numbered var-lanes.
- But: This should only be done if there are multiple variables that
  can share the same var-lane. Otherwise it makes no sense, and can
  even be counter-productive.
- If the EBB does not use all of the temporaries, then the variable
  could use one of those var-lanes.
  (this optimization could go into CSBE, perhaps as a function such as
   csbe_ebb_varlane_status(csbe, varlane, status={unused, initially_unused, used}))

Variables that are used many times and/or in many EBB's should also
be given low-numbered var-lanes.