[PATCH] D91556: [OpenMPIRBuilder} Add capturing of parameters to pass to omp::parallel

2020-12-14 Thread Lubomir Litchev via Phabricator via cfe-commits
llitchev updated this revision to Diff 311557.
llitchev added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Merged in master.

Removed unnecessary (now) code from D92189 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91556

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/parallel_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
  mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
  mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir

Index: mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir
===
--- /dev/null
+++ mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir
@@ -0,0 +1,42 @@
+// RUN: mlir-translate  --mlir-to-llvmir %s | FileCheck %s
+
+module {
+  llvm.func @malloc(!llvm.i64) -> !llvm.ptr
+  llvm.func @main() {
+%0 = llvm.mlir.constant(4 : index) : !llvm.i64
+%1 = llvm.mlir.constant(4 : index) : !llvm.i64
+%2 = llvm.mlir.null : !llvm.ptr
+%3 = llvm.mlir.constant(1 : index) : !llvm.i64
+%4 = llvm.getelementptr %2[%3] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr
+%5 = llvm.ptrtoint %4 : !llvm.ptr to !llvm.i64
+%6 = llvm.mul %1, %5 : !llvm.i64
+%7 = llvm.call @malloc(%6) : (!llvm.i64) -> !llvm.ptr
+%8 = llvm.bitcast %7 : !llvm.ptr to !llvm.ptr
+%9 = llvm.mlir.undef : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%10 = llvm.insertvalue %8, %9[0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%11 = llvm.insertvalue %8, %10[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%12 = llvm.mlir.constant(0 : index) : !llvm.i64
+%13 = llvm.insertvalue %12, %11[2] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%14 = llvm.mlir.constant(1 : index) : !llvm.i64
+%15 = llvm.insertvalue %1, %13[3, 0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%16 = llvm.insertvalue %14, %15[4, 0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%17 = llvm.mlir.constant(4.20e+01 : f32) : !llvm.float
+// CHECK: %CaptureStructAlloca = alloca %CapturedStructType
+// CHECK: %{{.*}} = insertvalue %CapturedStructType undef, {{.*}}, 0
+// CHECK: store %CapturedStructType %{{.*}}, %CapturedStructType* %CaptureStructAlloca
+omp.parallel num_threads(%0 : !llvm.i64) {
+  // CHECK: %{{.*}} = load %CapturedStructType, %CapturedStructType* %CaptureStructAlloca
+  // CHECK: %{{.*}} = extractvalue %CapturedStructType %{{.*}}, 0
+  %27 = llvm.mlir.constant(1 : i64) : !llvm.i64
+  %28 = llvm.extractvalue %16[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+  %29 = llvm.mlir.constant(0 : index) : !llvm.i64
+  %30 = llvm.mlir.constant(1 : index) : !llvm.i64
+  %31 = llvm.mul %27, %30 : !llvm.i64
+  %32 = llvm.add %29, %31 : !llvm.i64
+  %33 = llvm.getelementptr %28[%32] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr
+  llvm.store %17, %33 : !llvm.ptr
+  omp.terminator
+}
+llvm.return
+  }
+}
Index: mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
===
--- mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
+++ mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
@@ -6,7 +6,7 @@
   %end = constant 0 : index
   // CHECK: omp.parallel
   omp.parallel {
-// CHECK-NEXT: llvm.br ^[[BB1:.*]](%{{[0-9]+}}, %{{[0-9]+}} : !llvm.i64, !llvm.i64
+// CHECK: llvm.br ^[[BB1:.*]](%{{[0-9]+}}, %{{[0-9]+}} : !llvm.i64, !llvm.i64
 br ^bb1(%start, %end : index, index)
   // CHECK-NEXT: ^[[BB1]](%[[ARG1:[0-9]+]]: !llvm.i64, %[[ARG2:[0-9]+]]: !llvm.i64):{{.*}}
   ^bb1(%0: index, %1: index):
Index: mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -424,7 +424,7 @@
   // attribute (shared, private, firstprivate, ...) of variables.
   // Currently defaults to shared.
   auto privCB = [&](InsertPointTy allocaIP, InsertPointTy codeGenIP,
-llvm::Value &, llvm::Value &vPtr,
+llvm::Value &vPtr,
 llvm::Value *&replacementValue) -> InsertPointTy {
 replacementValue = &vPtr;
 
Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -60,25 +60,6 @@
   DebugLoc DL;
 };
 
-// Returns 

[PATCH] D91556: [OpenMPIRBuilder} Add capturing of parameters to pass to omp::parallel

2020-12-14 Thread Lubomir Litchev via Phabricator via cfe-commits
llitchev updated this revision to Diff 311648.
llitchev added a comment.

Fixed a failing Windows test. The issue is that that the order of the operands 
for add operation has changed. I cant see how these changes could cause the 
issue, but it is a failing test that blocks push of this Diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91556

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/parallel_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/test/CodeGen/XCore/threads.ll
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
  mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
  mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir

Index: mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir
===
--- /dev/null
+++ mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir
@@ -0,0 +1,42 @@
+// RUN: mlir-translate  --mlir-to-llvmir %s | FileCheck %s
+
+module {
+  llvm.func @malloc(!llvm.i64) -> !llvm.ptr
+  llvm.func @main() {
+%0 = llvm.mlir.constant(4 : index) : !llvm.i64
+%1 = llvm.mlir.constant(4 : index) : !llvm.i64
+%2 = llvm.mlir.null : !llvm.ptr
+%3 = llvm.mlir.constant(1 : index) : !llvm.i64
+%4 = llvm.getelementptr %2[%3] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr
+%5 = llvm.ptrtoint %4 : !llvm.ptr to !llvm.i64
+%6 = llvm.mul %1, %5 : !llvm.i64
+%7 = llvm.call @malloc(%6) : (!llvm.i64) -> !llvm.ptr
+%8 = llvm.bitcast %7 : !llvm.ptr to !llvm.ptr
+%9 = llvm.mlir.undef : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%10 = llvm.insertvalue %8, %9[0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%11 = llvm.insertvalue %8, %10[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%12 = llvm.mlir.constant(0 : index) : !llvm.i64
+%13 = llvm.insertvalue %12, %11[2] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%14 = llvm.mlir.constant(1 : index) : !llvm.i64
+%15 = llvm.insertvalue %1, %13[3, 0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%16 = llvm.insertvalue %14, %15[4, 0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%17 = llvm.mlir.constant(4.20e+01 : f32) : !llvm.float
+// CHECK: %CaptureStructAlloca = alloca %CapturedStructType
+// CHECK: %{{.*}} = insertvalue %CapturedStructType undef, {{.*}}, 0
+// CHECK: store %CapturedStructType %{{.*}}, %CapturedStructType* %CaptureStructAlloca
+omp.parallel num_threads(%0 : !llvm.i64) {
+  // CHECK: %{{.*}} = load %CapturedStructType, %CapturedStructType* %CaptureStructAlloca
+  // CHECK: %{{.*}} = extractvalue %CapturedStructType %{{.*}}, 0
+  %27 = llvm.mlir.constant(1 : i64) : !llvm.i64
+  %28 = llvm.extractvalue %16[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+  %29 = llvm.mlir.constant(0 : index) : !llvm.i64
+  %30 = llvm.mlir.constant(1 : index) : !llvm.i64
+  %31 = llvm.mul %27, %30 : !llvm.i64
+  %32 = llvm.add %29, %31 : !llvm.i64
+  %33 = llvm.getelementptr %28[%32] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr
+  llvm.store %17, %33 : !llvm.ptr
+  omp.terminator
+}
+llvm.return
+  }
+}
Index: mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
===
--- mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
+++ mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
@@ -6,7 +6,7 @@
   %end = constant 0 : index
   // CHECK: omp.parallel
   omp.parallel {
-// CHECK-NEXT: llvm.br ^[[BB1:.*]](%{{[0-9]+}}, %{{[0-9]+}} : !llvm.i64, !llvm.i64
+// CHECK: llvm.br ^[[BB1:.*]](%{{[0-9]+}}, %{{[0-9]+}} : !llvm.i64, !llvm.i64
 br ^bb1(%start, %end : index, index)
   // CHECK-NEXT: ^[[BB1]](%[[ARG1:[0-9]+]]: !llvm.i64, %[[ARG2:[0-9]+]]: !llvm.i64):{{.*}}
   ^bb1(%0: index, %1: index):
Index: mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -424,7 +424,7 @@
   // attribute (shared, private, firstprivate, ...) of variables.
   // Currently defaults to shared.
   auto privCB = [&](InsertPointTy allocaIP, InsertPointTy codeGenIP,
-llvm::Value &, llvm::Value &vPtr,
+llvm::Value &vPtr,
 llvm::Value *&replacementValue) -> InsertPointTy {
 replacementValue = &vPtr;
 
Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittes

[PATCH] D91556: [OpenMPIRBuilder} Add capturing of parameters to pass to omp::parallel

2020-12-14 Thread Lubomir Litchev via Phabricator via cfe-commits
llitchev updated this revision to Diff 311698.
llitchev added a comment.

Added separate tests for Windows for specific tests.

On Windows the registers for the add operation are swapped. This test is 
completely unrelated to this change, but it fails.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91556

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/parallel_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/test/CodeGen/XCore/threads.ll
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
  mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
  mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir

Index: mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir
===
--- /dev/null
+++ mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir
@@ -0,0 +1,42 @@
+// RUN: mlir-translate  --mlir-to-llvmir %s | FileCheck %s
+
+module {
+  llvm.func @malloc(!llvm.i64) -> !llvm.ptr
+  llvm.func @main() {
+%0 = llvm.mlir.constant(4 : index) : !llvm.i64
+%1 = llvm.mlir.constant(4 : index) : !llvm.i64
+%2 = llvm.mlir.null : !llvm.ptr
+%3 = llvm.mlir.constant(1 : index) : !llvm.i64
+%4 = llvm.getelementptr %2[%3] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr
+%5 = llvm.ptrtoint %4 : !llvm.ptr to !llvm.i64
+%6 = llvm.mul %1, %5 : !llvm.i64
+%7 = llvm.call @malloc(%6) : (!llvm.i64) -> !llvm.ptr
+%8 = llvm.bitcast %7 : !llvm.ptr to !llvm.ptr
+%9 = llvm.mlir.undef : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%10 = llvm.insertvalue %8, %9[0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%11 = llvm.insertvalue %8, %10[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%12 = llvm.mlir.constant(0 : index) : !llvm.i64
+%13 = llvm.insertvalue %12, %11[2] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%14 = llvm.mlir.constant(1 : index) : !llvm.i64
+%15 = llvm.insertvalue %1, %13[3, 0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%16 = llvm.insertvalue %14, %15[4, 0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%17 = llvm.mlir.constant(4.20e+01 : f32) : !llvm.float
+// CHECK: %CaptureStructAlloca = alloca %CapturedStructType
+// CHECK: %{{.*}} = insertvalue %CapturedStructType undef, {{.*}}, 0
+// CHECK: store %CapturedStructType %{{.*}}, %CapturedStructType* %CaptureStructAlloca
+omp.parallel num_threads(%0 : !llvm.i64) {
+  // CHECK: %{{.*}} = load %CapturedStructType, %CapturedStructType* %CaptureStructAlloca
+  // CHECK: %{{.*}} = extractvalue %CapturedStructType %{{.*}}, 0
+  %27 = llvm.mlir.constant(1 : i64) : !llvm.i64
+  %28 = llvm.extractvalue %16[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+  %29 = llvm.mlir.constant(0 : index) : !llvm.i64
+  %30 = llvm.mlir.constant(1 : index) : !llvm.i64
+  %31 = llvm.mul %27, %30 : !llvm.i64
+  %32 = llvm.add %29, %31 : !llvm.i64
+  %33 = llvm.getelementptr %28[%32] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr
+  llvm.store %17, %33 : !llvm.ptr
+  omp.terminator
+}
+llvm.return
+  }
+}
Index: mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
===
--- mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
+++ mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
@@ -6,7 +6,7 @@
   %end = constant 0 : index
   // CHECK: omp.parallel
   omp.parallel {
-// CHECK-NEXT: llvm.br ^[[BB1:.*]](%{{[0-9]+}}, %{{[0-9]+}} : !llvm.i64, !llvm.i64
+// CHECK: llvm.br ^[[BB1:.*]](%{{[0-9]+}}, %{{[0-9]+}} : !llvm.i64, !llvm.i64
 br ^bb1(%start, %end : index, index)
   // CHECK-NEXT: ^[[BB1]](%[[ARG1:[0-9]+]]: !llvm.i64, %[[ARG2:[0-9]+]]: !llvm.i64):{{.*}}
   ^bb1(%0: index, %1: index):
Index: mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -424,7 +424,7 @@
   // attribute (shared, private, firstprivate, ...) of variables.
   // Currently defaults to shared.
   auto privCB = [&](InsertPointTy allocaIP, InsertPointTy codeGenIP,
-llvm::Value &, llvm::Value &vPtr,
+llvm::Value &vPtr,
 llvm::Value *&replacementValue) -> InsertPointTy {
 replacementValue = &vPtr;
 
Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -6

[PATCH] D91556: [OpenMPIRBuilder} Add capturing of parameters to pass to omp::parallel

2020-12-21 Thread Lubomir Litchev via Phabricator via cfe-commits
llitchev updated this revision to Diff 313039.
llitchev marked 10 inline comments as done.
llitchev added a comment.

Addressed CR.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91556

Files:
  clang/test/OpenMP/parallel_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/test/CodeGen/XCore/threads.ll
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
  mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir

Index: mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir
===
--- /dev/null
+++ mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir
@@ -0,0 +1,42 @@
+// RUN: mlir-translate  --mlir-to-llvmir %s | FileCheck %s
+
+module {
+  llvm.func @malloc(!llvm.i64) -> !llvm.ptr
+  llvm.func @main() {
+%0 = llvm.mlir.constant(4 : index) : !llvm.i64
+%1 = llvm.mlir.constant(4 : index) : !llvm.i64
+%2 = llvm.mlir.null : !llvm.ptr
+%3 = llvm.mlir.constant(1 : index) : !llvm.i64
+%4 = llvm.getelementptr %2[%3] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr
+%5 = llvm.ptrtoint %4 : !llvm.ptr to !llvm.i64
+%6 = llvm.mul %1, %5 : !llvm.i64
+%7 = llvm.call @malloc(%6) : (!llvm.i64) -> !llvm.ptr
+%8 = llvm.bitcast %7 : !llvm.ptr to !llvm.ptr
+%9 = llvm.mlir.undef : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%10 = llvm.insertvalue %8, %9[0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%11 = llvm.insertvalue %8, %10[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%12 = llvm.mlir.constant(0 : index) : !llvm.i64
+%13 = llvm.insertvalue %12, %11[2] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%14 = llvm.mlir.constant(1 : index) : !llvm.i64
+%15 = llvm.insertvalue %1, %13[3, 0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%16 = llvm.insertvalue %14, %15[4, 0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%17 = llvm.mlir.constant(4.20e+01 : f32) : !llvm.float
+// CHECK: %CaptureStructAlloca = alloca %CapturedStructType
+// CHECK: %{{.*}} = insertvalue %CapturedStructType undef, {{.*}}, 0
+// CHECK: store %CapturedStructType %{{.*}}, %CapturedStructType* %CaptureStructAlloca
+omp.parallel num_threads(%0 : !llvm.i64) {
+  // CHECK: %{{.*}} = load %CapturedStructType, %CapturedStructType* %CaptureStructAlloca
+  // CHECK: %{{.*}} = extractvalue %CapturedStructType %{{.*}}, 0
+  %27 = llvm.mlir.constant(1 : i64) : !llvm.i64
+  %28 = llvm.extractvalue %16[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+  %29 = llvm.mlir.constant(0 : index) : !llvm.i64
+  %30 = llvm.mlir.constant(1 : index) : !llvm.i64
+  %31 = llvm.mul %27, %30 : !llvm.i64
+  %32 = llvm.add %29, %31 : !llvm.i64
+  %33 = llvm.getelementptr %28[%32] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr
+  llvm.store %17, %33 : !llvm.ptr
+  omp.terminator
+}
+llvm.return
+  }
+}
Index: mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
===
--- mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
+++ mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
@@ -6,7 +6,7 @@
   %end = constant 0 : index
   // CHECK: omp.parallel
   omp.parallel {
-// CHECK-NEXT: llvm.br ^[[BB1:.*]](%{{[0-9]+}}, %{{[0-9]+}} : !llvm.i64, !llvm.i64
+// CHECK: llvm.br ^[[BB1:.*]](%{{[0-9]+}}, %{{[0-9]+}} : !llvm.i64, !llvm.i64
 br ^bb1(%start, %end : index, index)
   // CHECK-NEXT: ^[[BB1]](%[[ARG1:[0-9]+]]: !llvm.i64, %[[ARG2:[0-9]+]]: !llvm.i64):{{.*}}
   ^bb1(%0: index, %1: index):
Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -60,25 +60,6 @@
   DebugLoc DL;
 };
 
-// Returns the value stored in the given allocation. Returns null if the given
-// value is not a result of an allocation, if no value is stored or if there is
-// more than one store.
-static Value *findStoredValue(Value *AllocaValue) {
-  Instruction *Alloca = dyn_cast(AllocaValue);
-  if (!Alloca)
-return nullptr;
-  StoreInst *Store = nullptr;
-  for (Use &U : Alloca->uses()) {
-if (auto *CandidateStore = dyn_cast(U.getUser())) {
-  EXPECT_EQ(Store, nullptr);
-  Store = CandidateStore;
-}
-  }
-  if (!Store)
-return nullptr;
-  return Store->getValueOperand();
-}
-
 TEST_F(OpenMPIRBuilderTest, CreateBarrier) {
   OpenMPIRBuilder OMPBuilder(*M);
   OMPBuilder.initialize();
@@ -425,7 +406,6 @@
   EXPECT_EQ(ForkCI->getArgOperand(1),
 ConstantInt::get(Type::getInt32Ty(Ctx)

[PATCH] D91556: [OpenMPIRBuilder} Add capturing of parameters to pass to omp::parallel

2020-12-21 Thread Lubomir Litchev via Phabricator via cfe-commits
llitchev added inline comments.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h:119
   ///  should be placed.
-  /// \param Original The value being copied/created, should not be used in the
-  /// generated IR.
-  /// \param Inner The equivalent of \p Original that should be used in the
-  ///  generated IR; this is equal to \p Original if the value is
-  ///  a pointer and can thus be passed directly, otherwise it is
-  ///  an equivalent but different value.
+  /// \param \param Val The value beeing copied/created.
   /// \param ReplVal The replacement value, thus a copy or new created version

jdoerfert wrote:
> wasn't that a spelling error before? and one `\param` is enough ;)
Fixed.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h:678
+  ///
+  /// \param CaptureAllocaInsPoint Insertion point for the alloca-ed struct.
+  /// \param OuterFn The function containing the omp::Parallel.

ftynse wrote:
> Nit: it looks like this file uses IP rather than InsPoint for names related 
> to insertion points
No need to store this value anymore. Used the InsertBB->getTerminator(), thus 
guaranteeing the alloca and stores are just before the fork call (they were 
before that call too, since the ThreadID was called last), so even if more 
codegen is introduced in the future the logic deals with it.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:441
+  IRBuilder<>::InsertPoint CaptureAllocaInsPoint(Builder.GetInsertBlock(),
+ --Builder.GetInsertPoint());
+

jdoerfert wrote:
> How do we know that `--` is valid here? Couldn't `Loc` point to the begin of 
> a function? If possible, let's just use `Loc.IP`.
There is always an instruction before - the ThreadID was always generated, and 
that is what -- points to. Changed it to use InsertBB->getTerminator(). It is 
much more sturdy this way. Even if the codegen is changed, the alloca, insert 
and store will be generated always just before the forkCall.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:760
+  SetVector BlockParents;
+  for (unsigned Counter = 0; Counter < Blocks.size(); Counter++) {
+BasicBlock *ParallelRegionBlock = Blocks[Counter];

ftynse wrote:
> Nit:  I think 
> https://llvm.org/docs/CodingStandards.html#don-t-evaluate-end-every-time-through-a-loop
>  applies to `.size()` the same way it applies to `.end()`
Fixed.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:807-808
+  llvm::IRBuilder<>::InsertPointGuard Guard(Builder);
+  Builder.SetInsertPoint(CaptureAllocaInsPoint.getBlock(),
+ CaptureAllocaInsPoint.getPoint());
+  // Allocate and populate the capture struct.

ftynse wrote:
> Nit: `Builder.restoreIP(CaptureAllocaInsPoint)` looks shorter
Refactored. No need to store the InsertPoint.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:810-815
+  AllocaInst = Builder.CreateAlloca(CaptureStructType, nullptr,
+"CaptureStructAlloca");
+  Value *InsertValue = UndefValue::get(CaptureStructType);
+  for (auto SrcIdx : enumerate(CapturedValues))
+InsertValue = Builder.CreateInsertValue(InsertValue, SrcIdx.value(),
+SrcIdx.index());

ftynse wrote:
> I suppose you may want to have `alloca` inserted in a block (function entry) 
> different from the one where you store into the memory. You need to store 
> just before calling the fork function (or, at least, so that the store 
> postdominates all stored values). Looking at the function API, I would have 
> assumed `CaptureAllocaInsPoint` to be an insertion point at the function 
> entry block specifically for `alloca`s, where these `insertvalue`s are 
> invalid.
Now it is guaranteed that. the codegen of the alloca, insert, and stores are 
done just before the forkCall. Even if the codegen changes in the future. It 
was the case before because the code was generated after the ThreadID getting 
call (which was just before the fork).



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:826-829
+  for (unsigned Counter = 0; Counter < Blocks.size(); Counter++)
+for (auto I = Blocks[Counter]->begin(), E = Blocks[Counter]->end();
+ I != E; ++I)
+  for (Use &U : I->operands())

ftynse wrote:
> Can we rather take each captured value and enumerate its uses, replacing 
> those within the parallel block set?
That was the first implementation I had. The issues was that the uses() was not 
returning all the uses (particularly the ones introduced by the loop unroller - 
spent bunch of time debugging it). Iterating to all the instruction parameter

[PATCH] D91556: [OpenMPIRBuilder} Add capturing of parameters to pass to omp::parallel

2020-12-21 Thread Lubomir Litchev via Phabricator via cfe-commits
llitchev updated this revision to Diff 313041.
llitchev added a comment.

Removed the changes from threads.ll.

I'll pull this is a new Diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91556

Files:
  clang/test/OpenMP/parallel_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
  mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir

Index: mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir
===
--- /dev/null
+++ mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir
@@ -0,0 +1,42 @@
+// RUN: mlir-translate  --mlir-to-llvmir %s | FileCheck %s
+
+module {
+  llvm.func @malloc(!llvm.i64) -> !llvm.ptr
+  llvm.func @main() {
+%0 = llvm.mlir.constant(4 : index) : !llvm.i64
+%1 = llvm.mlir.constant(4 : index) : !llvm.i64
+%2 = llvm.mlir.null : !llvm.ptr
+%3 = llvm.mlir.constant(1 : index) : !llvm.i64
+%4 = llvm.getelementptr %2[%3] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr
+%5 = llvm.ptrtoint %4 : !llvm.ptr to !llvm.i64
+%6 = llvm.mul %1, %5 : !llvm.i64
+%7 = llvm.call @malloc(%6) : (!llvm.i64) -> !llvm.ptr
+%8 = llvm.bitcast %7 : !llvm.ptr to !llvm.ptr
+%9 = llvm.mlir.undef : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%10 = llvm.insertvalue %8, %9[0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%11 = llvm.insertvalue %8, %10[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%12 = llvm.mlir.constant(0 : index) : !llvm.i64
+%13 = llvm.insertvalue %12, %11[2] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%14 = llvm.mlir.constant(1 : index) : !llvm.i64
+%15 = llvm.insertvalue %1, %13[3, 0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%16 = llvm.insertvalue %14, %15[4, 0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%17 = llvm.mlir.constant(4.20e+01 : f32) : !llvm.float
+// CHECK: %CaptureStructAlloca = alloca %CapturedStructType
+// CHECK: %{{.*}} = insertvalue %CapturedStructType undef, {{.*}}, 0
+// CHECK: store %CapturedStructType %{{.*}}, %CapturedStructType* %CaptureStructAlloca
+omp.parallel num_threads(%0 : !llvm.i64) {
+  // CHECK: %{{.*}} = load %CapturedStructType, %CapturedStructType* %CaptureStructAlloca
+  // CHECK: %{{.*}} = extractvalue %CapturedStructType %{{.*}}, 0
+  %27 = llvm.mlir.constant(1 : i64) : !llvm.i64
+  %28 = llvm.extractvalue %16[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+  %29 = llvm.mlir.constant(0 : index) : !llvm.i64
+  %30 = llvm.mlir.constant(1 : index) : !llvm.i64
+  %31 = llvm.mul %27, %30 : !llvm.i64
+  %32 = llvm.add %29, %31 : !llvm.i64
+  %33 = llvm.getelementptr %28[%32] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr
+  llvm.store %17, %33 : !llvm.ptr
+  omp.terminator
+}
+llvm.return
+  }
+}
Index: mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
===
--- mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
+++ mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
@@ -6,7 +6,7 @@
   %end = constant 0 : index
   // CHECK: omp.parallel
   omp.parallel {
-// CHECK-NEXT: llvm.br ^[[BB1:.*]](%{{[0-9]+}}, %{{[0-9]+}} : !llvm.i64, !llvm.i64
+// CHECK: llvm.br ^[[BB1:.*]](%{{[0-9]+}}, %{{[0-9]+}} : !llvm.i64, !llvm.i64
 br ^bb1(%start, %end : index, index)
   // CHECK-NEXT: ^[[BB1]](%[[ARG1:[0-9]+]]: !llvm.i64, %[[ARG2:[0-9]+]]: !llvm.i64):{{.*}}
   ^bb1(%0: index, %1: index):
Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -60,25 +60,6 @@
   DebugLoc DL;
 };
 
-// Returns the value stored in the given allocation. Returns null if the given
-// value is not a result of an allocation, if no value is stored or if there is
-// more than one store.
-static Value *findStoredValue(Value *AllocaValue) {
-  Instruction *Alloca = dyn_cast(AllocaValue);
-  if (!Alloca)
-return nullptr;
-  StoreInst *Store = nullptr;
-  for (Use &U : Alloca->uses()) {
-if (auto *CandidateStore = dyn_cast(U.getUser())) {
-  EXPECT_EQ(Store, nullptr);
-  Store = CandidateStore;
-}
-  }
-  if (!Store)
-return nullptr;
-  return Store->getValueOperand();
-}
-
 TEST_F(OpenMPIRBuilderTest, CreateBarrier) {
   OpenMPIRBuilder OMPBuilder(*M);
   OMPBuilder.initialize();
@@ -425,7 +406,6 @@
   EXPECT_EQ(ForkCI->getArgOperand(1),
 ConstantInt::get(Type::getInt32Ty(Ctx), 1U));
   EXPECT_EQ(ForkCI

[PATCH] D91556: [OpenMPIRBuilder} Add capturing of parameters to pass to omp::parallel

2020-12-21 Thread Lubomir Litchev via Phabricator via cfe-commits
llitchev updated this revision to Diff 313048.
llitchev added a comment.

Some minor optimizations related to CR.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91556

Files:
  clang/test/OpenMP/parallel_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
  mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir

Index: mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir
===
--- /dev/null
+++ mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir
@@ -0,0 +1,42 @@
+// RUN: mlir-translate  --mlir-to-llvmir %s | FileCheck %s
+
+module {
+  llvm.func @malloc(!llvm.i64) -> !llvm.ptr
+  llvm.func @main() {
+%0 = llvm.mlir.constant(4 : index) : !llvm.i64
+%1 = llvm.mlir.constant(4 : index) : !llvm.i64
+%2 = llvm.mlir.null : !llvm.ptr
+%3 = llvm.mlir.constant(1 : index) : !llvm.i64
+%4 = llvm.getelementptr %2[%3] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr
+%5 = llvm.ptrtoint %4 : !llvm.ptr to !llvm.i64
+%6 = llvm.mul %1, %5 : !llvm.i64
+%7 = llvm.call @malloc(%6) : (!llvm.i64) -> !llvm.ptr
+%8 = llvm.bitcast %7 : !llvm.ptr to !llvm.ptr
+%9 = llvm.mlir.undef : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%10 = llvm.insertvalue %8, %9[0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%11 = llvm.insertvalue %8, %10[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%12 = llvm.mlir.constant(0 : index) : !llvm.i64
+%13 = llvm.insertvalue %12, %11[2] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%14 = llvm.mlir.constant(1 : index) : !llvm.i64
+%15 = llvm.insertvalue %1, %13[3, 0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%16 = llvm.insertvalue %14, %15[4, 0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%17 = llvm.mlir.constant(4.20e+01 : f32) : !llvm.float
+// CHECK: %CaptureStructAlloca = alloca %CapturedStructType
+// CHECK: %{{.*}} = insertvalue %CapturedStructType undef, {{.*}}, 0
+// CHECK: store %CapturedStructType %{{.*}}, %CapturedStructType* %CaptureStructAlloca
+omp.parallel num_threads(%0 : !llvm.i64) {
+  // CHECK: %{{.*}} = load %CapturedStructType, %CapturedStructType* %CaptureStructAlloca
+  // CHECK: %{{.*}} = extractvalue %CapturedStructType %{{.*}}, 0
+  %27 = llvm.mlir.constant(1 : i64) : !llvm.i64
+  %28 = llvm.extractvalue %16[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+  %29 = llvm.mlir.constant(0 : index) : !llvm.i64
+  %30 = llvm.mlir.constant(1 : index) : !llvm.i64
+  %31 = llvm.mul %27, %30 : !llvm.i64
+  %32 = llvm.add %29, %31 : !llvm.i64
+  %33 = llvm.getelementptr %28[%32] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr
+  llvm.store %17, %33 : !llvm.ptr
+  omp.terminator
+}
+llvm.return
+  }
+}
Index: mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
===
--- mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
+++ mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
@@ -6,7 +6,7 @@
   %end = constant 0 : index
   // CHECK: omp.parallel
   omp.parallel {
-// CHECK-NEXT: llvm.br ^[[BB1:.*]](%{{[0-9]+}}, %{{[0-9]+}} : !llvm.i64, !llvm.i64
+// CHECK: llvm.br ^[[BB1:.*]](%{{[0-9]+}}, %{{[0-9]+}} : !llvm.i64, !llvm.i64
 br ^bb1(%start, %end : index, index)
   // CHECK-NEXT: ^[[BB1]](%[[ARG1:[0-9]+]]: !llvm.i64, %[[ARG2:[0-9]+]]: !llvm.i64):{{.*}}
   ^bb1(%0: index, %1: index):
Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -60,25 +60,6 @@
   DebugLoc DL;
 };
 
-// Returns the value stored in the given allocation. Returns null if the given
-// value is not a result of an allocation, if no value is stored or if there is
-// more than one store.
-static Value *findStoredValue(Value *AllocaValue) {
-  Instruction *Alloca = dyn_cast(AllocaValue);
-  if (!Alloca)
-return nullptr;
-  StoreInst *Store = nullptr;
-  for (Use &U : Alloca->uses()) {
-if (auto *CandidateStore = dyn_cast(U.getUser())) {
-  EXPECT_EQ(Store, nullptr);
-  Store = CandidateStore;
-}
-  }
-  if (!Store)
-return nullptr;
-  return Store->getValueOperand();
-}
-
 TEST_F(OpenMPIRBuilderTest, CreateBarrier) {
   OpenMPIRBuilder OMPBuilder(*M);
   OMPBuilder.initialize();
@@ -425,7 +406,6 @@
   EXPECT_EQ(ForkCI->getArgOperand(1),
 ConstantInt::get(Type::getInt32Ty(Ctx), 1U));
   EXPECT_EQ(ForkCI->getArgOperand(2), Usr);
- 

[PATCH] D91556: [OpenMPIRBuilder} Add capturing of parameters to pass to omp::parallel

2020-12-21 Thread Lubomir Litchev via Phabricator via cfe-commits
llitchev updated this revision to Diff 313077.
llitchev added a comment.

Fixed a casing issue with a local var.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91556

Files:
  clang/test/OpenMP/parallel_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
  mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir

Index: mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir
===
--- /dev/null
+++ mlir/test/Conversion/OpenMPToLLVM/openmp_float-parallel_param.mlir
@@ -0,0 +1,42 @@
+// RUN: mlir-translate  --mlir-to-llvmir %s | FileCheck %s
+
+module {
+  llvm.func @malloc(!llvm.i64) -> !llvm.ptr
+  llvm.func @main() {
+%0 = llvm.mlir.constant(4 : index) : !llvm.i64
+%1 = llvm.mlir.constant(4 : index) : !llvm.i64
+%2 = llvm.mlir.null : !llvm.ptr
+%3 = llvm.mlir.constant(1 : index) : !llvm.i64
+%4 = llvm.getelementptr %2[%3] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr
+%5 = llvm.ptrtoint %4 : !llvm.ptr to !llvm.i64
+%6 = llvm.mul %1, %5 : !llvm.i64
+%7 = llvm.call @malloc(%6) : (!llvm.i64) -> !llvm.ptr
+%8 = llvm.bitcast %7 : !llvm.ptr to !llvm.ptr
+%9 = llvm.mlir.undef : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%10 = llvm.insertvalue %8, %9[0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%11 = llvm.insertvalue %8, %10[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%12 = llvm.mlir.constant(0 : index) : !llvm.i64
+%13 = llvm.insertvalue %12, %11[2] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%14 = llvm.mlir.constant(1 : index) : !llvm.i64
+%15 = llvm.insertvalue %1, %13[3, 0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%16 = llvm.insertvalue %14, %15[4, 0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+%17 = llvm.mlir.constant(4.20e+01 : f32) : !llvm.float
+// CHECK: %CaptureStructAlloca = alloca %CapturedStructType
+// CHECK: %{{.*}} = insertvalue %CapturedStructType undef, {{.*}}, 0
+// CHECK: store %CapturedStructType %{{.*}}, %CapturedStructType* %CaptureStructAlloca
+omp.parallel num_threads(%0 : !llvm.i64) {
+  // CHECK: %{{.*}} = load %CapturedStructType, %CapturedStructType* %CaptureStructAlloca
+  // CHECK: %{{.*}} = extractvalue %CapturedStructType %{{.*}}, 0
+  %27 = llvm.mlir.constant(1 : i64) : !llvm.i64
+  %28 = llvm.extractvalue %16[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+  %29 = llvm.mlir.constant(0 : index) : !llvm.i64
+  %30 = llvm.mlir.constant(1 : index) : !llvm.i64
+  %31 = llvm.mul %27, %30 : !llvm.i64
+  %32 = llvm.add %29, %31 : !llvm.i64
+  %33 = llvm.getelementptr %28[%32] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr
+  llvm.store %17, %33 : !llvm.ptr
+  omp.terminator
+}
+llvm.return
+  }
+}
Index: mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
===
--- mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
+++ mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
@@ -6,7 +6,7 @@
   %end = constant 0 : index
   // CHECK: omp.parallel
   omp.parallel {
-// CHECK-NEXT: llvm.br ^[[BB1:.*]](%{{[0-9]+}}, %{{[0-9]+}} : !llvm.i64, !llvm.i64
+// CHECK: llvm.br ^[[BB1:.*]](%{{[0-9]+}}, %{{[0-9]+}} : !llvm.i64, !llvm.i64
 br ^bb1(%start, %end : index, index)
   // CHECK-NEXT: ^[[BB1]](%[[ARG1:[0-9]+]]: !llvm.i64, %[[ARG2:[0-9]+]]: !llvm.i64):{{.*}}
   ^bb1(%0: index, %1: index):
Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -60,25 +60,6 @@
   DebugLoc DL;
 };
 
-// Returns the value stored in the given allocation. Returns null if the given
-// value is not a result of an allocation, if no value is stored or if there is
-// more than one store.
-static Value *findStoredValue(Value *AllocaValue) {
-  Instruction *Alloca = dyn_cast(AllocaValue);
-  if (!Alloca)
-return nullptr;
-  StoreInst *Store = nullptr;
-  for (Use &U : Alloca->uses()) {
-if (auto *CandidateStore = dyn_cast(U.getUser())) {
-  EXPECT_EQ(Store, nullptr);
-  Store = CandidateStore;
-}
-  }
-  if (!Store)
-return nullptr;
-  return Store->getValueOperand();
-}
-
 TEST_F(OpenMPIRBuilderTest, CreateBarrier) {
   OpenMPIRBuilder OMPBuilder(*M);
   OMPBuilder.initialize();
@@ -425,7 +406,6 @@
   EXPECT_EQ(ForkCI->getArgOperand(1),
 ConstantInt::get(Type::getInt32Ty(Ctx), 1U));
   EXPECT_EQ(ForkCI->getArgOperand(2), Usr);
-  

[PATCH] D92189: [OpenMPIRBuilder] forward arguments as pointers to outlined function

2020-12-01 Thread Lubomir Litchev via Phabricator via cfe-commits
llitchev added a comment.

In D92189#2425639 , @jdoerfert wrote:

> While only partially related, can you leave a FIXME saying that more than 15 
> arguments need to be packed in a structure?

Yes, the number of varargs that is guarantee to work is 15, if more are needed, 
there is a need to wrap the parameters in a struct.
As we discussed (bring it here too) the issue here is how parameters are passed 
following the calling convention. The varargs assumes that parameters are 
passed in GPR (INTEGER classifications based on the calling conventions). The 
varargs approach works fine for the INTEGER classified args. It breaks for the 
SSE(UP) and vector clarified parameters. If we pass the pointers to the SSE 
params (floats for example) everything will work - pointers are INTEGER 
classification.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92189

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