From: Slava Zakharin Date: Thu, 19 Jan 2023 16:46:52 +0000 (-0800) Subject: [NFC][flang] Added debug option to bisect TBAA tag attachments. X-Git-Tag: upstream/17.0.6~20402 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b14763652f8519e9ec6b10667a17e32bc3dce913;p=platform%2Fupstream%2Fllvm.git [NFC][flang] Added debug option to bisect TBAA tag attachments. Reviewed By: jeanPerier, PeteSteinfeld Differential Revision: https://reviews.llvm.org/D142070 --- diff --git a/flang/lib/Optimizer/CodeGen/TBAABuilder.cpp b/flang/lib/Optimizer/CodeGen/TBAABuilder.cpp index 1bee674..2d206ed 100644 --- 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 @@ static llvm::cl::opt disableTBAA( "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 @@ TBAABuilder::TBAABuilder(mlir::ModuleOp module, bool applyTBAA) 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 @@ void TBAABuilder::attachTBAATag(Operation *op, Type baseFIRType, 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); diff --git a/flang/lib/Optimizer/CodeGen/TBAABuilder.h b/flang/lib/Optimizer/CodeGen/TBAABuilder.h index dff924b..f0dfc0e 100644 --- a/flang/lib/Optimizer/CodeGen/TBAABuilder.h +++ b/flang/lib/Optimizer/CodeGen/TBAABuilder.h @@ -251,6 +251,9 @@ private: // 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.