[flang] [libc] [mlir] [llvm] [compiler-rt] [lldb] [clang-tools-extra] [libcxxabi] [libcxx] [clang] [mlir][flang][openacc] Support device_type on loop construct (PR #76892)
https://github.com/razvanlupusoru approved this pull request. Looks great to me! Thank you! 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
[clang] [flang][openacc] Enable lowering support for OpenACC atomic operations (PR #65776)
https://github.com/razvanlupusoru updated https://github.com/llvm/llvm-project/pull/65776: >From 967089f4e81d5bfcddeabddf81ab90912b5cc3b3 Mon Sep 17 00:00:00 2001 From: Razvan Lupusoru Date: Fri, 8 Sep 2023 09:06:57 -0700 Subject: [PATCH 1/4] [flang][openacc] Enable lowering support for OpenACC atomic operations Since the OpenACC atomics specification is a subset of OpenMP atomics, the same lowering implementation can be used. This change extracts out the necessary pieces from the OpenMP lowering and puts them in a shared spot. The shared spot is a header file so that each implementation can template specialize directly. After putting the OpenMP implementation in a common spot, the following changes were needed to make it work for OpenACC: * Ensure parsing works correctly by avoiding hardcoded offsets. * Templatize based on atomic type. * The checking whether it is OpenMP or OpenACC is done by checking for OmpAtomicClauseList (OpenACC does not implement this so we just templatize with void). It was preferable to check this instead of atomic type because in some cases, like atomic capture, the read/write/update implementations are called - and we want compile time evaluation of these conditional parts. * The memory order and hint are used only for OpenMP. * Generate acc dialect operations instead of omp dialect operations. --- flang/lib/Lower/Bridge.cpp| 2 + flang/lib/Lower/DirectivesCommon.h| 610 ++ flang/lib/Lower/OpenACC.cpp | 34 +- flang/lib/Lower/OpenMP.cpp| 523 +-- .../test/Lower/OpenACC/acc-atomic-capture.f90 | 99 +++ flang/test/Lower/OpenACC/acc-atomic-read.f90 | 48 ++ .../Lower/OpenACC/acc-atomic-update-hlfir.f90 | 23 + .../test/Lower/OpenACC/acc-atomic-update.f90 | 74 +++ flang/test/Lower/OpenACC/acc-atomic-write.f90 | 57 ++ 9 files changed, 979 insertions(+), 491 deletions(-) create mode 100644 flang/lib/Lower/DirectivesCommon.h create mode 100644 flang/test/Lower/OpenACC/acc-atomic-capture.f90 create mode 100644 flang/test/Lower/OpenACC/acc-atomic-read.f90 create mode 100644 flang/test/Lower/OpenACC/acc-atomic-update-hlfir.f90 create mode 100644 flang/test/Lower/OpenACC/acc-atomic-update.f90 create mode 100644 flang/test/Lower/OpenACC/acc-atomic-write.f90 diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp index 75784f4e5a72be2..cbe108194dd212f 100644 --- a/flang/lib/Lower/Bridge.cpp +++ b/flang/lib/Lower/Bridge.cpp @@ -2287,9 +2287,11 @@ class FirConverter : public Fortran::lower::AbstractConverter { void genFIR(const Fortran::parser::OpenACCConstruct &acc) { mlir::OpBuilder::InsertPoint insertPt = builder->saveInsertionPoint(); +localSymbols.pushScope(); genOpenACCConstruct(*this, bridge.getSemanticsContext(), getEval(), acc); for (Fortran::lower::pft::Evaluation &e : getEval().getNestedEvaluations()) genFIR(e); +localSymbols.popScope(); builder->restoreInsertionPoint(insertPt); } diff --git a/flang/lib/Lower/DirectivesCommon.h b/flang/lib/Lower/DirectivesCommon.h new file mode 100644 index 000..7177576e039a219 --- /dev/null +++ b/flang/lib/Lower/DirectivesCommon.h @@ -0,0 +1,610 @@ +//===-- Lower/DirectivesCommon.h *- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/ +// +//===--===// +/// +/// A location to place directive utilities shared across multiple lowering +/// files, e.g. utilities shared in OpenMP and OpenACC. The header file can +/// be used for both declarations and templated/inline implementations. +//===--===// + +#ifndef FORTRAN_LOWER_DIRECTIVES_COMMON_H +#define FORTRAN_LOWER_DIRECTIVES_COMMON_H + +#include "flang/Common/idioms.h" +#include "flang/Lower/Bridge.h" +#include "flang/Lower/ConvertExpr.h" +#include "flang/Lower/ConvertVariable.h" +#include "flang/Lower/OpenACC.h" +#include "flang/Lower/OpenMP.h" +#include "flang/Lower/PFTBuilder.h" +#include "flang/Lower/StatementContext.h" +#include "flang/Optimizer/Builder/BoxValue.h" +#include "flang/Optimizer/Builder/FIRBuilder.h" +#include "flang/Optimizer/Builder/Todo.h" +#include "flang/Optimizer/HLFIR/HLFIROps.h" +#include "flang/Parser/parse-tree.h" +#include "flang/Semantics/openmp-directive-sets.h" +#include "flang/Semantics/tools.h" +#include "mlir/Dialect/OpenACC/OpenACC.h" +#include "mlir/Dialect/OpenMP/OpenMPDialect.h" +#include "mlir/Dialect/SCF/IR/SCF.h" +#include "llvm/Frontend/OpenMP/OMPConstants.h" +#inc
[clang-tools-extra] [flang][openacc] Enable lowering support for OpenACC atomic operations (PR #65776)
https://github.com/razvanlupusoru updated https://github.com/llvm/llvm-project/pull/65776: >From 967089f4e81d5bfcddeabddf81ab90912b5cc3b3 Mon Sep 17 00:00:00 2001 From: Razvan Lupusoru Date: Fri, 8 Sep 2023 09:06:57 -0700 Subject: [PATCH 1/4] [flang][openacc] Enable lowering support for OpenACC atomic operations Since the OpenACC atomics specification is a subset of OpenMP atomics, the same lowering implementation can be used. This change extracts out the necessary pieces from the OpenMP lowering and puts them in a shared spot. The shared spot is a header file so that each implementation can template specialize directly. After putting the OpenMP implementation in a common spot, the following changes were needed to make it work for OpenACC: * Ensure parsing works correctly by avoiding hardcoded offsets. * Templatize based on atomic type. * The checking whether it is OpenMP or OpenACC is done by checking for OmpAtomicClauseList (OpenACC does not implement this so we just templatize with void). It was preferable to check this instead of atomic type because in some cases, like atomic capture, the read/write/update implementations are called - and we want compile time evaluation of these conditional parts. * The memory order and hint are used only for OpenMP. * Generate acc dialect operations instead of omp dialect operations. --- flang/lib/Lower/Bridge.cpp| 2 + flang/lib/Lower/DirectivesCommon.h| 610 ++ flang/lib/Lower/OpenACC.cpp | 34 +- flang/lib/Lower/OpenMP.cpp| 523 +-- .../test/Lower/OpenACC/acc-atomic-capture.f90 | 99 +++ flang/test/Lower/OpenACC/acc-atomic-read.f90 | 48 ++ .../Lower/OpenACC/acc-atomic-update-hlfir.f90 | 23 + .../test/Lower/OpenACC/acc-atomic-update.f90 | 74 +++ flang/test/Lower/OpenACC/acc-atomic-write.f90 | 57 ++ 9 files changed, 979 insertions(+), 491 deletions(-) create mode 100644 flang/lib/Lower/DirectivesCommon.h create mode 100644 flang/test/Lower/OpenACC/acc-atomic-capture.f90 create mode 100644 flang/test/Lower/OpenACC/acc-atomic-read.f90 create mode 100644 flang/test/Lower/OpenACC/acc-atomic-update-hlfir.f90 create mode 100644 flang/test/Lower/OpenACC/acc-atomic-update.f90 create mode 100644 flang/test/Lower/OpenACC/acc-atomic-write.f90 diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp index 75784f4e5a72be2..cbe108194dd212f 100644 --- a/flang/lib/Lower/Bridge.cpp +++ b/flang/lib/Lower/Bridge.cpp @@ -2287,9 +2287,11 @@ class FirConverter : public Fortran::lower::AbstractConverter { void genFIR(const Fortran::parser::OpenACCConstruct &acc) { mlir::OpBuilder::InsertPoint insertPt = builder->saveInsertionPoint(); +localSymbols.pushScope(); genOpenACCConstruct(*this, bridge.getSemanticsContext(), getEval(), acc); for (Fortran::lower::pft::Evaluation &e : getEval().getNestedEvaluations()) genFIR(e); +localSymbols.popScope(); builder->restoreInsertionPoint(insertPt); } diff --git a/flang/lib/Lower/DirectivesCommon.h b/flang/lib/Lower/DirectivesCommon.h new file mode 100644 index 000..7177576e039a219 --- /dev/null +++ b/flang/lib/Lower/DirectivesCommon.h @@ -0,0 +1,610 @@ +//===-- Lower/DirectivesCommon.h *- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/ +// +//===--===// +/// +/// A location to place directive utilities shared across multiple lowering +/// files, e.g. utilities shared in OpenMP and OpenACC. The header file can +/// be used for both declarations and templated/inline implementations. +//===--===// + +#ifndef FORTRAN_LOWER_DIRECTIVES_COMMON_H +#define FORTRAN_LOWER_DIRECTIVES_COMMON_H + +#include "flang/Common/idioms.h" +#include "flang/Lower/Bridge.h" +#include "flang/Lower/ConvertExpr.h" +#include "flang/Lower/ConvertVariable.h" +#include "flang/Lower/OpenACC.h" +#include "flang/Lower/OpenMP.h" +#include "flang/Lower/PFTBuilder.h" +#include "flang/Lower/StatementContext.h" +#include "flang/Optimizer/Builder/BoxValue.h" +#include "flang/Optimizer/Builder/FIRBuilder.h" +#include "flang/Optimizer/Builder/Todo.h" +#include "flang/Optimizer/HLFIR/HLFIROps.h" +#include "flang/Parser/parse-tree.h" +#include "flang/Semantics/openmp-directive-sets.h" +#include "flang/Semantics/tools.h" +#include "mlir/Dialect/OpenACC/OpenACC.h" +#include "mlir/Dialect/OpenMP/OpenMPDialect.h" +#include "mlir/Dialect/SCF/IR/SCF.h" +#include "llvm/Frontend/OpenMP/OMPConstants.h" +#inc
[clang] [OpenACC][CIR] Start work to lower 'loop' (PR #137972)
https://github.com/razvanlupusoru edited https://github.com/llvm/llvm-project/pull/137972 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC][CIR] Start work to lower 'loop' (PR #137972)
@@ -13,17 +13,103 @@ #include "CIRGenBuilder.h" #include "CIRGenFunction.h" #include "CIRGenOpenACCClause.h" -#include "mlir/Dialect/OpenACC/OpenACC.h" + #include "clang/AST/OpenACCClause.h" #include "clang/AST/StmtOpenACC.h" +#include "mlir/Dialect/OpenACC/OpenACC.h" + using namespace clang; using namespace clang::CIRGen; using namespace cir; using namespace mlir::acc; mlir::LogicalResult CIRGenFunction::emitOpenACCLoopConstruct(const OpenACCLoopConstruct &s) { - cgm.errorNYI(s.getSourceRange(), "OpenACC Loop Construct"); - return mlir::failure(); + mlir::Location start = getLoc(s.getSourceRange().getBegin()); + mlir::Location end = getLoc(s.getSourceRange().getEnd()); + llvm::SmallVector retTy; + llvm::SmallVector operands; + auto op = builder.create(start, retTy, operands); + + // TODO(OpenACC): In the future we are going to need to come up with a + // transformation here that can teach the acc.loop how to figure out the + // 'lowerbound', 'upperbound', and 'step'. + // + // -'upperbound' should fortunately be pretty easy as it should be + // in the initialization section of the cir.for loop. In Sema, we limit to + // just the forms 'Var = init', `Type Var = init`, or `Var = init` (where it + // is an operator= call)`. However, as those are all necessary to emit for + // the init section of the for loop, they should be inside the initial + // cir.scope. + // + // -'upperbound' should be somewhat easy to determine. Sema is limiting this + // to: ==, <, >, !=, <=, >= builtin operators, the overloaded 'comparison' + // operations, and member-call expressions. + // + // For the builtin comparison operators, we can pretty well deduce based on + // the comparison what the 'end' object is going to be, and the inclusive + // nature of it. + // + // For the overloaded operators, Sema will ensure that at least one side of + // the operator is the init variable, so we can deduce the comparison there + // too. The standard places no real bounds on WHAT the comparison operators do + // for a `RandomAccessIterator` however, so we'll have to just 'assume' they + // do the right thing? Note that this might be incrementing by a different + // 'object', not an integral, so it isn't really clear to me what we can do to + // determine the other side. + // + // Member-call expressions are the difficult ones. I don't think there is + // anything we can deduce from this to determine the 'end', so we might end up + // having to go back to Sema and make this ill-formed. + // + // HOWEVER: What ACC dialect REALLY cares about is the tripcount, which you + // cannot get (in the case of `RandomAccessIterator`) from JUST 'upperbound' + // and 'lowerbound'. We will likely have to provide a 'recipe' equivilent to + // `std::distance` instead. In the case of integer/pointers, it is fairly + // simple to find: it is just the mathematical subtraction. Howver, in the + // case of `RandomAccessIterator`, we have to enable the use of `operator-`. + // FORTUNATELY the standard requires this to work correctly for + // `RandomAccessIterator`, so we don't have to implement a `std::distance` + // that loops through, like we would for a forward/etc iterator. + // + // 'step': Sema is currently allowing builtin ++,--, +=, -=, *=, /=, and = + // operators. Additionally, it allows the equivilent for the operator-call, as razvanlupusoru wrote: equivilent -> equivalent https://github.com/llvm/llvm-project/pull/137972 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC][CIR] Start work to lower 'loop' (PR #137972)
https://github.com/razvanlupusoru approved this pull request. Thank you Erich! Your prose on possibilities and challenges is a great idea for inclusion. https://github.com/llvm/llvm-project/pull/137972 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC][CIR] Start work to lower 'loop' (PR #137972)
@@ -13,17 +13,103 @@ #include "CIRGenBuilder.h" #include "CIRGenFunction.h" #include "CIRGenOpenACCClause.h" -#include "mlir/Dialect/OpenACC/OpenACC.h" + #include "clang/AST/OpenACCClause.h" #include "clang/AST/StmtOpenACC.h" +#include "mlir/Dialect/OpenACC/OpenACC.h" + using namespace clang; using namespace clang::CIRGen; using namespace cir; using namespace mlir::acc; mlir::LogicalResult CIRGenFunction::emitOpenACCLoopConstruct(const OpenACCLoopConstruct &s) { - cgm.errorNYI(s.getSourceRange(), "OpenACC Loop Construct"); - return mlir::failure(); + mlir::Location start = getLoc(s.getSourceRange().getBegin()); + mlir::Location end = getLoc(s.getSourceRange().getEnd()); + llvm::SmallVector retTy; + llvm::SmallVector operands; + auto op = builder.create(start, retTy, operands); + + // TODO(OpenACC): In the future we are going to need to come up with a + // transformation here that can teach the acc.loop how to figure out the + // 'lowerbound', 'upperbound', and 'step'. + // + // -'upperbound' should fortunately be pretty easy as it should be + // in the initialization section of the cir.for loop. In Sema, we limit to + // just the forms 'Var = init', `Type Var = init`, or `Var = init` (where it + // is an operator= call)`. However, as those are all necessary to emit for + // the init section of the for loop, they should be inside the initial + // cir.scope. + // + // -'upperbound' should be somewhat easy to determine. Sema is limiting this + // to: ==, <, >, !=, <=, >= builtin operators, the overloaded 'comparison' + // operations, and member-call expressions. + // + // For the builtin comparison operators, we can pretty well deduce based on + // the comparison what the 'end' object is going to be, and the inclusive + // nature of it. + // + // For the overloaded operators, Sema will ensure that at least one side of + // the operator is the init variable, so we can deduce the comparison there + // too. The standard places no real bounds on WHAT the comparison operators do + // for a `RandomAccessIterator` however, so we'll have to just 'assume' they + // do the right thing? Note that this might be incrementing by a different + // 'object', not an integral, so it isn't really clear to me what we can do to + // determine the other side. + // + // Member-call expressions are the difficult ones. I don't think there is + // anything we can deduce from this to determine the 'end', so we might end up + // having to go back to Sema and make this ill-formed. + // + // HOWEVER: What ACC dialect REALLY cares about is the tripcount, which you + // cannot get (in the case of `RandomAccessIterator`) from JUST 'upperbound' + // and 'lowerbound'. We will likely have to provide a 'recipe' equivilent to + // `std::distance` instead. In the case of integer/pointers, it is fairly + // simple to find: it is just the mathematical subtraction. Howver, in the + // case of `RandomAccessIterator`, we have to enable the use of `operator-`. + // FORTUNATELY the standard requires this to work correctly for + // `RandomAccessIterator`, so we don't have to implement a `std::distance` + // that loops through, like we would for a forward/etc iterator. + // + // 'step': Sema is currently allowing builtin ++,--, +=, -=, *=, /=, and = + // operators. Additionally, it allows the equivilent for the operator-call, as + // well as member-call. + // + // For builtin operators, we perhaps should refine the assignment here. It + // doesn't reallly help us know the 'step' count at all, but we could perhaps razvanlupusoru wrote: reallly -> really https://github.com/llvm/llvm-project/pull/137972 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir] [OpenACC][CIR] Implement Loop lowering of seq/auto/independent (PR #138164)
https://github.com/razvanlupusoru approved this pull request. Awesome. Thank you for continuing to contribute the builders to the dialect. https://github.com/llvm/llvm-project/pull/138164 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir] [OpenACC] Implement tile/collapse lowering (PR #138576)
https://github.com/razvanlupusoru approved this pull request. Thank you. LGTM https://github.com/llvm/llvm-project/pull/138576 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir] [OpenACC] Implement tile/collapse lowering (PR #138576)
@@ -336,6 +348,52 @@ class OpenACCClauseCIREmitter final return clauseNotImplemented(clause); } } + + void VisitCollapseClause(const OpenACCCollapseClause &clause) { +if constexpr (isOneOfTypes) { + llvm::APInt value = + clause.getIntExpr()->EvaluateKnownConstInt(cgf.cgm.getASTContext()); + + if (value.getBitWidth() != 64) +value = value.sext(64); razvanlupusoru wrote: The OpenACC spec does not provide exact clarification on what "integer expression" is - except in one spot in the spec: ``` 5348 Async-argument – an async-argument is a nonnegative scalar integer expression (int for C or C++, integer for Fortran) ``` It seems the intent is that they are 32-bit integers. https://github.com/llvm/llvm-project/pull/138576 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir] [OpenACC] Implement tile/collapse lowering (PR #138576)
https://github.com/razvanlupusoru edited https://github.com/llvm/llvm-project/pull/138576 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir] [NFC][OpenACC] addDeviceType to init/shutdown ops (PR #137372)
https://github.com/razvanlupusoru approved this pull request. Thank you! I am happy to see this improvement! https://github.com/llvm/llvm-project/pull/137372 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir] [mlir][acc] Use consistent name for device_num operand (PR #136745)
razvanlupusoru wrote: > Also, we have `getIfCondMutable` in a number of places as well, which is now > inconsistent with skipping the 'operand'. I am not sure I follow - are you saying that for consistency, you think that the word 'operand' should be included in the name of `ifCond` (or excluded for other cases)? We do have multiple cases where we do not use the word 'operand' - for example in acc.parallel we have numGangs, numWorkers, vectorLength, selfCond, ifCond. It is used in cases where it looks awkward to not have it. For example `asyncOperands` and `waitOperands`. This is subjective though :) https://github.com/llvm/llvm-project/pull/136745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir] [mlir][acc] Use consistent name for device_num operand (PR #136745)
razvanlupusoru wrote: I plan on merging this as soon as the 2 pending checks complete :) https://github.com/llvm/llvm-project/pull/136745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir] [OpenACC][NFCI] Implement 'helpers' for all of the clauses I've used so far (PR #137396)
https://github.com/razvanlupusoru approved this pull request. Thank you so much for doing this! https://github.com/llvm/llvm-project/pull/137396 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC][CIR] Implement basic lowering for combined constructs (PR #139119)
https://github.com/razvanlupusoru approved this pull request. Thank you! https://github.com/llvm/llvm-project/pull/139119 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC][CIR] Implement basic lowering for combined constructs (PR #139119)
razvanlupusoru wrote: > in that they are the only one where there are two operations for a single > construct. https://mlir.llvm.org/docs/Dialects/OpenACCDialect/#operation-categories There are other categories where a single construct leads to multiple operations. See description at the link above about the "second group". I should add combined constructs to that list. https://github.com/llvm/llvm-project/pull/139119 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir] [OpenACC][CIR] Implement 'gang' lowering for 'loop' (PR #138968)
https://github.com/razvanlupusoru approved this pull request. Nice work! https://github.com/llvm/llvm-project/pull/138968 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir] [OpenACC][CIR] Implement copyin/copyout/create lowering for compute/c… (PR #145976)
https://github.com/razvanlupusoru approved this pull request. Thank you! https://github.com/llvm/llvm-project/pull/145976 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC][Sema] Implement warning for non-effective 'private' (PR #149004)
https://github.com/razvanlupusoru approved this pull request. The private variable requirements look correct to me! Thank you! https://github.com/llvm/llvm-project/pull/149004 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir] [OpenACC][CIR] Implement enter-data + clause lowering (PR #146146)
https://github.com/razvanlupusoru approved this pull request. Nice work! And I keep appreciating the dialect changes to improve its verification and construction! https://github.com/llvm/llvm-project/pull/146146 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir] [OpenACC][CIR] Implement enter-data + clause lowering (PR #146146)
https://github.com/razvanlupusoru edited https://github.com/llvm/llvm-project/pull/146146 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir] [OpenACC][CIR] Implement enter-data + clause lowering (PR #146146)
@@ -572,8 +593,8 @@ class OpenACCClauseCIREmitter final applyToComputeOp(clause); } else { // TODO: When we've implemented this for everything, switch this to an - // unreachable. Combined constructs remain. Data, enter data, exit data, - // update constructs remain. + // unreachable. Combined constructs remain. Exit data,update constructs razvanlupusoru wrote: nit: missing space https://github.com/llvm/llvm-project/pull/146146 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add PointerLikeType interface support for cir::PointerType (PR #139768)
https://github.com/razvanlupusoru approved this pull request. Thank you! Nice work! https://github.com/llvm/llvm-project/pull/139768 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add PointerLikeType interface support for cir::PointerType (PR #139768)
@@ -0,0 +1,364 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Unit tests for CIR implementation of OpenACC's PointertLikeType interface +// +//===--===// + +#include "mlir/Dialect/OpenACC/OpenACC.h" +#include "mlir/IR/BuiltinTypes.h" +#include "mlir/IR/Diagnostics.h" +#include "mlir/IR/MLIRContext.h" +#include "mlir/IR/Value.h" +#include "clang/CIR/Dialect/Builder/CIRBaseBuilder.h" +#include "clang/CIR/Dialect/IR/CIRDialect.h" +#include "clang/CIR/Dialect/IR/CIRTypes.h" +#include "clang/CIR/Dialect/OpenACC/CIROpenACCTypeInterfaces.h" +#include "clang/CIR/Dialect/OpenACC/RegisterOpenACCExtensions.h" +#include "gtest/gtest.h" + +using namespace mlir; +using namespace cir; + +//===--===// +// Test Fixture +//===--===// + +class CIROpenACCPointerLikeTest : public ::testing::Test { +protected: + CIROpenACCPointerLikeTest() : b(&context), loc(UnknownLoc::get(&context)) { +context.loadDialect(); +context.loadDialect(); + +// Register extension to integrate CIR types with OpenACC. +mlir::DialectRegistry registry; +cir::acc::registerOpenACCExtensions(registry); +context.appendDialectRegistry(registry); + } + + MLIRContext context; + OpBuilder b; + Location loc; + llvm::StringMap recordNames; + + mlir::IntegerAttr getAlignOne(mlir::MLIRContext *ctx) { +// Note that mlir::IntegerType is used instead of cir::IntType here +// because we don't need sign information for this to be useful, so keep +// it simple. +clang::CharUnits align = clang::CharUnits::One(); +return mlir::IntegerAttr::get(mlir::IntegerType::get(ctx, 64), + align.getQuantity()); + } + + mlir::StringAttr getUniqueRecordName(const std::string &baseName) { +auto it = recordNames.find(baseName); +if (it == recordNames.end()) { + recordNames[baseName] = 0; + return b.getStringAttr(baseName); +} + +return b.getStringAttr(baseName + "." + + std::to_string(recordNames[baseName]++)); + } + + // General handler for types without a specific test + void testSingleType(mlir::Type ty, + mlir::acc::VariableTypeCategory expectedTypeCategory) { +mlir::Type ptrTy = cir::PointerType::get(ty); + +// cir::PointerType should be castable to acc::PointerLikeType +auto pltTy = dyn_cast_if_present(ptrTy); +ASSERT_NE(pltTy, nullptr); + +EXPECT_EQ(pltTy.getElementType(), ty); + +OwningOpRef varPtrOp = +b.create(loc, ptrTy, ty, "", getAlignOne(&context)); + +mlir::Value val = varPtrOp.get(); +mlir::acc::VariableTypeCategory typeCategory = pltTy.getPointeeTypeCategory( +cast>(val), +mlir::acc::getVarType(varPtrOp.get())); + +EXPECT_EQ(typeCategory, expectedTypeCategory); + } + + void testScalarType(mlir::Type ty) { +testSingleType(ty, mlir::acc::VariableTypeCategory::scalar); + } + + void testNonScalarType(mlir::Type ty) { +testSingleType(ty, mlir::acc::VariableTypeCategory::nonscalar); + } + + void testUncategorizedType(mlir::Type ty) { +testSingleType(ty, mlir::acc::VariableTypeCategory::uncategorized); + } + + void testArrayType(mlir::Type ty) { +// Build the array pointer type. +mlir::Type arrTy = cir::ArrayType::get(ty, 10); +mlir::Type ptrTy = cir::PointerType::get(arrTy); + +// Verify that the pointer points to the array type.. +auto pltTy = dyn_cast_if_present(ptrTy); +ASSERT_NE(pltTy, nullptr); +EXPECT_EQ(pltTy.getElementType(), arrTy); + +// Create an alloca for the array +OwningOpRef varPtrOp = +b.create(loc, ptrTy, arrTy, "", getAlignOne(&context)); + +// Verify that the type category is array. +mlir::Value val = varPtrOp.get(); +mlir::acc::VariableTypeCategory typeCategory = pltTy.getPointeeTypeCategory( +cast>(val), +mlir::acc::getVarType(varPtrOp.get())); +EXPECT_EQ(typeCategory, mlir::acc::VariableTypeCategory::array); + +// Create an array-to-pointer decay cast. +mlir::Type ptrToElemTy = cir::PointerType::get(ty); +OwningOpRef decayPtr = b.create( +loc, ptrToElemTy, cir::CastKind::array_to_ptrdecay, val); +mlir::Value decayVal = decayPtr.get(); + +// Verify that we still get the expected element type. +auto decayPltTy = +dyn_cast_if_present(decayVal.getType()); +ASSERT_NE(decayPltTy, nullptr); +EXPECT_EQ(decayPltTy.getElementType(), ty); + +// Veri
[clang] [OpenACC][CIR] Add lowering for 'copy' array indexes (PR #140971)
https://github.com/razvanlupusoru approved this pull request. Nice work! https://github.com/llvm/llvm-project/pull/140971 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC][CIR] Add lowering for 'copy' array indexes (PR #140971)
@@ -184,37 +189,94 @@ class OpenACCClauseCIREmitter final mlir::Location beginLoc; mlir::Value varValue; llvm::StringRef name; +llvm::SmallVector bounds; }; + mlir::Value createBound(mlir::Location boundLoc, mlir::Value lowerBound, + mlir::Value upperBound, mlir::Value extent) { +// Arrays always have a start-idx of 0. +mlir::Value startIdx = createConstantInt(boundLoc, 64, 0); +// TODO: OpenACC: It isn't clear that stride would ever be anything other +// than '1'? We emit the type of the reference 'correctly' as far as I razvanlupusoru wrote: I think it is OK to remove the TODO here. I agree both with the choice to have stride as '1' and not specified in bytes. The acc dialect permits non-1 stride because not all languages have contiguous arrays. And in particular, I imagine if CIR allowed native representation of non-contiguous array views - taking advantage of this functionality would be necessary. https://github.com/llvm/llvm-project/pull/140971 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add bitfield offset calculation for big-endian targets (PR #145067)
razvanlupusoru wrote: @Andres-Salamanca Are you expecting the test to be failing? Here is what I am seeing: ``` error: ClangIR code gen Not Yet Implemented: NYI AAPCS bit-fields error: ClangIR code gen Not Yet Implemented: NYI AAPCS bit-fields error: ClangIR code gen Not Yet Implemented: NYI AAPCS bit-fields 3 errors generated. -- Failed Tests (1): Clang :: CIR/CodeGen/bitfields_be.c ``` https://github.com/llvm/llvm-project/pull/145067 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC][CIR] Implement 'init' lowering for private clause vars (PR #151781)
https://github.com/razvanlupusoru approved this pull request. LGTM - Thank you! https://github.com/llvm/llvm-project/pull/151781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir] [OpenACC][CIR] Implement 'private' clause lowering. (PR #151360)
https://github.com/razvanlupusoru approved this pull request. Thank you! https://github.com/llvm/llvm-project/pull/151360 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add PointerLikeType interface support for cir::PointerType (PR #139768)
@@ -0,0 +1,36 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file contains external dialect interfaces for CIR. +// +//===--===// + +#ifndef CLANG_CIR_DIALECT_OPENACC_CIROPENACCTYPEINTERFACES_H +#define CLANG_CIR_DIALECT_OPENACC_CIROPENACCTYPEINTERFACES_H + +#include "mlir/Dialect/OpenACC/OpenACC.h" +#include "clang/CIR/Dialect/IR/CIRTypes.h" + +namespace cir::acc { + +template +struct OpenACCPointerLikeModel razvanlupusoru wrote: Maybe this clarifies it a bit? https://mlir.llvm.org/docs/Interfaces/#external-models-for-attribute-operation-and-type-interfaces https://github.com/llvm/llvm-project/pull/139768 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add PointerLikeType interface support for cir::PointerType (PR #139768)
@@ -0,0 +1,41 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Implementation of external dialect interfaces for CIR. +// +//===--===// + +#include "clang/CIR/Dialect/OpenACC/CIROpenACCTypeInterfaces.h" + +namespace cir::acc { + +template <> +mlir::acc::VariableTypeCategory +OpenACCPointerLikeModel::getPointeeTypeCategory( +mlir::Type pointer, mlir::TypedValue varPtr, +mlir::Type varType) const { + mlir::Type eleTy = mlir::cast(pointer).getPointee(); + + if (auto mappableTy = mlir::dyn_cast(eleTy)) +return mappableTy.getTypeCategory(varPtr); + + if (isAnyIntegerOrFloatingPointType(eleTy) || + mlir::isa(eleTy) || mlir::isa(eleTy)) +return mlir::acc::VariableTypeCategory::scalar; razvanlupusoru wrote: Seems the CIR type system allows computation of interior pointers: https://godbolt.org/z/aPn1j5a69 Which means that scalar categorization might capture things which it shouldn't. More specifically, "a member of a composite variable" is not considered a "scalar" in OpenACC terminology - and the CIR type system by itself does not provide the appropriate features to distinguish this. Here is how we dealt with this case in FIR which allows the same: https://github.com/llvm/llvm-project/blob/main/flang/lib/Optimizer/OpenACC/FIROpenACCTypeInterfaces.cpp#L386 https://github.com/llvm/llvm-project/pull/139768 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add PointerLikeType interface support for cir::PointerType (PR #139768)
razvanlupusoru wrote: I just had one concern - otherwise looks great! Nice job! https://github.com/llvm/llvm-project/pull/139768 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir] [OpenACC][CIR] Add parallelism determ. to all acc.loops (PR #143751)
https://github.com/razvanlupusoru approved this pull request. Thank you! https://github.com/llvm/llvm-project/pull/143751 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement firstprivate lowering except init. (PR #153847)
https://github.com/razvanlupusoru approved this pull request. Thank you. https://github.com/llvm/llvm-project/pull/153847 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement firstprivate lowering except init. (PR #153847)
@@ -0,0 +1,571 @@ +// RUN: %clang_cc1 -fopenacc -triple x86_64-linux-gnu -Wno-openacc-self-if-potential-conflict -emit-cir -fclangir -triple x86_64-linux-pc %s -o - | FileCheck %s + +struct NoCopyConstruct {}; + +struct CopyConstruct { + CopyConstruct() = default; + CopyConstruct(const CopyConstruct&); +}; + +struct NonDefaultCtor { + NonDefaultCtor(); +}; + +struct HasDtor { + ~HasDtor(); +}; + +// CHECK: acc.firstprivate.recipe @firstprivatization__ZTSA5_7HasDtor : !cir.ptr> init { +// CHECK-NEXT: ^bb0(%[[ARG:.*]]: !cir.ptr> {{.*}}): +// CHECK-NEXT: cir.alloca !cir.array, !cir.ptr>, ["openacc.private.init"] +// CHECK-NEXT: acc.yield +// CHECK-NEXT: } copy { +// CHECK-NEXT: ^bb0(%[[ARG_FROM:.*]]: !cir.ptr> {{.*}}, %[[ARG_TO:.*]]: !cir.ptr> {{.*}}): +// +// CHECK-NEXT: acc.yield +// +// CHECK-NEXT: } destroy { +// CHECK-NEXT: ^bb0(%[[ARG:.*]]: !cir.ptr> {{.*}}): +// CHECK-NEXT: %[[LAST_IDX:.*]] = cir.const #cir.int<4> : !u64i +// CHECK-NEXT: %[[ARRPTR:.*]] = cir.cast(array_to_ptrdecay, %[[ARG]] : !cir.ptr>), !cir.ptr +// CHECK-NEXT: %[[ELEM:.*]] = cir.ptr_stride(%[[ARRPTR]] : !cir.ptr, %[[LAST_IDX]] : !u64i), !cir.ptr +// CHECK-NEXT: %[[ITR:.*]] = cir.alloca !cir.ptr, !cir.ptr>, ["__array_idx"] +// CHECK-NEXT: cir.store %[[ELEM]], %[[ITR]] : !cir.ptr, !cir.ptr> +// CHECK-NEXT: cir.do { +// CHECK-NEXT: %[[ELEM_LOAD:.*]] = cir.load %[[ITR]] : !cir.ptr>, !cir.ptr +// CHECK-NEXT: cir.call @_ZN7HasDtorD1Ev(%[[ELEM_LOAD]]) nothrow : (!cir.ptr) -> () +// CHECK-NEXT: %[[NEG_ONE:.*]] = cir.const #cir.int<-1> : !s64i +// CHECK-NEXT: %[[PREVELEM:.*]] = cir.ptr_stride(%[[ELEM_LOAD]] : !cir.ptr, %[[NEG_ONE]] : !s64i), !cir.ptr +// CHECK-NEXT: cir.store %[[PREVELEM]], %[[ITR]] : !cir.ptr, !cir.ptr> +// CHECK-NEXT: cir.yield +// CHECK-NEXT: } while { +// CHECK-NEXT: %[[ELEM_LOAD:.*]] = cir.load %[[ITR]] : !cir.ptr>, !cir.ptr +// CHECK-NEXT: %[[CMP:.*]] = cir.cmp(ne, %[[ELEM_LOAD]], %[[ARRPTR]]) : !cir.ptr, !cir.bool +// CHECK-NEXT: cir.condition(%[[CMP]]) +// CHECK-NEXT: } +// CHECK-NEXT: acc.yield +// CHECK-NEXT: } +// +// CHECK-NEXT: acc.firstprivate.recipe @firstprivatization__ZTSA5_14NonDefaultCtor : !cir.ptr> init { +// CHECK-NEXT: ^bb0(%[[ARG:.*]]: !cir.ptr> {{.*}}): +// CHECK-NEXT: %[[ALLOCA:.*]] = cir.alloca !cir.array, !cir.ptr>, ["openacc.private.init"] razvanlupusoru wrote: And it is also best to leave such handling to the codegen when target accelerator is decided. Since allocation space needs decided by compiler (global memory, shared memory, stack) based on heuristics and assignment of parallelism. https://github.com/llvm/llvm-project/pull/153847 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Change lowering signature for 'destroy' (PR #156716)
https://github.com/razvanlupusoru approved this pull request. Thank you! https://github.com/llvm/llvm-project/pull/156716 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Partial Reduction recipe Lowering (PR #155635)
https://github.com/razvanlupusoru approved this pull request. Impressively thorough testing! Thank you! https://github.com/llvm/llvm-project/pull/155635 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR][OpenACC] Implement pointer/array recipe destructors (PR #160189)
razvanlupusoru wrote: > Also hoping @razvanlupusoru could do a quick look at the tests to make sure > I'm not doing anything silly with the bounds/misinterpreting what I'm > supposed to be doing with it! Would it be possible to have the C++ code and the CHECK lines for recipes intertwined? With the mangling I cannot tell which ones correspond together! https://github.com/llvm/llvm-project/pull/160189 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR][OpenACC] Implement pointer/array recipe destructors (PR #160189)
@@ -1715,8 +1715,15 @@ class CIRGenFunction : public CIRGenTypeCache { mlir::Location beginLoc; mlir::Value varValue; std::string name; +// The type of the original variable reference: that is, after 'bounds' have +// removed pointers/array types/etc. So in the case of int arr[5], and a +// private(arr[1]), 'origType' is 'int', but 'baseType' is 'int[5]'. +QualType origType; razvanlupusoru wrote: Is this the "element type"? https://github.com/llvm/llvm-project/pull/160189 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR][OpenACC] Implement pointer/array recipe destructors (PR #160189)
https://github.com/razvanlupusoru approved this pull request. Thank you Erich for the comments showing type of array. That helped! The changes look great to me! A few semi-relevant comments: - I noticed you use the upperbound instead of extent in the recipes - despite the fact that only extent is filled in in the bounds used in the `acc.private` operations. I am guessing you will be relying on the promise I made (but not yet implemented) - https://mlir.llvm.org/docs/Dialects/OpenACCDialect/#accget_upperbound-accgetupperboundop - It is expected that you are not using stride from `acc.bounds` (since OpenACC spec does not actually allow stride). We currently do use this in flang because the language can express non-contiguous array views. I am imagining that if ever mdspan was natively represented in compiler as some sort of built-in type, then using stride would be necessary. - I noticed you collapse multi-dimension arrays into a single loop. I imagine normal declarations do not result in non-contiguous arrays. However, does your semantics checking verify for contiguous sections in the case when acc bounds are used? https://github.com/llvm/llvm-project/pull/160189 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR][OpenACC] Implement pointer/array recipe destructors (PR #160189)
razvanlupusoru wrote: > Open for suggestions how how to do so! One of the problems I ran into with > this is that the 'recipe' is always added at the 'top' when we create it, so > it is inverse order. AND FileCheck doesn't let you go 'backwards', so I was > unable to put the recipes inline. I agree that it is wonky to use FileCheck with CHECK-DAG especially if it is backwards. One suggestion to alleviate the FileCheck issue is to actually insert in order - one possible way is to keep last recipe insertion point. https://github.com/llvm/llvm-project/pull/160189 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits