[PATCH] D46100: WIP: [IR/Verifier] Diagnose use-before-def scenarios for debug intrinsics

Vedant Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 25 19:46:20 PDT 2018


vsk created this revision.
vsk added reviewers: davide, mattd, aprantl, dblaikie.
Herald added a subscriber: JDevlieghere.

I'd like to use this WIP patch to start a discussion about use-before-def scenarios with debug info intrinsics.

One motivation for preventing use-before-def is to ensure correctness of sinking/hoisting code. For example, if we sink Inst from BB1 to BB2, the debug values for Inst should be moved as well. This is sometimes written as:

  Begin = next(Inst.getIterator())
  for I in range(Begin, BB.end()):
    if I.isDebugValue():
      break
    if I.getDebugVariable() == Inst:
      DbgValuesToSink.push_back(I)

If use-before-def is permitted, we might not sink all the relevant debug intrinsics. There may be debug uses of Inst before Begin. Also, once DbgValuesToSink is processed, there may be leftover debug uses of Inst in BB1 after the final value of I.

To avoid these issues, I propose checking for use-before-def in the IR and MIR verifiers, possibly gated by EXPENSIVE_CHECKS. The IR check catches several issues in a stage2-RelWithDebInfo build.

Use-before-def may be generally illegal in SSA form, so we might consider enabling this check for all instructions. I'd appreciate any feedback on whether or how to enable this check.


https://reviews.llvm.org/D46100

Files:
  lib/IR/Verifier.cpp


Index: lib/IR/Verifier.cpp
===================================================================
--- lib/IR/Verifier.cpp
+++ lib/IR/Verifier.cpp
@@ -4491,6 +4491,13 @@
            &DII, BB, F, Var, Var->getScope()->getSubprogram(), Loc,
            Loc->getScope()->getSubprogram());
 
+  if (auto *Def = dyn_cast_or_null<Instruction>(DII.getVariableLocation())) {
+    bool DefBeforeUse = DT.dominates(Def, &DII);
+    AssertDI(DefBeforeUse,
+             "debug info intrinsic uses variable before its definition", &DII,
+             BB, F);
+  }
+
   verifyFnArgs(DII);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46100.144052.patch
Type: text/x-patch
Size: 577 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180426/efc7758a/attachment.bin>


More information about the llvm-commits mailing list