[clang] [flang] [flang][Frontend] Implement printing defined macros via -dM (PR #87627)

2024-04-09 Thread Valentin Clement バレンタイン クレメン via cfe-commits

clementval wrote:

> How is this code used outside of LLVM? Why do people want to use _without_ 
> LLVM? Just curious.

I can see language features in IDE like vscode being a good candidate. 

https://github.com/llvm/llvm-project/pull/87627
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][cuda] Enable cuda with -x cuda option (PR #84944)

2024-03-13 Thread Valentin Clement バレンタイン クレメン via cfe-commits

https://github.com/clementval closed 
https://github.com/llvm/llvm-project/pull/84944
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][cuda] Enable cuda with -x cuda option (PR #84944)

2024-03-13 Thread Valentin Clement バレンタイン クレメン via cfe-commits


@@ -0,0 +1,13 @@
+! Test -fcuda option
+! RUN: %flang -fc1 -cpp -fcuda -fdebug-unparse %s -o - | FileCheck %s

clementval wrote:

Added

https://github.com/llvm/llvm-project/pull/84944
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][cuda] Enable cuda with -x cuda option (PR #84944)

2024-03-13 Thread Valentin Clement バレンタイン クレメン via cfe-commits

https://github.com/clementval edited 
https://github.com/llvm/llvm-project/pull/84944
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)

2024-03-12 Thread Valentin Clement バレンタイン クレメン via cfe-commits


@@ -6488,6 +6488,9 @@ defm stack_arrays : BoolOptionWithoutMarshalling<"f", 
"stack-arrays",
 defm loop_versioning : BoolOptionWithoutMarshalling<"f", 
"version-loops-for-stride",
   PosFlag,
NegFlag>;
+
+def fcuda : Flag<["-"], "fcuda">, Group,

clementval wrote:

I switch to use the `-x cuda` option which has a similar meaning. 

https://github.com/llvm/llvm-project/pull/84944
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)

2024-03-12 Thread Valentin Clement バレンタイン クレメン via cfe-commits

https://github.com/clementval deleted 
https://github.com/llvm/llvm-project/pull/84944
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)

2024-03-12 Thread Valentin Clement バレンタイン クレメン via cfe-commits

https://github.com/clementval updated 
https://github.com/llvm/llvm-project/pull/84944

>From e42e8fe7f1dfe503a6735ef76e9d6483f5c9b5ec Mon Sep 17 00:00:00 2001
From: Valentin Clement 
Date: Tue, 12 Mar 2024 09:33:17 -0700
Subject: [PATCH 1/2] [flang][cuda] Add -fcuda option

---
 clang/include/clang/Driver/Options.td |  3 +++
 clang/lib/Driver/ToolChains/Flang.cpp |  1 +
 flang/lib/Frontend/CompilerInvocation.cpp |  6 ++
 flang/lib/Frontend/FrontendAction.cpp | 11 ---
 flang/test/Driver/cuda-option.f90 | 13 +
 flang/test/Driver/driver-help-hidden.f90  |  1 +
 flang/test/Driver/driver-help.f90 |  2 ++
 7 files changed, 34 insertions(+), 3 deletions(-)
 create mode 100644 flang/test/Driver/cuda-option.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index aca8c9b0d5487a..bd28ec90bf7283 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6488,6 +6488,9 @@ defm stack_arrays : BoolOptionWithoutMarshalling<"f", 
"stack-arrays",
 defm loop_versioning : BoolOptionWithoutMarshalling<"f", 
"version-loops-for-stride",
   PosFlag,
