[flang-commits] [flang] [flang] Support declarations scoping in FIR AA. (PR #201216)
via flang-commits
flang-commits at lists.llvm.org
Mon Jun 8 00:59:17 PDT 2026
================
@@ -286,8 +288,74 @@ static fir::AliasAnalysis::Source mergeRegionBranchPredecessorSources(
mlir::Type mergedTy = allTypesSame ? sources[0].valueType : fallbackType;
- return {mergedOrigin, mergedKind, mergedTy, mergedAttrs,
- mergedApprox, mergedPath, mergedCaptured};
+ // Intersect scopedOrigins across predecessors by (scope, declValue).
+ // For an entry that matches in every predecessor, take the bitwise
+ // union (|=) of its 'attributes' and 'approximateSource' bits and
+ // keep the first predecessor's path steps (the steps must be equal
+ // to match, so there is nothing to merge there). Drop the entry on a
+ // path-step or isData mismatch, because different control-flow shapes
+ // from the same declare to the merge point cannot be summarised
+ // safely.
+ llvm::SmallVector<fir::AliasAnalysis::Source::ScopedOrigin, 4>
+ mergedScopedOrigins;
+ if (!sources.empty()) {
+ // Seed with the first predecessor's snapshots, keyed by
+ // (scope, declValue) for intersection lookups.
+ llvm::DenseMap<std::pair<void *, void *>, unsigned> indexInMerged;
+ mergedScopedOrigins.assign(sources[0].scopedOrigins.begin(),
+ sources[0].scopedOrigins.end());
+ for (unsigned i = 0; i < mergedScopedOrigins.size(); ++i) {
+ const auto &scopedOrigin = mergedScopedOrigins[i];
+ indexInMerged[{scopedOrigin.scope.getAsOpaquePointer(),
----------------
jeanPerier wrote:
Is it really needed to use the scope as a key given the scope can be deduced from the declValue (so I think you should never have two keys with a same declare but different scopes)?
https://github.com/llvm/llvm-project/pull/201216
More information about the flang-commits
mailing list