[llvm] [AMDGPU] Introduce "amdgpu-sw-lower-lds" pass to lower LDS accesses. (PR #87265)

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 13 04:46:50 PDT 2024


skc7 wrote:

> Large blocks of this will be correct. I know that because they're exact copy and pastes from the LDS lowering pass I wrote, complete with my esoteric naming convention choices.
> 
> Heuristically, I think this will be broken. It's very large, heavily copy&paste themed from another pass, and has very large amounts of generated lit tests. No runtime tests. No tests for interaction with other passes. It also runs unconditionally which means it'll change code which doesn't use the sanitizer which is extra wrong.
> 
> However I really don't want this to land in rocm as it will then stay in the current state forever, and if it lands in trunk there's a better chance of fixing it post commit.
> 
> So overall, landing this might be the lesser of two evils.

This pass is not copy-paste from lower-module-lds pass. It has been inspired from "lower-module-lds" pass since that is the working reference we have to lower lds globals and designed accordingly to suit asan requirements.
- This pass only runs when asan is enabled using sanitize_address fn attribute to identify kernels to be lowered. It doesn't break the normal flow when asan is turned off.
- Utilities from "lower-module-lds" pass were moved to AMDGPUMemoryUtils and are used in this pass. I'm not sure if you are terming usage of utility APIs as "copy-paste"? 
- "lower-module-lds" pass packs LDS globals into a struct and replace them with GEPs into members of struct. This pass assigns a global variable of ptr type to each kernel and replaces LDS globals in the kernel with ptr GEPs.
- Pass uses a metadata global to track the offsets of replacement. Also adds redzone data required for asan instrumentation in the metadata.
- There is usage of amdgcn.kernel.id to lower LDS globals in non-kernel functions. There is usage of base table and offset table as mentioned in PR description to lower non-kernel LDS accesses.
- There is usage of new utilities from AMDGPUAsanInstrumentation to asan instrument lowered global memory operations.

The design of this pass has been discussed in asan internal meetings and design/changes have been conveyed to @b-sumner. 



https://github.com/llvm/llvm-project/pull/87265


More information about the llvm-commits mailing list