]> granicus.if.org Git - clang/commitdiff
[OpenMP] Make default parallel for schedule in NVPTX target regions in SPMD mode...
authorGheorghe-Teodor Bercea <gheorghe-teod.bercea@ibm.com>
Thu, 27 Sep 2018 20:29:00 +0000 (20:29 +0000)
committerGheorghe-Teodor Bercea <gheorghe-teod.bercea@ibm.com>
Thu, 27 Sep 2018 20:29:00 +0000 (20:29 +0000)
Summary: Set default schedule for parallel for loops to schedule(static, 1) when using SPMD mode on the NVPTX device offloading toolchain to ensure coalescing.

Reviewers: ABataev, Hahnfeld, caomhin

Reviewed By: ABataev

Subscribers: jholewinski, guansong, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@343260 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGOpenMPRuntime.h
lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
lib/CodeGen/CGOpenMPRuntimeNVPTX.h
lib/CodeGen/CGStmtOpenMP.cpp
test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp

index 982aeb3cf7ae1dad36fd1d5ee33b25496bbc3cbb..35f75a9ec0861654d82e561321e719733b630a80 100644 (file)
@@ -1496,6 +1496,12 @@ public:
       const OMPLoopDirective &S, OpenMPDistScheduleClauseKind &ScheduleKind,
       llvm::Value *&Chunk) const {}
 
+  /// Choose default schedule type and chunk value for the
+  /// schedule clause.
+  virtual void getDefaultScheduleAndChunk(CodeGenFunction &CGF,
+      const OMPLoopDirective &S, OpenMPScheduleClauseKind &ScheduleKind,
+      llvm::Value *&Chunk) const {}
+
   /// Emits call of the outlined function with the provided arguments,
   /// translating these arguments to correct target-specific arguments.
   virtual void
index 56b244d0ae8802c090fb0c7999d26f8f3ba5faaf..14fd4a3113b9cb0d877692198ed73154bfa3214c 100644 (file)
@@ -4093,3 +4093,14 @@ void CGOpenMPRuntimeNVPTX::getDefaultDistScheduleAndChunk(
         S.getIterationVariable()->getType(), S.getBeginLoc());
   }
 }
+
+void CGOpenMPRuntimeNVPTX::getDefaultScheduleAndChunk(
+    CodeGenFunction &CGF, const OMPLoopDirective &S,
+    OpenMPScheduleClauseKind &ScheduleKind,
+    llvm::Value *&Chunk) const {
+  if (getExecutionMode() == CGOpenMPRuntimeNVPTX::EM_SPMD) {
+    ScheduleKind = OMPC_SCHEDULE_static;
+    Chunk = CGF.Builder.getIntN(CGF.getContext().getTypeSize(
+        S.getIterationVariable()->getType()), 1);
+  }
+}
index 76343dfc7f5a9e28bb21fe5d1a8110d591a9c490..fc8cd2467bf255908fc301bb145c19f7f5958800 100644 (file)
@@ -340,11 +340,16 @@ public:
   ///
   void functionFinished(CodeGenFunction &CGF) override;
 
-  /// Choose a default value for the schedule clause.
+  /// Choose a default value for the dist_schedule clause.
   void getDefaultDistScheduleAndChunk(CodeGenFunction &CGF,
       const OMPLoopDirective &S, OpenMPDistScheduleClauseKind &ScheduleKind,
       llvm::Value *&Chunk) const override;
 
+  /// Choose a default value for the schedule clause.
+  void getDefaultScheduleAndChunk(CodeGenFunction &CGF,
+      const OMPLoopDirective &S, OpenMPScheduleClauseKind &ScheduleKind,
+      llvm::Value *&Chunk) const override;
+
 private:
   /// Track the execution mode when codegening directives within a target
   /// region. The appropriate mode (SPMD/NON-SPMD) is set on entry to the
index 4bafb8ba9fc9c51b6afe7db666923b1e5473832b..79ffa7c8e9410435eaae62a309248eae30936ef7 100644 (file)
@@ -2310,6 +2310,10 @@ bool CodeGenFunction::EmitOMPWorksharingLoop(
                                        S.getIterationVariable()->getType(),
                                        S.getBeginLoc());
         }
+      } else {
+        // Default behaviour for schedule clause.
+        CGM.getOpenMPRuntime().getDefaultScheduleAndChunk(
+            *this, S, ScheduleKind.Schedule, Chunk);
       }
       const unsigned IVSize = getContext().getTypeSize(IVExpr->getType());
       const bool IVSigned = IVExpr->getType()->hasSignedIntegerRepresentation();
index 19993351198f83169fde2c1a97688114a9ecf4a8..6539b0e3c96d7f190a3b76389ee1d0193924fd3b 100644 (file)
@@ -94,7 +94,7 @@ int bar(int n){
 // CHECK: ret void
 
 // CHECK: define internal void [[OUTL2]](
-// CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 34,
+// CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 33,
 // CHECK: call void @__kmpc_for_static_fini(
 // CHECK: ret void
 
@@ -108,7 +108,7 @@ int bar(int n){
 // CHECK: ret void
 
 // CHECK: define internal void [[OUTL3]](
-// CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 34,
+// CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 33,
 // CHECK: call void @__kmpc_for_static_fini(
 // CHECK: ret void
 
@@ -124,7 +124,7 @@ int bar(int n){
 // CHECK: ret void
 
 // CHECK: define internal void [[OUTL4]](
-// CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 34,
+// CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 33,
 // CHECK: call void @__kmpc_for_static_fini(
 // CHECK: ret void
 
index 92436c40f46832e04f695a1ca1119dba602442b4..5f7c071140cd1d2ef504be8315d76858aa31b3b8 100644 (file)
@@ -89,7 +89,7 @@ int bar(int n){
 // CHECK: ret void
 
 // CHECK: define internal void [[OUTL2]](
-// CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 34,
+// CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 33,
 // CHECK: call void @__kmpc_for_static_fini(
 // CHECK: ret void
 
@@ -103,7 +103,7 @@ int bar(int n){
 // CHECK: ret void
 
 // CHECK: define internal void [[OUTL3]](
-// CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 34,
+// CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 33,
 // CHECK: call void @__kmpc_for_static_fini(
 // CHECK: ret void
 
@@ -119,7 +119,7 @@ int bar(int n){
 // CHECK: ret void
 
 // CHECK: define internal void [[OUTL4]](
-// CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 34,
+// CHECK: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, {{.+}} 33,
 // CHECK: call void @__kmpc_for_static_fini(
 // CHECK: ret void