I am looking at LLVM to see how they use load
, store
, and alloca
. In the first slide below, there is no use of them. In the second, there is use of alloca
.
I am not familiar with C so going to have to bring myself up to speed in order to run an example and figure this out myself, but wanted to ask if anyone knew already. Not sure the kind of example C code to write in order to determine the output that uses load
, store
, and alloca
in LLVM.
The question is, when LLVM uses load
, store
, and alloca
.
Wondering if load/store are necessary as well, or LLVM can do without it.
Figure 1 ↓
Figure 2 ↓
Without optimizations, clang will produce LLVM code where there's one alloca
for each local variable, one read
for each use of that variable as an r-value and one store
for each assignment to that variable (including its initialization).
With optimizations, clang will try to minimize the number of read
s and store
and will often eliminate the alloca
completely if possible (using only registers).
One way to ensure that the variable is stored in memory, even with optimizations, would be to take its address (since registers don't have an address).
Wondering if load/store are necessary as well, or LLVM can do without it.
You need store
/ load
whenever you write to memory locations. So the question becomes whether you can do without memory, storing everything in registers. Since LLVM (unlike real machines) supports an infinite amount of registers, that's a valid question.
However, as I mentioned, registers don't have addresses. So any code that takes the address of a variable, needs to use memory. So does any code that performs arithmetic on addresses, such as code that indexes arrays.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With