[llvm] [llvm/llvm-project][Coroutines] Improve debugging and minor refactoring (PR #104642)

Tyler Nowicki via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 22 10:28:09 PDT 2024


================
@@ -52,6 +53,16 @@ extern cl::opt<bool> UseNewDbgInfoFormat;
 
 enum { SmallVectorThreshold = 32 };
 
+static std::string getBasicBlockLabel(const BasicBlock *BB) {
+  if (BB->hasName())
+    return BB->getName().str();
+
+  std::string S;
+  raw_string_ostream OS(S);
+  BB->printAsOperand(OS, false);
+  return OS.str().substr(1);
----------------
TylerNowicki wrote:

In addressing the reviewers concerns I realized why I added this in the first place. When dumping if we use BB->getName and there is no name, it will not print anything. You are right it is not stable across passes, so it should only be used for dumping. I have made that correction. But when dumping it is important to use otherwise the output will not be understandable. For example, without getBasicBlockLabel the output for coro-suspend-crossing will produce

:
   Consumes: 
      Kills:
:
   Consumes:  
      Kills:
:
   Consumes:   
      Kills:
:
   Consumes:    
      Kills:
.from.:
   Consumes:     .from.
      Kills:
.from.1:
   Consumes:    .from.1
      Kills:
:
   Consumes:     .from. .from.1 
      Kills:
:
   Consumes:     .from. .from.1  
      Kills:


with getBasicBlockLabel we see

2:
   Consumes: 2
      Kills:
16:
   Consumes: 2 16
      Kills:
65:
   Consumes: 2 16 65
      Kills:
100:
   Consumes: 2 16 65 100
      Kills:
.from.:
   Consumes: 2 16 65 100 .from.
      Kills:
.from.1:
   Consumes: 2 16 65 .from.1
      Kills:


You can see there is a lot of missing information if we use getName...

https://github.com/llvm/llvm-project/pull/104642


More information about the llvm-commits mailing list