[all-commits] [llvm/llvm-project] 1d1de7: [Assignment Tracking][Analysis] Add analysis pass

Orlando Cazalet-Hyams via All-commits all-commits at lists.llvm.org
Fri Dec 9 08:18:45 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 1d1de7467c32d52926ca56b9167a2c65c451ecfa
      https://github.com/llvm/llvm-project/commit/1d1de7467c32d52926ca56b9167a2c65c451ecfa
  Author: OCHyams <orlando.hyams at sony.com>
  Date:   2022-12-09 (Fri, 09 Dec 2022)

  Changed paths:
    A llvm/include/llvm/CodeGen/AssignmentTrackingAnalysis.h
    M llvm/include/llvm/CodeGen/SelectionDAG.h
    M llvm/include/llvm/InitializePasses.h
    A llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
    M llvm/lib/CodeGen/CMakeLists.txt
    M llvm/lib/CodeGen/CodeGen.cpp
    M llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
    M llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
    M llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
    M llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
    A llvm/test/DebugInfo/assignment-tracking/X86/DSE.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/dbg-phi-produces-undef.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/diamond-1.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/diamond-2.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/diamond-3.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/lit.local.cfg
    A llvm/test/DebugInfo/assignment-tracking/X86/loop-hoist.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/loop-sink.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/loop-unroll.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/lower-offset-expression.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/lower-to-value.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/mem-loc-frag-fill-cfg.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/mem-loc-frag-fill.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/nested-loop-frags.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/nested-loop-sroa.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/nested-loop.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/no-redundant-def-after-alloca.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/order-of-defs.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/remove-redundant-defs-to-prevent-reordering.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/remove-undef-fragment.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/sdag-dangling-dbgassign.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/sdag-ir-salvage-assign.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/sdag-transfer-dbgassign.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/single-memory-location-2.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/single-memory-location.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/split-alloca.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/untagged-store-frag.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/use-known-value-at-early-mem-def-2.ll
    A llvm/test/DebugInfo/assignment-tracking/X86/use-known-value-at-early-mem-def.ll

  Log Message:
  -----------
  [Assignment Tracking][Analysis] Add analysis pass

The Assignment Tracking debug-info feature is outlined in this RFC:

https://discourse.llvm.org/t/
rfc-assignment-tracking-a-better-way-of-specifying-variable-locations-in-ir

Add initial revision of assignment tracking analysis pass
---------------------------------------------------------
This patch squashes five individually reviewed patches into one:

    #1 https://reviews.llvm.org/D136320
    #2 https://reviews.llvm.org/D136321
    #3 https://reviews.llvm.org/D136325
    #4 https://reviews.llvm.org/D136331
    #5 https://reviews.llvm.org/D136335

Patch #1 introduces 2 new files: AssignmentTrackingAnalysis.h and .cpp. The
two subsequent patches modify those files only. Patch #4 plumbs the analysis
into SelectionDAG, and patch #5 is a collection of tests for the analysis as
a whole.

The analysis was broken up into smaller chunks for review purposes but for the
most part the tests were written using the whole analysis. It would be possible
to break up the tests for patches #1 through #3 for the purpose of landing the
patches seperately. However, most them would require an update for each
patch. In addition, patch #4 - which connects the analysis to SelectionDAG - is
required by all of the tests.

If there is build-bot trouble, we might try a different landing sequence.

Analysis problem and goal
-------------------------

Variables values can be stored in memory, or available as SSA values, or both.
Using the Assignment Tracking metadata, it's not possible to determine a
variable location just by looking at a debug intrinsic in
isolation. Instructions without any metadata can change the location of a
variable. The meaning of dbg.assign intrinsics changes depending on whether
there are linked instructions, and where they are relative to those
instructions. So we need to analyse the IR and convert the embedded information
into a form that SelectionDAG can consume to produce debug variable locations
in MIR.

The solution is a dataflow analysis which, aiming to maximise the memory
location coverage for variables, outputs a mapping of instruction positions to
variable location definitions.

API usage
---------

The analysis is named `AssignmentTrackingAnalysis`. It is added as a required
pass for SelectionDAGISel when assignment tracking is enabled.

The results of the analysis are exposed via `getResults` using the returned
`const FunctionVarLocs *`'s const methods:

    const VarLocInfo *single_locs_begin() const;
    const VarLocInfo *single_locs_end() const;
    const VarLocInfo *locs_begin(const Instruction *Before) const;
    const VarLocInfo *locs_end(const Instruction *Before) const;
    void print(raw_ostream &OS, const Function &Fn) const;

Debug intrinsics can be ignored after running the analysis. Instead, variable
location definitions that occur between an instruction `Inst` and its
predecessor (or block start) can be found by looping over the range:

    locs_begin(Inst), locs_end(Inst)

Similarly, variables with a memory location that is valid for their lifetime
can be iterated over using the range:

    single_locs_begin(), single_locs_end()

Further detail
--------------

For an explanation of the dataflow implementation and the integration with
SelectionDAG, please see the reviews linked at the top of this commit message.

Reviewed By: jmorse




More information about the All-commits mailing list