[llvm] [RemoveDIs] Enable DPLabels conversion [3b/3] (PR #82639)

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 22 07:48:39 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Orlando Cazalet-Hyams (OCHyams)

<details>
<summary>Changes</summary>

Enables conversion between llvm.dbg.label and DPLabel.

---
Full diff: https://github.com/llvm/llvm-project/pull/82639.diff


1 Files Affected:

- (modified) llvm/lib/IR/BasicBlock.cpp (+20-3) 


``````````diff
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index 0680754444f17f..8a5bfdb0506854 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -81,6 +81,12 @@ void BasicBlock::convertToNewDbgValues() {
       continue;
     }
 
+    if (DbgLabelInst *DLI = dyn_cast<DbgLabelInst>(&I)) {
+      DPVals.push_back(new DPLabel(DLI->getLabel(), DLI->getDebugLoc()));
+      DLI->eraseFromParent();
+      continue;
+    }
+
     if (DPVals.empty())
       continue;
 
@@ -108,15 +114,26 @@ void BasicBlock::convertFromNewDbgValues() {
 
     DPMarker &Marker = *Inst.DbgMarker;
     for (DbgRecord &DR : Marker.getDbgValueRange()) {
-      if (auto *DPV = dyn_cast<DPValue>(&DR))
+      if (auto *DPV = dyn_cast<DPValue>(&DR)) {
         InstList.insert(Inst.getIterator(),
                         DPV->createDebugIntrinsic(getModule(), nullptr));
-      else
+      } else if (auto *DPL = dyn_cast<DPLabel>(&DR)) {
+        auto *LabelFn =
+            Intrinsic::getDeclaration(getModule(), Intrinsic::dbg_label);
+        Value *Args[] = {
+            MetadataAsValue::get(getModule()->getContext(), DPL->getLabel())};
+        DbgLabelInst *DbgLabel = cast<DbgLabelInst>(
+            CallInst::Create(LabelFn->getFunctionType(), LabelFn, Args));
+        DbgLabel->setTailCall();
+        DbgLabel->setDebugLoc(DPL->getDebugLoc());
+        InstList.insert(Inst.getIterator(), DbgLabel);
+      } else {
         llvm_unreachable("unsupported DbgRecord kind");
+      }
     }
 
     Marker.eraseFromParent();
-  };
+  }
 
   // Assume no trailing DPValues: we could technically create them at the end
   // of the block, after a terminator, but this would be non-cannonical and

``````````

</details>


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


More information about the llvm-commits mailing list