[llvm] [RemoveDIs] Read/write DbgRecords directly from/to bitcode (PR #83251)
Jeremy Morse via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 4 10:10:27 PST 2024
================
@@ -409,26 +423,49 @@ ValueEnumerator::ValueEnumerator(const Module &M,
for (const BasicBlock &BB : F)
for (const Instruction &I : BB) {
+ // Local metadata is enumerated during function-incorporation, but
+ // any ConstantAsMetadata arguments in a DIArgList should be examined
+ // now.
+ auto EnumerateNonLocalValuesFromMetadata = [&](Metadata *MD) {
+ assert(MD && "Metadata unexpectedly null");
+ if (const auto *AL = dyn_cast<DIArgList>(MD)) {
+ for (const auto *VAM : AL->getArgs()) {
+ if (isa<ConstantAsMetadata>(VAM))
+ EnumerateMetadata(&F, VAM);
+ }
+ return;
+ }
+
+ if (!isa<LocalAsMetadata>(MD))
+ EnumerateMetadata(&F, MD);
+ };
+
+ for (DbgRecord &DR : I.getDbgValueRange()) {
+ if (DPLabel *DPL = dyn_cast<DPLabel>(&DR)) {
+ EnumerateMetadata(&F, DPL->getLabel());
+ EnumerateMetadata(&F, &*DPL->getDebugLoc());
+ continue;
+ }
+ // Enumerate non-local location metadata.
+ DPValue &DPV = cast<DPValue>(DR);
+ EnumerateNonLocalValuesFromMetadata(DPV.getRawLocation());
+ EnumerateMetadata(&F, DPV.getExpression());
+ EnumerateMetadata(&F, DPV.getVariable());
+ EnumerateMetadata(&F, &*DPV.getDebugLoc());
+ if (DPV.isDbgAssign()) {
+ EnumerateNonLocalValuesFromMetadata(DPV.getRawAddress());
+ EnumerateMetadata(&F, DPV.getAssignID());
+ EnumerateMetadata(&F, DPV.getAddressExpression());
+ }
+ }
for (const Use &Op : I.operands()) {
auto *MD = dyn_cast<MetadataAsValue>(&Op);
if (!MD) {
EnumerateOperandType(Op);
continue;
}
- // Local metadata is enumerated during function-incorporation, but
- // any ConstantAsMetadata arguments in a DIArgList should be examined
- // now.
- if (isa<LocalAsMetadata>(MD->getMetadata()))
- continue;
- if (auto *AL = dyn_cast<DIArgList>(MD->getMetadata())) {
- for (auto *VAM : AL->getArgs())
- if (isa<ConstantAsMetadata>(VAM))
- EnumerateMetadata(&F, VAM);
- continue;
- }
-
- EnumerateMetadata(&F, MD->getMetadata());
----------------
jmorse wrote:
Deleting this hunk is going to knacker anyone not running in RemoveDIs mode right now, yes? IMO it's worth stick a comment in saying it's scheduled for removal instead.
https://github.com/llvm/llvm-project/pull/83251
More information about the llvm-commits
mailing list