[llvm] 43aa4ac - [StandardInstrumentations] Assign names to basic blocks without names

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 2 11:06:35 PDT 2022


Author: Arthur Eubanks
Date: 2022-08-02T11:04:01-07:00
New Revision: 43aa4ac70b82c8e378f84b65b49b4613649da8e0

URL: https://github.com/llvm/llvm-project/commit/43aa4ac70b82c8e378f84b65b49b4613649da8e0
DIFF: https://github.com/llvm/llvm-project/commit/43aa4ac70b82c8e378f84b65b49b4613649da8e0.diff

LOG: [StandardInstrumentations] Assign names to basic blocks without names

Fixes code in OrderedChangedData<T>::report which assumes that a string will only appear once in Before/After.

Reviewed By: jamieschmeiser

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

Added: 
    llvm/test/Other/ChangePrinters/print-changed-diff-empty-bb-name.ll

Modified: 
    llvm/lib/Passes/StandardInstrumentations.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index e6dab5f09a452..c44e3eb3ea451 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -615,9 +615,15 @@ template <typename T>
 bool IRComparer<T>::generateFunctionData(IRDataT<T> &Data, const Function &F) {
   if (!F.isDeclaration() && isFunctionInPrintList(F.getName())) {
     FuncDataT<T> FD(F.getEntryBlock().getName().str());
+    int I = 0;
     for (const auto &B : F) {
-      FD.getOrder().emplace_back(B.getName());
-      FD.getData().insert({B.getName(), B});
+      std::string BBName = B.getName().str();
+      if (BBName.empty()) {
+        BBName = formatv("{0}", I);
+        ++I;
+      }
+      FD.getOrder().emplace_back(BBName);
+      FD.getData().insert({BBName, B});
     }
     Data.getOrder().emplace_back(F.getName());
     Data.getData().insert({F.getName(), FD});

diff  --git a/llvm/test/Other/ChangePrinters/print-changed-
diff -empty-bb-name.ll b/llvm/test/Other/ChangePrinters/print-changed-
diff -empty-bb-name.ll
new file mode 100644
index 0000000000000..7f03e6979375d
--- /dev/null
+++ b/llvm/test/Other/ChangePrinters/print-changed-
diff -empty-bb-name.ll
@@ -0,0 +1,18 @@
+; RUN: opt -passes=inline %s -disable-output --print-changed=
diff  2>&1 | FileCheck %s
+
+; CHECK: IR Dump After InlinerPass
+
+define void @f(i1 %i) {
+  call void @g(i1 %i)
+  ret void
+}
+
+define void @g(i1 %i) {
+  br i1 %i, label %1, label %2
+
+1:
+  ret void
+
+2:
+  ret void
+}


        


More information about the llvm-commits mailing list