Skip to content
  1. Oct 14, 2021
    • Jeremy Morse's avatar
      Follow up to a3936a6c, correctly select LiveDebugValues implementation · e3e1da20
      Jeremy Morse authored
      Some functions get opted out of instruction referencing if they're being
      compiled with no optimisations, however the LiveDebugValues pass picks one
      implementation and then sticks with it through the rest of compilation.
      This leads to a segfault if we encounter a function that doesn't use
      instr-ref (because it's optnone, for example), but we've already decided
      to use InstrRefBasedLDV which expects to be passed a DomTree.
      
      Solution: keep both implementations around in the pass, and pick whichever
      one is appropriate to the current function.
      e3e1da20
  2. Oct 13, 2021
    • Jeremy Morse's avatar
      [DebugInfo][InstrRef] Only calculate IDF for reg units · fbf269c7
      Jeremy Morse authored
      In D110173 we start using the existing LLVM IDF calculator to place PHIs as
      we reconstruct an SSA form of machine-code program. Sadly that's slower
      than the old (but broken) way, this patch attempts to recover some of that
      performance.
      
      The key observation: every time we def a register, we also have to def it's
      register units. If we def'd $rax, in the current implementation we
      independently calculate PHI locations for {al, ah, ax, eax, hax, rax}, and
      they will all have the same PHI positions. Instead of doing that, we can
      calculate the PHI positions for {al, ah} and place PHIs for any aliasing
      registers in the same positions. Any def of a super-register has to def
      the unit, and vice versa, so this is sound. It cuts down the SSA placement
      we need to do significantly.
      
      This doesn't work for stack slots, or registers we only ever read, so place
      PHIs normally for those. LiveDebugValues choses to ignore writes to SP at
      calls, and now have to ignore writes to SP register units too.
      
      Differential Revision: https://reviews.llvm.org/D111627
      fbf269c7
    • Jeremy Morse's avatar
      Follow up a3936a6c to work around an old compiler bug · e845ca2f
      Jeremy Morse authored
      Old versions of gcc want template specialisations to happen within the
      namespace where the template lives; this is still present in gcc 5.1, which
      we officially support, so it has to be worked around.
      e845ca2f
    • Jeremy Morse's avatar
      [DebugInfo][InstrRef] Use PHI placement utilities for machine locations · a3936a6c
      Jeremy Morse authored
      InstrRefBasedLDV used to try and determine which values are in which
      registers using a lattice approach; however this is hard to understand, and
      broken in various ways. This patch replaces that approach with a standard
      SSA approach using existing LLVM utilities. PHIs are placed at dominance
      frontiers; value propagation then eliminates un-necessary PHIs.
      
      This patch also adds a bunch of unit tests that should cover many of the
      weirder forms of control flow.
      
      Differential Revision: https://reviews.llvm.org/D110173
      a3936a6c
  3. Oct 12, 2021
  4. Oct 07, 2021
    • Jack Andersen's avatar
      [MachineInstr] Move MIParser's DBG_VALUE RegState::Debug invariant into MachineInstr::addOperand · bd4dad87
      Jack Andersen authored
      Based on the reasoning of D53903, register operands of DBG_VALUE are
      invariably treated as RegState::Debug operands. This change enforces
      this invariant as part of MachineInstr::addOperand so that all passes
      emit this flag consistently.
      
      RegState::Debug is inconsistently set on DBG_VALUE registers throughout
      LLVM. This runs the risk of a filtering iterator like
      MachineRegisterInfo::reg_nodbg_iterator to process these operands
      erroneously when not parsed from MIR sources.
      
      This issue was observed in the development of the llvm-mos fork which
      adds a backend that relies on physical register operands much more than
      existing targets. Physical RegUnit 0 has the same numeric encoding as
      $noreg (indicating an undef for DBG_VALUE). Allowing debug operands into
      the machine scheduler correlates $noreg with RegUnit 0 (i.e. a collision
      of register numbers with different zero semantics). Eventually, this
      causes an assert where DBG_VALUE instructions are prohibited from
      participating in live register ranges.
      
      Reviewed By: MatzeB, StephenTozer
      
      Differential Revision: https://reviews.llvm.org/D110105
      bd4dad87
  5. Oct 05, 2021
    • Jeremy Morse's avatar
      [DebugInfo][InstrRef] Track all of DBG_PHIs operands · e265644b
      Jeremy Morse authored
      An important part of the instruction referencing solution is that we
      identify all the registers that values move between before we then compute
      an SSA-like function from the machine code, and from the variable
      intrinsics. DBG_PHIs weren't causing all the subregisters of their operands
      to be tracked; this patch forces that to happen.
      
      The practical implications were that not enough space is allocated for
      storing values when analysing the function -- asan will crash on the
      attached test case with an unpatched compiler. Non-asan llc's will produce
      a DBG_VALUE $noreg, where it should be $dil.
      
      Differential Revision: https://reviews.llvm.org/D109064
      e265644b
  6. Oct 01, 2021
    • Marcelo Juchem's avatar
      Fix ambiguous overload build failure · dfb213c2
      Marcelo Juchem authored
      LLVM (llvmorg-14-init) under Debian sid using latest gcc (Debian
      10.3.0-9) 10.3.0 fails due to ambiguous overload on operators == and !=:
      
      /root/src/llvm/src/llvm/tools/obj2yaml/elf2yaml.cpp:212:22:
      error: ambiguous overload for 'operator!='
      (operand types are 'llvm::ELFYAML::ELF_SHF' and 'int')
      
      /root/src/llvm/src/llvm/tools/obj2yaml/elf2yaml.cpp:204:32:
      error: ambiguous overload for 'operator!='
      (operand types are 'const llvm::yaml::Hex64' and 'int')
      
      /root/src/llvm/src/llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp:629:35:
      error: ambiguous overload for 'operator=='
      (operand types are 'const uint64_t' {aka 'const long unsigned int'} and
      'llvm::Register')
      
      Reviewed by: StephenTozer, jmorse, Higuoxing
      
      Differential Revision: https://reviews.llvm.org/D109534
      dfb213c2
  7. Sep 17, 2021
  8. Sep 08, 2021
  9. Aug 30, 2021
    • Djordje Todorovic's avatar
      [LiveDebugValues] Cleanup Transfers when removing Entry Value · 86f5288e
      Djordje Todorovic authored
      If we encounter a new debug value, describing the same parameter,
      we should stop tracking the parameter's Entry Value. At that point,
      in some cases, the Transfer which uses the parameter's Entry Value,
      is already emitted. Thanks to the RemoveRedundantDebugValues pass,
      many problems with incorrect instruction order and number of DBG_VALUEs
      are fixed. However, we still cannot rely on the rule that each new
      debug value is set by the previous non-debug instruction in Machine
      Basic Block.
      
      When new parameter debug value triggers removal of Backup Entry Value
      for the same parameter, do the cleanup of Transfers emitted from Backup
      Entry Values. Get the Transfer Instruction which created the new debug
      value and search for debug values already emitted from the to-be-deleted
      Backup Entry Value and attached to the Transfer Instruction. If found,
      delete the Transfer and remove "primary" Entry Value Var Loc from
      OpenRanges.
      
      This patch fixes PR47628.
      
      Patch by Nikola Tesic.
      
      Differential revision: https://reviews.llvm.org/D106856
      86f5288e
  10. Aug 25, 2021
    • Jeremy Morse's avatar
      [DebugInfo][InstrRef] Don't use instr-ref for unoptimised functions · 0116ed00
      Jeremy Morse authored
      InstrRefBasedLDV is marginally slower than VarlocBasedLDV when analysing
      optimised code -- however, it's much slower when analysing code compiled
      -O0.
      
      To avoid this: don't use instruction referencing for -O0 functions. In the
      "pure" case of unoptimised code, this won't really harm the debugging
      experience because most variables won't have been promoted off the stack,
      so can't go missing. It becomes more complicated when optimised code is
      inlined into functions marked optnone; however these are rare, and as -O0
      doesn't run many optimisations there should be little damage to the debug
      experience as a result.
      
      I've taken the opportunity to refactor testing for instruction-referencing
      into a MachineFunction method, which seems the most appropriate place to
      put it.
      
      Differential Revision: https://reviews.llvm.org/D108585
      0116ed00
  11. Aug 20, 2021
    • Jeremy Morse's avatar
      [DebugInfo][InstrRef] Correctly ignore DBG_VALUE_LIST in InstrRef mode · ce8254d0
      Jeremy Morse authored
      This patch makes InstrRefBasedLDV "safe" to work with DBG_VALUE_LISTs. It
      doesn't actually interpret them, but it recognises that they specify
      variable locations and avoids propagating false locations, which is better
      than the current state. Observe the attached tes
      
       * We avoid propagating DBG_VALUE_LISTs into successor blocks, as they're
         not "currently" supported,
       * We don't propagate other variable locations across DBG_VALUE_LISTs,
         because we know that the variable location is terminated by the
         DBG_VALUE_LIST.
      
      Differential Revision: https://reviews.llvm.org/D108143
      ce8254d0
    • Jeremy Morse's avatar
      [DebugInfo][InstrRef] Remove a faulty assertion · c76c24e4
      Jeremy Morse authored
      This patch removes an assertion, and adds a regression test showing why the
      assertion is broken.
      
      For context, LocIdx is a key/index number for machine locations, so that we
      can describe locations as a single integer and ignore whether they're on
      the stack, in registers or otherwise. Back when InstrRefBasedLDV was added,
      I happened to bake in a "special" zero number for various reasons, which
      Vedant identified as undesirable in this review comment:
      https://reviews.llvm.org/D83047#inline-765495 . I subsequently removed that
      special zero number, but it looks like I didn't delete this assertion at
      the time, which assumes that a zero LocIdx is invalid.
      
      The attached test shows that this assertion is reachable on valid code --
      on x86 $rsp always gets the LocIdx number zero, and if you transfer a
      variable value into it, InstrRefBasedLDV crashes on that assertion. The
      code might be a bit wild to be storing variables to $rsp like that, however
      we shouldn't crash on it.
      
      Differential Revision: https://reviews.llvm.org/D108134
      c76c24e4
  12. Aug 17, 2021
    • Jeremy Morse's avatar
      [DebugInfo][InstrRef] Honour too-much-debug-info cutouts · 708cbda5
      Jeremy Morse authored
      This reapplies 54a61c94, its follow up in 547b7125, which were
      reverted 95fe61e6. Original commit message:
      
      VarLoc based LiveDebugValues will abandon variable location propagation if
      there are too many blocks and variable assignments in the function. If it
      didn't, and we had (say) 1000 blocks and 1000 variables in scope, we'd end
      up with 1 million DBG_VALUEs just at the start of blocks.
      
      Instruction-referencing LiveDebugValues should honour this limitation too
      (because the same limitation applies to it). Hoist the relevant command
      line options into LiveDebugValues.cpp and pass it down into the
      implementation classes as an argument to ExtendRanges. I've duplicated all
      the run-lines in live-debug-values-cutoffs.mir to have an
      instruction-referencing flavour.
      
      Differential Revision: https://reviews.llvm.org/D107823
      708cbda5
  13. Aug 16, 2021
  14. Jul 09, 2021
    • Jeremy Morse's avatar
      [X86] Return src/dest register from stack spill/restore recogniser · 30cce54d
      Jeremy Morse authored
      LLVM provides target hooks to recognise stack spill and restore
      instructions, such as isLoadFromStackSlot, and it also provides post frame
      elimination versions such as isLoadFromStackSlotPostFE. These are supposed
      to return the store-source and load-destination registers; unfortunately on
      X86, the PostFE recognisers just return "1", apparently to signify "yes
      it's a spill/load". This patch alters the hooks to correctly return the
      store-source and load-destination registers:
      
      This is really useful for debug-info as we it helps follow variable values
      as they move on/off the stack. There should be no codegen changes: the only
      other users of these PostFE target hooks are MachineInstr::getRestoreSize
      and MachineInstr::getSpillSize, which don't attempt to interpret the
      returned register location.
      
      While we're here, delete the (InstrRef) LiveDebugValues heuristic that
      tries to find the spill source register by looking for a killed reg -- we
      should be able to rely on the target hooks for that. This involves
      temporarily turning off a n InstrRef LivedDebugValues test on aarch64
      (patch to re-enable it is in D104521).
      
      Differential Revision: https://reviews.llvm.org/D105428
      30cce54d
    • Jeremy Morse's avatar
      [Debug-info][InstrRef] Avoid an unnecessary map ordering · f551fb96
      Jeremy Morse authored
      We keep a record of substitutions between debug value numbers post-isel,
      however we never actually look them up until the end of compilation. As a
      result, there's nothing gained by the collection being a std::map. This
      patch downgrades it to being a vector, that's then sorted at the end of
      compilation in LiveDebugValues.
      
      Differential Revision: https://reviews.llvm.org/D105029
      f551fb96
  15. Jul 01, 2021
    • Jeremy Morse's avatar
      [DebugInfo][InstrRef][2/4] Use subreg substitutions in LiveDebugValues · e9641c91
      Jeremy Morse authored
      Added in 47c3fe2a, we sometimes need to describe a variable value
      substitution with a subregister qualifier, to say that "the value is the
      lower 32 bits of this 64 bit register def" for example. That then needs
      support during LiveDebugValues to interpret the subregister qualifiers,
      which is what this patch adds.
      
      Whenever we encounter a DBG_INSTR_REF and find its value by using a
      substitution, collect any subregister qualifiers seen. Then, accumulate the
      effects of the qualifiers to work out what offset and what size should be
      extracted from the defined register. Finally, for the target ValueIDNum,
      extract whatever subregister is in the correct position
      
      Currently, describing a subregister field of a larger value that has been
      spilt to the stack, is unimplemented.
      
      Differential Revision: https://reviews.llvm.org/D88894
      e9641c91
    • Jeremy Morse's avatar
      [DebugInfo][InstrRef][1/4] Support transformations that widen values · 47c3fe2a
      Jeremy Morse authored
      Very late in compilation, backends like X86 will perform optimisations like
      this:
      
          $cx = MOV16rm $rax, ...
          ->
          $rcx = MOV64rm $rax, ...
      
      Widening the load from 16 bits to 64 bits. SEeing how the lower 16 bits
      remain the same, this doesn't affect execution. However, any debug
      instruction reference to the defined operand now refers to a 64 bit value,
      nto a 16 bit one, which might be unexpected. Elsewhere in codegen, there's
      often this pattern:
      
          CALL64pcrel32 @foo, implicit-def $rax
          %0:gr64 = COPY $rax
          %1:gr32 = COPY %0.sub_32bit
      
      Where we want to refer to the definition of $eax by the call, but don't
      want to refer the copies (they don't define values in the way
      LiveDebugValues sees it). To solve this, add a subregister field to the
      existing "substitutions" facility, so that we can describe a field within
      a larger value definition. I would imagine that this would be used most
      often when a value is widened, and we need to refer to the original,
      narrower definition.
      
      Differential Revision: https://reviews.llvm.org/D88891
      47c3fe2a
    • Jeremy Morse's avatar
      [LiveDebugValues][InstrRef][2/2] Emit entry value variable locations · 1575583f
      Jeremy Morse authored
      This patch adds support to the instruction-referencing LiveDebugValues
      implementation for emitting entry values. The instruction referencing
      implementations tracking by value rather than location means that we can
      get around two of the issues with VarLocs. DBG_VALUE instructions that
      re-assign the same value to a variable are no longer a problem, because we
      can "see through" to the value being assigned. We also don't need to do
      anything special during the dataflow stages: the "variable value problem"
      doesn't need to know whether a value is available most of the time, and the
      times it deoes need to know are always when entry values need to be
      terminated.
      
      The patch modifies the "TransferTracker" class, adding methods to identify
      when a variable ias an entry value candidate, and when a machine value is
      an entry value. recoverAsEntryValue tests these two things and emits an
      entry-value expression if they're true. It's used when we clobber or
      otherwise lose a value and can't find a replacement location for the value
      it contained.
      
      Differential Revision: https://reviews.llvm.org/D88406
      1575583f
  16. Jun 30, 2021
  17. Jun 29, 2021
    • Jeremy Morse's avatar
      Catch an extremely obvious memory leak, thanks asan · e63b18bc
      Jeremy Morse authored
      https://lab.llvm.org/buildbot/#/builders/5/builds/9208
      
      (dbg-phis-merging-in-ldv.mir and dbg-phis-with-loops.mir in the asan
       check stage)
      e63b18bc
    • Jeremy Morse's avatar
      [DebugInstrRef][3/3] Follow DBG_PHI instructions through LiveDebugValues · 010108bb
      Jeremy Morse authored
      This patch reads machine value numbers from DBG_PHI instructions (marking
      where SSA PHIs used to be), and matches them up with DBG_INSTR_REF
      instructions that refer to them. Essentially they are two separate parts of
      a DBG_VALUE: the place to read the value (register and program position),
      and where the variable is assigned that value.
      
      Sometimes these DBG_PHIs can be duplicated, usually by tail duplication.
      This corresponds to the SSA structure of the program being destroyed, and
      the original PHI being split. When this happens: run LLVMs standard
      SSAUpdater utility, to work out what values should appear in which blocks.
      The majority of this patch is boilerplate to make use of SSAUpdater.
      
      If there are any additional PHIs on the path between multiple DBG_PHIs and
      their using DBG_INSTR_REF, their existance is validated, just in case a
      value gets clobbered along the way (see dbg-phis-with-loops.mir for
      several examples).
      
      Differential Revision: https://reviews.llvm.org/D86814
      010108bb
  18. Jun 19, 2021
  19. Apr 28, 2021
  20. Mar 09, 2021
    • gbtozers's avatar
      [DebugInfo] Process DBG_VALUE_LIST in LiveDebugValues · e2196ddc
      gbtozers authored
      This patch implements DBG_VALUE_LIST handling to the LiveDebugValues pass. This
      is a substantial change, and makes a few fundamental changes to the existing
      logic.
      
      We still use the basic model of a VarLocMap that is indexed by a LocIndex, with
      a VarLocSet (a CoalescingBitVector underneath) giving us efficient lookups of
      existing variable locations for a given location type. The main change is that
      the VarLocMap may contain a given VarLoc multiple times (once for each unique
      location operand), so that a VarLoc can be looked up from any of the registers
      that it uses. This means that each VarLoc has multiple corresponding LocIndexes;
      to allow us to iterate through the set of VarLocs (previously we would iterate
      through the VarLocSet), we now also maintain a single entry in the VarLocMap
      that contains every VarLoc exactly once.
      
      The VarLoc class itself is also changed; this change is much simpler,
      refactoring out location-specific members into a MachineLocation class and
      adding a vector of these locations.
      
      Differential Revision: https://reviews.llvm.org/D83890
      e2196ddc
  21. Feb 14, 2021
  22. Jan 30, 2021
  23. Jan 29, 2021
  24. Jan 28, 2021
  25. Jan 15, 2021
  26. Jan 12, 2021
  27. Jan 06, 2021
  28. Dec 19, 2020
  29. Dec 11, 2020
Loading