[PATCH] D49281: [Unroll/UnrollAndJam/Vectorizer/Distribute] Add followup loop attributes.

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 12 22:15:43 PDT 2018


Meinersbur created this revision.
Meinersbur added reviewers: hfinkel, dmgreen, hsaito, jeffhammond, jingyue, eliben, anemet, Ashutosh, ashutosh.nema, mcrosier, fhahn, hiraditya, meheff.
Herald added subscribers: dexonsmith, steven_wu, zzheng, eraman, mgorny, mehdi_amini.
Herald added a reviewer: bollu.

When multiple loop transformation are defined in a loop's metadata, their order of execution is defined by the order of their respective passes in the pass pipeline. For instance, e.g.

  #pragma clang loop unroll_and_jam(enable)
  #pragma clang loop distribute(enable)

is the same as

  #pragma clang loop distribute(enable)
  #pragma clang loop unroll_and_jam(enable)

and will try to loop-distribute before Unroll-And-Jam because the LoopDistribute pass is scheduled after UnrollAndJam pass. UnrollAndJamPass only supports one inner loop, i.e. it will necessarily fail after loop distribution. It is not possible to specify another execution order. Also,t the order of passes in the pipeline is subject to change between versions of LLVM, optimization options and which pass manager is used.

This patch adds 'followup' attributes to various loop transformation passes. These attributes define which attributes the resulting loop of a transformation should have. For instance,

  !0 = !{!0, !1, !2}
  !1 = !{!"llvm.loop.unroll_and_jam.enable"}
  !2 = !{!"llvm.loop.unroll_and_jam.followup_inner", !3}
  !3 = !{!"llvm.loop.distribute.enable"}

defines a loop ID (!0) to be unrolled-and-jammed (!1) and then the attribute !3 to be added to the jammed inner loop, which contains the instruction to distribute the inner loop.

Currently, in both pass managers, pass execution is in a fixed order and UnrollAndJamPass will not execute again after LoopDistribute. We hope to fix this in the future by allowing pass managers to run passes until a fixpoint is reached, use Polly to perform these transformations, or add a loop transformation pass which takes the order issue into account.

For mandatory/forced transformations (e.g. by having been declared by #pragma omp simd), the user must be notified when a transformation could not be performed. It is not possible that the responsible pass emits such a warning because the transformation might be 'hidden' in a followup attribute when it is executed, or it is not present in the pipeline at all. For this reason, this patche introduces a WarnMissedTransformations pass, to warn about orphaned transformations.

To ensure that no other transformation is executed before the intended one, the attribute `llvm.loop.transformations.disable_nonforced` can be added which should disable transformation heuristics before the intended transformation is applied. E.g. it would be surprising if a loop is distributed before a #pragma unroll_and_jam is applied.

With more supported code transformations (loop fusion, interchange, stripmining, offloading, etc.), transformations can be used as building blocks for more complex transformations (e.g. stripmining+stripmining+interchange -> tiling).

This approach deviates from proposal in the RFC at http://lists.llvm.org/pipermail/llvm-dev/2018-May/123690.html. There are three reasons:

- In the RFC approach, when a pass wants to determine whether it should perform a transformation, it must search the list of transformations for the first transformation on its loop. When inlining, the two transformation list must be combined.
- For compatibility, the current approach using loop IDs must still be supported, either each pass looks up both metadata formats, or using the AutoUpgrade mechanism. This patch's approach keeps the current mechanism.
- The "loop IDs" can change. When a attribute is added/removed from the Loop ID metata (e.g. adding "llvm.loop.isvectorized" after vectorizing), the loop is assigned a new, distrinct MDNode. Every reference to these nodes needs to be updated as well, and metadata nodes do not support RAUW. Some of the current passes (e.g. LoopDistribution) keep the same loop ID for multiple output loops such that the loop ID is not uniquely identifying loops anymore. This patch's approach does not reference loop IDs in the attribute values.


Repository:
  rL LLVM

https://reviews.llvm.org/D49281

Files:
  docs/LangRef.rst
  docs/Passes.rst
  docs/TransformMetadata.rst
  docs/index.rst
  include/llvm/InitializePasses.h
  include/llvm/LinkAllPasses.h
  include/llvm/Transforms/Scalar.h
  include/llvm/Transforms/Scalar/WarnMissedTransforms.h
  include/llvm/Transforms/Utils/LoopUtils.h
  include/llvm/Transforms/Utils/UnrollLoop.h
  include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
  lib/Analysis/LoopInfo.cpp
  lib/Passes/PassBuilder.cpp
  lib/Passes/PassRegistry.def
  lib/Transforms/IPO/PassManagerBuilder.cpp
  lib/Transforms/Scalar/CMakeLists.txt
  lib/Transforms/Scalar/LoopDistribute.cpp
  lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp
  lib/Transforms/Scalar/LoopUnrollPass.cpp
  lib/Transforms/Scalar/LoopVersioningLICM.cpp
  lib/Transforms/Scalar/Scalar.cpp
  lib/Transforms/Scalar/WarnMissedTransforms.cpp
  lib/Transforms/Utils/LoopUnroll.cpp
  lib/Transforms/Utils/LoopUnrollAndJam.cpp
  lib/Transforms/Utils/LoopUnrollRuntime.cpp
  lib/Transforms/Utils/LoopUtils.cpp
  lib/Transforms/Vectorize/LoopVectorize.cpp
  test/Other/new-pm-defaults.ll
  test/Other/new-pm-thinlto-defaults.ll
  test/Other/opt-O2-pipeline.ll
  test/Other/opt-O3-pipeline.ll
  test/Other/opt-Os-pipeline.ll
  test/Transforms/LoopDistribute/disable-heuristic.ll
  test/Transforms/LoopDistribute/followup.ll
  test/Transforms/LoopTransformWarning/distribution-remarks-missed.ll
  test/Transforms/LoopTransformWarning/unrollandjam-remarks-missed.ll
  test/Transforms/LoopTransformWarning/unrolling-remarks-missed.ll
  test/Transforms/LoopTransformWarning/vectorization-remarks-missed.ll
  test/Transforms/LoopUnroll/disable-heuristic.ll
  test/Transforms/LoopUnroll/runtime-loop_transform.ll
  test/Transforms/LoopUnroll/unroll-count_transform.ll
  test/Transforms/LoopUnroll/unroll-pragmas-disabled_transform.ll
  test/Transforms/LoopUnroll/unroll-pragmas_transform.ll
  test/Transforms/LoopUnrollAndJam/disable_heuristic.ll
  test/Transforms/LoopUnrollAndJam/followup-metadata.ll
  test/Transforms/LoopUnrollAndJam/pragma.ll
  test/Transforms/LoopVectorize/X86/already-vectorized_transform.ll
  test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll
  test/Transforms/LoopVectorize/X86/x86_fp80-vector-store_transform.ll
  test/Transforms/LoopVectorize/disable-heuristic.ll
  test/Transforms/LoopVectorize/duplicated-metadata_transform.ll
  test/Transforms/LoopVectorize/followups.ll
  test/Transforms/LoopVectorize/hints-trans_transform.ll
  test/Transforms/LoopVectorize/multiple-strides-vectorization_transform.ll
  test/Transforms/LoopVectorize/no_array_bounds.ll
  test/Transforms/LoopVectorize/no_switch.ll
  test/Transforms/LoopVectorize/vectorize-once_transform.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49281.155318.patch
Type: text/x-patch
Size: 162407 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180713/122599aa/attachment-0001.bin>


More information about the llvm-commits mailing list