[flang-commits] [flang] [flang] Create TBAA subtree for COMMON block variables. (PR #153918)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Tue Aug 19 09:34:54 PDT 2025
================
@@ -310,14 +318,55 @@ void AddAliasTagsPass::runOnAliasInterface(fir::FirAliasTagOpInterface op,
source.kind == fir::AliasAnalysis::SourceKind::Global &&
!source.isBoxData()) {
mlir::SymbolRefAttr glbl = llvm::cast<mlir::SymbolRefAttr>(source.origin.u);
- const char *name = glbl.getRootReference().data();
- LLVM_DEBUG(llvm::dbgs().indent(2) << "Found reference to global " << name
- << " at " << *op << "\n");
- if (source.isPointer())
+ mlir::StringAttr name = glbl.getRootReference();
+ LLVM_DEBUG(llvm::dbgs().indent(2) << "Found reference to global "
+ << name.str() << " at " << *op << "\n");
+ if (source.isPointer()) {
tag = state.getFuncTreeWithScope(func, scopeOp).targetDataTree.getTag();
- else
- tag =
- state.getFuncTreeWithScope(func, scopeOp).globalDataTree.getTag(name);
+ } else {
+ // In general, place the tags under the "global data" root.
+ fir::TBAATree::SubtreeState *subTree =
+ &state.getMutableFuncTreeWithScope(func, scopeOp).globalDataTree;
+
+ // The COMMON blocks have their own sub-tree root under the "global data"
----------------
vzakhari wrote:
I believe the answer is no. There is a way to `equivalence` a non-common variable `A` with a common variable `B`, but then `A` effectively becomes a part of the `B`'s common block, so we think of `A` as just another section of the common block.
I think we can put the common blocks roots as siblings of the global data tree. I think it should not matter now, because we may never create tags attached to the root of the global data tree, since the global variable names are always present. I would like to keep the common blocks sub-trees under the global data tree for the following (aritificial) reason: if we ever step on a memory access that we know accesses global memory, but we do not know exactly which one, we should assume this access aliases with any global variable (including the COMMON ones). In this case, the common sub-trees have to be under the global data root.
https://github.com/llvm/llvm-project/pull/153918
More information about the flang-commits
mailing list