[PATCH] D71478: [BasicBlockUtils] Add utility to remove redundant dbg.value instrs

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 13 10:15:42 PST 2019


bjope created this revision.
bjope added reviewers: aprantl, jmorse, vsk.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

Add a RemoveRedundantDbgInstrs to BasicBlockUtils with the
goal to remove redundant dbg intrinsics from a basic block.

This can be useful after various transforms, as it might
be simpler to do a filtering of dbg intrinsics after the
transform than during the transform.
One primary use case would be to replace a too aggressive
removal done by MergeBlockIntoPredecessor, seen at loop
rotate (not done in this patch).

The elimination algorithm currently focuses on dbg.value
intrinsics and is doing two iterations over the BB.

First we iterate backward starting at the last instruction
in the BB. Whenever a consecutive sequence of dbg.value
instructions are found we keep the last dbg.value for
each variable found (variable fragments are identified
using the  {DILocalVariable, FragmentInfo, inlinedAt}
triple as given by the DebugVariable helper class).

Next we iterate forward starting at the first instruction
in the BB. Whenever we find a dbg.value describing a
DebugVariable (identified by {DILocalVariable, inlinedAt})
we save the {DIValue, DIExpression} that describes that
variables value. But if the variable already was mapped
to the same {DIValue, DIExpression} pair we instead drop
the second dbg.value.

To ease the process of making lit tests for this utility a
new pass is introduced called RedundantDbgInstElimination.
It can be executed by opt using -redundant-dbg-inst-elim.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71478

Files:
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/LinkAllPasses.h
  llvm/include/llvm/Transforms/Scalar.h
  llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
  llvm/lib/Transforms/Scalar/DCE.cpp
  llvm/lib/Transforms/Scalar/Scalar.cpp
  llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
  llvm/test/Transforms/DCE/dbg-value-removal.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71478.233829.patch
Type: text/x-patch
Size: 16959 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191213/af740991/attachment.bin>


More information about the llvm-commits mailing list