Commit Graph

1174 Commits

Author SHA1 Message Date
Alexey Bataev 2cd7fafc11 [OPENMP][NVPTX]Fix critical region codegen.
Summary:
Previously critical regions were emitted with the barrier making it a
worksharing construct though it is not. Also, it leads to incorrect
behavior in Cuda9+. Patch fixes this problem.

Reviewers: ABataev, jdoerfert

Subscribers: jholewinski, guansong, cfe-commits, grokos

Tags: #clang

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

llvm-svn: 369946
2019-08-26 19:07:48 +00:00
Alexey Bataev 07a3b59279 [OPENMP5]Use nonmonotonic modifier by default for non-static and
non-ordered loops.

According to OpenMP 5.0, 2.9.2 Worksharing-Loop Construct, Desription, If the static schedule kind is specified or if the ordered clause is specified, and if the nonmonotonic modifier is not specified, the effect is as if the monotonic modifier is specified. Otherwise, unless the monotonic modifier is specified, the effect is as if the nonmonotonic modifier is specified.
The first part of this requirement is implemented in runtime. Patch adds
support for the second, nonmonotonic, part of this requirement.

llvm-svn: 369801
2019-08-23 19:52:05 +00:00
Alexey Bataev 729e242a79 [OPENMP5.0]Add support for device_type clause in declare target
construct.

OpenMP 5.0 introduced new clause for declare target directive, device_type clause, which may accept values host, nohost, and any. Host means
that the function must be emitted only for the host, nohost - only for
the device, and any - for both, device and the host.

llvm-svn: 369775
2019-08-23 16:11:14 +00:00
Joel E. Denny 7d5bc55433 [OpenMP] Permit map with DSA on combined directive
For `map`, the following restriction changed in OpenMP 5.0:

* OpenMP 4.5 [2.15.5.1, Restrictions]: "A list item cannot appear in
  both a map clause and a data-sharing attribute clause on the same
  construct.

* OpenMP 5.0 [2.19.7.1, Restrictions]: "A list item cannot appear in
  both a map clause and a data-sharing attribute clause on the same
  construct unless the construct is a combined construct."

This patch removes this restriction in the case of combined constructs
and OpenMP 5.0, and it updates Sema not to capture a scalar by copy in
the target region when `firstprivate` and `map` appear for that scalar
on a combined target construct.

This patch also adds a fixme to a test that now reveals that a
diagnostic about loop iteration variables is dropped in the case of
OpenMP 5.0.  That bug exists regardless of this patch's changes.

Reviewed By: ABataev, jdoerfert, hfinkel, kkwli0

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

llvm-svn: 369619
2019-08-22 03:34:30 +00:00
Alexey Bataev 9fd495be1f [OPENMP]Fix delayed diagnostics for standalone declare target directive.
If the function is marked as declare target in a standalone directive,
the delayed diagnostics is not emitted. Patch fixes this problem.

llvm-svn: 369432
2019-08-20 19:50:13 +00:00
Alexey Bataev 217ff1e445 [OPENMP5.0]Diagnose global variables in lambda not marked as declare
target.

According to OpenMP 5.0, if a lambda declaration and definition appears between a declare target directive and the matching end declare target directive, all variables that are captured by the lambda expression must also appear in a to clause.

llvm-svn: 369146
2019-08-16 20:15:02 +00:00
Alexey Bataev f8be476f0c [OPENMP]Support for non-rectangular loops.
Added basic support for non-rectangular loops. It requires an additional
analysis of min/max boundaries for non-rectangular loops. Since only
linear dependency is allowed, we can do this analysis.

llvm-svn: 368903
2019-08-14 19:30:06 +00:00
Gheorghe-Teodor Bercea 0fd073b1bf [OpenMP] Add support for close map modifier in Clang
Summary:
This patch adds support for the close map modifier in Clang.

This ensures that the new map type is marked and passed to the OpenMP runtime appropriately.

Additional regression tests have been merged from patch D55892 (author @saghir).

Reviewers: ABataev, caomhin, jdoerfert, kkwli0

Reviewed By: ABataev

Subscribers: kkwli0, Hahnfeld, saghir, guansong, cfe-commits

Tags: #clang

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

