Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[RemoveDIs] Read/write DbgRecords directly from/to bitcode" #85382

Merged
merged 1 commit into from
Mar 15, 2024

Conversation

OCHyams
Copy link
Contributor

@OCHyams OCHyams commented Mar 15, 2024

@OCHyams OCHyams merged commit 861ebe6 into main Mar 15, 2024
4 of 5 checks passed
@OCHyams OCHyams deleted the revert-83251-ddd-bitcode branch March 15, 2024 11:04
@llvmbot llvmbot added LTO Link time optimization (regular/full LTO or ThinLTO) llvm:ir llvm:transforms labels Mar 15, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 15, 2024

@llvm/pr-subscribers-lto
@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-llvm-transforms

Author: Orlando Cazalet-Hyams (OCHyams)

Changes

Reverts llvm/llvm-project#83251

Buildbot: https://lab.llvm.org/buildbot/#/builders/139/builds/61485


Patch is 40.97 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/85382.diff

12 Files Affected:

  • (modified) llvm/include/llvm/Bitcode/LLVMBitCodes.h (-11)
  • (modified) llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp (-5)
  • (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+3-98)
  • (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+18-102)
  • (modified) llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp (+10-10)
  • (modified) llvm/lib/Bitcode/Writer/ValueEnumerator.cpp (+49-100)
  • (modified) llvm/lib/IR/BasicBlock.cpp (-5)
  • (modified) llvm/lib/Linker/IRMover.cpp (+3-18)
  • (modified) llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp (+4-5)
  • (removed) llvm/test/Bitcode/dbg-record-roundtrip.ll (-128)
  • (modified) llvm/tools/llvm-as/llvm-as.cpp (-7)
  • (modified) llvm/tools/verify-uselistorder/verify-uselistorder.cpp (-11)
diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
index 39303e64852141..c0a52d64a101d0 100644
--- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
@@ -624,17 +624,6 @@ enum FunctionCodes {
                                   //             operation, align, vol,
                                   //             ordering, synchscope]
   FUNC_CODE_BLOCKADDR_USERS = 60, // BLOCKADDR_USERS: [value...]
-
-  FUNC_CODE_DEBUG_RECORD_VALUE =
-      61, // [DILocation, DILocalVariable, DIExpression, ValueAsMetadata]
-  FUNC_CODE_DEBUG_RECORD_DECLARE =
-      62, // [DILocation, DILocalVariable, DIExpression, ValueAsMetadata]
-  FUNC_CODE_DEBUG_RECORD_ASSIGN =
-      63, // [DILocation, DILocalVariable, DIExpression, ValueAsMetadata,
-          //  DIAssignID, DIExpression (addr), ValueAsMetadata (addr)]
-  FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE =
-      64, // [DILocation, DILocalVariable, DIExpression, Value]
-  FUNC_CODE_DEBUG_RECORD_LABEL = 65, // [DILocation, DILabel]
 };
 
 enum UseListCodes {
diff --git a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
index c085c715179ba6..7005011980ebc9 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
@@ -270,11 +270,6 @@ GetCodeName(unsigned CodeID, unsigned BlockID,
       STRINGIFY_CODE(FUNC_CODE, INST_CMPXCHG)
       STRINGIFY_CODE(FUNC_CODE, INST_CALLBR)
       STRINGIFY_CODE(FUNC_CODE, BLOCKADDR_USERS)
-      STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_DECLARE)
-      STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_VALUE)
-      STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_ASSIGN)
-      STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_VALUE_SIMPLE)
-      STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_LABEL)
     }
   case bitc::VALUE_SYMTAB_BLOCK_ID:
     switch (CodeID) {
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index d284c9823c9ede..9c63116114f3c5 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -100,6 +100,9 @@ static cl::opt<bool> ExpandConstantExprs(
     cl::desc(
         "Expand constant expressions to instructions for testing purposes"));
 
+// Declare external flag for whether we're using the new debug-info format.
+extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
+
 namespace {
 
 enum {
@@ -4276,10 +4279,6 @@ Error BitcodeReader::parseGlobalIndirectSymbolRecord(
 Error BitcodeReader::parseModule(uint64_t ResumeBit,
                                  bool ShouldLazyLoadMetadata,
                                  ParserCallbacks Callbacks) {
-  // Force the debug-info mode into the old format for now.
-  // FIXME: Remove this once all tools support RemoveDIs.
-  TheModule->IsNewDbgInfoFormat = false;
-
   this->ValueTypeCallback = std::move(Callbacks.ValueType);
   if (ResumeBit) {
     if (Error JumpFailed = Stream.JumpToBit(ResumeBit))
@@ -6399,89 +6398,6 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
       InstructionList.push_back(I);
       break;
     }
-    case bitc::FUNC_CODE_DEBUG_RECORD_LABEL: {
-      // DPLabels are placed after the Instructions that they are attached to.
-      Instruction *Inst = getLastInstruction();
-      if (!Inst)
-        return error("Invalid dbg record: missing instruction");
-      DILocation *DIL = cast<DILocation>(getFnMetadataByID(Record[0]));
-      DILabel *Label = cast<DILabel>(getFnMetadataByID(Record[1]));
-      Inst->getParent()->insertDbgRecordBefore(
-          new DPLabel(Label, DebugLoc(DIL)), Inst->getIterator());
-      continue; // This isn't an instruction.
-    }
-    case bitc::FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE:
-    case bitc::FUNC_CODE_DEBUG_RECORD_VALUE:
-    case bitc::FUNC_CODE_DEBUG_RECORD_DECLARE:
-    case bitc::FUNC_CODE_DEBUG_RECORD_ASSIGN: {
-      // DPValues are placed after the Instructions that they are attached to.
-      Instruction *Inst = getLastInstruction();
-      if (!Inst)
-        return error("Invalid dbg record: missing instruction");
-
-      // First 3 fields are common to all kinds:
-      //   DILocation, DILocalVariable, DIExpression
-      // dbg_value (FUNC_CODE_DEBUG_RECORD_VALUE)
-      //   ..., LocationMetadata
-      // dbg_value (FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE - abbrev'd)
-      //   ..., Value
-      // dbg_declare (FUNC_CODE_DEBUG_RECORD_DECLARE)
-      //   ..., LocationMetadata
-      // dbg_assign (FUNC_CODE_DEBUG_RECORD_ASSIGN)
-      //   ..., LocationMetadata, DIAssignID, DIExpression, LocationMetadata
-      unsigned Slot = 0;
-      // Common fields (0-2).
-      DILocation *DIL = cast<DILocation>(getFnMetadataByID(Record[Slot++]));
-      DILocalVariable *Var =
-          cast<DILocalVariable>(getFnMetadataByID(Record[Slot++]));
-      DIExpression *Expr =
-          cast<DIExpression>(getFnMetadataByID(Record[Slot++]));
-
-      // Union field (3: LocationMetadata | Value).
-      Metadata *RawLocation = nullptr;
-      if (BitCode == bitc::FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE) {
-        Value *V = nullptr;
-        unsigned TyID = 0;
-        // We never expect to see a fwd reference value here because
-        // use-before-defs are encoded with the standard non-abbrev record
-        // type (they'd require encoding the type too, and they're rare). As a
-        // result, getValueTypePair only ever increments Slot by one here (once
-        // for the value, never twice for value and type).
-        unsigned SlotBefore = Slot;
-        if (getValueTypePair(Record, Slot, NextValueNo, V, TyID, CurBB))
-          return error("Invalid dbg record: invalid value");
-        (void)SlotBefore;
-        assert((SlotBefore == Slot - 1) && "unexpected fwd ref");
-        RawLocation = ValueAsMetadata::get(V);
-      } else {
-        RawLocation = getFnMetadataByID(Record[Slot++]);
-      }
-
-      DPValue *DPV = nullptr;
-      switch (BitCode) {
-      case bitc::FUNC_CODE_DEBUG_RECORD_VALUE:
-      case bitc::FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE:
-        DPV = new DPValue(RawLocation, Var, Expr, DIL,
-                          DPValue::LocationType::Value);
-        break;
-      case bitc::FUNC_CODE_DEBUG_RECORD_DECLARE:
-        DPV = new DPValue(RawLocation, Var, Expr, DIL,
-                          DPValue::LocationType::Declare);
-        break;
-      case bitc::FUNC_CODE_DEBUG_RECORD_ASSIGN: {
-        DIAssignID *ID = cast<DIAssignID>(getFnMetadataByID(Record[Slot++]));
-        DIExpression *AddrExpr =
-            cast<DIExpression>(getFnMetadataByID(Record[Slot++]));
-        Metadata *Addr = getFnMetadataByID(Record[Slot++]);
-        DPV = new DPValue(RawLocation, Var, Expr, ID, Addr, AddrExpr, DIL);
-        break;
-      }
-      default:
-        llvm_unreachable("Unknown DPValue bitcode");
-      }
-      Inst->getParent()->insertDbgRecordBefore(DPV, Inst->getIterator());
-      continue; // This isn't an instruction.
-    }
     case bitc::FUNC_CODE_INST_CALL: {
       // CALL: [paramattrs, cc, fmf, fnty, fnid, arg0, arg1...]
       if (Record.size() < 3)
@@ -6761,21 +6677,10 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
   // Move the bit stream to the saved position of the deferred function body.
   if (Error JumpFailed = Stream.JumpToBit(DFII->second))
     return JumpFailed;
-
-  // Set the debug info mode to "new", forcing a mismatch between
-  // module and function debug modes. This is okay because we'll convert
-  // everything back to the old mode after parsing.
-  // FIXME: Remove this once all tools support RemoveDIs.
-  F->IsNewDbgInfoFormat = true;
-
   if (Error Err = parseFunctionBody(F))
     return Err;
   F->setIsMaterializable(false);
 
-  // Convert new debug info records into intrinsics.
-  // FIXME: Remove this once all tools support RemoveDIs.
-  F->convertFromNewDbgValues();
-
   if (StripDebugInfo)
     stripDebugInfo(*F);
 
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 6f0879a4e0ee74..597f49332fad25 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -99,9 +99,6 @@ namespace llvm {
 extern FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold;
 }
 
-extern bool WriteNewDbgInfoFormatToBitcode;
-extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
-
 namespace {
 
 /// These are manifest constants used by the bitcode writer. They do not need to
@@ -131,7 +128,6 @@ enum {
   FUNCTION_INST_RET_VAL_ABBREV,
   FUNCTION_INST_UNREACHABLE_ABBREV,
   FUNCTION_INST_GEP_ABBREV,
-  FUNCTION_DEBUG_RECORD_VALUE_ABBREV,
 };
 
 /// Abstract class to manage the bitcode writing, subclassed for each bitcode
@@ -3516,95 +3512,25 @@ void ModuleBitcodeWriter::writeFunction(
       NeedsMetadataAttachment |= I.hasMetadataOtherThanDebugLoc();
 
       // If the instruction has a debug location, emit it.
-      if (DILocation *DL = I.getDebugLoc()) {
-        if (DL == LastDL) {
-          // Just repeat the same debug loc as last time.
-          Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC_AGAIN, Vals);
-        } else {
-          Vals.push_back(DL->getLine());
-          Vals.push_back(DL->getColumn());
-          Vals.push_back(VE.getMetadataOrNullID(DL->getScope()));
-          Vals.push_back(VE.getMetadataOrNullID(DL->getInlinedAt()));
-          Vals.push_back(DL->isImplicitCode());
-          Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals);
-          Vals.clear();
-          LastDL = DL;
-        }
-      }
+      DILocation *DL = I.getDebugLoc();
+      if (!DL)
+        continue;
 
-      // If the instruction has DbgRecords attached to it, emit them. Note that
-      // they come after the instruction so that it's easy to attach them again
-      // when reading the bitcode, even though conceptually the debug locations
-      // start "before" the instruction.
-      if (I.hasDbgRecords() && WriteNewDbgInfoFormatToBitcode) {
-        /// Try to push the value only (unwrapped), otherwise push the
-        /// metadata wrapped value. Returns true if the value was pushed
-        /// without the ValueAsMetadata wrapper.
-        auto PushValueOrMetadata = [&Vals, InstID,
-                                    this](Metadata *RawLocation) {
-          assert(RawLocation && "RawLocation unexpectedly null in DPValue");
-          if (ValueAsMetadata *VAM = dyn_cast<ValueAsMetadata>(RawLocation)) {
-            SmallVector<unsigned, 2> ValAndType;
-            // If the value is a fwd-ref the type is also pushed. We don't
-            // want the type, so fwd-refs are kept wrapped (pushValueAndType
-            // returns false if the value is pushed without type).
-            if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
-              Vals.push_back(ValAndType[0]);
-              return true;
-            }
-          }
-          // The metadata is a DIArgList, or ValueAsMetadata wrapping a
-          // fwd-ref. Push the metadata ID.
-          Vals.push_back(VE.getMetadataID(RawLocation));
-          return false;
-        };
-
-        // Write out non-instruction debug information attached to this
-        // instruction. Write it after the instruction so that it's easy to
-        // re-attach to the instruction reading the records in.
-        for (DbgRecord &DR : I.DbgMarker->getDbgRecordRange()) {
-          if (DPLabel *DPL = dyn_cast<DPLabel>(&DR)) {
-            Vals.push_back(VE.getMetadataID(&*DPL->getDebugLoc()));
-            Vals.push_back(VE.getMetadataID(DPL->getLabel()));
-            Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_LABEL, Vals);
-            Vals.clear();
-            continue;
-          }
-
-          // First 3 fields are common to all kinds:
-          //   DILocation, DILocalVariable, DIExpression
-          // dbg_value (FUNC_CODE_DEBUG_RECORD_VALUE)
-          //   ..., LocationMetadata
-          // dbg_value (FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE - abbrev'd)
-          //   ..., Value
-          // dbg_declare (FUNC_CODE_DEBUG_RECORD_DECLARE)
-          //   ..., LocationMetadata
-          // dbg_assign (FUNC_CODE_DEBUG_RECORD_ASSIGN)
-          //   ..., LocationMetadata, DIAssignID, DIExpression, LocationMetadata
-          DPValue &DPV = cast<DPValue>(DR);
-          Vals.push_back(VE.getMetadataID(&*DPV.getDebugLoc()));
-          Vals.push_back(VE.getMetadataID(DPV.getVariable()));
-          Vals.push_back(VE.getMetadataID(DPV.getExpression()));
-          if (DPV.isDbgValue()) {
-            if (PushValueOrMetadata(DPV.getRawLocation()))
-              Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE, Vals,
-                                FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
-            else
-              Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_VALUE, Vals);
-          } else if (DPV.isDbgDeclare()) {
-            Vals.push_back(VE.getMetadataID(DPV.getRawLocation()));
-            Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_DECLARE, Vals);
-          } else {
-            assert(DPV.isDbgAssign() && "Unexpected DbgRecord kind");
-            Vals.push_back(VE.getMetadataID(DPV.getRawLocation()));
-            Vals.push_back(VE.getMetadataID(DPV.getAssignID()));
-            Vals.push_back(VE.getMetadataID(DPV.getAddressExpression()));
-            Vals.push_back(VE.getMetadataID(DPV.getRawAddress()));
-            Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_ASSIGN, Vals);
-          }
-          Vals.clear();
-        }
+      if (DL == LastDL) {
+        // Just repeat the same debug loc as last time.
+        Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC_AGAIN, Vals);
+        continue;
       }
+
+      Vals.push_back(DL->getLine());
+      Vals.push_back(DL->getColumn());
+      Vals.push_back(VE.getMetadataOrNullID(DL->getScope()));
+      Vals.push_back(VE.getMetadataOrNullID(DL->getInlinedAt()));
+      Vals.push_back(DL->isImplicitCode());
+      Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals);
+      Vals.clear();
+
+      LastDL = DL;
     }
 
     if (BlockAddress *BA = BlockAddress::lookup(&BB)) {
@@ -3845,17 +3771,7 @@ void ModuleBitcodeWriter::writeBlockInfo() {
         FUNCTION_INST_GEP_ABBREV)
       llvm_unreachable("Unexpected abbrev ordering!");
   }
