[llvm-dev] SROA for global arrays

David Chisnall via llvm-dev llvm-dev at lists.llvm.org
Thu Mar 25 07:07:19 PDT 2021


Hi,

Doing such a transform in the general case would require whole-program 
analysis.  If you have an array in your source code such as:

int x[42];

To do an SROA-like transform, you need to find everything that takes the 
address of the array and find which elements they access.  SROA can do 
this for locals because the only things that can name the array are 
instructions within the function.  If none of these allow a pointer to 
the array to escape then it can inspect each load and store and try to 
determine if they are independent.  With a global, any other compilation 
unit (in the general case, including ones that you dynamically link) may 
take the address of the global and rely on its layout.

You can restrict this somewhat.  If you have a global that's private or 
internal, then you can find all direct references to it in the current 
module and so the same techniques that SROA uses would work (though 
they'd require more work because they'd have to look at every function 
in the module).  For DSO-local globals, you could do the same thing at 
link time with some form of LTO.

This seems like a lot of work though and I wouldn't expect to see much 
benefit in normal code.  What is your use case?

David

On 25/03/2021 06:01, sushant gokhale via llvm-dev wrote:
> hi,
> 
> My requirement is if I have an global array, then can I break it into 
> individual elements similar to what SROA does ? I know that allocation 
> for globals is different from those of locals but still asking.
> 
> Regards
> Sushant
> 
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> 


More information about the llvm-dev mailing list