Replace all memory access with registry access

Hi all,
Is there any way for converting any instruction that is loading or storing in memory into an instruction that just deal with registries?

I’m not even sure if it is possible. Any suggestion?

Thanks

Hi,

Could you share some more details about what you're trying to accomplish?

Generally speaking, some instructions necessarily load/store from/to memory (e.g. updates to a shared memory region).

best,
vedant

Hi,
Thanks for getting back to me. I’d like to understand if it possible to avoid instructions that relies on memory address and instead have all the necessary data inside registers. I think this would simplify a lot analysis on the LLVM IR…

Thanks again

Hi,
There is a pass called mem2reg (Mem2Reg.cpp) which you can take a look. I used this pass in a project
to reduce accesses to memory.

best,

Andreu

What you are probably looking for are the mem2reg pass and scalar replacement of aggregates (SROA) pass, which includes a more aggressive version of mem2reg. These passes try to eliminate alloca instructions by converting the stack variables to registers when possible.

Hi all,
Thanks for your help with this. I’ll try what you suggested.

Appreciated