[clang] [APINotes] Upstream APINotesOptions (PR #70827)

2023-11-01 Thread Egor Zhdan via cfe-commits

egorzhdan wrote:

Apologies for the broken build!
I put up a re-land patch: https://github.com/llvm/llvm-project/pull/70975

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


[clang] [APINotes] Upstream APINotesOptions (PR #70827)

2023-11-01 Thread Egor Zhdan via cfe-commits

egorzhdan wrote:

```
47.207 [1384/8/4064] ASTNodeAPI.json
FAILED: tools/clang/lib/Tooling/ASTNodeAPI.json 
/home/buildbot/worker/as-builder-7/ramdisk/flang-runtime-cuda-clang/build/clang/tools/clang/lib/Tooling/ASTNodeAPI.json
```

Looking into this

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


[clang] [APINotes] Upstream APINotesOptions (PR #70827)

2023-11-01 Thread Slava Zakharin via cfe-commits

vzakhari wrote:

Hello @egorzhdan, this change breaks 
https://lab.llvm.org/buildbot/#/builders/270/builds/2125.  Could you please fix 
or revert?

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


[clang] [APINotes] Upstream APINotesOptions (PR #70827)

2023-11-01 Thread Egor Zhdan via cfe-commits

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


[clang] [APINotes] Upstream APINotesOptions (PR #70827)

2023-11-01 Thread Egor Zhdan via cfe-commits

https://github.com/egorzhdan updated 
https://github.com/llvm/llvm-project/pull/70827

>From 573e7ea751af1be41b3c984e7dc6b334f0ac0142 Mon Sep 17 00:00:00 2001
From: Egor Zhdan 
Date: Tue, 31 Oct 2023 16:39:45 +
Subject: [PATCH] [APINotes] Upstream APINotesOptions

This upstreams more of the Clang API Notes functionality that is currently 
implemented in the Apple fork: 
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes

This adds the first compiler options related to API Notes to the upstream 
Clang: `-iapinotes-modules` and `-fapinotes-swift-version=`. However, this does 
not add the `-fapinotes` flag that enables API Notes, since the feature is not 
fully functional yet.
---
 .../include/clang/APINotes/APINotesOptions.h  | 34 +++
 clang/include/clang/Driver/Options.td |  7 
 .../clang/Frontend/CompilerInvocation.h   |  6 
 clang/lib/Frontend/CompilerInvocation.cpp | 12 +++
 4 files changed, 59 insertions(+)
 create mode 100644 clang/include/clang/APINotes/APINotesOptions.h

diff --git a/clang/include/clang/APINotes/APINotesOptions.h 
b/clang/include/clang/APINotes/APINotesOptions.h
new file mode 100644
index 000..e8b8a9ed2261fa1
--- /dev/null
+++ b/clang/include/clang/APINotes/APINotesOptions.h
@@ -0,0 +1,34 @@
+//===--- APINotesOptions.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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_APINOTES_APINOTESOPTIONS_H
+#define LLVM_CLANG_APINOTES_APINOTESOPTIONS_H
+
+#include "llvm/Support/VersionTuple.h"
+#include 
+#include 
+
+namespace clang {
+
+/// Tracks various options which control how API notes are found and handled.
+class APINotesOptions {
+public:
+  /// The Swift version which should be used for API notes.
+  llvm::VersionTuple SwiftVersion;
+
+  /// The set of search paths where we API notes can be found for particular
+  /// modules.
+  ///
+  /// The API notes in this directory are stored as .apinotes, and
+  /// are only applied when building the module .
+  std::vector ModuleSearchPaths;
+};
+
+} // namespace clang
+
+#endif // LLVM_CLANG_APINOTES_APINOTESOPTIONS_H
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c8b730e0f7ecd84..940f63dd5736750 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1733,6 +1733,10 @@ def fswift_async_fp_EQ : Joined<["-"], 
"fswift-async-fp=">,
 NormalizedValuesScope<"CodeGenOptions::SwiftAsyncFramePointerKind">,
 NormalizedValues<["Auto", "Always", "Never"]>,
 MarshallingInfoEnum, "Always">;
+def fapinotes_swift_version : Joined<["-"], "fapinotes-swift-version=">,
+  Group, Visibility<[ClangOption, CC1Option]>,
+  MetaVarName<"">,
+  HelpText<"Specify the Swift version to use when filtering API notes">;
 
 defm addrsig : BoolFOption<"addrsig",
   CodeGenOpts<"Addrsig">, DefaultFalse,
@@ -4129,6 +4133,9 @@ def ibuiltininc : Flag<["-"], "ibuiltininc">, 
Group,
 def index_header_map : Flag<["-"], "index-header-map">,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Make the next included directory (-I or -F) an indexer header 
map">;
+def iapinotes_modules : JoinedOrSeparate<["-"], "iapinotes-modules">, 
Group,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Add directory to the API notes search path referenced by module 
name">, MetaVarName<"">;
 def idirafter : JoinedOrSeparate<["-"], "idirafter">, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Add directory to AFTER include search path">;
diff --git a/clang/include/clang/Frontend/CompilerInvocation.h 
b/clang/include/clang/Frontend/CompilerInvocation.h
index 45e263e7bc76822..d9c757a8a156861 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H
 #define LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H
 
+#include "clang/APINotes/APINotesOptions.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Basic/FileSystemOptions.h"
@@ -92,6 +93,9 @@ class CompilerInvocationBase {
 
   std::shared_ptr MigratorOpts;
 
+  /// Options controlling API notes.
+  std::shared_ptr APINotesOpts;
+
   /// Options controlling IRgen and the backend.
   std::shared_ptr CodeGenOpts;
 
@@ -131,6 +135,7 @@ class CompilerInvocationBase {
   const PreprocessorOptions &getPreprocessorOpts() const { return *PPOpts; }
   const AnalyzerOptions &getAnalyzerOpts() const { return *AnalyzerOpts; }
   const MigratorOptions &getMigratorOpts() const { return *MigratorOpts; }
+  const APINotesOptions &getAPINotesOpts() const { return *APINotesOpts; }
   

[clang] [APINotes] Upstream APINotesOptions (PR #70827)

2023-10-31 Thread Egor Zhdan via cfe-commits

https://github.com/egorzhdan updated 
https://github.com/llvm/llvm-project/pull/70827

>From 552995265316fd04bd73148fce010aa3cd0368f5 Mon Sep 17 00:00:00 2001
From: Egor Zhdan 
Date: Tue, 31 Oct 2023 16:39:45 +
Subject: [PATCH] [APINotes] Upstream APINotesOptions

This upstreams more of the Clang API Notes functionality that is currently 
implemented in the Apple fork: 
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes

This adds the first compiler options related to API Notes to the upstream 
Clang: `-iapinotes-modules` and `-fapinotes-swift-version=`. However, this does 
not add the `-fapinotes` flag that enables API Notes, since the feature is not 
fully functional yet.
---
 .../include/clang/APINotes/APINotesOptions.h  | 34 +++
 clang/include/clang/Driver/Options.td |  7 
 .../clang/Frontend/CompilerInvocation.h   |  6 
 clang/lib/Frontend/CompilerInvocation.cpp | 12 +++
 4 files changed, 59 insertions(+)
 create mode 100644 clang/include/clang/APINotes/APINotesOptions.h

diff --git a/clang/include/clang/APINotes/APINotesOptions.h 
b/clang/include/clang/APINotes/APINotesOptions.h
new file mode 100644
index 000..e8b8a9ed2261fa1
--- /dev/null
+++ b/clang/include/clang/APINotes/APINotesOptions.h
@@ -0,0 +1,34 @@
+//===--- APINotesOptions.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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_APINOTES_APINOTESOPTIONS_H
+#define LLVM_CLANG_APINOTES_APINOTESOPTIONS_H
+
+#include "llvm/Support/VersionTuple.h"
+#include 
+#include 
+
+namespace clang {
+
+/// Tracks various options which control how API notes are found and handled.
+class APINotesOptions {
+public:
+  /// The Swift version which should be used for API notes.
+  llvm::VersionTuple SwiftVersion;
+
+  /// The set of search paths where we API notes can be found for particular
+  /// modules.
+  ///
+  /// The API notes in this directory are stored as .apinotes, and
+  /// are only applied when building the module .
+  std::vector ModuleSearchPaths;
+};
+
+} // namespace clang
+
+#endif // LLVM_CLANG_APINOTES_APINOTESOPTIONS_H
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c8b730e0f7ecd84..940f63dd5736750 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1733,6 +1733,10 @@ def fswift_async_fp_EQ : Joined<["-"], 
"fswift-async-fp=">,
 NormalizedValuesScope<"CodeGenOptions::SwiftAsyncFramePointerKind">,
 NormalizedValues<["Auto", "Always", "Never"]>,
 MarshallingInfoEnum, "Always">;
+def fapinotes_swift_version : Joined<["-"], "fapinotes-swift-version=">,
+  Group, Visibility<[ClangOption, CC1Option]>,
+  MetaVarName<"">,
+  HelpText<"Specify the Swift version to use when filtering API notes">;
 
 defm addrsig : BoolFOption<"addrsig",
   CodeGenOpts<"Addrsig">, DefaultFalse,
@@ -4129,6 +4133,9 @@ def ibuiltininc : Flag<["-"], "ibuiltininc">, 
Group,
 def index_header_map : Flag<["-"], "index-header-map">,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Make the next included directory (-I or -F) an indexer header 
map">;
+def iapinotes_modules : JoinedOrSeparate<["-"], "iapinotes-modules">, 
Group,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Add directory to the API notes search path referenced by module 
name">, MetaVarName<"">;
 def idirafter : JoinedOrSeparate<["-"], "idirafter">, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Add directory to AFTER include search path">;
diff --git a/clang/include/clang/Frontend/CompilerInvocation.h 
b/clang/include/clang/Frontend/CompilerInvocation.h
index 45e263e7bc76822..d9c757a8a156861 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H
 #define LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H
 
+#include "clang/APINotes/APINotesOptions.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Basic/FileSystemOptions.h"
@@ -92,6 +93,9 @@ class CompilerInvocationBase {
 
   std::shared_ptr MigratorOpts;
 
+  /// Options controlling API notes.
+  std::shared_ptr APINotesOpts;
+
   /// Options controlling IRgen and the backend.
   std::shared_ptr CodeGenOpts;
 
@@ -131,6 +135,7 @@ class CompilerInvocationBase {
   const PreprocessorOptions &getPreprocessorOpts() const { return *PPOpts; }
   const AnalyzerOptions &getAnalyzerOpts() const { return *AnalyzerOpts; }
   const MigratorOptions &getMigratorOpts() const { return *MigratorOpts; }
+  const APINotesOptions &getAPINotesOpts() const { return *APINotesOpts; }
   

[clang] [APINotes] Upstream APINotesOptions (PR #70827)

2023-10-31 Thread Egor Zhdan via cfe-commits

egorzhdan wrote:

The clang-format failure is not related to the changes in this PR.

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


[clang] [APINotes] Upstream APINotesOptions (PR #70827)

2023-10-31 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff f8742b8d6a3489dc8974f4166d413a66cb8d9c21 
368f2b2580ef7ba8777020c40edcbb3b08c5b9ad -- 
clang/include/clang/APINotes/APINotesOptions.h 
clang/include/clang/Frontend/CompilerInvocation.h 
clang/lib/Frontend/CompilerInvocation.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Frontend/CompilerInvocation.h 
b/clang/include/clang/Frontend/CompilerInvocation.h
index d9c757a8a..13f3d14cd 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -21,8 +21,8 @@
 #include "clang/Frontend/MigratorOptions.h"
 #include "clang/Frontend/PreprocessorOutputOptions.h"
 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
-#include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include 
 #include 
 

``




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


[clang] [APINotes] Upstream APINotesOptions (PR #70827)

2023-10-31 Thread Saleem Abdulrasool via cfe-commits

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


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


[clang] [APINotes] Upstream APINotesOptions (PR #70827)

2023-10-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Egor Zhdan (egorzhdan)


Changes

This upstreams more of the Clang API Notes functionality that is currently 
implemented in the Apple fork: 
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes

This adds the first compiler options related to API Notes to the upstream 
Clang: `-iapinotes-modules` and `-fapinotes-swift-version=`. However, this does 
not add the `-fapinotes` flag that enables API Notes, since the feature is not 
fully functional yet.

---
Full diff: https://github.com/llvm/llvm-project/pull/70827.diff


4 Files Affected:

- (added) clang/include/clang/APINotes/APINotesOptions.h (+34) 
- (modified) clang/include/clang/Driver/Options.td (+7) 
- (modified) clang/include/clang/Frontend/CompilerInvocation.h (+6) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+12) 


``diff
diff --git a/clang/include/clang/APINotes/APINotesOptions.h 
b/clang/include/clang/APINotes/APINotesOptions.h
new file mode 100644
index 000..e8b8a9ed2261fa1
--- /dev/null
+++ b/clang/include/clang/APINotes/APINotesOptions.h
@@ -0,0 +1,34 @@
+//===--- APINotesOptions.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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_APINOTES_APINOTESOPTIONS_H
+#define LLVM_CLANG_APINOTES_APINOTESOPTIONS_H
+
+#include "llvm/Support/VersionTuple.h"
+#include 
+#include 
+
+namespace clang {
+
+/// Tracks various options which control how API notes are found and handled.
+class APINotesOptions {
+public:
+  /// The Swift version which should be used for API notes.
+  llvm::VersionTuple SwiftVersion;
+
+  /// The set of search paths where we API notes can be found for particular
+  /// modules.
+  ///
+  /// The API notes in this directory are stored as .apinotes, and
+  /// are only applied when building the module .
+  std::vector ModuleSearchPaths;
+};
+
+} // namespace clang
+
+#endif // LLVM_CLANG_APINOTES_APINOTESOPTIONS_H
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c8b730e0f7ecd84..940f63dd5736750 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1733,6 +1733,10 @@ def fswift_async_fp_EQ : Joined<["-"], 
"fswift-async-fp=">,
 NormalizedValuesScope<"CodeGenOptions::SwiftAsyncFramePointerKind">,
 NormalizedValues<["Auto", "Always", "Never"]>,
 MarshallingInfoEnum, "Always">;
+def fapinotes_swift_version : Joined<["-"], "fapinotes-swift-version=">,
+  Group, Visibility<[ClangOption, CC1Option]>,
+  MetaVarName<"">,
+  HelpText<"Specify the Swift version to use when filtering API notes">;
 
 defm addrsig : BoolFOption<"addrsig",
   CodeGenOpts<"Addrsig">, DefaultFalse,
@@ -4129,6 +4133,9 @@ def ibuiltininc : Flag<["-"], "ibuiltininc">, 
Group,
 def index_header_map : Flag<["-"], "index-header-map">,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Make the next included directory (-I or -F) an indexer header 
map">;
+def iapinotes_modules : JoinedOrSeparate<["-"], "iapinotes-modules">, 
Group,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Add directory to the API notes search path referenced by module 
name">, MetaVarName<"">;
 def idirafter : JoinedOrSeparate<["-"], "idirafter">, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Add directory to AFTER include search path">;
diff --git a/clang/include/clang/Frontend/CompilerInvocation.h 
b/clang/include/clang/Frontend/CompilerInvocation.h
index 45e263e7bc76822..d9c757a8a156861 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H
 #define LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H
 
+#include "clang/APINotes/APINotesOptions.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Basic/FileSystemOptions.h"
@@ -92,6 +93,9 @@ class CompilerInvocationBase {
 
   std::shared_ptr MigratorOpts;
 
+  /// Options controlling API notes.
+  std::shared_ptr APINotesOpts;
+
   /// Options controlling IRgen and the backend.
   std::shared_ptr CodeGenOpts;
 
@@ -131,6 +135,7 @@ class CompilerInvocationBase {
   const PreprocessorOptions &getPreprocessorOpts() const { return *PPOpts; }
   const AnalyzerOptions &getAnalyzerOpts() const { return *AnalyzerOpts; }
   const MigratorOptions &getMigratorOpts() const { return *MigratorOpts; }
+  const APINotesOptions &getAPINotesOpts() const { return *APINotesOpts; }
   const CodeGenOptions &getCodeGenOpts() const { return *CodeGenOpts; }
   const FileSystemOptions &getFileSystemOpts() const { return *FSOpts; }
   const FrontendOptions &getF

[clang] [APINotes] Upstream APINotesOptions (PR #70827)

2023-10-31 Thread Egor Zhdan via cfe-commits

https://github.com/egorzhdan created 
https://github.com/llvm/llvm-project/pull/70827

This upstreams more of the Clang API Notes functionality that is currently 
implemented in the Apple fork: 
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes

This adds the first compiler options related to API Notes to the upstream 
Clang: `-iapinotes-modules` and `-fapinotes-swift-version=`. However, this does 
not add the `-fapinotes` flag that enables API Notes, since the feature is not 
fully functional yet.

>From 368f2b2580ef7ba8777020c40edcbb3b08c5b9ad Mon Sep 17 00:00:00 2001
From: Egor Zhdan 
Date: Tue, 31 Oct 2023 16:39:45 +
Subject: [PATCH] [APINotes] Upstream APINotesOptions

This upstreams more of the Clang API Notes functionality that is currently 
implemented in the Apple fork: 
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes

This adds the first compiler options related to API Notes to the upstream 
Clang: `-iapinotes-modules` and `-fapinotes-swift-version=`. However, this does 
not add the `-fapinotes` flag that enables API Notes, since the feature is not 
fully functional yet.
---
 .../include/clang/APINotes/APINotesOptions.h  | 34 +++
 clang/include/clang/Driver/Options.td |  7 
 .../clang/Frontend/CompilerInvocation.h   |  6 
 clang/lib/Frontend/CompilerInvocation.cpp | 12 +++
 4 files changed, 59 insertions(+)
 create mode 100644 clang/include/clang/APINotes/APINotesOptions.h

diff --git a/clang/include/clang/APINotes/APINotesOptions.h 
b/clang/include/clang/APINotes/APINotesOptions.h
new file mode 100644
index 000..e8b8a9ed2261fa1
--- /dev/null
+++ b/clang/include/clang/APINotes/APINotesOptions.h
@@ -0,0 +1,34 @@
+//===--- APINotesOptions.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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_APINOTES_APINOTESOPTIONS_H
+#define LLVM_CLANG_APINOTES_APINOTESOPTIONS_H
+
+#include "llvm/Support/VersionTuple.h"
+#include 
+#include 
+
+namespace clang {
+
+/// Tracks various options which control how API notes are found and handled.
+class APINotesOptions {
+public:
+  /// The Swift version which should be used for API notes.
+  llvm::VersionTuple SwiftVersion;
+
+  /// The set of search paths where we API notes can be found for particular
+  /// modules.
+  ///
+  /// The API notes in this directory are stored as .apinotes, and
+  /// are only applied when building the module .
+  std::vector ModuleSearchPaths;
+};
+
+} // namespace clang
+
+#endif // LLVM_CLANG_APINOTES_APINOTESOPTIONS_H
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c8b730e0f7ecd84..940f63dd5736750 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1733,6 +1733,10 @@ def fswift_async_fp_EQ : Joined<["-"], 
"fswift-async-fp=">,
 NormalizedValuesScope<"CodeGenOptions::SwiftAsyncFramePointerKind">,
 NormalizedValues<["Auto", "Always", "Never"]>,
 MarshallingInfoEnum, "Always">;
+def fapinotes_swift_version : Joined<["-"], "fapinotes-swift-version=">,
+  Group, Visibility<[ClangOption, CC1Option]>,
+  MetaVarName<"">,
+  HelpText<"Specify the Swift version to use when filtering API notes">;
 
 defm addrsig : BoolFOption<"addrsig",
   CodeGenOpts<"Addrsig">, DefaultFalse,
@@ -4129,6 +4133,9 @@ def ibuiltininc : Flag<["-"], "ibuiltininc">, 
Group,
 def index_header_map : Flag<["-"], "index-header-map">,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Make the next included directory (-I or -F) an indexer header 
map">;
+def iapinotes_modules : JoinedOrSeparate<["-"], "iapinotes-modules">, 
Group,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Add directory to the API notes search path referenced by module 
name">, MetaVarName<"">;
 def idirafter : JoinedOrSeparate<["-"], "idirafter">, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Add directory to AFTER include search path">;
diff --git a/clang/include/clang/Frontend/CompilerInvocation.h 
b/clang/include/clang/Frontend/CompilerInvocation.h
index 45e263e7bc76822..d9c757a8a156861 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H
 #define LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H
 
+#include "clang/APINotes/APINotesOptions.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Basic/FileSystemOptions.h"
@@ -92,6 +93,9 @@ class CompilerInvocationBase {
 
   std::shared_ptr MigratorOpts;
 
+  /// Options controlling API notes.
+  std::shared_ptr APINotesOpts;
+
   /// Op