[PATCH] D51749: [GlobalISel] Lower dbg.declare into indirect DBG_VALUE

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 6 14:07:48 PDT 2018


rnk added a comment.

In https://reviews.llvm.org/D51749#1226398, @aprantl wrote:

> Because of LiveDebugValues this patch might still work though.
>
> Does GlobalISel support the MMI side table? Otherwise this seems a fine approach.


It already uses the (now MachineFunction, no longer MMI) side table, if the argument is a static alloca. The original code with more context:

  auto AI = dyn_cast<AllocaInst>(Address);
  if (AI && AI->isStaticAlloca()) {
    // Static allocas are tracked at the MF level, no need for DBG_VALUE
    // instructions (in fact, they get ignored if they *do* exist).
    MF->setVariableDbgInfo(DI.getVariable(), DI.getExpression(),
                           getOrCreateFrameIndex(*AI), DI.getDebugLoc());
  } else
    MIRBuilder.buildDirectDbgValue(getOrCreateVReg(*Address),
                                   DI.getVariable(), DI.getExpression());
  return true;

So, this only affects variables that are declared in not-allocas at -O0, i.e. things passed indirectly with `byval`, or `sret`, or by address in the way that non-trivially copyable C++ types are.

This code could be improved to handle more cases where the value in question actually has a frame index. `byval` and `inalloca` are the obvious ways that I know of to get those. Looks like this is the code we use in SDAG ISel for it:

  } else if (const auto *Arg = dyn_cast<Argument>(
                 Address->stripInBoundsConstantOffsets())) {
    FI = FuncInfo.getArgumentFrameIndex(Arg);
  }

I think this change could use a more direct test, consider starting with the IR generated for a C++ object, like:

  struct NTCopy {
    NTCopy();
    NTCopy(const NTCopy &);
    int x;
  };
  int foo(NTCopy o) {
    return o.x;
  }



================
Comment at: test/CodeGen/AArch64/GlobalISel/debug-insts.ll:12
 entry:
   %in.addr = alloca i32, align 4
----------------
This test is strange, it declares the variable twice, once in %in.addr (correct) and again in %in (incorrect).


================
Comment at: test/CodeGen/AArch64/GlobalISel/debug-insts.ll:20
 ; CHECK-LABEL: name: debug_declare_vla
-; CHECK: DBG_VALUE debug-use %{{[0-9]+}}(p0), debug-use $noreg, !14, !DIExpression(), debug-location !15
+; CHECK: DBG_VALUE debug-use %{{[0-9]+}}(p0), 0, !14, !DIExpression(), debug-location !15
 define void @debug_declare_vla(i32 %in) #0 !dbg !13 {
----------------
This change makes sense, though. The VLA is at some stack pointer offset. I assume p0 is the SP reg.


Repository:
  rL LLVM

https://reviews.llvm.org/D51749





More information about the llvm-commits mailing list