llvm-svn: 368491
2019-08-09 21:42:13 +00:00
Alexey Bataev 195ae90307 [OPENMP]Add support for analysis of linear variables and step.
Summary:
Added support for basic analysis of the linear variables and linear step
expression. Linear loop iteration variables must be excluded from this
analysis, only non-loop iteration variables must be analyzed.

Reviewers: NoQ

Subscribers: guansong, cfe-commits, caomhin, kkwli0

Tags: #clang

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

llvm-svn: 368295
2019-08-08 13:42:45 +00:00
Alexey Bataev a06155ddc4 [OPENMP]Set default version to OpenMP 4.5.
Since clang fully supports OpenMP 4.5, set the default version to 4.5
instead of 3.1.

llvm-svn: 368172
2019-08-07 14:39:17 +00:00
Alexey Bataev 2e3a07fcb8 [OPENMP]Add standard macro value _OPENMP for OpenMP 5.0.
According to the OpenMP standard, compiler must define _OPENMP macro,
which has value in format yyyymm, where yyyy is the year of the standard
and mm is the month of the standard. For OpenMP 5.0 this value must be
set to 201811.

llvm-svn: 368170
2019-08-07 14:02:11 +00:00
Michael Kruse d47b9438d7 [OpenMP 5.0] Codegen support for user-defined mappers.
This patch implements the code generation for OpenMP 5.0 declare mapper
(user-defined mapper) constructs. For each declare mapper, a mapper
function is generated. These mapper functions will be called by the
runtime and/or other mapper functions to achieve user defined mapping.

The design slides can be found at
https://github.com/lingda-li/public-sharing/blob/master/mapper_runtime_design.pptx

Re-commit after revert in r367773 because r367755 changed the LLVM-IR
output such that a CHECK line failed.

Patch by Lingda Li <lildmh@gmail.com>

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

llvm-svn: 367905
2019-08-05 18:43:21 +00:00
Michael Kruse 7eb2f08b9c Revert "[OpenMP 5.0] Codegen support for user-defined mappers."
This reverts commit r367773. The test case
OpenMP/declare_mapper_codegen.cpp is failing.

llvm-svn: 367774
2019-08-04 05:16:52 +00:00
Michael Kruse a04ffdbb05 [OpenMP 5.0] Codegen support for user-defined mappers.
This patch implements the code generation for OpenMP 5.0 declare mapper
(user-defined mapper) constructs. For each declare mapper, a mapper
function is generated. These mapper functions will be called by the
runtime and/or other mapper functions to achieve user defined mapping.

The design slides can be found at
https://github.com/lingda-li/public-sharing/blob/master/mapper_runtime_design.pptx

Patch by Lingda Li <lildmh@gmail.com>

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

llvm-svn: 367773
2019-08-04 04:18:42 +00:00
Tim Northover a009a60a91 IR: print value numbers for unnamed function arguments
For consistency with normal instructions and clarity when reading IR,
it's best to print the %0, %1, ... names of function arguments in
definitions.

Also modifies the parser to accept IR in that form for obvious reasons.

llvm-svn: 367755
2019-08-03 14:28:34 +00:00
Gheorghe-Teodor Bercea 625f59d190 [OpenMP] Fix declare target link implementation
Summary:
This patch fixes the case where variables in different compilation units or the same compilation unit are under the declare target link clause AND have the same name.
This also fixes the name clash error that occurs when unified memory is activated.
The changes in this patch include:
- Pointers to internal variables are given unique names.
- Externally visible variables are given the same name as before.
- All pointer variables (external or internal) are weakly linked.

Reviewers: ABataev, jdoerfert, caomhin

Reviewed By: ABataev

Subscribers: lebedev.ri, guansong, cfe-commits

Tags: #clang

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

llvm-svn: 367613
2019-08-01 21:15:58 +00:00
Alexey Bataev 8a8c69808c [OPENMP]Add support for analysis of reduction variables.
Summary:
Reduction variables are the variables, for which the private copies
must be created in the OpenMP regions. Then they are initialized with
the predefined values depending on the reduction operation. After exit
from the OpenMP region the original variable is updated using the
reduction value and the value of the original reduction variable.

Reviewers: NoQ

Subscribers: guansong, jdoerfert, caomhin, kkwli0, cfe-commits

Tags: #clang

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

