<div dir="ltr">Hi LLVM community,<br><br>Earlier this year I first proposed a new way of writing analyses that can be applied to multiple IRs, for example, applying the same analysis to both LLVM IR and MachineIR.<br><br>LLVM already has some analyses like that; for example, dominator tree construction and loop info. However, they're all limited to looking at the control flow graph: basic blocks and lists of predecessors and successors. We want to push the envelope with a divergence analysis that is also aware of instructions and values, and ran into severe limitations in what we could do with the techniques that are commonly used in LLVM today. Some limitations are around which concepts are exposed generically at all, though the bulk of limitations revolves around readability and maintainability of the resulting generic code.<br><br>After more evolution of the ideas and many discussions over the last few months, I want to raise this proposal once more -- this time with an extensive document: <a href="https://docs.google.com/document/d/1sbeGw5uNGFV0ZPVk6h8Q5_dRhk4qFnKHa-uZ-O3c4UY/edit?usp=sharing">https://docs.google.com/document/d/1sbeGw5uNGFV0ZPVk6h8Q5_dRhk4qFnKHa-uZ-O3c4UY/edit?usp=sharing</a><br><br>Feel free to comment on the document, though high-level discussion is probably best kept in this email thread.<br><br>The concrete proposal is to enable 4 tools for use by generic analyses:<br><br>- type erasure<br>- an SsaContext context class concept with a fairly small surface area<br>- dynamic polymorphism via per-analysis adapters<br>- dynamic polymorphism via an LLVM-wide adapter of SsaContext<br><br>The document goes to some length to explain what precisely is meant by each of those bullets, including code examples, as well as describing a few other options that we _don't_ propose, based on their relative merits.<br><br>There are concrete patches that go along with the proposal and you can refer to for additional context. In logical sequence, they are:<br>- <a href="https://reviews.llvm.org/D92924">https://reviews.llvm.org/D92924</a>: Introduce opaque handles for type erasure<br>- <a href="https://reviews.llvm.org/D83089">https://reviews.llvm.org/D83089</a>: Based on the handle infrastructure, refactor the dominator tree with type-erased base classes that can be used by generic algorithms<br>- <a href="https://reviews.llvm.org/D92925">https://reviews.llvm.org/D92925</a>: Introduce an SsaContext context class concept for static polymorphism<br>- <a href="https://reviews.llvm.org/D92926">https://reviews.llvm.org/D92926</a>: Introduce an ISsaContext “global” interface class for dynamic polymorphism built on top of SsaContext and opaque handles<br>- <a href="https://reviews.llvm.org/D83094">https://reviews.llvm.org/D83094</a>: A new analysis (cycle info) written generically as non-template code using opaque handles, ISsaContext, and analysis-specific dynamic polymorphism via the ICycleInfoSsaContext interface added in the patch<br><br>I would like us to get to general agreement on this thread that this is a direction we want to go in and that we can proceed with the proposed code changes.<br><br>Thanks,<br>Nicolai<br>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Lerne, wie die Welt wirklich ist,<br>aber vergiss niemals, wie sie sein sollte.</div></div>