-  {
-    auto Abbv = std::make_shared<BitCodeAbbrev>();
-    Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE));
-    Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 7)); // dbgloc
-    Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 7)); // var
-    Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 7)); // expr
-    Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // val
-    if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
-        FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
-      llvm_unreachable("Unexpected abbrev ordering! 1");
-  }
+
   Stream.ExitBlock();
 }
 
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp
index de2396f31f6669..0eb9c246f2a9b6 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp
@@ -18,12 +18,11 @@
 #include "llvm/Pass.h"
 using namespace llvm;
 
-extern bool WriteNewDbgInfoFormatToBitcode;
-
 PreservedAnalyses BitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
-  bool ConvertToOldDbgFormatForWrite =
-      M.IsNewDbgInfoFormat && !WriteNewDbgInfoFormatToBitcode;
-  if (ConvertToOldDbgFormatForWrite)
+  // RemoveDIs: there's no bitcode representation of the DbgRecord debug-info,
+  // convert to dbg.values before writing out.
+  bool IsNewDbgInfoFormat = M.IsNewDbgInfoFormat;
+  if (IsNewDbgInfoFormat)
     M.convertFromNewDbgValues();
 
   const ModuleSummaryIndex *Index =
@@ -31,7 +30,7 @@ PreservedAnalyses BitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
                        : nullptr;
   WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, Index, EmitModuleHash);
 