llvm-svn: 367116
2019-07-26 14:50:05 +00:00
Alexey Bataev 25569296c6 [OPENMP]Add support for analysis of firstprivate variables.
Summary:
Firstprivate variables are the variables, for which the private copies
must be created in the OpenMP regions and must be initialized with the
original values. Thus, we must report if the uninitialized variable is
used as firstprivate.

Reviewers: NoQ

Subscribers: guansong, jdoerfert, caomhin, kkwli0, cfe-commits

Tags: #clang

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

llvm-svn: 366689
2019-07-22 13:51:07 +00:00
Alexey Bataev 0c99d19470 [OPENMP]Fix sharing of threadprivate variables with TLS support.
If the threadprivate variable is used in the copyin clause on inner
parallel directive with TLS support, we capture this variable in all
outer OpenMP scopes. It leads to the fact that in all scopes we're
working with the original variable, not the threadprivate copies.

llvm-svn: 366483
2019-07-18 19:40:24 +00:00
Alexey Bataev 05be1da24c [OPENMP]Provide correct data sharing attributes for loop control
variables.

Loop control variables are private in loop-based constructs and we shall
take this into account when generate the code for inner constructs.
Currently, those variables are reported as shared in many cases. Moved
the analysis of the data-sharing attributes of the loop control variable
to an early semantic stage to correctly handle their attributes.

llvm-svn: 366474
2019-07-18 17:49:13 +00:00
Alexey Bataev a44b216036 [OPENMP][NVPTX]Mark barrier functions calls as convergent.
Added convergent attribute to the barrier functions calls for correct
optimizations.

llvm-svn: 366437
2019-07-18 13:49:24 +00:00
Mike Rice 552c2c09d3 [OPENMP]Fix crash in LoopCounterRefChecker when MemberExpr is not Var or Field
checkDecl is only valid for VarDecls or FieldDecls, since getCanonicalDecl
expects only these. Prevent other Decl kinds (such as CXXMethodDecls and
EnumConstantDecls) from entering and asserting.

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

llvm-svn: 366336
2019-07-17 15:18:45 +00:00
Alexey Bataev 655cb4a2d7 [OPENMP]Add support for analysis of if clauses.
Summary:
Added support for analysis of if clauses in the OpenMP directives to be
able to check for the use of uninitialized variables.

Reviewers: NoQ

Subscribers: guansong, jfb, jdoerfert, caomhin, kkwli0, cfe-commits

Tags: clang

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

llvm-svn: 366211
2019-07-16 14:51:46 +00:00
Ali Tamur e7e8789a63 Revert "[OPENMP]Add support for analysis of if clauses."
This reverts commit rL366068.
The patch broke 86 tests under clang/test/OpenMP/ when run with address sanitizer.

llvm-svn: 366169
2019-07-16 03:20:15 +00:00
Alexey Bataev 63d00b19e5 [OPENMP]Add support for analysis of if clauses.
Summary:
Added support for analysis of if clauses in the OpenMP directives to be
able to check for the use of uninitialized variables.

Reviewers: NoQ

Subscribers: guansong, jfb, jdoerfert, caomhin, kkwli0, cfe-commits

Tags: #clang

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

llvm-svn: 366068
2019-07-15 14:46:23 +00:00
Alexey Bataev 8526031c5b [OPENMP]Improve handling of analysis of unsupported VLAs in reductions.
Fixed the processing of the unsupported VLAs in the reduction clauses.
Used targetDiag if the diagnostics can be delayed and emit it
immediately if the target does not support VLAs and we're parsing target
directive with the reduction clauses.

llvm-svn: 365821
2019-07-11 20:35:31 +00:00
Alexey Bataev c2c21ef9d2 [OPENMP]Initial fix PR42392: Improve -Wuninitialized warnings for OpenMP programs.
Summary:
Some OpenMP clauses rely on the values of the variables. If the variable
is not initialized and used in OpenMP clauses that depend on the
variables values, it should be reported that the uninitialized variable
is used in the OpenMP clause expression.
This patch adds initial processing for uninitialized variables in OpenMP
constructs. Currently, it checks for use of the uninitialized variables
in the structured blocks.

Reviewers: NoQ, Szelethus, dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet

