[llvm] [RemoveDIs] Auto-upgrade debug intrinsics to DbgRecords (default false) (PR #85650)

Orlando Cazalet-Hyams via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 19 05:54:41 PDT 2024


================
@@ -609,17 +609,25 @@ class MetadataLoader::MetadataLoaderImpl {
     if (!NeedDeclareExpressionUpgrade)
       return;
 
+    auto UpdateDeclareIfNeeded = [&](auto *Declare) {
+      auto *DIExpr = Declare->getExpression();
+      if (!DIExpr || !DIExpr->startsWithDeref() ||
+          !isa_and_nonnull<Argument>(Declare->getAddress()))
+        return;
+      SmallVector<uint64_t, 8> Ops;
+      Ops.append(std::next(DIExpr->elements_begin()), DIExpr->elements_end());
+      Declare->setExpression(DIExpression::get(Context, Ops));
+    };
+
     for (auto &BB : F)
-      for (auto &I : BB)
+      for (auto &I : BB) {
+        for (DPValue &DPV : filterDbgVars(I.getDbgRecordRange())) {
----------------
OCHyams wrote:

> I guess the intention here is to port all these accumulated debug info upgrades so that apply to the new format as well (since anyone might convert upgrade-needing-debug-info from old to new format)?

Yeah that's right. It could be unnecessary but I figure there's no harm since it's easy to do.

> Will NeedDeclareExpressionUpgrade be set properly by upgradeDIExpression for the new format as well?

That's a good question. Yes, because the `DIExpression` is stored separately to the debug record/intrinsic bitcode records. The `DIExpressions` are stored in the `METADATA_BLOCK` and the debug bitcode records only store a reference to it. `NeedDeclareExpressionUpgrade ` is set (from `writeMetadataRecords`.. `upgradeDIExpression`) while parsing the `METADATA_BLOCK`.

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


More information about the llvm-commits mailing list