llvm-project/clang/lib/AST
Johannes Doerfert df729e2b82 [OpenMP] Overhaul `declare target` handling
This patch fixes various issues with our prior `declare target` handling
and extends it to support `omp begin declare target` as well.

This started with PR49649 in mind, trying to provide a way for users to
avoid the "ref" global use introduced for globals with internal linkage.
From there it went down the rabbit hole, e.g., all variables, even
`nohost` ones, were emitted into the device code so it was impossible to
determine if "ref" was needed late in the game (based on the name only).
To make it really useful, `begin declare target` was needed as it can
carry the `device_type`. Not emitting variables eagerly had a ripple
effect. Finally, the precedence of the (explicit) declare target list
items needed to be taken into account, that meant we cannot just look
for any declare target attribute to make a decision. This caused the
handling of functions to require fixup as well.

I tried to clean up things while I was at it, e.g., we should not "parse
declarations and defintions" as part of OpenMP parsing, this will always
break at some point. Instead, we keep track what region we are in and
act on definitions and declarations instead, this is what we do for
declare variant and other begin/end directives already.

Highlights:
  - new diagnosis for restrictions specificed in the standard,
  - delayed emission of globals not mentioned in an explicit
    list of a declare target,
  - omission of `nohost` globals on the host and `host` globals on the
    device,
  - no explicit parsing of declarations in-between `omp [begin] declare
    variant` and the corresponding end anymore, regular parsing instead,
  - precedence for explicit mentions in `declare target` lists over
    implicit mentions in the declaration-definition-seq, and
  - `omp allocate` declarations will now replace an earlier emitted
    global, if necessary.

---

Notes:

The patch is larger than I hoped but it turns out that most changes do
on their own lead to "inconsistent states", which seem less desirable
overall.

After working through this I feel the standard should remove the
explicit declare target forms as the delayed emission is horrible.
That said, while we delay things anyway, it seems to me we check too
often for the current status even though that is often not sufficient to
act upon. There seems to be a lot of duplication that can probably be
trimmed down. Eagerly emitting some things seems pretty weak as an
argument to keep so much logic around.

