Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tools to show spills in a c code

Tags:

c

assembly

Is there a tool to where I have spills in my c code?

I mean see what block of code potentially make a register move to memory.

EDIT: what is a spill:

In the process of compiling your code at some point you will have to do register allocation. The compiler will do an interference graph ( "variables" are nodes and they are connected if they are alive at the same time ). From this point there is a linear process that will do graph coloring: for each variable assign a register that wont interfere with other variables... If you don't have enough register to color the graph the algorithm will fail and a variable(register) will be spilled ( moved to memory ).

From a software engineering point of view, this mean you should always minimize a variable live so you can minimize the chance of having a spill.

When you want to optimize code you should look for those kinds of things since a spill will give an extra time to read/write memory. I was looking for a tool or a compiler flag that could tell me where is spill so I can optimize.

like image 845
Guillaume Massé Avatar asked Oct 14 '22 20:10

Guillaume Massé


1 Answers

I'm aware of no such tool.

Because decisions about spills vary from compiler to compiler, and version of the compiler and even by settings within a given version of a given compiler, any such tool would have to be tightly coupled to a compiler and would likely only support one.

On the other hand, you can always look at the generated assembly yourself and see if a given variable is spilled or not.

like image 124
wnoise Avatar answered Oct 18 '22 01:10

wnoise