Author: meinersbur
Date: Wed Dec 12 09:32:52 2018
New Revision: 348944

URL: http://llvm.org/viewvc/llvm-project?rev=348944&view=rev
Log:
[Unroll/UnrollAndJam/Vectorizer/Distribute] Add followup loop attributes.

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.

Since this changes the user-visible diagnostic message when a transformation is 
applied, two test cases in the clang repository need to be updated.

To ensure that no other transformation is executed before the intended one, the 
attribute `llvm.loop.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).

Reviewed By: hfinkel, dmgreen

Differential Revision: https://reviews.llvm.org/D49281
Differential Revision: https://reviews.llvm.org/D55288

Modified:
    cfe/trunk/test/Misc/backend-optimization-failure-nodbg.cpp
    cfe/trunk/test/Misc/backend-optimization-failure.cpp

Modified: cfe/trunk/test/Misc/backend-optimization-failure-nodbg.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/backend-optimization-failure-nodbg.cpp?rev=348944&r1=348943&r2=348944&view=diff
==============================================================================
--- cfe/trunk/test/Misc/backend-optimization-failure-nodbg.cpp (original)
+++ cfe/trunk/test/Misc/backend-optimization-failure-nodbg.cpp Wed Dec 12 
09:32:52 2018
@@ -4,7 +4,7 @@
 // Test verifies optimization failures generated by the backend are handled
 // correctly by clang. LLVM tests verify all of the failure conditions.
 
-void test_switch(int *A, int *B, int Length, int J) { /* expected-warning 
{{loop not vectorized: failed explicitly specified loop vectorization}} */
+void test_switch(int *A, int *B, int Length, int J) { /* expected-warning 
{{loop not vectorized: the optimizer was unable to perform the requested 
transformation; the transformation might be disabled or specified as part of an 
unsupported transformation ordering}} */
 #pragma clang loop vectorize(enable) unroll(disable)
   for (int i = 0; i < Length; i++) {
     switch (A[i]) {

Modified: cfe/trunk/test/Misc/backend-optimization-failure.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/backend-optimization-failure.cpp?rev=348944&r1=348943&r2=348944&view=diff
==============================================================================
--- cfe/trunk/test/Misc/backend-optimization-failure.cpp (original)
+++ cfe/trunk/test/Misc/backend-optimization-failure.cpp Wed Dec 12 09:32:52 
2018
@@ -7,7 +7,7 @@
 void test_switch(int *A, int *B, int Length,int J) {
 #pragma clang loop vectorize(enable) unroll(disable)
   for (int i = 0; i < Length; i++) {
-/* expected-warning@-1 {{loop not vectorized: failed explicitly specified loop 
vectorization}} */ switch (A[i]) {
+/* expected-warning@-1 {{loop not vectorized: the optimizer was unable to 
perform the requested transformation; the transformation might be disabled or 
specified as part of an unsupported transformation ordering}} */ switch (A[i]) {
     case 0:
       B[i] = 1;
       break;


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to