[NFC][flang] Added debug option to bisect TBAA tag attachments.
authorSlava Zakharin <szakharin@nvidia.com>
Thu, 19 Jan 2023 16:46:52 +0000 (08:46 -0800)
committerSlava Zakharin <szakharin@nvidia.com>
Thu, 19 Jan 2023 17:27:50 +0000 (09:27 -0800)
Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D142070

flang/lib/Optimizer/CodeGen/TBAABuilder.cpp
flang/lib/Optimizer/CodeGen/TBAABuilder.h

index 1bee674..2d206ed 100644 (file)
@@ -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<bool> 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<unsigned>::max();
+static llvm::cl::opt<unsigned>
+    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("<unknown>") << "'\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<fir::BaseBoxType>())
     tbaaTagSym = getBoxAccessTag(baseFIRType, accessFIRType, gep);
index dff924b..f0dfc0e 100644 (file)
@@ -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.