Subscribers: rnkovacs, guansong, jfb, jdoerfert, cfe-commits

Tags: #clang

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

llvm-svn: 365786
2019-07-11 14:54:17 +00:00
Alexey Bataev af6725baa4 Added mapping for pointers captured in Lambdas in OpenMP target regions,
by David Truby.

Summary:
This adds a zero length array section mapping for each pointer captured by a lambda that is used in a target region, as per section 2.19.7.1 of the OpenMP 5 specification.

Reviewers: ABataev

Reviewed By: ABataev

Subscribers: guansong, jdoerfert, cfe-commits

Tags: #clang

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

llvm-svn: 365777
2019-07-11 13:54:26 +00:00
Alexey Bataev 780030844d [OPENMP]Remove not used check line from the test, NFC.
llvm-svn: 365691
2019-07-10 19:30:25 +00:00
Alexey Bataev e509af3cd6 [OPENMP]Fix the float point semantics handling on the device.
The device should use the same float point representation as the host.
Previous patch fixed the handling of the sizes of the float point types,
but did not fixed the fp semantics. This patch makes target device to
use the host fp semantics. this is required for the correct data
transfer between host and device and correct codegen.

llvm-svn: 365485
2019-07-09 14:09:53 +00:00
Alexey Bataev 62892599e8 [OPENMP]Improve error message for device unsupported types.
Provide more data to the user in the error message about unsupported
type for device compilation.

llvm-svn: 365374
2019-07-08 19:21:54 +00:00
Alexey Bataev a914888b49 [OPENMP]Add -Wunintialized to the erroneous tests for future fix PR42392,
NFC.

llvm-svn: 365334
2019-07-08 15:45:24 +00:00
Alexey Bataev b600ae37a5 [OPENMP]Fix handling of lambda captures in target regions.
Previously, lambda captures were processed in the function called during
capturing the variables. It leads to the recursive functions calls and
may result in the compiler crash.

llvm-svn: 364820
2019-07-01 17:46:52 +00:00
Alexey Bataev 1242d8f333 [OPENMP]Improve analysis of implicit captures.
If the variable is used in the OpenMP region implicitly, we need to
check the data-sharing attributes for such variables and generate
implicit clauses for them. Patch improves analysis of such variables for
better handling of data-sharing rules.

llvm-svn: 364683
2019-06-28 20:45:14 +00:00
Alexey Bataev 73f9d9aa64 [OPENMP]Fix top DSA for static members.
Fixed handling of the data-sharing attributes for static members when
requesting top most attribute. Previously, it might return the incorrect
attributes for static members if they were overriden in the outer
constructs.

llvm-svn: 364655
2019-06-28 16:16:00 +00:00
Alexey Bataev b7c31ff4a2 [OPENMP]Fix DSA for loop iteration variables in simd loops.
According to the OpenMP 5.0 standard, the loop iteration variable in the associated
for-loop of a simd construct with just one associated for-loop may be
listed in a private, lastprivate, or linear clause with a linear-step
that is the increment of the associated for-loop. Also, the loop
teration variables in the associated for-loops of a simd construct with
multiple associated for-loops may be listed in a private or lastprivate
clause.

llvm-svn: 364650
2019-06-28 15:16:37 +00:00
Alexey Bataev 405f8fc812 [OPENMP]Fix checks for DSA in simd constructs.
The errors for incorrectly specified data-sharing attributes for simd
constructs must be emitted only for the explicitly provided clauses, not
the predetermined ones.

llvm-svn: 364647
2019-06-28 14:59:25 +00:00
Alexey Bataev f288cf9dfa [OPENMP]Generate correctly implicit flags for mapped data.
Implicit flag must not be emitted for explicitly specified firstprivate
variables, but for implicitly captured sizes of the VLAs.

llvm-svn: 364575
2019-06-27 18:53:07 +00:00
Alexey Bataev a90fc6617f [OPENMP]Fix PR41966: type mismatch in runtime functions.
Target-based runtime functions use int64_t type for sizes, while the
compiler uses size_t type. It leads to miscompilation in 32 bit mode.