---

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D101030
2021-05-06 02:10:41 -05:00
..
Interp [clang][NFC] Use SmallString instead of SmallVector<char 2020-11-17 13:02:58 +00:00
APValue.cpp [NFC] Move readAPValue/writeAPValue up the inheritance hierarchy 2021-01-06 16:44:50 -08:00
ASTConcept.cpp [Concepts] Transform constraints of non-template functions to ConstantEvaluated 2020-01-25 23:00:24 +02:00
ASTConsumer.cpp
ASTContext.cpp [clang] Add -fc++-abi= flag for specifying which C++ ABI to use 2021-05-04 10:52:13 -07:00
ASTDiagnostic.cpp [c++20] For P0732R2 / P1907R1: Basic frontend support for class types as 2020-10-21 13:21:41 -07:00
ASTDumper.cpp Undo Revert "Ignore template instantiations if not in AsIs mode" 2020-11-03 13:59:01 -08:00
ASTImporter.cpp [ASTImporter] Import member specialization/instantiation of enum decls 2021-03-30 11:57:46 +02:00
ASTImporterLookupTable.cpp [ASTImporter] Add Visitor for TypedefNameDecl's 2020-07-28 11:52:29 -05:00
ASTStructuralEquivalence.cpp Revert "Following up on PR48517, fix handling of template arguments that refer" 2021-01-20 15:55:35 +01:00
ASTTypeTraits.cpp [clangd] Selection handles CXXBaseSpecifier 2021-01-26 18:58:53 +00:00
AttrImpl.cpp [OpenMP] Overhaul `declare target` handling 2021-05-06 02:10:41 -05:00
CMakeLists.txt [Ignore Expressions] Fix performance regression by inlining `Ignore*SingleStep` 2020-09-09 07:32:40 +00:00
CXXABI.h Recommit of a2fdf9d4d7. 2021-02-05 11:27:30 -05:00
CXXInheritance.cpp Make iteration over the DeclContext::lookup_result safe. 2021-03-17 08:59:04 +00:00
Comment.cpp Fix "pointer is null" static analyzer warning. NFCI. 2020-01-07 13:41:52 +00:00
CommentBriefParser.cpp
CommentCommandTraits.cpp Explicitly include <cassert> when using assert 2020-03-02 22:45:28 +01:00
CommentLexer.cpp [clang][NFC] Rearrange Comment Token and Lexer fields to reduce padding 2020-10-27 00:03:43 +00:00
CommentParser.cpp
CommentSema.cpp [AST] Remove DeclCXX.h dep on ASTContext.h 2020-04-06 10:09:01 -07:00
ComparisonCategories.cpp Revert "Revert "Ensure that checkInitIsICE is called exactly once for every variable"" 2020-10-26 12:08:57 -07:00
ComputeDependence.cpp Revert "Following up on PR48517, fix handling of template arguments that refer" 2021-01-20 15:55:35 +01:00
DataCollection.cpp Avoid SourceManager.h include in RawCommentList.h, add missing incs 2020-02-27 13:49:40 -08:00
Decl.cpp Introduce -Wreserved-identifier 2021-05-04 11:19:01 +02:00
DeclBase.cpp Make iteration over the DeclContext::lookup_result safe. 2021-03-17 08:59:04 +00:00
DeclCXX.cpp [clang] Spell correct variable 2021-05-03 05:33:47 -07:00
DeclFriend.cpp
DeclGroup.cpp
DeclObjC.cpp [ObjC] Add a command line flag that disables recognition of objc_direct for testability 2021-04-06 11:17:01 -04:00
DeclOpenMP.cpp [OPENMP]Redesign of OMPExecutableDirective/OMPDeclarativeDirective representation. 2020-08-06 12:25:19 -04:00
DeclPrinter.cpp [clang][DeclPrinter] Pass Context into StmtPrinter whenever possible 2021-02-23 09:42:19 +01:00
DeclTemplate.cpp Revert "[NFC, Refactor] Modernize StorageClass from Specifiers.h to a scoped enum (II)" 2021-01-04 23:17:45 +01:00
DeclarationName.cpp [clang][AST] Encapsulate DeclarationNameLoc, NFCI 2021-01-27 11:21:01 +00:00
Expr.cpp [clang][AST] Handle overload callee type in CallExpr::getCallReturnType. 2021-04-12 09:44:17 +02:00
ExprCXX.cpp Revert "Following up on PR48517, fix handling of template arguments that refer" 2021-01-20 15:55:35 +01:00
ExprClassification.cpp [c++20] For P0732R2 / P1907R1: Basic frontend support for class types as 2020-10-21 13:21:41 -07:00
ExprConcepts.cpp [AST] Make Expr::setDependence protected and remove add/removeDependence. NFC 2020-03-19 21:54:40 +01:00
ExprConstant.cpp [Matrix] Implement C-style explicit type conversions for matrix types. 2021-04-10 11:48:41 +01:00
ExprObjC.cpp [AST] Move dependence computations into a separate file 2020-03-17 09:22:31 +01:00
ExternalASTMerger.cpp Make iteration over the DeclContext::lookup_result safe. 2021-03-17 08:59:04 +00:00
ExternalASTSource.cpp Avoid including FileManager.h from SourceManager.h 2020-03-11 13:53:12 -07:00
FormatString.cpp [Sema] Emit a -Wformat warning for printf("%s", (void*)p) 2020-07-10 15:10:24 -04:00
FormatStringParsing.h
InheritViz.cpp
ItaniumCXXABI.cpp Recommit of a2fdf9d4d7. 2021-02-05 11:27:30 -05:00
ItaniumMangle.cpp [SYCL] Implement SYCL address space attributes handling 2021-04-26 13:44:10 +03:00
JSONNodeDumper.cpp Fix null ptr crash dumping TemplateTemplateParmDecl 2021-04-24 12:28:10 -04:00
Linkage.h [c++20] For P0732R2 / P1907R1: Basic code generation and name 2020-11-09 22:10:27 -08:00
Mangle.cpp [clang/Basic] Make TargetInfo.h not use DataLayout again 2021-04-27 22:26:10 -04:00
MicrosoftCXXABI.cpp Recommit of a2fdf9d4d7. 2021-02-05 11:27:30 -05:00
MicrosoftMangle.cpp [Clang][RISCV] Define RISC-V V builtin types 2021-02-18 10:17:31 +08:00
NSAPI.cpp [Clang][RISCV] Define RISC-V V builtin types 2021-02-18 10:17:31 +08:00
NestedNameSpecifier.cpp [AST][RecoveryExpr] Avoid spurious 'missing typename' diagnostic when the NNS contains errors. 2020-06-30 16:18:32 +02:00
ODRHash.cpp Revert "Following up on PR48517, fix handling of template arguments that refer" 2021-01-20 15:55:35 +01:00
OSLog.cpp [clang][NFC] Add 'override' keyword to virtual function overrides 2020-07-14 08:59:57 -07:00
OpenMPClause.cpp [OpenMP51] Initial support for masked directive and filter clause 2021-04-09 14:00:36 -05:00
ParentMap.cpp
ParentMapContext.cpp [ASTMatchers] Fix hasParent while ignoring unwritten nodes 2021-02-18 15:04:03 +00:00
PrintfFormatString.cpp [Clang][RISCV] Define RISC-V V builtin types 2021-02-18 10:17:31 +08:00
QualTypeNames.cpp Fix crash in getFullyQualifiedName for inline namespace 2019-12-28 16:35:51 +03:00
RawCommentList.cpp [clang] fix undefined behaviour in RawComment::getFormattedText() 2020-04-06 10:48:25 +02:00
RecordLayout.cpp [AIX] Implement AIX special alignment rule about double/long double 2020-07-27 15:13:03 -04:00
RecordLayoutBuilder.cpp [Windows Itanium][PS4] handle dllimport/export w.r.t vtables/rtti 2021-04-13 11:41:10 +01:00
ScanfFormatString.cpp
SelectorLocationsKind.cpp
Stmt.cpp [clang][OpenMP] Use OpenMPIRBuilder for workshare loops. 2021-03-04 22:52:59 -06:00
StmtCXX.cpp
StmtIterator.cpp
StmtObjC.cpp
StmtOpenMP.cpp [OpenMP51] Initial support for masked directive and filter clause 2021-04-09 14:00:36 -05:00
StmtPrinter.cpp [OpenMP51] Initial support for masked directive and filter clause 2021-04-09 14:00:36 -05:00
StmtProfile.cpp [OpenMP51] Initial support for masked directive and filter clause 2021-04-09 14:00:36 -05:00
StmtViz.cpp
TemplateBase.cpp Fix type printing of array template args 2021-05-01 18:50:09 +00:00
TemplateName.cpp [NFC] Refactor DiagnosticBuilder and PartialDiagnostic 2020-10-19 17:48:04 -04:00
TextNodeDumper.cpp Revert "[NFC, Refactor] Modernize StorageClass from Specifiers.h to a scoped enum (II)" 2021-01-04 23:17:45 +01:00
Type.cpp [clang] Treat variable-length array of incomplete element type as 2021-03-24 14:22:15 +01:00
TypeLoc.cpp [Clang][RISCV] Define RISC-V V builtin types 2021-02-18 10:17:31 +08:00
TypePrinter.cpp [SYCL] Implement SYCL address space attributes handling 2021-04-26 13:44:10 +03:00
VTTBuilder.cpp
VTableBuilder.cpp [NFC] [Clang]: fix spelling mistake in assert message 2021-04-12 14:10:52 +08:00