Region objects capture the address of the creating RegionInfo instance. Because the RegionInfo class is movable, moving a RegionInfo object creates dangling references. This patch fixes these references by walking the Regions post-move, and updating references to the new parent.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
include/llvm/Analysis/RegionInfo.h | ||
---|---|---|
896–903 ↗ | (On Diff #94349) | Would it be feasible to remove the move-ctors and instead force users to allocate RegionInfo on the heap? |
include/llvm/Analysis/RegionInfo.h | ||
---|---|---|
896–903 ↗ | (On Diff #94349) | As LoopInfo is also a movable type, this might be required by the new pass manager. Looking at the implementation of AnalysisManager, analysis are stored as typedef std::list<std::pair<AnalysisKey *, std::unique_ptr<ResultConceptT>>> AnalysisResultListT; that is, it only has ownership, but does not require it to be movable. On the other side, the unique_ptr is created using std::unique_ptr< AnalysisResultConcept<IRUnitT, PreservedAnalysesT, InvalidatorT>> run(IRUnitT &IR, AnalysisManager<IRUnitT, ExtraArgTs...> &AM, ExtraArgTs... ExtraArgs) override { return llvm::make_unique<ResultModelT>(Pass.run(IR, AM, ExtraArgs...)); } in PassManagerInternals.h. It is effectively used by bool registerPass(PassBuilderT &&PassBuilder). I don't expect you to explore this unknown territory. Could you maybe add a comment to the source mentioning why the analysis result needs to be moved so it will be considered when someone is going to improve the situation? |
include/llvm/Analysis/RegionInfo.h | ||
---|---|---|
896–903 ↗ | (On Diff #94349) | The fundamental difference between LoopInfo and RegionInfo in this regard is that Loop does not hold any references to LoopInfo. It might be worthwhile to move the RegionInfo and Region API more towards LoopInfo, meaning to remove the captured reference from the Region-class and pass it in the relevant functions instead.
That's not how the PassManager is supposed to be used, and that won't change in the future. The explicit design decision is that Analyses and Passes do not depend on PassManager internals, such as deriving from an interface- or base-class. That is precisely the idea of concept-based programming. |
include/llvm/Analysis/RegionInfo.h | ||
---|---|---|
896–903 ↗ | (On Diff #94349) | AFAIR the getRegionInfo() function is not used very often, so if we can get rid of it entirely that would be nice. Now, I believe this is an orthogonal issue. Meaning, the patch as written solves the direct correctness issue and seems consequently worth committing. If we can then also simplify the interface, this is certainly something I would be glad about. |