[flang-commits] [flang] [flang] Create TBAA subtree for COMMON block variables. (PR #156558)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Wed Sep 3 10:45:22 PDT 2025
================
@@ -98,8 +223,65 @@ class PassState {
// attachment.
bool attachLocalAllocTag();
+ // Return fir.global for the given name.
+ fir::GlobalOp getGlobalDefiningOp(mlir::StringAttr name) const {
+ return symTab.lookup<fir::GlobalOp>(name);
+ }
+
+ // Process fir::FortranVariableStorageOpInterface operations within
+ // the given op, and fill in declToStorageMap with the information
+ // about their physical storages and layouts.
+ void collectPhysicalStorageAliasSets(mlir::Operation *op);
+
+ // Return the byte size of the given declaration.
+ std::size_t getDeclarationSize(fir::FortranVariableStorageOpInterface decl) {
+ mlir::Type memType = fir::unwrapRefType(decl.getBase().getType());
+ auto [size, alignment] =
+ getTypeSizeAndAlignment(memType, llvmTypeConverter);
+ return llvm::alignTo(size, alignment);
+ }
+
+ // A StorageDesc specifies an operation that defines a physical storage
+ // and the <offset, size> pair within that physical storage where
+ // a variable resides.
+ struct StorageDesc {
+ StorageDesc() = delete;
+ StorageDesc(mlir::Operation *storageDef, std::uint64_t start,
+ std::size_t size)
+ : storageDef(storageDef), interval(start, size) {}
+
+ // Return a string representing the byte range of the variable within
+ // its storage, e.g. bytes_0_to_0 for a 1-byte variable starting
+ // at offset 0.
+ std::string getByteRangeStr() const {
+ return ("bytes_" + llvm::Twine(interval.getStart()) + "_to_" +
+ llvm::Twine(interval.getEnd()))
+ .str();
+ }
+
+ mlir::Operation *storageDef;
+ IntervalTy interval;
+ };
+
+ const StorageDesc *getStorageDesc(mlir::Operation *op) {
+ auto it = declToStorageMap.find(op);
+ return it == declToStorageMap.end() ? nullptr : &it->second;
+ }
----------------
vzakhari wrote:
Sounds reasonable - I will do it!
https://github.com/llvm/llvm-project/pull/156558
More information about the flang-commits
mailing list