[flang-commits] [flang] [flang] Create TBAA subtree for COMMON block variables. (PR #153918)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Tue Aug 19 04:01:46 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"
+ // root, which is named after the name of the COMMON block.
+ // If we can identify the name of the member variable, then
+ // we create a sub-tree under the root of the COMMON block
+ // and place the tag there. If we cannot identify the name
+ // of the member variable (e.g. for whatever reason there is no
+ // fir.declare for it), then we place the tag under the root
+ // of the COMMON block.
+ auto globalOp = state.getGlobalDefiningOp(name);
+ // TODO: this is a subtle identification of the fact that
+ // the variable belongs to a COMMON block.
+ // Should we have an attribute on [hl]fir.declare
+ // that specifies the name of the COMMON block the variable
+ // belongs to?
----------------
tblah wrote:
Yes I agree this would be better. In OpenMP we handle it all whilst we still have access to the symbol table, but I think with that gone it would be worth including that information here.
https://github.com/llvm/llvm-project/pull/153918
More information about the flang-commits
mailing list