NegFlag>;
+
+def fcuda : Flag<["-"], "fcuda">, Group,
+  HelpText<"Enable CUDA">;
 } // let Visibility = [FC1Option, FlangOption]
 
 def J : JoinedOrSeparate<["-"], "J">,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 6168b42dc78292..9b47ab0e7fcbf3 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -41,6 +41,7 @@ void Flang::addFortranDialectOptions(const ArgList ,
 options::OPT_fopenmp,
 options::OPT_fopenmp_version_EQ,
 options::OPT_fopenacc,
+options::OPT_fcuda,
 options::OPT_finput_charset_EQ,
 options::OPT_fimplicit_none,
 options::OPT_fno_implicit_none,
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 4707de0e976ca7..435f1df152c40d 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -877,6 +877,12 @@ static bool parseDialectArgs(CompilerInvocation , 
llvm::opt::ArgList ,
   if (args.hasArg(clang::driver::options::OPT_flarge_sizes))
 res.getDefaultKinds().set_sizeIntegerKind(8);
 
+  // -fcuda
+  if (args.hasArg(clang::driver::options::OPT_fcuda)) {
+res.getFrontendOpts().features.Enable(
+Fortran::common::LanguageFeature::CUDA);
+  }
+
   // -fopenmp and -fopenacc
   if (args.hasArg(clang::driver::options::OPT_fopenacc)) {
 res.getFrontendOpts().features.Enable(
diff --git a/flang/lib/Frontend/FrontendAction.cpp 
b/flang/lib/Frontend/FrontendAction.cpp
index 599b4e11f0cfbd..bb1c239540d9f5 100644
--- a/flang/lib/Frontend/FrontendAction.cpp
+++ b/flang/lib/Frontend/FrontendAction.cpp
@@ -86,9 +86,14 @@ bool FrontendAction::beginSourceFile(CompilerInstance ,
 invoc.collectMacroDefinitions();
   }
 
-  // Enable CUDA Fortran if source file is *.cuf/*.CUF.
-  
invoc.getFortranOpts().features.Enable(Fortran::common::LanguageFeature::CUDA,
- getCurrentInput().getIsCUDAFortran());
+  if (!invoc.getFortranOpts().features.IsEnabled(
+  Fortran::common::LanguageFeature::CUDA)) {
+// Enable CUDA Fortran if source file is *.cuf/*.CUF and not already
+// enabled.
+invoc.getFortranOpts().features.Enable(
+Fortran::common::LanguageFeature::CUDA,
+getCurrentInput().getIsCUDAFortran());
+  }
 
   // Decide between fixed and free form (if the user didn't express any
   // preference, use the file extension to decide)
diff --git a/flang/test/Driver/cuda-option.f90 
b/flang/test/Driver/cuda-option.f90
new file mode 100644
index 00..7bd1b3ddbffc3c
--- /dev/null
+++ b/flang/test/Driver/cuda-option.f90
@@ -0,0 +1,13 @@
+! Test -fcuda option
+! RUN: %flang -fc1 -cpp -fcuda -fdebug-unparse %s -o - | FileCheck %s
+
+program main
+#if _CUDA
+  integer :: var = _CUDA
+#endif
+  integer, device :: dvar
+end program
+
+! CHECK-LABEL: PROGRAM main
+! CHECK: INTEGER :: var = 1
+! CHECK: INTEGER, DEVICE :: dvar
diff --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 44dbac44772b29..7b2e28263a825a 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -32,6 +32,7 @@
 ! CHECK-NEXT: -fbackslash Specify that backslash in string 
introduces an escape character
 ! CHECK-NEXT: -fcolor-diagnostics Enable colors in diagnostics
 ! CHECK-NEXT: -fconvert=   Set endian conversion of data for 
unformatted files
+! CHECK-NEXT: -fcuda  Enable CUDA
 ! CHECK-NEXT: -fdefault-double-8  Set the default double precision kind to 
an 8 byte wide type
 

[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)

2024-03-12 Thread Valentin Clement バレンタイン クレメン via cfe-commits


@@ -6488,6 +6488,9 @@ defm stack_arrays : BoolOptionWithoutMarshalling<"f", 
"stack-arrays",
 defm loop_versioning : BoolOptionWithoutMarshalling<"f", 
"version-loops-for-stride",
   PosFlag,
NegFlag>;
+
+def fcuda : Flag<["-"], "fcuda">, Group,

clementval wrote:

The alternative is to use the same as `clang` with `-x `. I will need 
to check if we can filter the language so only the ones meaningful to flang can 
be passed. 

https://github.com/llvm/llvm-project/pull/84944
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)

2024-03-12 Thread Valentin Clement バレンタイン クレメン via cfe-commits

https://github.com/clementval edited 
https://github.com/llvm/llvm-project/pull/84944
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)

2024-03-12 Thread Valentin Clement バレンタイン クレメン via cfe-commits


@@ -0,0 +1,13 @@
+! Test -fcuda option
+! RUN: %flang -fc1 -cpp -fcuda -fdebug-unparse %s -o - | FileCheck %s

clementval wrote:

Without it, it would just fail during parsing. Do you want a test that check 
the failure?

https://github.com/llvm/llvm-project/pull/84944
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][cuda] Add -fcuda option (PR #84944)

2024-03-12 Thread Valentin Clement バレンタイン クレメン via cfe-commits

https://github.com/clementval created 
https://github.com/llvm/llvm-project/pull/84944

Flang driver was already able to enable the CUDA language feature base on the 
file extension but there was no command line option. This PR adds one. 

>From e42e8fe7f1dfe503a6735ef76e9d6483f5c9b5ec Mon Sep 17 00:00:00 2001
From: Valentin Clement 
Date: Tue, 12 Mar 2024 09:33:17 -0700
Subject: [PATCH] [flang][cuda] Add -fcuda option

---
 clang/include/clang/Driver/Options.td |  3 +++
 clang/lib/Driver/ToolChains/Flang.cpp |  1 +
 flang/lib/Frontend/CompilerInvocation.cpp |  6 ++
 flang/lib/Frontend/FrontendAction.cpp | 11 ---
 flang/test/Driver/cuda-option.f90 | 13 +
 flang/test/Driver/driver-help-hidden.f90  |  1 +
 flang/test/Driver/driver-help.f90 |  2 ++
 7 files changed, 34 insertions(+), 3 deletions(-)
 create mode 100644 flang/test/Driver/cuda-option.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index aca8c9b0d5487a..bd28ec90bf7283 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6488,6 +6488,9 @@ defm stack_arrays : BoolOptionWithoutMarshalling<"f", 
"stack-arrays",
 defm loop_versioning : BoolOptionWithoutMarshalling<"f", 
"version-loops-for-stride",
   PosFlag,
NegFlag>;
+
+def fcuda : Flag<["-"], "fcuda">, Group,
+  HelpText<"Enable CUDA">;
 } // let Visibility = [FC1Option, FlangOption]
 
 def J : JoinedOrSeparate<["-"], "J">,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 6168b42dc78292..9b47ab0e7fcbf3 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -41,6 +41,7 @@ void Flang::addFortranDialectOptions(const ArgList ,
 options::OPT_fopenmp,
 options::OPT_fopenmp_version_EQ,
 options::OPT_fopenacc,
+options::OPT_fcuda,
 options::OPT_finput_charset_EQ,
 options::OPT_fimplicit_none,
 options::OPT_fno_implicit_none,
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 4707de0e976ca7..435f1df152c40d 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -877,6 +877,12 @@ static bool parseDialectArgs(CompilerInvocation , 
llvm::opt::ArgList ,
   if (args.hasArg(clang::driver::options::OPT_flarge_sizes))
 res.getDefaultKinds().set_sizeIntegerKind(8);
 
+  // -fcuda
+  if (args.hasArg(clang::driver::options::OPT_fcuda)) {
+res.getFrontendOpts().features.Enable(
+Fortran::common::LanguageFeature::CUDA);
+  }
+
   // -fopenmp and -fopenacc
   if (args.hasArg(clang::driver::options::OPT_fopenacc)) {
 res.getFrontendOpts().features.Enable(
diff --git a/flang/lib/Frontend/FrontendAction.cpp 
b/flang/lib/Frontend/FrontendAction.cpp
index 599b4e11f0cfbd..bb1c239540d9f5 100644
--- a/flang/lib/Frontend/FrontendAction.cpp
+++ b/flang/lib/Frontend/FrontendAction.cpp
@@ -86,9 +86,14 @@ bool FrontendAction::beginSourceFile(CompilerInstance ,
 invoc.collectMacroDefinitions();
   }
 
-  // Enable CUDA Fortran if source file is *.cuf/*.CUF.
-  
invoc.getFortranOpts().features.Enable(Fortran::common::LanguageFeature::CUDA,
- getCurrentInput().getIsCUDAFortran());
+  if (!invoc.getFortranOpts().features.IsEnabled(
+  Fortran::common::LanguageFeature::CUDA)) {
+// Enable CUDA Fortran if source file is *.cuf/*.CUF and not already
+// enabled.
+invoc.getFortranOpts().features.Enable(
+Fortran::common::LanguageFeature::CUDA,
+getCurrentInput().getIsCUDAFortran());
+  }
 
   // Decide between fixed and free form (if the user didn't express any
   // preference, use the file extension to decide)
diff --git a/flang/test/Driver/cuda-option.f90 
b/flang/test/Driver/cuda-option.f90
new file mode 100644
index 00..7bd1b3ddbffc3c
--- /dev/null
+++ b/flang/test/Driver/cuda-option.f90
@@ -0,0 +1,13 @@
+! Test -fcuda option
+! RUN: %flang -fc1 -cpp -fcuda -fdebug-unparse %s -o - | FileCheck %s
+
+program main
+#if _CUDA
+  integer :: var = _CUDA
+#endif
+  integer, device :: dvar
+end program
+
+! CHECK-LABEL: PROGRAM main
+! CHECK: INTEGER :: var = 1
+! CHECK: INTEGER, DEVICE :: dvar
diff --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 44dbac44772b29..7b2e28263a825a 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -32,6 +32,7 @@
 ! CHECK-NEXT: -fbackslash Specify that backslash in string 
introduces an escape character
 ! CHECK-NEXT: -fcolor-diagnostics Enable colors in diagnostics
 ! CHECK-NEXT: -fconvert=   Set endian conversion of data for 
unformatted files
+! 

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-01 Thread Valentin Clement バレンタイン クレメン via cfe-commits

https://github.com/clementval approved this pull request.

Looks good to me from the OpenACC point of view. Someone from OpenMP should 
approve as well.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang] Enable polymorphic lowering by default (PR #83285)

2024-02-28 Thread Valentin Clement バレンタイン クレメン via cfe-commits

https://github.com/clementval approved this pull request.

Looks great! Thanks Jean to work on this!

https://github.com/llvm/llvm-project/pull/83285
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [clang] [flang]Add support for -moutline-atomics and -mno-outline-atomics (PR #78755)

2024-02-05 Thread Valentin Clement バレンタイン クレメン via cfe-commits

clementval wrote:

If you think this is the right fix then you should push it to solve the 
buildbots or revert the initial commit.

https://github.com/llvm/llvm-project/pull/78755
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [clang] [flang]Add support for -moutline-atomics and -mno-outline-atomics (PR #78755)

2024-02-05 Thread Valentin Clement バレンタイン クレメン via cfe-commits

clementval wrote:

This is breaking couple of arm buildbots. 

https://github.com/llvm/llvm-project/pull/78755
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [libc] [compiler-rt] [lldb] [clang-tools-extra] [libcxxabi] [libcxx] [llvm] [mlir][flang][openacc] Support device_type on loop construct (PR #76892)

2024-01-04 Thread Valentin Clement バレンタイン クレメン via cfe-commits

https://github.com/clementval closed 
https://github.com/llvm/llvm-project/pull/76892
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [llvm] [libcxx] [mlir] [flang] [libc] [libcxxabi] [clang-tools-extra] [clang] [compiler-rt] [mlir][flang][openacc] Support device_type on loop construct (PR #76892)

2024-01-04 Thread Valentin Clement バレンタイン クレメン via cfe-commits

https://github.com/clementval updated 
https://github.com/llvm/llvm-project/pull/76892

>From ee784de88ed77d406eefe9f4ea65e823bde53e2e Mon Sep 17 00:00:00 2001
From: Valentin Clement 
Date: Tue, 2 Jan 2024 16:08:02 -0800
Subject: [PATCH 1/2] [mlir][flang][openacc] Support device_type on loop
 construct

---
 flang/lib/Lower/OpenACC.cpp   | 183 +---
 flang/test/Lower/OpenACC/acc-kernels-loop.f90 |  36 +-
 flang/test/Lower/OpenACC/acc-loop.f90 |  41 +-
 .../test/Lower/OpenACC/acc-parallel-loop.f90  |  36 +-
 flang/test/Lower/OpenACC/acc-reduction.f90|   6 +-
 flang/test/Lower/OpenACC/acc-serial-loop.f90  |  36 +-
 .../mlir/Dialect/OpenACC/OpenACCOps.td| 150 +-
 mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp   | 438 ++
 mlir/test/Dialect/OpenACC/invalid.mlir|  57 ++-
 mlir/test/Dialect/OpenACC/ops.mlir|  80 ++--
 10 files changed, 747 insertions(+), 316 deletions(-)

diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index ecf70818c4ac0f..d8aedca90acf4b 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -1542,67 +1542,89 @@ createLoopOp(Fortran::lower::AbstractConverter 
,
  const Fortran::parser::AccClauseList ,
  bool needEarlyReturnHandling = false) {
   fir::FirOpBuilder  = converter.getFirOpBuilder();
-
-  mlir::Value workerNum;
-  mlir::Value vectorNum;
-  mlir::Value gangNum;
-  mlir::Value gangDim;
-  mlir::Value gangStatic;
   llvm::SmallVector tileOperands, privateOperands,
-  reductionOperands, cacheOperands;
+  reductionOperands, cacheOperands, vectorOperands, workerNumOperands,
+  gangOperands;
   llvm::SmallVector privatizations, reductionRecipes;
-  bool hasGang = false, hasVector = false, hasWorker = false;
+  llvm::SmallVector tileOperandsSegments, gangOperandsSegments;
+  llvm::SmallVector collapseValues;
+
+  llvm::SmallVector gangArgTypes;
+  llvm::SmallVector seqDeviceTypes, independentDeviceTypes,
+  autoDeviceTypes, vectorOperandsDeviceTypes, workerNumOperandsDeviceTypes,
+  vectorDeviceTypes, workerNumDeviceTypes, tileOperandsDeviceTypes,
+  collapseDeviceTypes, gangDeviceTypes, gangOperandsDeviceTypes;
+
+  // device_type attribute is set to `none` until a device_type clause is
+  // encountered.
+  auto crtDeviceTypeAttr = mlir::acc::DeviceTypeAttr::get(
+  builder.getContext(), mlir::acc::DeviceType::None);
 
   for (const Fortran::parser::AccClause  : accClauseList.v) {
 mlir::Location clauseLocation = converter.genLocation(clause.source);
 if (const auto *gangClause =
 std::get_if()) {
   if (gangClause->v) {
+auto crtGangOperands = gangOperands.size();
 const Fortran::parser::AccGangArgList  = *gangClause->v;
 for (const Fortran::parser::AccGangArg  : x.v) {
   if (const auto *num =
   std::get_if()) {
-gangNum = fir::getBase(converter.genExprValue(
-*Fortran::semantics::GetExpr(num->v), stmtCtx));
+gangOperands.push_back(fir::getBase(converter.genExprValue(
+*Fortran::semantics::GetExpr(num->v), stmtCtx)));
+gangArgTypes.push_back(mlir::acc::GangArgTypeAttr::get(
+builder.getContext(), mlir::acc::GangArgType::Num));
   } else if (const auto *staticArg =
  std::get_if(
  )) {
 const Fortran::parser::AccSizeExpr  = staticArg->v;
 if (sizeExpr.v) {
-  gangStatic = fir::getBase(converter.genExprValue(
-  *Fortran::semantics::GetExpr(*sizeExpr.v), stmtCtx));
+  gangOperands.push_back(fir::getBase(converter.genExprValue(
+  *Fortran::semantics::GetExpr(*sizeExpr.v), stmtCtx)));
 } else {
   // * was passed as value and will be represented as a special
   // constant.
-  gangStatic = builder.createIntegerConstant(
-  clauseLocation, builder.getIndexType(), starCst);
+  gangOperands.push_back(builder.createIntegerConstant(
+  clauseLocation, builder.getIndexType(), starCst));
 }
+gangArgTypes.push_back(mlir::acc::GangArgTypeAttr::get(
+builder.getContext(), mlir::acc::GangArgType::Static));
   } else if (const auto *dim =
  std::get_if(
  )) {
-gangDim = fir::getBase(converter.genExprValue(
-*Fortran::semantics::GetExpr(dim->v), stmtCtx));
+gangOperands.push_back(fir::getBase(converter.genExprValue(
+*Fortran::semantics::GetExpr(dim->v), stmtCtx)));
+gangArgTypes.push_back(mlir::acc::GangArgTypeAttr::get(
+builder.getContext(), mlir::acc::GangArgType::Dim));
   }
 }
+gangOperandsSegments.push_back(gangOperands.size() - 

[clang] [flang] [clang-tools-extra] [llvm] [flang][openacc/mp][NFC] Remove unused baseAddr argument (PR #75537)

2023-12-15 Thread Valentin Clement バレンタイン クレメン via cfe-commits

https://github.com/clementval closed 
https://github.com/llvm/llvm-project/pull/75537
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang-tools-extra] [flang] [flang][openacc/mp][NFC] Remove unused baseAddr argument (PR #75537)

2023-12-15 Thread Valentin Clement バレンタイン クレメン via cfe-commits

https://github.com/clementval updated 
https://github.com/llvm/llvm-project/pull/75537

>From ae0e461d8c9c013d7d3c2d16d811df6b30e66abd Mon Sep 17 00:00:00 2001
From: Valentin Clement 
Date: Thu, 14 Dec 2023 13:58:33 -0800
Subject: [PATCH] [flang][openacc/mp][NFC] Remove unused baseAddr argument

---
 flang/lib/Lower/DirectivesCommon.h | 6 +++---
 flang/lib/Lower/OpenMP.cpp | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Lower/DirectivesCommon.h 
b/flang/lib/Lower/DirectivesCommon.h
index 88a8916663df75..5168fb902df923 100644
--- a/flang/lib/Lower/DirectivesCommon.h
+++ b/flang/lib/Lower/DirectivesCommon.h
@@ -666,7 +666,7 @@ template 
 llvm::SmallVector
 genBaseBoundsOps(fir::FirOpBuilder , mlir::Location loc,
  Fortran::lower::AbstractConverter ,
- fir::ExtendedValue dataExv, mlir::Value baseAddr) {
+ fir::ExtendedValue dataExv) {
   mlir::Type idxTy = builder.getIndexType();
   mlir::Type boundTy = builder.getType();
   llvm::SmallVector bounds;
@@ -899,7 +899,7 @@ mlir::Value gatherDataOperandAddrAndBounds(
 if (fir::unwrapRefType(baseAddr.getType())
 .isa())
   bounds = genBaseBoundsOps(
-  builder, operandLocation, converter, compExv, baseAddr);
+  builder, operandLocation, converter, compExv);
 asFortran << (*expr).AsFortran();
 
 if (auto loadOp = mlir::dyn_cast_or_null(
@@ -949,7 +949,7 @@ mlir::Value gatherDataOperandAddrAndBounds(
   if (fir::unwrapRefType(baseAddr.getType())
   .isa())
 bounds = genBaseBoundsOps(
-builder, operandLocation, converter, dataExv, 
baseAddr);
+builder, operandLocation, converter, dataExv);
   asFortran << name.ToString();
 } else { // Unsupported
   llvm::report_fatal_error(
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index eeba87fcd15116..7ad644f55f5076 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -2671,7 +2671,7 @@ genTargetOp(Fortran::lower::AbstractConverter ,
   bounds = Fortran::lower::genBaseBoundsOps(
   converter.getFirOpBuilder(), converter.getCurrentLocation(),
-  converter, dataExv, baseAddr);
+  converter, dataExv);
 
 llvm::omp::OpenMPOffloadMappingFlags mapFlag =
 llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_IMPLICIT;

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


[flang] [llvm] [clang] [mlir] [libc] [flang] Fold MATMUL() (PR #72176)

2023-11-14 Thread Valentin Clement バレンタイン クレメン via cfe-commits

https://github.com/clementval approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/72176
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang][openacc] Support assumed shape array in firstprivate recipe (PR #68640)

2023-10-10 Thread Valentin Clement バレンタイン クレメン via cfe-commits

https://github.com/clementval updated 
https://github.com/llvm/llvm-project/pull/68640

>From 8459381299602a80b26ea44b5d099f59b0169ba3 Mon Sep 17 00:00:00 2001
From: Valentin Clement 
Date: Mon, 9 Oct 2023 15:00:12 -0700
Subject: [PATCH] [flang][openacc] Support assumed shape array in firstprivate
 recipe

---
 flang/include/flang/Lower/OpenACC.h   |   8 +-
 flang/lib/Lower/OpenACC.cpp   | 280 +++---
 .../test/Lower/OpenACC/acc-parallel-loop.f90  |   4 +-
 flang/test/Lower/OpenACC/acc-parallel.f90 |   4 +-
 flang/test/Lower/OpenACC/acc-private.f90  |  64 +++-
 flang/test/Lower/OpenACC/acc-serial-loop.f90  |   4 +-
 flang/test/Lower/OpenACC/acc-serial.f90   |   4 +-
 mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp   |   2 +-
 8 files changed, 246 insertions(+), 124 deletions(-)

diff --git a/flang/include/flang/Lower/OpenACC.h 
b/flang/include/flang/Lower/OpenACC.h
index b342e4a4704dab1..c73af0a6eb0f874 100644
--- a/flang/include/flang/Lower/OpenACC.h
+++ b/flang/include/flang/Lower/OpenACC.h
@@ -90,10 +90,10 @@ createOrGetReductionRecipe(fir::FirOpBuilder &, 
llvm::StringRef, mlir::Location,
 
 /// Get a acc.firstprivate.recipe op for the given type or create it if it does
 /// not exist yet.
-mlir::acc::FirstprivateRecipeOp createOrGetFirstprivateRecipe(mlir::OpBuilder 
&,
-  llvm::StringRef,
-  mlir::Location,
-  mlir::Type);
+mlir::acc::FirstprivateRecipeOp
+createOrGetFirstprivateRecipe(mlir::OpBuilder &, llvm::StringRef,
+  mlir::Location, mlir::Type,
+  llvm::SmallVector &);
 
 void attachDeclarePostAllocAction(AbstractConverter &, fir::FirOpBuilder &,
   const Fortran::semantics::Symbol &);
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 3d3fcce44c529fe..de551c36c9dc9d5 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -427,9 +427,78 @@ Fortran::lower::createOrGetPrivateRecipe(mlir::OpBuilder 
,
   return recipe;
 }
 
+/// Check if the DataBoundsOp is a constant bound (lb and ub are constants or
+/// extent is a constant).
+bool isConstantBound(mlir::acc::DataBoundsOp ) {
+  if (op.getLowerbound() && fir::getIntIfConstant(op.getLowerbound()) &&
+  op.getUpperbound() && fir::getIntIfConstant(op.getUpperbound()))
+return true;
+  if (op.getExtent() && fir::getIntIfConstant(op.getExtent()))
+return true;
+  return false;
+}
+
+/// Return true iff all the bounds are expressed with constant values.
+bool areAllBoundConstant(llvm::SmallVector ) {
+  for (auto bound : bounds) {
+auto dataBound =
+mlir::dyn_cast(bound.getDefiningOp());
+assert(dataBound && "Must be DataBoundOp operation");
+if (!isConstantBound(dataBound))
+  return false;
+  }
+  return true;
+}
+
+static fir::ShapeOp
+genShapeFromBounds(mlir::Location loc, fir::FirOpBuilder ,
+   const llvm::SmallVector ) {
+  assert(args.size() % 3 == 0 && "Triplets must be a multiple of 3");
+  llvm::SmallVector extents;
+  mlir::Type idxTy = builder.getIndexType();
+  mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1);
+  mlir::Value zero = builder.createIntegerConstant(loc, idxTy, 0);
+  for (unsigned i = 0; i < args.size(); i += 3) {
+mlir::Value s1 =
+builder.create(loc, args[i + 1], args[0]);
+mlir::Value s2 = builder.create(loc, s1, one);
+mlir::Value s3 = builder.create(loc, s2, args[i + 
2]);
+mlir::Value cmp = builder.create(
+loc, mlir::arith::CmpIPredicate::sgt, s3, zero);
+mlir::Value ext = builder.create(loc, cmp, s3, 
zero);
+extents.push_back(ext);
+  }
+  return builder.create(loc, extents);
+}
+
+static llvm::SmallVector
+genConstantBounds(fir::FirOpBuilder , mlir::Location loc,
+  mlir::acc::DataBoundsOp ) {
+  mlir::Type idxTy = builder.getIndexType();
+  mlir::Value lb, ub, step;
+  if (dataBound.getLowerbound() &&
+  fir::getIntIfConstant(dataBound.getLowerbound()) &&
+  dataBound.getUpperbound() &&
+  fir::getIntIfConstant(dataBound.getUpperbound())) {
+lb = builder.createIntegerConstant(
+loc, idxTy, *fir::getIntIfConstant(dataBound.getLowerbound()));
+ub = builder.createIntegerConstant(
+loc, idxTy, *fir::getIntIfConstant(dataBound.getUpperbound()));
+step = builder.createIntegerConstant(loc, idxTy, 1);
+  } else if (dataBound.getExtent()) {
+lb = builder.createIntegerConstant(loc, idxTy, 0);
+ub = builder.createIntegerConstant(
+loc, idxTy, *fir::getIntIfConstant(dataBound.getExtent()) - 1);
+step = builder.createIntegerConstant(loc, idxTy, 1);
+  } else {
+llvm::report_fatal_error("Expect constant lb/ub or extent");
+  }
+  return {lb, ub, step};
+}
+
 mlir::acc::FirstprivateRecipeOp