Browse Source

[OpenCL] Generate 'unroll.enable' metadata for __attribute__((opencl_unroll_hint))

Summary:
[OpenCL] Generate 'unroll.enable' metadata for  __attribute__((opencl_unroll_hint))
    
For both !{!"llvm.loop.unroll.enable"} and !{!"llvm.loop.unroll.full"} the unroller
will try to fully unroll a loop unless the trip count is not known at compile time.
In that case for '.full' metadata no unrolling will be processed, while for '.enable'
the loop will be partially unrolled with a heuristically chosen unroll factor.
    
See: docs/LanguageExtensions.rst
    
From https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/attributes-loopUnroll.html

    __attribute__((opencl_unroll_hint))
    for (int i=0; i<2; i++)
    {
        ...
    }
    
In the example above, the compiler will determine how much to unroll the loop.

    
Before the patch for  __attribute__((opencl_unroll_hint)) was generated metadata
!{!"llvm.loop.unroll.full"}, which limits ability of loop unroller to decide, how
much to unroll the loop.

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Subscribers: zzheng, dmgreen, jdoerfert, cfe-commits, asavonic, AlexeySotkin

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59493

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356571 91177308-0d34-0410-b5e6-96231b3b80d8
Andrew Savonichev 6 years ago
parent
commit
a5df1086a2
2 changed files with 15 additions and 15 deletions
  1. 2 2
      lib/CodeGen/CGLoopInfo.cpp
  2. 13 13
      test/CodeGenOpenCL/unroll-hint.cl

+ 2 - 2
lib/CodeGen/CGLoopInfo.cpp

@@ -208,13 +208,13 @@ void LoopInfoStack::push(BasicBlock *Header, clang::ASTContext &Ctx,
     // Translate opencl_unroll_hint attribute argument to
     // Translate opencl_unroll_hint attribute argument to
     // equivalent LoopHintAttr enums.
     // equivalent LoopHintAttr enums.
     // OpenCL v2.0 s6.11.5:
     // OpenCL v2.0 s6.11.5:
-    // 0 - full unroll (no argument).
+    // 0 - enable unroll (no argument).
     // 1 - disable unroll.
     // 1 - disable unroll.
     // other positive integer n - unroll by n.
     // other positive integer n - unroll by n.
     if (OpenCLHint) {
     if (OpenCLHint) {
       ValueInt = OpenCLHint->getUnrollHint();
       ValueInt = OpenCLHint->getUnrollHint();
       if (ValueInt == 0) {
       if (ValueInt == 0) {
-        State = LoopHintAttr::Full;
+        State = LoopHintAttr::Enable;
       } else if (ValueInt != 1) {
       } else if (ValueInt != 1) {
         Option = LoopHintAttr::UnrollCount;
         Option = LoopHintAttr::UnrollCount;
         State = LoopHintAttr::Numeric;
         State = LoopHintAttr::Numeric;

+ 13 - 13
test/CodeGenOpenCL/unroll-hint.cl

@@ -18,12 +18,12 @@ void for_disable()
 // CHECK: br label %{{.*}}, !llvm.loop ![[FOR_DISABLE:.*]]
 // CHECK: br label %{{.*}}, !llvm.loop ![[FOR_DISABLE:.*]]
 }
 }
 
 
-void for_full()
+void for_enable()
 {
 {
-// CHECK-LABEL: for_full
+// CHECK-LABEL: for_enable
     __attribute__((opencl_unroll_hint))
     __attribute__((opencl_unroll_hint))
     for( int i = 0; i < 1000; ++i);
     for( int i = 0; i < 1000; ++i);
-// CHECK: br label %{{.*}}, !llvm.loop ![[FOR_FULL:.*]]
+// CHECK: br label %{{.*}}, !llvm.loop ![[FOR_ENABLE:.*]]
 }
 }
 
 
 /*** while ***/
 /*** while ***/
@@ -45,13 +45,13 @@ void while_disable()
 // CHECK: br label %{{.*}}, !llvm.loop ![[WHILE_DISABLE:.*]]
 // CHECK: br label %{{.*}}, !llvm.loop ![[WHILE_DISABLE:.*]]
 }
 }
 
 
-void while_full()
+void while_enable()
 {
 {
-// CHECK-LABEL: while_full
+// CHECK-LABEL: while_enable
     int i = 1000;
     int i = 1000;
     __attribute__((opencl_unroll_hint))
     __attribute__((opencl_unroll_hint))
     while(i-->0);
     while(i-->0);
-// CHECK: br label %{{.*}}, !llvm.loop ![[WHILE_FULL:.*]]
+// CHECK: br label %{{.*}}, !llvm.loop ![[WHILE_ENABLE:.*]]
 }
 }
 
 
 /*** do ***/
 /*** do ***/
@@ -73,13 +73,13 @@ void do_disable()
 // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !llvm.loop ![[DO_DISABLE:.*]]
 // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !llvm.loop ![[DO_DISABLE:.*]]
 }
 }
 
 
-void do_full()
+void do_enable()
 {
 {
-// CHECK-LABEL: do_full
+// CHECK-LABEL: do_enable
     int i = 1000;
     int i = 1000;
     __attribute__((opencl_unroll_hint))
     __attribute__((opencl_unroll_hint))
     do {} while(i--> 0);
     do {} while(i--> 0);
-// CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !llvm.loop ![[DO_FULL:.*]]
+// CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !llvm.loop ![[DO_ENABLE:.*]]
 }
 }
 
 
 
 
@@ -87,11 +87,11 @@ void do_full()
 // CHECK: ![[COUNT]]         =  !{!"llvm.loop.unroll.count", i32 8}
 // CHECK: ![[COUNT]]         =  !{!"llvm.loop.unroll.count", i32 8}
 // CHECK: ![[FOR_DISABLE]]   =  distinct !{![[FOR_DISABLE]],  ![[DISABLE:.*]]}
 // CHECK: ![[FOR_DISABLE]]   =  distinct !{![[FOR_DISABLE]],  ![[DISABLE:.*]]}
 // CHECK: ![[DISABLE]]       =  !{!"llvm.loop.unroll.disable"}
 // CHECK: ![[DISABLE]]       =  !{!"llvm.loop.unroll.disable"}
-// CHECK: ![[FOR_FULL]]      =  distinct !{![[FOR_FULL]],  ![[FULL:.*]]}
-// CHECK: ![[FULL]]          =  !{!"llvm.loop.unroll.full"}
+// CHECK: ![[FOR_ENABLE]]      =  distinct !{![[FOR_ENABLE]],  ![[ENABLE:.*]]}
+// CHECK: ![[ENABLE]]          =  !{!"llvm.loop.unroll.enable"}
 // CHECK: ![[WHILE_COUNT]]   =  distinct !{![[WHILE_COUNT]],    ![[COUNT]]}
 // CHECK: ![[WHILE_COUNT]]   =  distinct !{![[WHILE_COUNT]],    ![[COUNT]]}
 // CHECK: ![[WHILE_DISABLE]] =  distinct !{![[WHILE_DISABLE]],  ![[DISABLE]]}
 // CHECK: ![[WHILE_DISABLE]] =  distinct !{![[WHILE_DISABLE]],  ![[DISABLE]]}
-// CHECK: ![[WHILE_FULL]]    =  distinct !{![[WHILE_FULL]],     ![[FULL]]}
+// CHECK: ![[WHILE_ENABLE]]    =  distinct !{![[WHILE_ENABLE]],     ![[ENABLE]]}
 // CHECK: ![[DO_COUNT]]      =  distinct !{![[DO_COUNT]],       ![[COUNT]]}
 // CHECK: ![[DO_COUNT]]      =  distinct !{![[DO_COUNT]],       ![[COUNT]]}
 // CHECK: ![[DO_DISABLE]]    =  distinct !{![[DO_DISABLE]],     ![[DISABLE]]}
 // CHECK: ![[DO_DISABLE]]    =  distinct !{![[DO_DISABLE]],     ![[DISABLE]]}
-// CHECK: ![[DO_FULL]]       =  distinct !{![[DO_FULL]],        ![[FULL]]}
+// CHECK: ![[DO_ENABLE]]       =  distinct !{![[DO_ENABLE]],        ![[ENABLE]]}