diff --git a/flang/lib/Optimizer/CodeGen/TBAABuilder.h b/flang/lib/Optimizer/CodeGen/TBAABuilder.h --- a/flang/lib/Optimizer/CodeGen/TBAABuilder.h +++ b/flang/lib/Optimizer/CodeGen/TBAABuilder.h @@ -251,6 +251,9 @@ // Counter for unique naming of TBAA operations' symbols. unsigned tbaaNodeCounter = 0; + // Number of attached TBAA tags (used for debugging). + unsigned tagAttachmentCounter = 0; + // Mapping from a FIR type to the symbol defined by the corresponding // TBAATypeDescriptorOp. It must be populated during the type conversion. // Currently unused. diff --git a/flang/lib/Optimizer/CodeGen/TBAABuilder.cpp b/flang/lib/Optimizer/CodeGen/TBAABuilder.cpp --- a/flang/lib/Optimizer/CodeGen/TBAABuilder.cpp +++ b/flang/lib/Optimizer/CodeGen/TBAABuilder.cpp @@ -13,6 +13,9 @@ #include "TBAABuilder.h" #include "flang/Optimizer/Dialect/FIRType.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Debug.h" + +#define DEBUG_TYPE "flang-tbaa-builder" using namespace mlir; using namespace mlir::LLVM; @@ -23,6 +26,15 @@ "to override default Flang behavior"), llvm::cl::init(false)); +// tagAttachmentLimit is a debugging option that allows limiting +// the number of TBAA access tag attributes attached to operations. +// It is set to kTagAttachmentUnlimited by default denoting "no limit". +static constexpr unsigned kTagAttachmentUnlimited = + std::numeric_limits::max(); +static llvm::cl::opt + tagAttachmentLimit("tbaa-attach-tag-max", llvm::cl::desc(""), + llvm::cl::init(kTagAttachmentUnlimited)); + namespace fir { std::string TBAABuilder::getNewTBAANodeName(llvm::StringRef basename) { return (llvm::Twine(basename) + llvm::Twine('_') + @@ -50,6 +62,9 @@ return; } + LLVM_DEBUG(llvm::dbgs() << "Creating TBAA MetadataOp for module '" + << module.getName().value_or("") << "'\n"); + // Create TBAA MetadataOp with the root and basic type descriptors. Location loc = module.getLoc(); MLIRContext *context = module.getContext(); @@ -130,6 +145,14 @@ if (!enableTBAA) return; + ++tagAttachmentCounter; + if (tagAttachmentLimit != kTagAttachmentUnlimited && + tagAttachmentCounter > tagAttachmentLimit) + return; + + LLVM_DEBUG(llvm::dbgs() << "Attaching TBAA tag #" << tagAttachmentCounter + << "\n"); + SymbolRefAttr tbaaTagSym; if (baseFIRType.isa()) tbaaTagSym = getBoxAccessTag(baseFIRType, accessFIRType, gep);