Questions tagged [register-allocation]

register allocation is the process of assigning a large number of target program variables onto a small number of available CPU registers.

In compiler optimization, register allocation is the process of assigning a large number of program variables onto a small number of CPU registers.

See:

67 questions
33
votes
2 answers

Register allocation and spilling, the easy way?

I'm looking for a way to allocate local variables to registers. I'm aware of a couple of serious methods for doing it (namely, those mentioned on Wikipedia), but I'm stuck on how "spilling" is accomplished. Also, the relevant literature is quite…
Edmund
  • 10,070
  • 1
  • 36
  • 52
22
votes
4 answers

GCC: Prohibit use of some registers

This is a strange request but I have a feeling that it could be possible. What I would like is to insert some pragmas or directives into areas of my code (written in C) so that GCC's register allocator will not use them. I understand that I can do…
hayesti
  • 2,665
  • 1
  • 20
  • 29
17
votes
4 answers

Goto prior to a variable definition - what happens with its value?

Here is some question I wondered about. Given the following code, can we be certain about its output? void f() { int i = 0; z: if(i == 1) goto x; else goto u; int a; x: if(a == 10) goto y; u: a = 10; i = 1; goto z; y: std::cout <<…
Johannes Schaub - litb
  • 466,055
  • 116
  • 851
  • 1,175
15
votes
2 answers

Why do compilers insist on using a callee-saved register here?

Consider this C code: void foo(void); long bar(long x) { foo(); return x; } When I compile it on GCC 9.3 with either -O3 or -Os, I get this: bar: push r12 mov r12, rdi call foo mov rax, r12 …
15
votes
8 answers

Address of register variable

In C, we cannot use & to find out the address of a register variable but in C++ we can do the same. Why is it legal in C++ but not in C? Can someone please explain this concept in-depth.
Naveen
  • 419
  • 6
  • 14
11
votes
2 answers

Concrete example of incorrect behavior of an early-clobber affecting a memory operand's addressing mode in GCC inline asm?

Below is excerpted from the GCC manual's Extended Asm docs, on embedding assembly instructions in C using asm keyword: The same problem can occur if one output parameter (a) allows a register constraint and another output parameter (b) allows a…
zzzhhh
  • 161
  • 5
9
votes
2 answers

How to force gcc to use all SSE (or AVX) registers?

I'm trying to write some computationally intensive code for Windows x64 target, with SSE or the new AVX instructions, compiling in GCC 4.5.2 and 4.6.1, MinGW64 (TDM GCC build, and some custom build). My compiler options are -O3 -mavx. (-m64 is…
Norbert P.
  • 2,687
  • 1
  • 16
  • 20
8
votes
3 answers

Using FPU and MMX registers as "general registers"

Most assembly programs make use of the 4 general purpose registers eax ebx ecx edx but I find that quite often I need to use more than 4 registers to accomplish my task easily without having to push and pop from the stack to much. Since my program…
user99545
  • 1,093
  • 3
  • 16
  • 31
7
votes
1 answer

Cost of x86 register renaming

The following code compiling with gcc or clang on amd64 // gcc -O2 file.c -c int f(int a, int b, int c, int d) { return a & b & c & d; } produces following assembly: 0000000000000000 : 0: 89 d0 mov %edx,%eax 2: …
jtaylor
  • 2,079
  • 13
  • 18
6
votes
1 answer

How would a register + stack based virtual machine work?

I know how register based and how stack based virtual machines work independently. I know the advantages and disadvantages of both. What I want to know is that has anyone ever tried to merge the two? I tried to search the net for the existence of…
5
votes
1 answer

Optimizing used registers when using inline ARM assembly in GCC

I want to write some inline ARM assembly in my C code. For this code, I need to use a register or two more than just the ones declared as inputs and outputs to the function. I know how to use the clobber list to tell GCC that I will be using some…
4
votes
3 answers

What makes a value unsafe to be stored in a register?

When talking about register allocation, texts on compilation (for example, Engineering a Compiler by Cooper) often mention that values stored in registers need to be "safe" - otherwise they should be stored in memory. What makes a value unsafe to be…
mijiturka
  • 161
  • 3
  • 14
4
votes
1 answer

Algorithm for register allocation

I'm trying to implement a code generation/register allocation algorithm for Trees in favor of my old one, where I put everything on stack. Now I'm trying to implement Sethi-Ullman algorithm but from only contents I've found on Wikipedia and some…
The Mask
  • 15,697
  • 36
  • 104
  • 172
4
votes
1 answer

Graph coloring register allocator

For my compiler course I'm building a register allocator based on graph coloring for MIPS architecture. I'm following Muchnick's treatment on the same for my implementation. Muchnick has been a little fuzzy about how to treat arguments of function…
3
votes
2 answers

Why do compilers construct a graph in register allocation?

I've been researching register allocation and was wondering why they all built graphs from the live registers list when there could be a better way to do it. The way I think they could do it is when the live registers crosses the number of registers…
1
2 3 4 5