-  if (ConvertToOldDbgFormatForWrite)
+  if (IsNewDbgInfoFormat)
     M.convertToNewDbgValues();
 
   return PreservedAnalyses::all();
@@ -57,15 +56,16 @@ namespace {
     StringRef getPassName() const override { return "Bitcode Writer"; }
 
     bool runOnModule(Module &M) override {
-      bool ConvertToOldDbgFormatForWrite =
-          M.IsNewDbgInfoFormat && !WriteNewDbgInfoFormatToBitcode;
-      if (ConvertToOldDbgFormatForWrite)
+      // RemoveDIs: there's no bitcode representation of the DbgRecord
+      // debug-info, convert to dbg.values before writing out.
+      bool IsNewDbgInfoFormat = M.IsNewDbgInfoFormat;
+      if (IsNewDbgInfoFormat)
         M.convertFromNewDbgValues();
 
       WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, /*Index=*/nullptr,
                          /*EmitModuleHash=*/false);
 
-      if (ConvertToOldDbgFormatForWrite)
+      if (IsNewDbgInfoFormat)
         M.convertToNewDbgValues();
       return false;
     }
diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
index 1c439c9543210e..fccb2a606f7ed9 100644
--- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
+++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
@@ -134,28 +134,20 @@ static OrderMap orderModule(const Module &M) {
     // Metadata used by instructions is decoded before the actual instructions,
     // so visit any constants used by it beforehand.
     for (const BasicBlock &BB : F)
-      for (const Instruction &I : BB) {
-        auto OrderConstantFromMetadata = [&](Metadata *MD) {
-          if (const auto *VAM = dyn_cast<ValueAsMetadata>(MD)) {
-            orderConstantValue(VAM->getValue());
-          } else if (const auto *AL = dyn_cast<DIArgList>(MD)) {
-            for (const auto *VAM : AL->getArgs())
+      for (const Instruction &I : BB)
+        for (const Value *V : I.operands()) {
+          if (const auto *MAV = dyn_cast<MetadataAsValue>(V)) {
+            if (const auto *VAM =
+                    dyn_cast<ValueAsMetadata>(MAV->getMetadata())) {
               orderConstantValue(VAM->getValue());
+            } else if (const auto *AL =
+                           dyn_cast<DIArgList>(MAV->getMetadata())) {
+              for (const auto *VAM : AL->getArgs())
+                orderConstantValue(VAM->getValue());
+            }
           }
-        };
-
-        for (DPValue &DPV : filterDbgVars(I.getDbgRecordRange())) {
-          OrderConstantFromMetadata(DPV.getRawLocation());
-          if (DPV.isDbgAssign())
-            OrderConstantFromMetadata(DPV.getRawAddress());
         }
 
-        for (const Value *V : I.operands()) {
-          if (const auto *MAV = dyn_cast<MetadataAsValue>(V))
-            OrderConstantFromMetadata(MAV->getMetadata());
-        }
-      }
-
     for (const Argument &A : F.args())
       orderValue(&A, OM);
     for (const BasicBlock &BB : F)
@@ -269,39 +261,33 @@ static UseListOrderStack predictUseListOrder(const Module &M) {
   // constants in the last Function they're used in.  Module-level constants
   // have already been visited above.
   for (const Function &F : llvm::reverse(M)) {
-    auto PredictValueOrderFromMetadata = [&](Metadata *MD) {
-      if (const auto *VAM = dyn_cast<ValueAsMetadata>(MD)) {
-        predictValueUseListOrder(VAM->getValue(), &F, OM, Stack);
-      } else if (const auto *AL = dyn_cast<DIArgList>(MD)) {
-        for (const auto *VAM : AL->getArgs())
-          predictValueUseListOrder(VAM->getValue(), &F, OM, Stack);
-      }
-    };
     if (F.isDeclaration())
       continue;
     for (const BasicBlock &BB : F)
       predictValueUseListOrder(&BB, &F, OM, Stack);
     for (const Argument &A : F.args())
       predictValueUseListOrder(&A, &F, OM, Stack);
-    for (const BasicBlock &BB : F) {
+    for (const BasicBlock &BB : F)
       for (const Instruction &I : BB) {
-        for (DPValue &DPV : filterDbgVars(I.getDbgRecordRange())) {
-          PredictValueOrderFromMetadata(DPV.getRawLocation());
-          if (DPV.isDbgAssign())
-            PredictValueOrderFromMetadata(DPV.getRawAddress());
-        }
         for (const Value *Op : I.operands()) {
           if (isa<Constant>(*Op) || isa<InlineAsm>(*Op)) // Visit GlobalValues.
             predictValueUseListOrder(Op, &F, OM, Stack);
-          if (const auto *MAV = dyn_cast<MetadataAsValue>(Op))
-            PredictValueOrderFromMetadata(MAV->getMetadata());
+          if (const auto *MA...
[truncated]

OCHyams added a commit that referenced this pull request Mar 15, 2024
…83251)

Reaplying after revert in #85382 (861ebe6).
Fixed intermittent test failure by avoiding piping output in some RUN lines.

If --write-experimental-debuginfo-iterators-to-bitcode is true (default false)
and --expermental-debuginfo-iterators is also true then the new debug info
format (non-instruction records) is written to bitcode directly.

Added the following records:

    FUNC_CODE_DEBUG_RECORD_LABEL
    FUNC_CODE_DEBUG_RECORD_VALUE
    FUNC_CODE_DEBUG_RECORD_DECLARE
    FUNC_CODE_DEBUG_RECORD_ASSIGN
    FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE

The last one has an abbrev in FUNCTION_BLOCK BLOCK_INFO. Incidentally, this uses
the last value available without widening the code-length for FUNCTION_BLOCK
from 4 to 5 bits.

Records are formatted as follows:

    All DbgRecord start with:
      1. DILocation

      FUNC_CODE_DEBUG_RECORD_LABEL
        2. DILabel

      DPValues then share common fields:
        2. DILocalVariable
        3. DIExpression

        FUNC_CODE_DEBUG_RECORD_VALUE
          4. Location Metadata

        FUNC_CODE_DEBUG_RECORD_DECLARE
          4. Location Metadata

        FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE
	  4. Location Value (single)

        FUNC_CODE_DEBUG_RECORD_ASSIGN
	  4. Location Metadata
	  5. DIAssignID
	  6. DIExpression (address)
	  7. Location Metadata (address)

Encoding the DILocation metadata reference directly appeared to yield smaller
bitcode files than encoding the operands seperately (as is done with instruction
DILocations).

FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE is by far the most common DbgRecord record
in optimized code (order of 5x-10x over other kinds). Unoptimized code should
only contain FUNC_CODE_DEBUG_RECORD_DECLARE.
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Mar 21, 2024
…lvm#83251)

RL: rebased on top of latest amd-staging

Reaplying after revert in llvm#85382 (861ebe6).
Fixed intermittent test failure by avoiding piping output in some RUN lines.

If --write-experimental-debuginfo-iterators-to-bitcode is true (default false)
and --expermental-debuginfo-iterators is also true then the new debug info
format (non-instruction records) is written to bitcode directly.

Added the following records:

    FUNC_CODE_DEBUG_RECORD_LABEL
    FUNC_CODE_DEBUG_RECORD_VALUE
    FUNC_CODE_DEBUG_RECORD_DECLARE
    FUNC_CODE_DEBUG_RECORD_ASSIGN
    FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE

The last one has an abbrev in FUNCTION_BLOCK BLOCK_INFO. Incidentally, this uses
the last value available without widening the code-length for FUNCTION_BLOCK
from 4 to 5 bits.

Records are formatted as follows:

    All DbgRecord start with:
      1. DILocation

      FUNC_CODE_DEBUG_RECORD_LABEL
        2. DILabel

      DPValues then share common fields:
        2. DILocalVariable
        3. DIExpression

        FUNC_CODE_DEBUG_RECORD_VALUE
          4. Location Metadata

        FUNC_CODE_DEBUG_RECORD_DECLARE
          4. Location Metadata

        FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE
	  4. Location Value (single)

        FUNC_CODE_DEBUG_RECORD_ASSIGN
	  4. Location Metadata
	  5. DIAssignID
	  6. DIExpression (address)
	  7. Location Metadata (address)

Encoding the DILocation metadata reference directly appeared to yield smaller
bitcode files than encoding the operands seperately (as is done with instruction
DILocations).

FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE is by far the most common DbgRecord record
in optimized code (order of 5x-10x over other kinds). Unoptimized code should
only contain FUNC_CODE_DEBUG_RECORD_DECLARE.

Change-Id: I1bbd2237f9d6a80eeedfaf155922b972249dc78a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:ir llvm:transforms LTO Link time optimization (regular/full LTO or ThinLTO)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants