[PATCH] D79921: [OPENMP] Fix mixture of omp and clang pragmas

2020-05-21 Thread ISHIGURO, Hiroshi via Phabricator via cfe-commits
hishiguro updated this revision to Diff 265450.
hishiguro added a comment.

Thank you for your comment. I updated source.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79921/new/

https://reviews.llvm.org/D79921

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/omp_with_loop_pragma.c


Index: clang/test/OpenMP/omp_with_loop_pragma.c
===
--- clang/test/OpenMP/omp_with_loop_pragma.c
+++ clang/test/OpenMP/omp_with_loop_pragma.c
@@ -3,12 +3,12 @@
 // expected-no-diagnostics
 
 // CHECK: !{{[0-9]+}} = !{!"llvm.loop.vectorize.width", i32 1}
-void sub(double * restrict a, double * restrict b, int n){ 
+void sub(double *restrict a, double *restrict b, int n) {
   int i;
 
 #pragma omp parallel for
 #pragma clang loop vectorize(disable)
-  for(i=0;i(&S);
-  const CapturedStmt *ICS = OMPED->getInnermostCapturedStmt();
+  const auto &OMPED = cast(S);
+  const CapturedStmt *ICS = OMPED.getInnermostCapturedStmt();
   const Stmt *SS = ICS->getCapturedStmt();
   const AttributedStmt *AS = dyn_cast_or_null(SS);
   if (AS)


Index: clang/test/OpenMP/omp_with_loop_pragma.c
===
--- clang/test/OpenMP/omp_with_loop_pragma.c
+++ clang/test/OpenMP/omp_with_loop_pragma.c
@@ -3,12 +3,12 @@
 // expected-no-diagnostics
 
 // CHECK: !{{[0-9]+}} = !{!"llvm.loop.vectorize.width", i32 1}
-void sub(double * restrict a, double * restrict b, int n){ 
+void sub(double *restrict a, double *restrict b, int n) {
   int i;
 
 #pragma omp parallel for
 #pragma clang loop vectorize(disable)
-  for(i=0;i(&S);
-  const CapturedStmt *ICS = OMPED->getInnermostCapturedStmt();
+  const auto &OMPED = cast(S);
+  const CapturedStmt *ICS = OMPED.getInnermostCapturedStmt();
   const Stmt *SS = ICS->getCapturedStmt();
   const AttributedStmt *AS = dyn_cast_or_null(SS);
   if (AS)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79921: [OpenMP] Fix omp and clang pragmas

2020-05-13 Thread ISHIGURO, Hiroshi via Phabricator via cfe-commits
hishiguro created this revision.
hishiguro added a reviewer: ABataev.
hishiguro added a project: clang.
Herald added subscribers: cfe-commits, guansong, yaxunl.
Herald added a reviewer: jdoerfert.

Fixes PR45753

When a program that contains a loop to which both "omp parallel for" pragma and 
"clang loop" pragma are associated is compiled with the -fopenmp option, "clang 
loop" pragma will not take effect.
The example below should not be vectorized by the "clang loop` pragma but is it 
actually vectorized.
The cause is that "llvm.loop.vectorize.width" is not output to the IR when 
-fopenmp is specified.
The fix attaches attributes if they exist in the loop.

[example.c]

  int a[100], b[100];
  int foo() {
  #pragma omp parallel for
  #pragma clang loop vectorize(disable)
  for (int i=0; i<100; i++)
a[i]+=b[i]*i;
  }

[compile]
clang -O2 -fopenmp a.c -c -Rpass=vect
a.c:3:1: remark: vectorized loop (vectorization width: 4, interleaved count: 2) 
[-Rpass=loop-vectorize] #pragma omp parallel for ^

[IR]

- -fopenmp

$ clang -O2 a.c -S -emit-llvm -mllvm -disable-llvm-optzns -o - -fopenmp |grep 
"vectorize\.width"
$

- -fno-openmp

$ clang -O2 a.c -S -emit-llvm -mllvm -disable-llvm-optzns -o - -fno-openmp 
|grep "vectorize\.width"
!7 = !{!"llvm.loop.vectorize.width", i32 1}


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79921

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp


Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1730,9 +1730,22 @@
   auto CondBlock = createBasicBlock("omp.inner.for.cond");
   EmitBlock(CondBlock);
   const SourceRange R = S.getSourceRange();
-  LoopStack.push(CondBlock, SourceLocToDebugLoc(R.getBegin()),
- SourceLocToDebugLoc(R.getEnd()));
 
+  // If attributes are attached, push to the basic block with them.
+  const AttributedStmt *AS = nullptr;
+  if (auto *OMPD = dyn_cast(&S)) {
+const CapturedStmt *CS = OMPD->getCapturedStmt(OMPD_parallel);
+const Stmt *SS = CS->getCapturedStmt();
+AS = dyn_cast_or_null(SS);
+  }
+  if (AS)
+LoopStack.push(CondBlock, CGM.getContext(), CGM.getCodeGenOpts(),
+   AS->getAttrs(), SourceLocToDebugLoc(R.getBegin()),
+   SourceLocToDebugLoc(R.getEnd()));
+  else
+LoopStack.push(CondBlock, SourceLocToDebugLoc(R.getBegin()),
+   SourceLocToDebugLoc(R.getEnd()));
+  
   // If there are any cleanups between here and the loop-exit scope,
   // create a block to stage a loop exit along.
   llvm::BasicBlock *ExitBlock = LoopExit.getBlock();


Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1730,9 +1730,22 @@
   auto CondBlock = createBasicBlock("omp.inner.for.cond");
   EmitBlock(CondBlock);
   const SourceRange R = S.getSourceRange();
-  LoopStack.push(CondBlock, SourceLocToDebugLoc(R.getBegin()),
- SourceLocToDebugLoc(R.getEnd()));
 
+  // If attributes are attached, push to the basic block with them.
+  const AttributedStmt *AS = nullptr;
+  if (auto *OMPD = dyn_cast(&S)) {
+const CapturedStmt *CS = OMPD->getCapturedStmt(OMPD_parallel);
+const Stmt *SS = CS->getCapturedStmt();
+AS = dyn_cast_or_null(SS);
+  }
+  if (AS)
+LoopStack.push(CondBlock, CGM.getContext(), CGM.getCodeGenOpts(),
+   AS->getAttrs(), SourceLocToDebugLoc(R.getBegin()),
+   SourceLocToDebugLoc(R.getEnd()));
+  else
+LoopStack.push(CondBlock, SourceLocToDebugLoc(R.getBegin()),
+   SourceLocToDebugLoc(R.getEnd()));
+  
   // If there are any cleanups between here and the loop-exit scope,
   // create a block to stage a loop exit along.
   llvm::BasicBlock *ExitBlock = LoopExit.getBlock();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79921: [OpenMP] Fix omp and clang pragmas

2020-05-14 Thread ISHIGURO, Hiroshi via Phabricator via cfe-commits
hishiguro updated this revision to Diff 263964.
hishiguro added a comment.

Fix clang-format error.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79921/new/

https://reviews.llvm.org/D79921

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp


Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1730,9 +1730,22 @@
   auto CondBlock = createBasicBlock("omp.inner.for.cond");
   EmitBlock(CondBlock);
   const SourceRange R = S.getSourceRange();
-  LoopStack.push(CondBlock, SourceLocToDebugLoc(R.getBegin()),
- SourceLocToDebugLoc(R.getEnd()));
 
+  // If attributes are attached, push to the basic block with them.
+  const AttributedStmt *AS = nullptr;
+  if (auto *OMPD = dyn_cast(&S)) {
+const CapturedStmt *CS = OMPD->getCapturedStmt(OMPD_parallel);
+const Stmt *SS = CS->getCapturedStmt();
+AS = dyn_cast_or_null(SS);
+  }
+  if (AS)
+LoopStack.push(CondBlock, CGM.getContext(), CGM.getCodeGenOpts(),
+   AS->getAttrs(), SourceLocToDebugLoc(R.getBegin()),
+   SourceLocToDebugLoc(R.getEnd()));
+  else
+LoopStack.push(CondBlock, SourceLocToDebugLoc(R.getBegin()),
+   SourceLocToDebugLoc(R.getEnd()));
+
   // If there are any cleanups between here and the loop-exit scope,
   // create a block to stage a loop exit along.
   llvm::BasicBlock *ExitBlock = LoopExit.getBlock();


Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1730,9 +1730,22 @@
   auto CondBlock = createBasicBlock("omp.inner.for.cond");
   EmitBlock(CondBlock);
   const SourceRange R = S.getSourceRange();
-  LoopStack.push(CondBlock, SourceLocToDebugLoc(R.getBegin()),
- SourceLocToDebugLoc(R.getEnd()));
 
+  // If attributes are attached, push to the basic block with them.
+  const AttributedStmt *AS = nullptr;
+  if (auto *OMPD = dyn_cast(&S)) {
+const CapturedStmt *CS = OMPD->getCapturedStmt(OMPD_parallel);
+const Stmt *SS = CS->getCapturedStmt();
+AS = dyn_cast_or_null(SS);
+  }
+  if (AS)
+LoopStack.push(CondBlock, CGM.getContext(), CGM.getCodeGenOpts(),
+   AS->getAttrs(), SourceLocToDebugLoc(R.getBegin()),
+   SourceLocToDebugLoc(R.getEnd()));
+  else
+LoopStack.push(CondBlock, SourceLocToDebugLoc(R.getBegin()),
+   SourceLocToDebugLoc(R.getEnd()));
+
   // If there are any cleanups between here and the loop-exit scope,
   // create a block to stage a loop exit along.
   llvm::BasicBlock *ExitBlock = LoopExit.getBlock();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79921: [OpenMP] Fix omp and clang pragmas

2020-05-15 Thread ISHIGURO, Hiroshi via Phabricator via cfe-commits
hishiguro added a comment.

Thank you for your comments. I will check those comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79921/new/

https://reviews.llvm.org/D79921



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


[PATCH] D79921: [OPENMP] Fix mixture of omp and clang pragmas

2020-05-19 Thread ISHIGURO, Hiroshi via Phabricator via cfe-commits
hishiguro updated this revision to Diff 264836.
hishiguro retitled this revision from "[OpenMP] Fix omp and clang pragmas" to 
"[OPENMP] Fix mixture of omp and clang pragmas".
hishiguro added a comment.
Herald added a reviewer: a.sidorin.

I checked that your comments are correct. I modified the source, and added a 
test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79921/new/

https://reviews.llvm.org/D79921

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/omp_with_loop_pragma.c


Index: clang/test/OpenMP/omp_with_loop_pragma.c
===
--- /dev/null
+++ clang/test/OpenMP/omp_with_loop_pragma.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify -fopenmp -x c -emit-llvm %s -triple 
x86_64-unknown-linux -o - -femit-all-decls -disable-llvm-passes | FileCheck %s
+// RUN: %clang_cc1 -verify -x c -emit-llvm %s -triple x86_64-unknown-linux -o 
- -femit-all-decls -disable-llvm-passes | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK: !{{[0-9]+}} = !{!"llvm.loop.vectorize.width", i32 1}
+void sub(double * restrict a, double * restrict b, int n){ 
+  int i;
+
+#pragma omp parallel for
+#pragma clang loop vectorize(disable)
+  for(i=0;i(&S);
+  const CapturedStmt *ICS = OMPED->getInnermostCapturedStmt();
+  const Stmt *SS = ICS->getCapturedStmt();
+  const AttributedStmt *AS = dyn_cast_or_null(SS);
+  if (AS)
+LoopStack.push(CondBlock, CGM.getContext(), CGM.getCodeGenOpts(),
+   AS->getAttrs(), SourceLocToDebugLoc(R.getBegin()),
+   SourceLocToDebugLoc(R.getEnd()));
+  else
+LoopStack.push(CondBlock, SourceLocToDebugLoc(R.getBegin()),
+   SourceLocToDebugLoc(R.getEnd()));
 
   // If there are any cleanups between here and the loop-exit scope,
   // create a block to stage a loop exit along.


Index: clang/test/OpenMP/omp_with_loop_pragma.c
===
--- /dev/null
+++ clang/test/OpenMP/omp_with_loop_pragma.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify -fopenmp -x c -emit-llvm %s -triple x86_64-unknown-linux -o - -femit-all-decls -disable-llvm-passes | FileCheck %s
+// RUN: %clang_cc1 -verify -x c -emit-llvm %s -triple x86_64-unknown-linux -o - -femit-all-decls -disable-llvm-passes | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK: !{{[0-9]+}} = !{!"llvm.loop.vectorize.width", i32 1}
+void sub(double * restrict a, double * restrict b, int n){ 
+  int i;
+
+#pragma omp parallel for
+#pragma clang loop vectorize(disable)
+  for(i=0;i(&S);
+  const CapturedStmt *ICS = OMPED->getInnermostCapturedStmt();
+  const Stmt *SS = ICS->getCapturedStmt();
+  const AttributedStmt *AS = dyn_cast_or_null(SS);
+  if (AS)
+LoopStack.push(CondBlock, CGM.getContext(), CGM.getCodeGenOpts(),
+   AS->getAttrs(), SourceLocToDebugLoc(R.getBegin()),
+   SourceLocToDebugLoc(R.getEnd()));
+  else
+LoopStack.push(CondBlock, SourceLocToDebugLoc(R.getBegin()),
+   SourceLocToDebugLoc(R.getEnd()));
 
   // If there are any cleanups between here and the loop-exit scope,
   // create a block to stage a loop exit along.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits