This patch introduces a generic implementation of mem2reg on unstructured control-flow, along with a specialization for LLVM IR. This is achieved by defining three new interfaces, representing 1. allocating operations, 2. operations doing memory accesses, 3. operations that can be rewired and/or deleted to stop using a specific use. The file containing the core implementation of the algorithm (`Mem2Reg.cpp`) contains a detailed explanation of how the algorithm works. The contract for this pass is that given a memory slot with a single non-aliased pointer, the pass will either remove all the uses of the pointer or not change anything. To help review this patch, I recommend starting by looking at the interfaces defined in `Mem2Reg.td`, along with their reference implementation for LLVM IR defined in `LLVMMem2Reg.cpp`. Then, the core algorithm is implemented in `Mem2Reg.cpp`. If this is all good I also have an implementation of the interfaces for 0-dimensional memref promotion that I can upstream afterwards. Reviewed By: gysit Differential Revision: https://reviews.llvm.org/D148109
22 KiB
22 KiB