[clang] [OpenACC] Implement beginning parts of the 'parallel' Sema impl (PR #81659)

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 15 07:16:48 PST 2024


================
@@ -0,0 +1,132 @@
+//===--- SemaOpenACC.cpp - Semantic Analysis for OpenACC constructs -------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+/// \file
+/// This file implements semantic analysis for OpenACC constructs and
+/// clauses.
+///
+//===----------------------------------------------------------------------===//
+
+#include "clang/Basic/DiagnosticSema.h"
+#include "clang/Basic/OpenACCKinds.h"
+#include "clang/Sema/Sema.h"
+
+using namespace clang;
+
+namespace {
+bool DiagnoseConstructAppertainment(Sema &S, OpenACCDirectiveKind K,
+                                    SourceLocation StartLoc, bool IsStmt) {
+  switch (K) {
+  default:
+  case OpenACCDirectiveKind::Invalid:
+    // Nothing to do here, both invalid and unimplemented don't really need to
+    // do anything.
+    break;
+  case OpenACCDirectiveKind::Parallel:
+    if (!IsStmt)
+      return S.Diag(StartLoc, diag::err_acc_construct_appertainment) << K;
+    break;
+  }
+  return false;
+}
+} // namespace
+
+bool Sema::ActOnOpenACCClause(OpenACCClauseKind ClauseKind,
+                              SourceLocation StartLoc) {
+  // TODO OpenACC: this will probably want to take the Directive Kind as well to
+  // help with legalization.
+  if (ClauseKind == OpenACCClauseKind::Invalid)
+    return false;
+  // For now just diagnose that it is unsupported and leave the parsing to do
+  // whatever it can do. This function will eventually need to start returning
+  // some sort of Clause AST type, but for now just return true/false based on
+  // success.
+  return Diag(StartLoc, diag::warn_acc_clause_unimplemented) << ClauseKind;
+}
+
+void Sema::ActOnOpenACCConstruct(OpenACCDirectiveKind K,
+                                 SourceLocation StartLoc) {
+  switch (K) {
+  case OpenACCDirectiveKind::Invalid:
+    // Nothing to do here, an invalid kind has nothing we can check here.  We
+    // want to continue parsing clauses as far as we can, so we will just
+    // ensure that we can still work and don't check any construct-specific
+    // rules anywhere.
+    break;
+  case OpenACCDirectiveKind::Parallel:
+    // Nothing to do here, there is no real legalization that needs to happen
+    // here as these constructs do not take any arguments.
+    break;
+  default:
+    Diag(StartLoc, diag::warn_acc_construct_unimplemented) << K;
+    break;
+  }
+}
+
+void Sema::ActOnStartOpenACCDeclDirective(OpenACCDirectiveKind K,
+                                          SourceLocation StartLoc,
+                                          SourceLocation EndLoc) {
+  // TODO OpenACC: This should likely return something with the modified
+  // declaration. At the moment, only handle appertainment.
+  DiagnoseConstructAppertainment(*this, K, StartLoc, /*IsStmt=*/false);
+}
+
+void Sema::ActOnEndOpenACCDeclDirective() {
+  // TODO OpenACC: Should diagnose anything having to do with the associated
+  // statement, or any clause diagnostics that can only be done at the 'end' of
+  // the directive.  We should also close any 'block' marking now that the decl
+  // parsing is complete.
+}
----------------
alexey-bataev wrote:

I mean, introduce all these finction (empty) in separate design-like patch, not only this particular function.

https://github.com/llvm/llvm-project/pull/81659


More information about the cfe-commits mailing list