llvm-svn: 364327
2019-06-25 16:00:43 +00:00
Alexey Bataev db26bcda8c [OPENMP]Relax the test checks to pacify 32bit buildbots, NFC.
llvm-svn: 364189
2019-06-24 15:30:20 +00:00
Alexey Bataev 0f21507b44 [OPENMP]Fix PR42068: Vla type is not captured.
If the variably modified type is declared outside of the captured region
and then used in the cast expression along with array subscript
expression, the type is not captured and it leads to the compiler crash.

llvm-svn: 364080
2019-06-21 17:28:41 +00:00
Alexey Bataev e0eb66bbff [OPENMP]Fix PR42159: do not capture threadprivate variables.
The threadprivate variables should not be captured in the outlined
regions, otherwise it leads to the compiler crash.

llvm-svn: 364061
2019-06-21 15:08:30 +00:00
Gheorghe-Teodor Bercea 0034e84aa5 [OpenMP] Add support for handling declare target to clause when unified memory is required
Summary:
This patch adds support for the handling of the variables under the declare target to clause.

The variables in this case are handled like link variables are. A pointer is created on the host and then mapped to the device. The runtime will then copy the address of the host variable in the device pointer.

Reviewers: ABataev, AlexEichenberger, caomhin

Reviewed By: ABataev

Subscribers: guansong, jdoerfert, cfe-commits

Tags: #clang

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

llvm-svn: 363959
2019-06-20 18:04:47 +00:00
Gheorghe-Teodor Bercea c74707cb39 [OpenMP] Strengthen regression tests for task allocation under nowait depend clauses NFC
Summary:
This patch strengthens the tests introduced in D63009 by:
- adding new test for default device ID.
- modifying existing tests to pass device ID local variable to the task allocation function.

Reviewers: ABataev, Hahnfeld, caomhin, jdoerfert

Reviewed By: ABataev

Subscribers: guansong, jdoerfert, cfe-commits

Tags: #clang

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

llvm-svn: 363809
2019-06-19 14:26:43 +00:00
Alexey Bataev 9f3a805ee9 [OPENMP]Use host's mangling for 128 bit float types on the device.
Device have to use the same mangling as the host for 128bit float types. Otherwise, the codegen for the device is unable to find the parent function when it tries to generate the outlined function for the target region and it leads to incorrect compilation and crash at the runtime.

llvm-svn: 363734
2019-06-18 20:29:06 +00:00
Alexey Bataev 7ae267dc0f [OPENMP][NVPTX]Correct codegen for 128 bit long double.
If the host uses 128 bit long doubles, the compiler should generate correct code for NVPTX devices. If the return type has 128 bit long doubles, in LLVM IR this type must be coerced to int array instead.

llvm-svn: 363720
2019-06-18 19:04:27 +00:00
Alexey Bataev 8557d1ac98 [OPENMP]Use host's long double when compiling the code for device.
The device code must use the same long double type as the host.
Otherwise the code cannot be linked and executed properly. Patch adds
only basic support and checks for supporting of the host long double
double on the device.

llvm-svn: 363717
2019-06-18 18:39:26 +00:00
Gheorghe-Teodor Bercea 545a9fe106 [OpenMP] Add target task alloc function with device ID
Summary: Add a new call to Clang to perform task allocation for the target.

Reviewers: ABataev, AlexEichenberger, caomhin

Reviewed By: ABataev, AlexEichenberger

Subscribers: openmp-commits, Hahnfeld, guansong, jdoerfert, cfe-commits

Tags: #clang, #openmp

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

llvm-svn: 363451
2019-06-14 20:19:54 +00:00
Gheorghe-Teodor Bercea 5254f0a9ab [OpenMP] Avoid emitting maps for target link variables when unified memory is used
Summary: This patch avoids the emission of maps for target link variables when unified memory is present.

Reviewers: ABataev, caomhin

Reviewed By: ABataev

Subscribers: guansong, jdoerfert, cfe-commits

Tags: #clang

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

llvm-svn: 363435
2019-06-14 17:58:26 +00:00
Tim Northover c46827c7ed LLVM IR: Generate new-style byval-with-Type from Clang
LLVM IR recently added a Type parameter to the byval Attribute, so that
when pointers become opaque and no longer have an element type the
information will still be present in IR.

For now the Type parameter is optional (which is why Clang didn't need
this change at the time), but it will become mandatory soon.

llvm-svn: 362652
2019-06-05 21:12:14 +00:00