[clang] [clang][CodeGen] Remove unnecessary ShouldLinkFiles conditional (PR #96951)

2024-06-28 Thread Jacob Lambert via cfe-commits

lamb-j wrote:

Should be fixed with 
https://github.com/llvm/llvm-project/commit/982c54719289c1d85d03be3ad9e95bbfd2862aee

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


[clang] [clang][CodeGen] Cleanup missed ShouldLinkFiles definitions (PR #97115)

2024-06-28 Thread Jacob Lambert via cfe-commits

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


[clang] [clang][CodeGen] Cleanup missed ShouldLinkFiles definitions (PR #97115)

2024-06-28 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j created 
https://github.com/llvm/llvm-project/pull/97115

Follow up to 
https://github.com/llvm/llvm-project/commit/2264544e2d13957f36fd19864d9633a3278a9d74

>From 6131f15194e0f97fea381d896f5f9847ad4ba786 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Fri, 28 Jun 2024 14:54:01 -0700
Subject: [PATCH] [clang][CodeGen] Cleanup missed ShouldLinkFiles definitions

---
 clang/lib/CodeGen/LinkInModulesPass.cpp | 3 +--
 clang/lib/CodeGen/LinkInModulesPass.h   | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/LinkInModulesPass.cpp 
b/clang/lib/CodeGen/LinkInModulesPass.cpp
index 9dfcca53754a4..44b2df52f001a 100644
--- a/clang/lib/CodeGen/LinkInModulesPass.cpp
+++ b/clang/lib/CodeGen/LinkInModulesPass.cpp
@@ -20,8 +20,7 @@
 
 using namespace llvm;
 
-LinkInModulesPass::LinkInModulesPass(clang::BackendConsumer *BC) : BC(BC),
-  ShouldLinkFiles(ShouldLinkFiles) {}
+LinkInModulesPass::LinkInModulesPass(clang::BackendConsumer *BC) : BC(BC) {}
 
 PreservedAnalyses LinkInModulesPass::run(Module , ModuleAnalysisManager ) 
{
   if (!BC)
diff --git a/clang/lib/CodeGen/LinkInModulesPass.h 
b/clang/lib/CodeGen/LinkInModulesPass.h
index a184cce184c03..3edbfd076e150 100644
--- a/clang/lib/CodeGen/LinkInModulesPass.h
+++ b/clang/lib/CodeGen/LinkInModulesPass.h
@@ -28,7 +28,6 @@ class Pass;
 /// for use with the legacy pass manager.
 class LinkInModulesPass : public PassInfoMixin {
   clang::BackendConsumer *BC;
-  bool ShouldLinkFiles;
 
 public:
   LinkInModulesPass(clang::BackendConsumer *BC);

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Remove unnecessary ShouldLinkFiles conditional (PR #96951)

2024-06-28 Thread Jacob Lambert via cfe-commits

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


[clang] [clang][CodeGen] Remove unnecessary ShouldLinkFiles conditional (PR #96951)

2024-06-27 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j created 
https://github.com/llvm/llvm-project/pull/96951

We have reworked the bitcode linking option to no longer link twice if 
post-optimization linking is requested. As such, we no longer need to 
conditionally link bitcodes supplied via -mlink-bitcode-file, as there is no 
danger of linking them twice

>From 08e0d825ca27e6a5718c28d1754787905bb872b5 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Thu, 27 Jun 2024 11:50:28 -0700
Subject: [PATCH] [clang][CodeGen] Remove unnecessary ShouldLinkFiles
 conditional

We have reworked the bitcode linking option to no longer
link twice if post-optimization linking is requested. As such,
we no longer need to conditionally link bitcodes supplied via
-mlink-bitcode-file, as there is no danger of linking them twice
---
 clang/lib/CodeGen/BackendConsumer.h | 2 +-
 clang/lib/CodeGen/BackendUtil.cpp   | 2 +-
 clang/lib/CodeGen/CodeGenAction.cpp | 9 ++---
 clang/lib/CodeGen/LinkInModulesPass.cpp | 7 +++
 clang/lib/CodeGen/LinkInModulesPass.h   | 2 +-
 5 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
index 0fe9929dca2b3..a648bd314e501 100644
--- a/clang/lib/CodeGen/BackendConsumer.h
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -112,7 +112,7 @@ class BackendConsumer : public ASTConsumer {
   void HandleVTable(CXXRecordDecl *RD) override;
 
   // Links each entry in LinkModules into our module.  Returns true on error.
-  bool LinkInModules(llvm::Module *M, bool ShouldLinkFiles = true);
+  bool LinkInModules(llvm::Module *M);
 
   /// Get the best possible source location to represent a diagnostic that
   /// may have associated debug info.
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index b09680086248d..22b593e8f2b7a 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1035,7 +1035,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 
   // Link against bitcodes supplied via the -mlink-builtin-bitcode option
   if (CodeGenOpts.LinkBitcodePostopt)
-MPM.addPass(LinkInModulesPass(BC, false));
+MPM.addPass(LinkInModulesPass(BC));
 
   // Add a verifier pass if requested. We don't have to do this if the action
   // requires code generation because there will already be a verifier pass in
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 7766383fdc890..0b92c5318a5c2 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -226,16 +226,11 @@ void BackendConsumer::HandleInterestingDecl(DeclGroupRef 
D) {
 HandleTopLevelDecl(D);
 }
 
-// Links each entry in LinkModules into our module.  Returns true on error.
-bool BackendConsumer::LinkInModules(llvm::Module *M, bool ShouldLinkFiles) {
+// Links each entry in LinkModules into our module. Returns true on error.
+bool BackendConsumer::LinkInModules(llvm::Module *M) {
   for (auto  : LinkModules) {
 assert(LM.Module && "LinkModule does not actually have a module");
 
-// If ShouldLinkFiles is not set, skip files added via the
-// -mlink-bitcode-files, only linking -mlink-builtin-bitcode
-if (!LM.Internalize && !ShouldLinkFiles)
-  continue;
-
 if (LM.PropagateAttrs)
   for (Function  : *LM.Module) {
 // Skip intrinsics. Keep consistent with how intrinsics are created
diff --git a/clang/lib/CodeGen/LinkInModulesPass.cpp 
b/clang/lib/CodeGen/LinkInModulesPass.cpp
index c3831aae13b64..9dfcca53754a4 100644
--- a/clang/lib/CodeGen/LinkInModulesPass.cpp
+++ b/clang/lib/CodeGen/LinkInModulesPass.cpp
@@ -20,15 +20,14 @@
 
 using namespace llvm;
 
-LinkInModulesPass::LinkInModulesPass(clang::BackendConsumer *BC,
- bool ShouldLinkFiles)
-: BC(BC), ShouldLinkFiles(ShouldLinkFiles) {}
+LinkInModulesPass::LinkInModulesPass(clang::BackendConsumer *BC) : BC(BC),
+  ShouldLinkFiles(ShouldLinkFiles) {}
 
 PreservedAnalyses LinkInModulesPass::run(Module , ModuleAnalysisManager ) 
{
   if (!BC)
 return PreservedAnalyses::all();
 
-  if (BC->LinkInModules(, ShouldLinkFiles))
+  if (BC->LinkInModules())
 report_fatal_error("Bitcode module postopt linking failed, aborted!");
 
   return PreservedAnalyses::none();
diff --git a/clang/lib/CodeGen/LinkInModulesPass.h 
b/clang/lib/CodeGen/LinkInModulesPass.h
index 7fe94d6250583..a184cce184c03 100644
--- a/clang/lib/CodeGen/LinkInModulesPass.h
+++ b/clang/lib/CodeGen/LinkInModulesPass.h
@@ -31,7 +31,7 @@ class LinkInModulesPass : public 
PassInfoMixin {
   bool ShouldLinkFiles;
 
 public:
-  LinkInModulesPass(clang::BackendConsumer *BC, bool ShouldLinkFiles = true);
+  LinkInModulesPass(clang::BackendConsumer *BC);
 
   PreservedAnalyses run(Module , AnalysisManager &);
   static bool isRequired() { return true; }

___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[clang] [NFC][amdgpuarch] Correct file names in file header comments (PR #92294)

2024-05-20 Thread Jacob Lambert via cfe-commits

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


[clang] [NFC][amdgpuarch] Correct file names in file header comments (PR #92294)

2024-05-15 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j created 
https://github.com/llvm/llvm-project/pull/92294

None

>From cbeb6bcbd4442af709823af75ca82a2d33be9482 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Wed, 15 May 2024 10:12:45 -0700
Subject: [PATCH] [NFC][amdgpuarch] Correct file names in file header comments

---
 clang/tools/amdgpu-arch/AMDGPUArchByHIP.cpp | 2 +-
 clang/tools/amdgpu-arch/AMDGPUArchByHSA.cpp | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/tools/amdgpu-arch/AMDGPUArchByHIP.cpp 
b/clang/tools/amdgpu-arch/AMDGPUArchByHIP.cpp
index 7c9071be09188..7338872dbf32f 100644
--- a/clang/tools/amdgpu-arch/AMDGPUArchByHIP.cpp
+++ b/clang/tools/amdgpu-arch/AMDGPUArchByHIP.cpp
@@ -1,4 +1,4 @@
-//===- AMDGPUArch.cpp - list AMDGPU installed --*- C++ -*-===//
+//===- AMDGPUArchByHIP.cpp - list AMDGPU installed --*- C++ 
-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/clang/tools/amdgpu-arch/AMDGPUArchByHSA.cpp 
b/clang/tools/amdgpu-arch/AMDGPUArchByHSA.cpp
index f82a4890f4655..432f2c414ed24 100644
--- a/clang/tools/amdgpu-arch/AMDGPUArchByHSA.cpp
+++ b/clang/tools/amdgpu-arch/AMDGPUArchByHSA.cpp
@@ -1,4 +1,4 @@
-//===- AMDGPUArchLinux.cpp - list AMDGPU installed --*- C++ 
-*-===//
+//===- AMDGPUArchByHSA.cpp - list AMDGPU installed --*- C++ 
-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC] Add missing spaces in BoolOption for apinotes (PR #92027)

2024-05-14 Thread Jacob Lambert via cfe-commits

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


[clang] [NFC] Add missing spaces in BoolOption for apinotes (PR #92027)

2024-05-13 Thread Jacob Lambert via cfe-commits

lamb-j wrote:

https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fapinotes

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


[clang] [NFC] Add missing spaces in BoolOption for apinotes (PR #92027)

2024-05-13 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j created 
https://github.com/llvm/llvm-project/pull/92027

None

>From b68e9e234c1ccd62be507fcb1a0ab77241216f75 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Mon, 13 May 2024 13:24:48 -0700
Subject: [PATCH] [NFC] Add missing spaces in BoolOption for apinotes

---
 clang/include/clang/Driver/Options.td | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index ed3f1b8b29810..c9d8a1f50fecf 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1858,13 +1858,13 @@ defm apinotes : BoolOption<"f", "apinotes",
 LangOpts<"APINotes">, DefaultFalse,
 PosFlag,
 NegFlag,
-BothFlags<[], [ClangOption, CC1Option], "external API notes support">>,
+BothFlags<[], [ClangOption, CC1Option], " external API notes support">>,
 Group;
 defm apinotes_modules : BoolOption<"f", "apinotes-modules",
 LangOpts<"APINotesModules">, DefaultFalse,
 PosFlag,
 NegFlag,
-BothFlags<[], [ClangOption, CC1Option], "module-based external API notes 
support">>,
+BothFlags<[], [ClangOption, CC1Option], " module-based external API notes 
support">>,
 Group;
 def fapinotes_swift_version : Joined<["-"], "fapinotes-swift-version=">,
   Group, Visibility<[ClangOption, CC1Option]>,

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)

2024-05-08 Thread Jacob Lambert via cfe-commits

lamb-j wrote:

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

Follow up PR to fix warning with now-unused private variable in BackendConsumer 
class (FileMgr)

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


[clang] [clang][CodeGen] Remove now-unused FileManager variable (PR #91495)

2024-05-08 Thread Jacob Lambert via cfe-commits

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


[clang] [clang][CodeGen] Remove now-unused FileManager variable (PR #91495)

2024-05-08 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/91495

>From 4c687db250dabbc13557df46433a3c1cb3dff01e Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Wed, 8 May 2024 08:52:14 -0700
Subject: [PATCH 1/2] [clang][CodeGen] Remove now-unused FileManager variable

Fixes "error: private field 'FileMgr' is not used"
---
 clang/lib/CodeGen/BackendConsumer.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
index f9edbe901bb85..7dce21e743f72 100644
--- a/clang/lib/CodeGen/BackendConsumer.h
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -34,7 +34,6 @@ class BackendConsumer : public ASTConsumer {
   const CodeGenOptions 
   const TargetOptions 
   const LangOptions 
-  const FileManager 
   std::unique_ptr AsmOutStream;
   ASTContext *Context;
   IntrusiveRefCntPtr FS;

>From 8a0a1efea67a84221318343f93633218163d742c Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Wed, 8 May 2024 09:14:33 -0700
Subject: [PATCH 2/2] Remove FileManager arguments from constructor

---
 clang/lib/CodeGen/CodeGenAction.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 0255f05b1f90e..fd3ece1695f71 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -120,7 +120,7 @@ BackendConsumer::BackendConsumer(
 CoverageSourceInfo *CoverageInfo)
 : Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts),
   CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts),
-  FileMgr(FileMgr), AsmOutStream(std::move(OS)), Context(nullptr), FS(VFS),
+  AsmOutStream(std::move(OS)), Context(nullptr), FS(VFS),
   LLVMIRGeneration("irgen", "LLVM IR Generation Time"),
   LLVMIRGenerationRefCount(0),
   Gen(CreateLLVMCodeGen(Diags, InFile, std::move(VFS), HeaderSearchOpts,
@@ -145,7 +145,7 @@ BackendConsumer::BackendConsumer(
 CoverageSourceInfo *CoverageInfo)
 : Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts),
   CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts),
-  FileMgr(FileMgr), Context(nullptr), FS(VFS),
+  Context(nullptr), FS(VFS),
   LLVMIRGeneration("irgen", "LLVM IR Generation Time"),
   LLVMIRGenerationRefCount(0),
   Gen(CreateLLVMCodeGen(Diags, "", std::move(VFS), HeaderSearchOpts, 
PPOpts,

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Remove now-unused FileManager variable (PR #91495)

2024-05-08 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j created 
https://github.com/llvm/llvm-project/pull/91495

Fixes "error: private field 'FileMgr' is not used"

>From 4c687db250dabbc13557df46433a3c1cb3dff01e Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Wed, 8 May 2024 08:52:14 -0700
Subject: [PATCH] [clang][CodeGen] Remove now-unused FileManager variable

Fixes "error: private field 'FileMgr' is not used"
---
 clang/lib/CodeGen/BackendConsumer.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
index f9edbe901bb85..7dce21e743f72 100644
--- a/clang/lib/CodeGen/BackendConsumer.h
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -34,7 +34,6 @@ class BackendConsumer : public ASTConsumer {
   const CodeGenOptions 
   const TargetOptions 
   const LangOptions 
-  const FileManager 
   std::unique_ptr AsmOutStream;
   ASTContext *Context;
   IntrusiveRefCntPtr FS;

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)

2024-05-08 Thread Jacob Lambert via cfe-commits

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


[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)

2024-05-03 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/85672

>From aff1a762a73ce30cde38a6fcbbed8a3e4f0b5366 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Mon, 18 Mar 2024 10:19:38 -0700
Subject: [PATCH 1/7] [clang][CodeGen] Omit pre-opt link when post-opt link
 requested

Currently, when the -relink-builtin-bitcodes-postop option is used
we link builtin bitcodes twice: once before optimization, and again
after optimization.

With this change, we omit the pre-opt linking when the option is
set, and we rename the option to the following:

  -link-builtin-bitcodes-postopt
---
 clang/lib/CodeGen/BackendUtil.cpp   | 13 +
 clang/lib/CodeGen/CodeGenAction.cpp |  6 +++---
 clang/lib/CodeGen/LinkInModulesPass.cpp |  4 
 3 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 82b30b8d815629..c5571eb15ce3a9 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -112,9 +112,9 @@ static cl::opt ClSanitizeOnOptimizerEarlyEP(
 extern cl::opt ProfileCorrelate;
 
 // Re-link builtin bitcodes after optimization
-cl::opt ClRelinkBuiltinBitcodePostop(
-"relink-builtin-bitcode-postop", cl::Optional,
-cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false));
+cl::opt ClLinkBuiltinBitcodePostopt(
+"link-builtin-bitcode-postopt", cl::Optional,
+cl::desc("Link builtin bitcodes after optimization."), cl::init(false));
 } // namespace llvm
 
 namespace {
@@ -1051,11 +1051,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 }
   }
 
-  // Re-link against any bitcodes supplied via the -mlink-builtin-bitcode 
option
-  // Some optimizations may generate new function calls that would not have
-  // been linked pre-optimization (i.e. fused sincos calls generated by
-  // AMDGPULibCalls::fold_sincos.)
-  if (ClRelinkBuiltinBitcodePostop)
+  // Link against bitcodes supplied via the -mlink-builtin-bitcode option
+  if (ClLinkBuiltinBitcodePostopt)
 MPM.addPass(LinkInModulesPass(BC, false));
 
   // Add a verifier pass if requested. We don't have to do this if the action
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index bb9aaba025fa59..51f54d178672d1 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -58,7 +58,7 @@ using namespace llvm;
 #define DEBUG_TYPE "codegenaction"
 
 namespace llvm {
-extern cl::opt ClRelinkBuiltinBitcodePostop;
+extern cl::opt ClLinkBuiltinBitcodePostopt;
 }
 
 namespace clang {
@@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) {
   }
 
   // Link each LinkModule into our module.
-  if (LinkInModules(getModule()))
+  if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule()))
 return;
 
   for (auto  : getModule()->functions()) {
@@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() {
  std::move(LinkModules), *VMContext, nullptr);
 
   // Link in each pending link module.
-  if (Result.LinkInModules(&*TheModule))
+  if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule))
 return;
 
   // PR44896: Force DiscardValueNames as false. DiscardValueNames cannot be
diff --git a/clang/lib/CodeGen/LinkInModulesPass.cpp 
b/clang/lib/CodeGen/LinkInModulesPass.cpp
index 929539cc8f3346..ce1c0ebe046a61 100644
--- a/clang/lib/CodeGen/LinkInModulesPass.cpp
+++ b/clang/lib/CodeGen/LinkInModulesPass.cpp
@@ -28,10 +28,6 @@ PreservedAnalyses LinkInModulesPass::run(Module , 
ModuleAnalysisManager ) {
   if (!BC)
 return PreservedAnalyses::all();
 
-  // Re-load bitcode modules from files
-  if (BC->ReloadModules())
-report_fatal_error("Bitcode module re-loading failed, aborted!");
-
   if (BC->LinkInModules(, ShouldLinkFiles))
 report_fatal_error("Bitcode module re-linking failed, aborted!");
 

>From 9a6757c9497019dbc2c9c0d449c0d1cbc70c98fd Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Mon, 18 Mar 2024 10:47:25 -0700
Subject: [PATCH 2/7] fix option name

---
 clang/lib/CodeGen/CodeGenAction.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 51f54d178672d1..a3ff5dc7d29e99 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) {
   }
 
   // Link each LinkModule into our module.
-  if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule()))
+  if (!ClLinkBuiltinBitcodePostopt && LinkInModules(getModule()))
 return;
 
   for (auto  : getModule()->functions()) {
@@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() {
  std::move(LinkModules), *VMContext, nullptr);
 
   // Link in each pending link module.
-  if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule))
+  if 

[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)

2024-05-02 Thread Jacob Lambert via cfe-commits

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


[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)

2024-05-02 Thread Jacob Lambert via cfe-commits

lamb-j wrote:

Switched the option from a cl::opt to a Clang/CodeGen option.

Also added a LIT test which tests both -mlink-builtin-bitcode-postopt and 
-mno-link-builtin-bitcode-postopt

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


[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)

2024-05-02 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/85672

>From aff1a762a73ce30cde38a6fcbbed8a3e4f0b5366 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Mon, 18 Mar 2024 10:19:38 -0700
Subject: [PATCH 1/6] [clang][CodeGen] Omit pre-opt link when post-opt link
 requested

Currently, when the -relink-builtin-bitcodes-postop option is used
we link builtin bitcodes twice: once before optimization, and again
after optimization.

With this change, we omit the pre-opt linking when the option is
set, and we rename the option to the following:

  -link-builtin-bitcodes-postopt
---
 clang/lib/CodeGen/BackendUtil.cpp   | 13 +
 clang/lib/CodeGen/CodeGenAction.cpp |  6 +++---
 clang/lib/CodeGen/LinkInModulesPass.cpp |  4 
 3 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 82b30b8d815629..c5571eb15ce3a9 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -112,9 +112,9 @@ static cl::opt ClSanitizeOnOptimizerEarlyEP(
 extern cl::opt ProfileCorrelate;
 
 // Re-link builtin bitcodes after optimization
-cl::opt ClRelinkBuiltinBitcodePostop(
-"relink-builtin-bitcode-postop", cl::Optional,
-cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false));
+cl::opt ClLinkBuiltinBitcodePostopt(
+"link-builtin-bitcode-postopt", cl::Optional,
+cl::desc("Link builtin bitcodes after optimization."), cl::init(false));
 } // namespace llvm
 
 namespace {
@@ -1051,11 +1051,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 }
   }
 
-  // Re-link against any bitcodes supplied via the -mlink-builtin-bitcode 
option
-  // Some optimizations may generate new function calls that would not have
-  // been linked pre-optimization (i.e. fused sincos calls generated by
-  // AMDGPULibCalls::fold_sincos.)
-  if (ClRelinkBuiltinBitcodePostop)
+  // Link against bitcodes supplied via the -mlink-builtin-bitcode option
+  if (ClLinkBuiltinBitcodePostopt)
 MPM.addPass(LinkInModulesPass(BC, false));
 
   // Add a verifier pass if requested. We don't have to do this if the action
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index bb9aaba025fa59..51f54d178672d1 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -58,7 +58,7 @@ using namespace llvm;
 #define DEBUG_TYPE "codegenaction"
 
 namespace llvm {
-extern cl::opt ClRelinkBuiltinBitcodePostop;
+extern cl::opt ClLinkBuiltinBitcodePostopt;
 }
 
 namespace clang {
@@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) {
   }
 
   // Link each LinkModule into our module.
-  if (LinkInModules(getModule()))
+  if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule()))
 return;
 
   for (auto  : getModule()->functions()) {
@@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() {
  std::move(LinkModules), *VMContext, nullptr);
 
   // Link in each pending link module.
-  if (Result.LinkInModules(&*TheModule))
+  if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule))
 return;
 
   // PR44896: Force DiscardValueNames as false. DiscardValueNames cannot be
diff --git a/clang/lib/CodeGen/LinkInModulesPass.cpp 
b/clang/lib/CodeGen/LinkInModulesPass.cpp
index 929539cc8f3346..ce1c0ebe046a61 100644
--- a/clang/lib/CodeGen/LinkInModulesPass.cpp
+++ b/clang/lib/CodeGen/LinkInModulesPass.cpp
@@ -28,10 +28,6 @@ PreservedAnalyses LinkInModulesPass::run(Module , 
ModuleAnalysisManager ) {
   if (!BC)
 return PreservedAnalyses::all();
 
-  // Re-load bitcode modules from files
-  if (BC->ReloadModules())
-report_fatal_error("Bitcode module re-loading failed, aborted!");
-
   if (BC->LinkInModules(, ShouldLinkFiles))
 report_fatal_error("Bitcode module re-linking failed, aborted!");
 

>From 9a6757c9497019dbc2c9c0d449c0d1cbc70c98fd Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Mon, 18 Mar 2024 10:47:25 -0700
Subject: [PATCH 2/6] fix option name

---
 clang/lib/CodeGen/CodeGenAction.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 51f54d178672d1..a3ff5dc7d29e99 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) {
   }
 
   // Link each LinkModule into our module.
-  if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule()))
+  if (!ClLinkBuiltinBitcodePostopt && LinkInModules(getModule()))
 return;
 
   for (auto  : getModule()->functions()) {
@@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() {
  std::move(LinkModules), *VMContext, nullptr);
 
   // Link in each pending link module.
-  if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule))
+  if 

[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)

2024-05-02 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/85672

>From aff1a762a73ce30cde38a6fcbbed8a3e4f0b5366 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Mon, 18 Mar 2024 10:19:38 -0700
Subject: [PATCH 1/5] [clang][CodeGen] Omit pre-opt link when post-opt link
 requested

Currently, when the -relink-builtin-bitcodes-postop option is used
we link builtin bitcodes twice: once before optimization, and again
after optimization.

With this change, we omit the pre-opt linking when the option is
set, and we rename the option to the following:

  -link-builtin-bitcodes-postopt
---
 clang/lib/CodeGen/BackendUtil.cpp   | 13 +
 clang/lib/CodeGen/CodeGenAction.cpp |  6 +++---
 clang/lib/CodeGen/LinkInModulesPass.cpp |  4 
 3 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 82b30b8d815629..c5571eb15ce3a9 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -112,9 +112,9 @@ static cl::opt ClSanitizeOnOptimizerEarlyEP(
 extern cl::opt ProfileCorrelate;
 
 // Re-link builtin bitcodes after optimization
-cl::opt ClRelinkBuiltinBitcodePostop(
-"relink-builtin-bitcode-postop", cl::Optional,
-cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false));
+cl::opt ClLinkBuiltinBitcodePostopt(
+"link-builtin-bitcode-postopt", cl::Optional,
+cl::desc("Link builtin bitcodes after optimization."), cl::init(false));
 } // namespace llvm
 
 namespace {
@@ -1051,11 +1051,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 }
   }
 
-  // Re-link against any bitcodes supplied via the -mlink-builtin-bitcode 
option
-  // Some optimizations may generate new function calls that would not have
-  // been linked pre-optimization (i.e. fused sincos calls generated by
-  // AMDGPULibCalls::fold_sincos.)
-  if (ClRelinkBuiltinBitcodePostop)
+  // Link against bitcodes supplied via the -mlink-builtin-bitcode option
+  if (ClLinkBuiltinBitcodePostopt)
 MPM.addPass(LinkInModulesPass(BC, false));
 
   // Add a verifier pass if requested. We don't have to do this if the action
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index bb9aaba025fa59..51f54d178672d1 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -58,7 +58,7 @@ using namespace llvm;
 #define DEBUG_TYPE "codegenaction"
 
 namespace llvm {
-extern cl::opt ClRelinkBuiltinBitcodePostop;
+extern cl::opt ClLinkBuiltinBitcodePostopt;
 }
 
 namespace clang {
@@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) {
   }
 
   // Link each LinkModule into our module.
-  if (LinkInModules(getModule()))
+  if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule()))
 return;
 
   for (auto  : getModule()->functions()) {
@@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() {
  std::move(LinkModules), *VMContext, nullptr);
 
   // Link in each pending link module.
-  if (Result.LinkInModules(&*TheModule))
+  if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule))
 return;
 
   // PR44896: Force DiscardValueNames as false. DiscardValueNames cannot be
diff --git a/clang/lib/CodeGen/LinkInModulesPass.cpp 
b/clang/lib/CodeGen/LinkInModulesPass.cpp
index 929539cc8f3346..ce1c0ebe046a61 100644
--- a/clang/lib/CodeGen/LinkInModulesPass.cpp
+++ b/clang/lib/CodeGen/LinkInModulesPass.cpp
@@ -28,10 +28,6 @@ PreservedAnalyses LinkInModulesPass::run(Module , 
ModuleAnalysisManager ) {
   if (!BC)
 return PreservedAnalyses::all();
 
-  // Re-load bitcode modules from files
-  if (BC->ReloadModules())
-report_fatal_error("Bitcode module re-loading failed, aborted!");
-
   if (BC->LinkInModules(, ShouldLinkFiles))
 report_fatal_error("Bitcode module re-linking failed, aborted!");
 

>From 9a6757c9497019dbc2c9c0d449c0d1cbc70c98fd Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Mon, 18 Mar 2024 10:47:25 -0700
Subject: [PATCH 2/5] fix option name

---
 clang/lib/CodeGen/CodeGenAction.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 51f54d178672d1..a3ff5dc7d29e99 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) {
   }
 
   // Link each LinkModule into our module.
-  if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule()))
+  if (!ClLinkBuiltinBitcodePostopt && LinkInModules(getModule()))
 return;
 
   for (auto  : getModule()->functions()) {
@@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() {
  std::move(LinkModules), *VMContext, nullptr);
 
   // Link in each pending link module.
-  if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule))
+  if 

[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)

2024-05-01 Thread Jacob Lambert via cfe-commits

lamb-j wrote:

> @lamb-j I appreciate your carrying out these performance tests!
> 
> Would you be open to providing an option to enable post-link optimization 
> that could be off by default for now?

Currently if a user doesn't supply the new "-link-builtin-bitcodes-postopt" 
option, linking builtin bitcodes happens first, then the optimization pipeline 
follows. Does that cover the case you're talking about?

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


[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)

2024-05-01 Thread Jacob Lambert via cfe-commits

lamb-j wrote:

I've been working on testing this patch with an array of OpenCL benchmarks over 
the past month. We did some high-level regression testing with the following 
benchmarks:

BlackMagic
Linpack_Dgemm
babelstream-Double
babelstream-Float
chimex
clfft
clmem
clpeak-Double-precision compute
clpeak-Global memory bandwidth
clpeak-Integer compute
clpeak-Single-precision compute
clpeak-Transfer bandwidth
computeApps
dgemm_linux
fahbench
flopscl
ge-workspace
ge_rdppenality
indigo-benchmark
lattice
luxmark
luxmark4
mixbench-ocl-ro
ocltst
shoc
silentarmy
viennacl

With apps, we didn't see any significant regressions.

I also did some in-depth testing with FAHbench and Chimex:

**FAHBench**

Current:
Final score:  216.8422, 218.2792, 218.3647
Scaled score: 216.8422 (23558 atoms)
 
App Runtime: 1m42.181s, 1m42.185s,  1m42.167s

Compilation time: 3226 ms

With this PR:
Final score:  222.3547,  219.8134, 223.3722
Scaled score: 222.3547 (23558 atoms)
 
App Runtime: 1m40.852s, 1m40.850s,  1m40.849s

 Compilation time: 1822 ms

Between the two builds, the total runtime difference is ~1.3 seconds, and the 
difference in compilation is also ~1.3 seconds. So it does seem to support that 
we're only removing overhead with this PR, not introducing regressions. I also 
looked into the intermediate files. If we dump the two final .so files, they're 
nearly identical, with only a few lines differing.

**Chimex**

Current:

Correlation matrices computation time: 2.3876s on GPU 
[Theoretical max: @13.9 TFLOPS, 1659.3 kHz; 83% efficiency]
[Algorithm max:   @13.9 TFLOPS, 1634.6 kHz; 84% efficiency]

Compilation Time: 742 ms

With this PR:

Correlation matrices computation time: 1.9782s on GPU
[Theoretical max: @13.9 TFLOPS, 1659.3 kHz; 100% efficiency]
[Algorithm max:   @13.9 TFLOPS, 1634.6 kHz; 101% efficiency]
   
 Compilation Time: 551 ms

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


[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)

2024-04-30 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/85672

>From aff1a762a73ce30cde38a6fcbbed8a3e4f0b5366 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Mon, 18 Mar 2024 10:19:38 -0700
Subject: [PATCH 1/5] [clang][CodeGen] Omit pre-opt link when post-opt link
 requested

Currently, when the -relink-builtin-bitcodes-postop option is used
we link builtin bitcodes twice: once before optimization, and again
after optimization.

With this change, we omit the pre-opt linking when the option is
set, and we rename the option to the following:

  -link-builtin-bitcodes-postopt
---
 clang/lib/CodeGen/BackendUtil.cpp   | 13 +
 clang/lib/CodeGen/CodeGenAction.cpp |  6 +++---
 clang/lib/CodeGen/LinkInModulesPass.cpp |  4 
 3 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 82b30b8d815629..c5571eb15ce3a9 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -112,9 +112,9 @@ static cl::opt ClSanitizeOnOptimizerEarlyEP(
 extern cl::opt ProfileCorrelate;
 
 // Re-link builtin bitcodes after optimization
-cl::opt ClRelinkBuiltinBitcodePostop(
-"relink-builtin-bitcode-postop", cl::Optional,
-cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false));
+cl::opt ClLinkBuiltinBitcodePostopt(
+"link-builtin-bitcode-postopt", cl::Optional,
+cl::desc("Link builtin bitcodes after optimization."), cl::init(false));
 } // namespace llvm
 
 namespace {
@@ -1051,11 +1051,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 }
   }
 
-  // Re-link against any bitcodes supplied via the -mlink-builtin-bitcode 
option
-  // Some optimizations may generate new function calls that would not have
-  // been linked pre-optimization (i.e. fused sincos calls generated by
-  // AMDGPULibCalls::fold_sincos.)
-  if (ClRelinkBuiltinBitcodePostop)
+  // Link against bitcodes supplied via the -mlink-builtin-bitcode option
+  if (ClLinkBuiltinBitcodePostopt)
 MPM.addPass(LinkInModulesPass(BC, false));
 
   // Add a verifier pass if requested. We don't have to do this if the action
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index bb9aaba025fa59..51f54d178672d1 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -58,7 +58,7 @@ using namespace llvm;
 #define DEBUG_TYPE "codegenaction"
 
 namespace llvm {
-extern cl::opt ClRelinkBuiltinBitcodePostop;
+extern cl::opt ClLinkBuiltinBitcodePostopt;
 }
 
 namespace clang {
@@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) {
   }
 
   // Link each LinkModule into our module.
-  if (LinkInModules(getModule()))
+  if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule()))
 return;
 
   for (auto  : getModule()->functions()) {
@@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() {
  std::move(LinkModules), *VMContext, nullptr);
 
   // Link in each pending link module.
-  if (Result.LinkInModules(&*TheModule))
+  if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule))
 return;
 
   // PR44896: Force DiscardValueNames as false. DiscardValueNames cannot be
diff --git a/clang/lib/CodeGen/LinkInModulesPass.cpp 
b/clang/lib/CodeGen/LinkInModulesPass.cpp
index 929539cc8f3346..ce1c0ebe046a61 100644
--- a/clang/lib/CodeGen/LinkInModulesPass.cpp
+++ b/clang/lib/CodeGen/LinkInModulesPass.cpp
@@ -28,10 +28,6 @@ PreservedAnalyses LinkInModulesPass::run(Module , 
ModuleAnalysisManager ) {
   if (!BC)
 return PreservedAnalyses::all();
 
-  // Re-load bitcode modules from files
-  if (BC->ReloadModules())
-report_fatal_error("Bitcode module re-loading failed, aborted!");
-
   if (BC->LinkInModules(, ShouldLinkFiles))
 report_fatal_error("Bitcode module re-linking failed, aborted!");
 

>From 9a6757c9497019dbc2c9c0d449c0d1cbc70c98fd Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Mon, 18 Mar 2024 10:47:25 -0700
Subject: [PATCH 2/5] fix option name

---
 clang/lib/CodeGen/CodeGenAction.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 51f54d178672d1..a3ff5dc7d29e99 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) {
   }
 
   // Link each LinkModule into our module.
-  if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule()))
+  if (!ClLinkBuiltinBitcodePostopt && LinkInModules(getModule()))
 return;
 
   for (auto  : getModule()->functions()) {
@@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() {
  std::move(LinkModules), *VMContext, nullptr);
 
   // Link in each pending link module.
-  if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule))
+  if 

[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)

2024-04-29 Thread Jacob Lambert via cfe-commits


@@ -28,12 +28,8 @@ PreservedAnalyses LinkInModulesPass::run(Module , 
ModuleAnalysisManager ) {
   if (!BC)
 return PreservedAnalyses::all();
 
-  // Re-load bitcode modules from files
-  if (BC->ReloadModules())
-report_fatal_error("Bitcode module re-loading failed, aborted!");
-
   if (BC->LinkInModules(, ShouldLinkFiles))
-report_fatal_error("Bitcode module re-linking failed, aborted!");
+report_fatal_error("Bitcode module postopt linking failed, aborted!");
 
-  return PreservedAnalyses::all();

lamb-j wrote:

This should fix the issue:

LLVM ERROR: Function @_Z6sincosfPU3AS5f changed by LinkInModulesPass without 
invalidating analyses

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


[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)

2024-03-18 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/85672

>From aff1a762a73ce30cde38a6fcbbed8a3e4f0b5366 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Mon, 18 Mar 2024 10:19:38 -0700
Subject: [PATCH 1/4] [clang][CodeGen] Omit pre-opt link when post-opt link
 requested

Currently, when the -relink-builtin-bitcodes-postop option is used
we link builtin bitcodes twice: once before optimization, and again
after optimization.

With this change, we omit the pre-opt linking when the option is
set, and we rename the option to the following:

  -link-builtin-bitcodes-postopt
---
 clang/lib/CodeGen/BackendUtil.cpp   | 13 +
 clang/lib/CodeGen/CodeGenAction.cpp |  6 +++---
 clang/lib/CodeGen/LinkInModulesPass.cpp |  4 
 3 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 82b30b8d815629..c5571eb15ce3a9 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -112,9 +112,9 @@ static cl::opt ClSanitizeOnOptimizerEarlyEP(
 extern cl::opt ProfileCorrelate;
 
 // Re-link builtin bitcodes after optimization
-cl::opt ClRelinkBuiltinBitcodePostop(
-"relink-builtin-bitcode-postop", cl::Optional,
-cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false));
+cl::opt ClLinkBuiltinBitcodePostopt(
+"link-builtin-bitcode-postopt", cl::Optional,
+cl::desc("Link builtin bitcodes after optimization."), cl::init(false));
 } // namespace llvm
 
 namespace {
@@ -1051,11 +1051,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 }
   }
 
-  // Re-link against any bitcodes supplied via the -mlink-builtin-bitcode 
option
-  // Some optimizations may generate new function calls that would not have
-  // been linked pre-optimization (i.e. fused sincos calls generated by
-  // AMDGPULibCalls::fold_sincos.)
-  if (ClRelinkBuiltinBitcodePostop)
+  // Link against bitcodes supplied via the -mlink-builtin-bitcode option
+  if (ClLinkBuiltinBitcodePostopt)
 MPM.addPass(LinkInModulesPass(BC, false));
 
   // Add a verifier pass if requested. We don't have to do this if the action
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index bb9aaba025fa59..51f54d178672d1 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -58,7 +58,7 @@ using namespace llvm;
 #define DEBUG_TYPE "codegenaction"
 
 namespace llvm {
-extern cl::opt ClRelinkBuiltinBitcodePostop;
+extern cl::opt ClLinkBuiltinBitcodePostopt;
 }
 
 namespace clang {
@@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) {
   }
 
   // Link each LinkModule into our module.
-  if (LinkInModules(getModule()))
+  if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule()))
 return;
 
   for (auto  : getModule()->functions()) {
@@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() {
  std::move(LinkModules), *VMContext, nullptr);
 
   // Link in each pending link module.
-  if (Result.LinkInModules(&*TheModule))
+  if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule))
 return;
 
   // PR44896: Force DiscardValueNames as false. DiscardValueNames cannot be
diff --git a/clang/lib/CodeGen/LinkInModulesPass.cpp 
b/clang/lib/CodeGen/LinkInModulesPass.cpp
index 929539cc8f3346..ce1c0ebe046a61 100644
--- a/clang/lib/CodeGen/LinkInModulesPass.cpp
+++ b/clang/lib/CodeGen/LinkInModulesPass.cpp
@@ -28,10 +28,6 @@ PreservedAnalyses LinkInModulesPass::run(Module , 
ModuleAnalysisManager ) {
   if (!BC)
 return PreservedAnalyses::all();
 
-  // Re-load bitcode modules from files
-  if (BC->ReloadModules())
-report_fatal_error("Bitcode module re-loading failed, aborted!");
-
   if (BC->LinkInModules(, ShouldLinkFiles))
 report_fatal_error("Bitcode module re-linking failed, aborted!");
 

>From 9a6757c9497019dbc2c9c0d449c0d1cbc70c98fd Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Mon, 18 Mar 2024 10:47:25 -0700
Subject: [PATCH 2/4] fix option name

---
 clang/lib/CodeGen/CodeGenAction.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 51f54d178672d1..a3ff5dc7d29e99 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) {
   }
 
   // Link each LinkModule into our module.
-  if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule()))
+  if (!ClLinkBuiltinBitcodePostopt && LinkInModules(getModule()))
 return;
 
   for (auto  : getModule()->functions()) {
@@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() {
  std::move(LinkModules), *VMContext, nullptr);
 
   // Link in each pending link module.
-  if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule))
+  if 

[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)

2024-03-18 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/85672

>From aff1a762a73ce30cde38a6fcbbed8a3e4f0b5366 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Mon, 18 Mar 2024 10:19:38 -0700
Subject: [PATCH 1/3] [clang][CodeGen] Omit pre-opt link when post-opt link
 requested

Currently, when the -relink-builtin-bitcodes-postop option is used
we link builtin bitcodes twice: once before optimization, and again
after optimization.

With this change, we omit the pre-opt linking when the option is
set, and we rename the option to the following:

  -link-builtin-bitcodes-postopt
---
 clang/lib/CodeGen/BackendUtil.cpp   | 13 +
 clang/lib/CodeGen/CodeGenAction.cpp |  6 +++---
 clang/lib/CodeGen/LinkInModulesPass.cpp |  4 
 3 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 82b30b8d815629..c5571eb15ce3a9 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -112,9 +112,9 @@ static cl::opt ClSanitizeOnOptimizerEarlyEP(
 extern cl::opt ProfileCorrelate;
 
 // Re-link builtin bitcodes after optimization
-cl::opt ClRelinkBuiltinBitcodePostop(
-"relink-builtin-bitcode-postop", cl::Optional,
-cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false));
+cl::opt ClLinkBuiltinBitcodePostopt(
+"link-builtin-bitcode-postopt", cl::Optional,
+cl::desc("Link builtin bitcodes after optimization."), cl::init(false));
 } // namespace llvm
 
 namespace {
@@ -1051,11 +1051,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 }
   }
 
-  // Re-link against any bitcodes supplied via the -mlink-builtin-bitcode 
option
-  // Some optimizations may generate new function calls that would not have
-  // been linked pre-optimization (i.e. fused sincos calls generated by
-  // AMDGPULibCalls::fold_sincos.)
-  if (ClRelinkBuiltinBitcodePostop)
+  // Link against bitcodes supplied via the -mlink-builtin-bitcode option
+  if (ClLinkBuiltinBitcodePostopt)
 MPM.addPass(LinkInModulesPass(BC, false));
 
   // Add a verifier pass if requested. We don't have to do this if the action
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index bb9aaba025fa59..51f54d178672d1 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -58,7 +58,7 @@ using namespace llvm;
 #define DEBUG_TYPE "codegenaction"
 
 namespace llvm {
-extern cl::opt ClRelinkBuiltinBitcodePostop;
+extern cl::opt ClLinkBuiltinBitcodePostopt;
 }
 
 namespace clang {
@@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) {
   }
 
   // Link each LinkModule into our module.
-  if (LinkInModules(getModule()))
+  if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule()))
 return;
 
   for (auto  : getModule()->functions()) {
@@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() {
  std::move(LinkModules), *VMContext, nullptr);
 
   // Link in each pending link module.
-  if (Result.LinkInModules(&*TheModule))
+  if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule))
 return;
 
   // PR44896: Force DiscardValueNames as false. DiscardValueNames cannot be
diff --git a/clang/lib/CodeGen/LinkInModulesPass.cpp 
b/clang/lib/CodeGen/LinkInModulesPass.cpp
index 929539cc8f3346..ce1c0ebe046a61 100644
--- a/clang/lib/CodeGen/LinkInModulesPass.cpp
+++ b/clang/lib/CodeGen/LinkInModulesPass.cpp
@@ -28,10 +28,6 @@ PreservedAnalyses LinkInModulesPass::run(Module , 
ModuleAnalysisManager ) {
   if (!BC)
 return PreservedAnalyses::all();
 
-  // Re-load bitcode modules from files
-  if (BC->ReloadModules())
-report_fatal_error("Bitcode module re-loading failed, aborted!");
-
   if (BC->LinkInModules(, ShouldLinkFiles))
 report_fatal_error("Bitcode module re-linking failed, aborted!");
 

>From 9a6757c9497019dbc2c9c0d449c0d1cbc70c98fd Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Mon, 18 Mar 2024 10:47:25 -0700
Subject: [PATCH 2/3] fix option name

---
 clang/lib/CodeGen/CodeGenAction.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 51f54d178672d1..a3ff5dc7d29e99 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) {
   }
 
   // Link each LinkModule into our module.
-  if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule()))
+  if (!ClLinkBuiltinBitcodePostopt && LinkInModules(getModule()))
 return;
 
   for (auto  : getModule()->functions()) {
@@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() {
  std::move(LinkModules), *VMContext, nullptr);
 
   // Link in each pending link module.
-  if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule))
+  if 

[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)

2024-03-18 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/85672

>From aff1a762a73ce30cde38a6fcbbed8a3e4f0b5366 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Mon, 18 Mar 2024 10:19:38 -0700
Subject: [PATCH 1/2] [clang][CodeGen] Omit pre-opt link when post-opt link
 requested

Currently, when the -relink-builtin-bitcodes-postop option is used
we link builtin bitcodes twice: once before optimization, and again
after optimization.

With this change, we omit the pre-opt linking when the option is
set, and we rename the option to the following:

  -link-builtin-bitcodes-postopt
---
 clang/lib/CodeGen/BackendUtil.cpp   | 13 +
 clang/lib/CodeGen/CodeGenAction.cpp |  6 +++---
 clang/lib/CodeGen/LinkInModulesPass.cpp |  4 
 3 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 82b30b8d815629..c5571eb15ce3a9 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -112,9 +112,9 @@ static cl::opt ClSanitizeOnOptimizerEarlyEP(
 extern cl::opt ProfileCorrelate;
 
 // Re-link builtin bitcodes after optimization
-cl::opt ClRelinkBuiltinBitcodePostop(
-"relink-builtin-bitcode-postop", cl::Optional,
-cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false));
+cl::opt ClLinkBuiltinBitcodePostopt(
+"link-builtin-bitcode-postopt", cl::Optional,
+cl::desc("Link builtin bitcodes after optimization."), cl::init(false));
 } // namespace llvm
 
 namespace {
@@ -1051,11 +1051,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 }
   }
 
-  // Re-link against any bitcodes supplied via the -mlink-builtin-bitcode 
option
-  // Some optimizations may generate new function calls that would not have
-  // been linked pre-optimization (i.e. fused sincos calls generated by
-  // AMDGPULibCalls::fold_sincos.)
-  if (ClRelinkBuiltinBitcodePostop)
+  // Link against bitcodes supplied via the -mlink-builtin-bitcode option
+  if (ClLinkBuiltinBitcodePostopt)
 MPM.addPass(LinkInModulesPass(BC, false));
 
   // Add a verifier pass if requested. We don't have to do this if the action
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index bb9aaba025fa59..51f54d178672d1 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -58,7 +58,7 @@ using namespace llvm;
 #define DEBUG_TYPE "codegenaction"
 
 namespace llvm {
-extern cl::opt ClRelinkBuiltinBitcodePostop;
+extern cl::opt ClLinkBuiltinBitcodePostopt;
 }
 
 namespace clang {
@@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) {
   }
 
   // Link each LinkModule into our module.
-  if (LinkInModules(getModule()))
+  if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule()))
 return;
 
   for (auto  : getModule()->functions()) {
@@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() {
  std::move(LinkModules), *VMContext, nullptr);
 
   // Link in each pending link module.
-  if (Result.LinkInModules(&*TheModule))
+  if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule))
 return;
 
   // PR44896: Force DiscardValueNames as false. DiscardValueNames cannot be
diff --git a/clang/lib/CodeGen/LinkInModulesPass.cpp 
b/clang/lib/CodeGen/LinkInModulesPass.cpp
index 929539cc8f3346..ce1c0ebe046a61 100644
--- a/clang/lib/CodeGen/LinkInModulesPass.cpp
+++ b/clang/lib/CodeGen/LinkInModulesPass.cpp
@@ -28,10 +28,6 @@ PreservedAnalyses LinkInModulesPass::run(Module , 
ModuleAnalysisManager ) {
   if (!BC)
 return PreservedAnalyses::all();
 
-  // Re-load bitcode modules from files
-  if (BC->ReloadModules())
-report_fatal_error("Bitcode module re-loading failed, aborted!");
-
   if (BC->LinkInModules(, ShouldLinkFiles))
 report_fatal_error("Bitcode module re-linking failed, aborted!");
 

>From 9a6757c9497019dbc2c9c0d449c0d1cbc70c98fd Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Mon, 18 Mar 2024 10:47:25 -0700
Subject: [PATCH 2/2] fix option name

---
 clang/lib/CodeGen/CodeGenAction.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 51f54d178672d1..a3ff5dc7d29e99 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) {
   }
 
   // Link each LinkModule into our module.
-  if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule()))
+  if (!ClLinkBuiltinBitcodePostopt && LinkInModules(getModule()))
 return;
 
   for (auto  : getModule()->functions()) {
@@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() {
  std::move(LinkModules), *VMContext, nullptr);
 
   // Link in each pending link module.
-  if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule))
+  if 

[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)

2024-03-18 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j created 
https://github.com/llvm/llvm-project/pull/85672

Currently, when the -relink-builtin-bitcodes-postop option is used we link 
builtin bitcodes twice: once before optimization, and again after optimization.

With this change, we omit the pre-opt linking when the option is set, and we 
rename the option to the following:

  -link-builtin-bitcodes-postopt

The goal of this change is to reduce compile time. We do lose the benefits of 
pre-opt linking, but we may be able to address this in a future patch by 
adjusting the position of the builtin-bitcode linking pass.

Compilations not setting the relink (link) option are unaffected

>From aff1a762a73ce30cde38a6fcbbed8a3e4f0b5366 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Mon, 18 Mar 2024 10:19:38 -0700
Subject: [PATCH] [clang][CodeGen] Omit pre-opt link when post-opt link
 requested

Currently, when the -relink-builtin-bitcodes-postop option is used
we link builtin bitcodes twice: once before optimization, and again
after optimization.

With this change, we omit the pre-opt linking when the option is
set, and we rename the option to the following:

  -link-builtin-bitcodes-postopt
---
 clang/lib/CodeGen/BackendUtil.cpp   | 13 +
 clang/lib/CodeGen/CodeGenAction.cpp |  6 +++---
 clang/lib/CodeGen/LinkInModulesPass.cpp |  4 
 3 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 82b30b8d815629..c5571eb15ce3a9 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -112,9 +112,9 @@ static cl::opt ClSanitizeOnOptimizerEarlyEP(
 extern cl::opt ProfileCorrelate;
 
 // Re-link builtin bitcodes after optimization
-cl::opt ClRelinkBuiltinBitcodePostop(
-"relink-builtin-bitcode-postop", cl::Optional,
-cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false));
+cl::opt ClLinkBuiltinBitcodePostopt(
+"link-builtin-bitcode-postopt", cl::Optional,
+cl::desc("Link builtin bitcodes after optimization."), cl::init(false));
 } // namespace llvm
 
 namespace {
@@ -1051,11 +1051,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 }
   }
 
-  // Re-link against any bitcodes supplied via the -mlink-builtin-bitcode 
option
-  // Some optimizations may generate new function calls that would not have
-  // been linked pre-optimization (i.e. fused sincos calls generated by
-  // AMDGPULibCalls::fold_sincos.)
-  if (ClRelinkBuiltinBitcodePostop)
+  // Link against bitcodes supplied via the -mlink-builtin-bitcode option
+  if (ClLinkBuiltinBitcodePostopt)
 MPM.addPass(LinkInModulesPass(BC, false));
 
   // Add a verifier pass if requested. We don't have to do this if the action
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index bb9aaba025fa59..51f54d178672d1 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -58,7 +58,7 @@ using namespace llvm;
 #define DEBUG_TYPE "codegenaction"
 
 namespace llvm {
-extern cl::opt ClRelinkBuiltinBitcodePostop;
+extern cl::opt ClLinkBuiltinBitcodePostopt;
 }
 
 namespace clang {
@@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) {
   }
 
   // Link each LinkModule into our module.
-  if (LinkInModules(getModule()))
+  if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule()))
 return;
 
   for (auto  : getModule()->functions()) {
@@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() {
  std::move(LinkModules), *VMContext, nullptr);
 
   // Link in each pending link module.
-  if (Result.LinkInModules(&*TheModule))
+  if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule))
 return;
 
   // PR44896: Force DiscardValueNames as false. DiscardValueNames cannot be
diff --git a/clang/lib/CodeGen/LinkInModulesPass.cpp 
b/clang/lib/CodeGen/LinkInModulesPass.cpp
index 929539cc8f3346..ce1c0ebe046a61 100644
--- a/clang/lib/CodeGen/LinkInModulesPass.cpp
+++ b/clang/lib/CodeGen/LinkInModulesPass.cpp
@@ -28,10 +28,6 @@ PreservedAnalyses LinkInModulesPass::run(Module , 
ModuleAnalysisManager ) {
   if (!BC)
 return PreservedAnalyses::all();
 
-  // Re-load bitcode modules from files
-  if (BC->ReloadModules())
-report_fatal_error("Bitcode module re-loading failed, aborted!");
-
   if (BC->LinkInModules(, ShouldLinkFiles))
 report_fatal_error("Bitcode module re-linking failed, aborted!");
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Shift relink option implementation away from module cloning (PR #81693)

2024-02-15 Thread Jacob Lambert via cfe-commits


@@ -257,37 +281,19 @@ bool BackendConsumer::LinkInModules(llvm::Module *M, bool 
ShouldLinkFiles) {
 CurLinkModule = LM.Module.get();
 bool Err;

lamb-j wrote:

Oversight on my part. Should be fixed by 
https://github.com/llvm/llvm-project/pull/81777

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


[clang] [clang][CodeGen] Add missing error check (PR #81777)

2024-02-14 Thread Jacob Lambert via cfe-commits

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


[clang] [clang][CodeGen] Add missing error check (PR #81777)

2024-02-14 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j created 
https://github.com/llvm/llvm-project/pull/81777

Add missing error check. This resolves "error: variable 'Err' set but not used" 
warnings

>From b802c3456e44d5cc39ce6d5bf93fc549e38a7a12 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Wed, 14 Feb 2024 11:04:08 -0800
Subject: [PATCH] [clang][CodeGen] Add missing error check

---
 clang/lib/CodeGen/CodeGenAction.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index ab08a875e7e9c1..bb9aaba025fa59 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -291,6 +291,9 @@ bool BackendConsumer::LinkInModules(llvm::Module *M, bool 
ShouldLinkFiles) {
   });
 } else
   Err = Linker::linkModules(*M, std::move(LM.Module), LM.LinkFlags);
+
+if (Err)
+  return true;
   }
 
   LinkModules.clear();

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Shift relink option implementation away from module cloning (PR #81693)

2024-02-14 Thread Jacob Lambert via cfe-commits

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


[clang] [clang][CodeGen] Shift relink option implementation away from module cloning (PR #81693)

2024-02-14 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/81693

>From aff288af78b94dbd7ef317ce368f25a305798adc Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 13 Feb 2024 17:30:21 -0800
Subject: [PATCH 1/3] [clang][CodeGen] Shift relink option implementation away
 from module cloning

We recently implemented a new option allowing relinking of
bitcode modules via the "-mllvm -relink-builtin-bitcode-postop"
option.

This implementation relied on llvm::CloneModule() in order to pass
copies to modules and preserve the original modules for later
relinking.

However, cloning modules has been found to be prohibitively
expensive, significantly increasing compilation time for large
bitcode libraries.

In this patch, we shift the relink option implementation to instead
link the original modules initially, and reload modules from the file
system if relinking is requested. This approach results in
significantly reduced overhead.
---
 clang/include/clang/Basic/FileManager.h |   4 +-
 clang/lib/Basic/FileManager.cpp |   2 +-
 clang/lib/CodeGen/BackendConsumer.h |  16 ++-
 clang/lib/CodeGen/CodeGenAction.cpp | 163 
 clang/lib/CodeGen/LinkInModulesPass.cpp |  14 +-
 5 files changed, 110 insertions(+), 89 deletions(-)

diff --git a/clang/include/clang/Basic/FileManager.h 
b/clang/include/clang/Basic/FileManager.h
index 997c17a0ffcfcc..2245fd78bfc9f0 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -283,7 +283,7 @@ class FileManager : public RefCountedBase {
bool RequiresNullTerminator = true);
   llvm::ErrorOr>
   getBufferForFile(StringRef Filename, bool isVolatile = false,
-   bool RequiresNullTerminator = true) {
+   bool RequiresNullTerminator = true) const {
 return getBufferForFileImpl(Filename, /*FileSize=*/-1, isVolatile,
 RequiresNullTerminator);
   }
@@ -291,7 +291,7 @@ class FileManager : public RefCountedBase {
 private:
   llvm::ErrorOr>
   getBufferForFileImpl(StringRef Filename, int64_t FileSize, bool isVolatile,
-   bool RequiresNullTerminator);
+   bool RequiresNullTerminator) const;
 
 public:
   /// Get the 'stat' information for the given \p Path.
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 6097a27e429d66..cd520a6375e07e 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -547,7 +547,7 @@ FileManager::getBufferForFile(FileEntryRef FE, bool 
isVolatile,
 llvm::ErrorOr>
 FileManager::getBufferForFileImpl(StringRef Filename, int64_t FileSize,
   bool isVolatile,
-  bool RequiresNullTerminator) {
+  bool RequiresNullTerminator) const {
   if (FileSystemOpts.WorkingDir.empty())
 return FS->getBufferForFile(Filename, FileSize, RequiresNullTerminator,
 isVolatile);
diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
index 72a814cd43d738..fd0f1984d6c0f7 100644
--- a/clang/lib/CodeGen/BackendConsumer.h
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -34,6 +34,7 @@ class BackendConsumer : public ASTConsumer {
   const CodeGenOptions 
   const TargetOptions 
   const LangOptions 
+  const FileManager 
   std::unique_ptr AsmOutStream;
   ASTContext *Context;
   IntrusiveRefCntPtr FS;
@@ -74,8 +75,8 @@ class BackendConsumer : public ASTConsumer {
   const HeaderSearchOptions ,
   const PreprocessorOptions ,
   const CodeGenOptions ,
-  const TargetOptions ,
-  const LangOptions , const std::string ,
+  const TargetOptions , const LangOptions ,
+  const FileManager , const std::string ,
   SmallVector LinkModules,
   std::unique_ptr OS, llvm::LLVMContext ,
   CoverageSourceInfo *CoverageInfo = nullptr);
@@ -88,8 +89,8 @@ class BackendConsumer : public ASTConsumer {
   const HeaderSearchOptions ,
   const PreprocessorOptions ,
   const CodeGenOptions ,
-  const TargetOptions ,
-  const LangOptions , llvm::Module *Module,
+  const TargetOptions , const LangOptions ,
+  const FileManager , llvm::Module *Module,
   SmallVector LinkModules, llvm::LLVMContext ,
   CoverageSourceInfo *CoverageInfo = nullptr);
 
@@ -111,10 +112,13 @@ class BackendConsumer : public ASTConsumer {
   void AssignInheritanceModel(CXXRecordDecl *RD) override;
   void HandleVTable(CXXRecordDecl *RD) override;
 
-
- // Links each entry in LinkModules into our module.  Returns true on error.
+  // Links each entry in LinkModules into our module.  Returns true on error.
 

[clang] [clang][CodeGen] Shift relink option implementation away from module cloning (PR #81693)

2024-02-14 Thread Jacob Lambert via cfe-commits

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


[clang] [clang][CodeGen] Shift relink option implementation away from module cloning (PR #81693)

2024-02-13 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/81693

>From aff288af78b94dbd7ef317ce368f25a305798adc Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 13 Feb 2024 17:30:21 -0800
Subject: [PATCH 1/2] [clang][CodeGen] Shift relink option implementation away
 from module cloning

We recently implemented a new option allowing relinking of
bitcode modules via the "-mllvm -relink-builtin-bitcode-postop"
option.

This implementation relied on llvm::CloneModule() in order to pass
copies to modules and preserve the original modules for later
relinking.

However, cloning modules has been found to be prohibitively
expensive, significantly increasing compilation time for large
bitcode libraries.

In this patch, we shift the relink option implementation to instead
link the original modules initially, and reload modules from the file
system if relinking is requested. This approach results in
significantly reduced overhead.
---
 clang/include/clang/Basic/FileManager.h |   4 +-
 clang/lib/Basic/FileManager.cpp |   2 +-
 clang/lib/CodeGen/BackendConsumer.h |  16 ++-
 clang/lib/CodeGen/CodeGenAction.cpp | 163 
 clang/lib/CodeGen/LinkInModulesPass.cpp |  14 +-
 5 files changed, 110 insertions(+), 89 deletions(-)

diff --git a/clang/include/clang/Basic/FileManager.h 
b/clang/include/clang/Basic/FileManager.h
index 997c17a0ffcfcc..2245fd78bfc9f0 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -283,7 +283,7 @@ class FileManager : public RefCountedBase {
bool RequiresNullTerminator = true);
   llvm::ErrorOr>
   getBufferForFile(StringRef Filename, bool isVolatile = false,
-   bool RequiresNullTerminator = true) {
+   bool RequiresNullTerminator = true) const {
 return getBufferForFileImpl(Filename, /*FileSize=*/-1, isVolatile,
 RequiresNullTerminator);
   }
@@ -291,7 +291,7 @@ class FileManager : public RefCountedBase {
 private:
   llvm::ErrorOr>
   getBufferForFileImpl(StringRef Filename, int64_t FileSize, bool isVolatile,
-   bool RequiresNullTerminator);
+   bool RequiresNullTerminator) const;
 
 public:
   /// Get the 'stat' information for the given \p Path.
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 6097a27e429d66..cd520a6375e07e 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -547,7 +547,7 @@ FileManager::getBufferForFile(FileEntryRef FE, bool 
isVolatile,
 llvm::ErrorOr>
 FileManager::getBufferForFileImpl(StringRef Filename, int64_t FileSize,
   bool isVolatile,
-  bool RequiresNullTerminator) {
+  bool RequiresNullTerminator) const {
   if (FileSystemOpts.WorkingDir.empty())
 return FS->getBufferForFile(Filename, FileSize, RequiresNullTerminator,
 isVolatile);
diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
index 72a814cd43d738..fd0f1984d6c0f7 100644
--- a/clang/lib/CodeGen/BackendConsumer.h
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -34,6 +34,7 @@ class BackendConsumer : public ASTConsumer {
   const CodeGenOptions 
   const TargetOptions 
   const LangOptions 
+  const FileManager 
   std::unique_ptr AsmOutStream;
   ASTContext *Context;
   IntrusiveRefCntPtr FS;
@@ -74,8 +75,8 @@ class BackendConsumer : public ASTConsumer {
   const HeaderSearchOptions ,
   const PreprocessorOptions ,
   const CodeGenOptions ,
-  const TargetOptions ,
-  const LangOptions , const std::string ,
+  const TargetOptions , const LangOptions ,
+  const FileManager , const std::string ,
   SmallVector LinkModules,
   std::unique_ptr OS, llvm::LLVMContext ,
   CoverageSourceInfo *CoverageInfo = nullptr);
@@ -88,8 +89,8 @@ class BackendConsumer : public ASTConsumer {
   const HeaderSearchOptions ,
   const PreprocessorOptions ,
   const CodeGenOptions ,
-  const TargetOptions ,
-  const LangOptions , llvm::Module *Module,
+  const TargetOptions , const LangOptions ,
+  const FileManager , llvm::Module *Module,
   SmallVector LinkModules, llvm::LLVMContext ,
   CoverageSourceInfo *CoverageInfo = nullptr);
 
@@ -111,10 +112,13 @@ class BackendConsumer : public ASTConsumer {
   void AssignInheritanceModel(CXXRecordDecl *RD) override;
   void HandleVTable(CXXRecordDecl *RD) override;
 
-
- // Links each entry in LinkModules into our module.  Returns true on error.
+  // Links each entry in LinkModules into our module.  Returns true on error.
 

[clang] [clang][CodeGen] Shift relink option implementation away from module cloning (PR #81693)

2024-02-13 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j created 
https://github.com/llvm/llvm-project/pull/81693

We recently implemented a new option allowing relinking of bitcode modules via 
the "-mllvm -relink-builtin-bitcode-postop" option.

This implementation relied on llvm::CloneModule() in order to pass copies to 
modules and preserve the original modules for later relinking.

However, cloning modules has been found to be prohibitively expensive, 
significantly increasing compilation time for large bitcode libraries.

In this patch, we shift the relink option implementation to instead link the 
original modules initially, and reload modules from the file system if 
relinking is requested. This approach results in significantly reduced overhead.

>From aff288af78b94dbd7ef317ce368f25a305798adc Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 13 Feb 2024 17:30:21 -0800
Subject: [PATCH] [clang][CodeGen] Shift relink option implementation away from
 module cloning

We recently implemented a new option allowing relinking of
bitcode modules via the "-mllvm -relink-builtin-bitcode-postop"
option.

This implementation relied on llvm::CloneModule() in order to pass
copies to modules and preserve the original modules for later
relinking.

However, cloning modules has been found to be prohibitively
expensive, significantly increasing compilation time for large
bitcode libraries.

In this patch, we shift the relink option implementation to instead
link the original modules initially, and reload modules from the file
system if relinking is requested. This approach results in
significantly reduced overhead.
---
 clang/include/clang/Basic/FileManager.h |   4 +-
 clang/lib/Basic/FileManager.cpp |   2 +-
 clang/lib/CodeGen/BackendConsumer.h |  16 ++-
 clang/lib/CodeGen/CodeGenAction.cpp | 163 
 clang/lib/CodeGen/LinkInModulesPass.cpp |  14 +-
 5 files changed, 110 insertions(+), 89 deletions(-)

diff --git a/clang/include/clang/Basic/FileManager.h 
b/clang/include/clang/Basic/FileManager.h
index 997c17a0ffcfcc..2245fd78bfc9f0 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -283,7 +283,7 @@ class FileManager : public RefCountedBase {
bool RequiresNullTerminator = true);
   llvm::ErrorOr>
   getBufferForFile(StringRef Filename, bool isVolatile = false,
-   bool RequiresNullTerminator = true) {
+   bool RequiresNullTerminator = true) const {
 return getBufferForFileImpl(Filename, /*FileSize=*/-1, isVolatile,
 RequiresNullTerminator);
   }
@@ -291,7 +291,7 @@ class FileManager : public RefCountedBase {
 private:
   llvm::ErrorOr>
   getBufferForFileImpl(StringRef Filename, int64_t FileSize, bool isVolatile,
-   bool RequiresNullTerminator);
+   bool RequiresNullTerminator) const;
 
 public:
   /// Get the 'stat' information for the given \p Path.
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 6097a27e429d66..cd520a6375e07e 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -547,7 +547,7 @@ FileManager::getBufferForFile(FileEntryRef FE, bool 
isVolatile,
 llvm::ErrorOr>
 FileManager::getBufferForFileImpl(StringRef Filename, int64_t FileSize,
   bool isVolatile,
-  bool RequiresNullTerminator) {
+  bool RequiresNullTerminator) const {
   if (FileSystemOpts.WorkingDir.empty())
 return FS->getBufferForFile(Filename, FileSize, RequiresNullTerminator,
 isVolatile);
diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
index 72a814cd43d738..fd0f1984d6c0f7 100644
--- a/clang/lib/CodeGen/BackendConsumer.h
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -34,6 +34,7 @@ class BackendConsumer : public ASTConsumer {
   const CodeGenOptions 
   const TargetOptions 
   const LangOptions 
+  const FileManager 
   std::unique_ptr AsmOutStream;
   ASTContext *Context;
   IntrusiveRefCntPtr FS;
@@ -74,8 +75,8 @@ class BackendConsumer : public ASTConsumer {
   const HeaderSearchOptions ,
   const PreprocessorOptions ,
   const CodeGenOptions ,
-  const TargetOptions ,
-  const LangOptions , const std::string ,
+  const TargetOptions , const LangOptions ,
+  const FileManager , const std::string ,
   SmallVector LinkModules,
   std::unique_ptr OS, llvm::LLVMContext ,
   CoverageSourceInfo *CoverageInfo = nullptr);
@@ -88,8 +89,8 @@ class BackendConsumer : public ASTConsumer {
   const HeaderSearchOptions ,
   const PreprocessorOptions ,
   const CodeGenOptions ,
-  const TargetOptions ,
-

[clang] [NFC][clang][Driver] Specify options for with -save-temps= (PR #80921)

2024-02-09 Thread Jacob Lambert via cfe-commits


@@ -5392,7 +5392,9 @@ def regcall4 : Flag<["-"], "regcall4">, Group,
   MarshallingInfoFlag>;
 def save_temps_EQ : Joined<["-", "--"], "save-temps=">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
-  HelpText<"Save intermediate compilation results.">;
+  HelpText<"Save intermediate compilation results. The  option can be set 
"

lamb-j wrote:

Ah good catch, thanks

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


[clang] [NFC][clang][Driver] Specify options for with -save-temps= (PR #80921)

2024-02-08 Thread Jacob Lambert via cfe-commits

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


[clang] [NFC][clang][Driver] Specify options for with -save-temps= (PR #80921)

2024-02-07 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/80921

>From 9f021f6d2b99ae73c47313ddc6043ab2af926f23 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 6 Feb 2024 17:57:12 -0800
Subject: [PATCH 1/2] [NFC][clang][Driver] Specify options for  with
 -save-temps=

---
 clang/include/clang/Driver/Options.td | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4b232b8aab722..6b13530799e10 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5392,7 +5392,9 @@ def regcall4 : Flag<["-"], "regcall4">, Group,
   MarshallingInfoFlag>;
 def save_temps_EQ : Joined<["-", "--"], "save-temps=">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
-  HelpText<"Save intermediate compilation results.">;
+  HelpText<"Save intermediate compilation results. The  option can be set 
"
+  "to cwd for current working directory, or obj which will save temporary "
+  "files in the same directory as the final output file">;
 def save_temps : Flag<["-", "--"], "save-temps">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, FlangOption, FC1Option]>,
   Alias, AliasArgs<["cwd"]>,

>From 52981d2f4131720d9e446b96c75db0769eef5c28 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Wed, 7 Feb 2024 12:47:57 -0800
Subject: [PATCH 2/2] Don't describe option as arg, and fix white space

---
 clang/include/clang/Driver/Options.td | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6b13530799e10..4f498db2d43e6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5392,9 +5392,9 @@ def regcall4 : Flag<["-"], "regcall4">, Group,
   MarshallingInfoFlag>;
 def save_temps_EQ : Joined<["-", "--"], "save-temps=">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
-  HelpText<"Save intermediate compilation results. The  option can be set 
"
-  "to cwd for current working directory, or obj which will save temporary "
-  "files in the same directory as the final output file">;
+  HelpText<"Save intermediate compilation results.  can be set to cwd for 
"
+  "current working directory, or obj which will save temporary files in the "
+  "same directory as the final output file">;
 def save_temps : Flag<["-", "--"], "save-temps">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, FlangOption, FC1Option]>,
   Alias, AliasArgs<["cwd"]>,

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][clang][Driver] Specify options for with -save-temps= (PR #80921)

2024-02-06 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j created 
https://github.com/llvm/llvm-project/pull/80921

None

>From 9f021f6d2b99ae73c47313ddc6043ab2af926f23 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 6 Feb 2024 17:57:12 -0800
Subject: [PATCH] [NFC][clang][Driver] Specify options for  with
 -save-temps=

---
 clang/include/clang/Driver/Options.td | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4b232b8aab722a..6b13530799e102 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5392,7 +5392,9 @@ def regcall4 : Flag<["-"], "regcall4">, Group,
   MarshallingInfoFlag>;
 def save_temps_EQ : Joined<["-", "--"], "save-temps=">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
-  HelpText<"Save intermediate compilation results.">;
+  HelpText<"Save intermediate compilation results. The  option can be set 
"
+  "to cwd for current working directory, or obj which will save temporary "
+  "files in the same directory as the final output file">;
 def save_temps : Flag<["-", "--"], "save-temps">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, FlangOption, FC1Option]>,
   Alias, AliasArgs<["cwd"]>,

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-offload-bundler][NFC] Remove blank line in doc (PR #73968)

2023-11-30 Thread Jacob Lambert via cfe-commits

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


[clang] [clang-offload-bundler][NFC] Remove blank line in doc (PR #73968)

2023-11-30 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j created 
https://github.com/llvm/llvm-project/pull/73968

None

>From 5582993e9c9aadf30ca2780cd37a280fe32fb439 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Thu, 30 Nov 2023 10:25:55 -0800
Subject: [PATCH] [clang-offload-bundler][NFC] Remove blank line in doc

---
 clang/docs/ClangOffloadBundler.rst | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/docs/ClangOffloadBundler.rst 
b/clang/docs/ClangOffloadBundler.rst
index 1d163db1a9a63bc..1f8c85a08f8c79c 100644
--- a/clang/docs/ClangOffloadBundler.rst
+++ b/clang/docs/ClangOffloadBundler.rst
@@ -500,7 +500,6 @@ Additional Options while Archive Unbundling
   as defined in :ref:`code-object-composition` before creating device-specific
   archive(s).
 
-
 **-debug-only=CodeObjectCompatibility**
   Verbose printing of matched/unmatched comparisons between bundle entry id of
   a device binary from HDA and bundle entry ID of a given target processor

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-offload-bundler] Add support for -check-input-archive (PR #73709)

2023-11-29 Thread Jacob Lambert via cfe-commits

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


[clang] [clang-offload-bundler] Add support for -check-input-archive (PR #73709)

2023-11-29 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/73709

>From 995706601f9f4aed021a9003ad79ca3e7e1d18af Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 28 Nov 2023 14:42:11 -0800
Subject: [PATCH 1/7] [clang-offload-bundler] Add support for
 -check-input-archive

In this patch, we add support for checking a heterogeneous archive.
We also significantly improve the clang-offload-bundler documentation.
---
 clang/docs/ClangOffloadBundler.rst| 297 +++---
 clang/include/clang/Driver/OffloadBundler.h   |   2 +-
 clang/lib/Driver/OffloadBundler.cpp   |  94 +-
 .../ClangOffloadBundler.cpp   |  19 ++
 4 files changed, 358 insertions(+), 54 deletions(-)

diff --git a/clang/docs/ClangOffloadBundler.rst 
b/clang/docs/ClangOffloadBundler.rst
index 1e21d3e7264d5c3..1fcfde011e46e2f 100644
--- a/clang/docs/ClangOffloadBundler.rst
+++ b/clang/docs/ClangOffloadBundler.rst
@@ -30,58 +30,139 @@ includes an ``init`` function that will use the runtime 
corresponding to the
 offload kind (see :ref:`clang-offload-kind-table`) to load the offload code
 objects appropriate to the devices present when the host program is executed.
 
+:program:`clang-offload-bundler` is located in
+`clang/tools/clang-offload-bundler`.
+
+.. code-block:: console
+
+  $ clang-offload-bundler -help
+  OVERVIEW: A tool to bundle several input files of the specified type 
+  referring to the same source file but different targets into a single
+  one. The resulting file can also be unbundled into different files by
+  this tool if -unbundle is provided.
+
+  USAGE: clang-offload-bundler [options]
+
+  OPTIONS:
+
+  Generic Options:
+
+--help  - Display available options (--help-hidden for 
more)
+--help-list - Display list of available options 
(--help-list-hidden for more)
+--version   - Display the version of this program
+
+  clang-offload-bundler options:
+
+--###   - Print any external commands that are to be 
executed instead of actually executing them - for testing purposes.
+--allow-missing-bundles - Create empty files if bundles are missing when 
unbundling.
+--bundle-align=   - Alignment of bundle for binary files
+--check-input-archive   - Check if input heterogeneous archive is valid in 
terms of TargetID rules.
+--inputs=   - [,...]
+--list  - List bundle IDs in the bundled file.
+--outputs=  - [,...]
+--targets=  - [-,...]
+--type= - Type of the files to be bundled/unbundled.
+  Current supported types are:
+i   - cpp-output
+ii  - c++-cpp-output
+cui - cuda/hip-output
+d   - dependency
+ll  - llvm
+bc  - llvm-bc
+s   - assembler
+o   - object
+a   - archive of bundled files
+gch - precompiled-header
+ast - clang AST file
+--unbundle  - Unbundle bundled file into several output files.
+
+Usage
+=
+
+This tool can be used as follows for bundling:
+
+::
+
+  clang-offload-bundler -targets=triple1,triple2 -type=ii 
-inputs=a.triple1.ii,a.triple2.ii -outputs=a.ii
+
+or, it can be used as follows for unbundling:
+
+::
+
+  clang-offload-bundler -targets=triple1,triple2 -type=ii 
-outputs=a.triple1.ii,a.triple2.ii -inputs=a.ii -unbundle
+
+
 Supported File Formats
 ==
-Several text and binary file formats are supported for bundling/unbundling. See
-:ref:`supported-file-formats-table` for a list of currently supported formats.
+
+Multiple text and binary file formats are supported for bundling/unbundling. 
See
+:ref:`supported-file-formats-table` for a list of currently supported input
+formats. Use the ``File Type`` column to determine the value to pass to the
+``--type`` option based on the type of input files while bundling/unbundling.
 
   .. table:: Supported File Formats
  :name: supported-file-formats-table
 
- +++-+
- | File Format| File Extension | Text/Binary |
- +++=+
- | CPP output |i   | Text|
- +++-+
- | C++ CPP output |   ii   | Text|
- +++-+
- | CUDA/HIP output|   cui  | Text|
- +++-+
- | Dependency |d   | Text|
- +++-+
- | LLVM   |   ll   | 

[clang] [clang-offload-bundler] Add support for -check-input-archive (PR #73709)

2023-11-29 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/73709

>From 995706601f9f4aed021a9003ad79ca3e7e1d18af Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 28 Nov 2023 14:42:11 -0800
Subject: [PATCH 1/5] [clang-offload-bundler] Add support for
 -check-input-archive

In this patch, we add support for checking a heterogeneous archive.
We also significantly improve the clang-offload-bundler documentation.
---
 clang/docs/ClangOffloadBundler.rst| 297 +++---
 clang/include/clang/Driver/OffloadBundler.h   |   2 +-
 clang/lib/Driver/OffloadBundler.cpp   |  94 +-
 .../ClangOffloadBundler.cpp   |  19 ++
 4 files changed, 358 insertions(+), 54 deletions(-)

diff --git a/clang/docs/ClangOffloadBundler.rst 
b/clang/docs/ClangOffloadBundler.rst
index 1e21d3e7264d5c3..1fcfde011e46e2f 100644
--- a/clang/docs/ClangOffloadBundler.rst
+++ b/clang/docs/ClangOffloadBundler.rst
@@ -30,58 +30,139 @@ includes an ``init`` function that will use the runtime 
corresponding to the
 offload kind (see :ref:`clang-offload-kind-table`) to load the offload code
 objects appropriate to the devices present when the host program is executed.
 
+:program:`clang-offload-bundler` is located in
+`clang/tools/clang-offload-bundler`.
+
+.. code-block:: console
+
+  $ clang-offload-bundler -help
+  OVERVIEW: A tool to bundle several input files of the specified type 
+  referring to the same source file but different targets into a single
+  one. The resulting file can also be unbundled into different files by
+  this tool if -unbundle is provided.
+
+  USAGE: clang-offload-bundler [options]
+
+  OPTIONS:
+
+  Generic Options:
+
+--help  - Display available options (--help-hidden for 
more)
+--help-list - Display list of available options 
(--help-list-hidden for more)
+--version   - Display the version of this program
+
+  clang-offload-bundler options:
+
+--###   - Print any external commands that are to be 
executed instead of actually executing them - for testing purposes.
+--allow-missing-bundles - Create empty files if bundles are missing when 
unbundling.
+--bundle-align=   - Alignment of bundle for binary files
+--check-input-archive   - Check if input heterogeneous archive is valid in 
terms of TargetID rules.
+--inputs=   - [,...]
+--list  - List bundle IDs in the bundled file.
+--outputs=  - [,...]
+--targets=  - [-,...]
+--type= - Type of the files to be bundled/unbundled.
+  Current supported types are:
+i   - cpp-output
+ii  - c++-cpp-output
+cui - cuda/hip-output
+d   - dependency
+ll  - llvm
+bc  - llvm-bc
+s   - assembler
+o   - object
+a   - archive of bundled files
+gch - precompiled-header
+ast - clang AST file
+--unbundle  - Unbundle bundled file into several output files.
+
+Usage
+=
+
+This tool can be used as follows for bundling:
+
+::
+
+  clang-offload-bundler -targets=triple1,triple2 -type=ii 
-inputs=a.triple1.ii,a.triple2.ii -outputs=a.ii
+
+or, it can be used as follows for unbundling:
+
+::
+
+  clang-offload-bundler -targets=triple1,triple2 -type=ii 
-outputs=a.triple1.ii,a.triple2.ii -inputs=a.ii -unbundle
+
+
 Supported File Formats
 ==
-Several text and binary file formats are supported for bundling/unbundling. See
-:ref:`supported-file-formats-table` for a list of currently supported formats.
+
+Multiple text and binary file formats are supported for bundling/unbundling. 
See
+:ref:`supported-file-formats-table` for a list of currently supported input
+formats. Use the ``File Type`` column to determine the value to pass to the
+``--type`` option based on the type of input files while bundling/unbundling.
 
   .. table:: Supported File Formats
  :name: supported-file-formats-table
 
- +++-+
- | File Format| File Extension | Text/Binary |
- +++=+
- | CPP output |i   | Text|
- +++-+
- | C++ CPP output |   ii   | Text|
- +++-+
- | CUDA/HIP output|   cui  | Text|
- +++-+
- | Dependency |d   | Text|
- +++-+
- | LLVM   |   ll   | 

[clang] [CodeGen] Add conditional to module cloning in bitcode linking (PR #72478)

2023-11-29 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/72478

>From 5bfc0608073cd699e42a23b07d68b4572a14fcbd Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Wed, 15 Nov 2023 22:06:46 -0800
Subject: [PATCH 1/5] [CodeGen] Add conditional to module cloning in bitcode
 linking

Now that we have a commandline option dictating a second link step,
(-relink-builtin-bitcode-postop), we can condition the module
creation when linking in bitcode modules. This aims to improve
performance by avoiding unnecessary linking
---
 clang/lib/CodeGen/BackendUtil.cpp   |  2 +-
 clang/lib/CodeGen/CodeGenAction.cpp | 56 -
 2 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index a7a47d17723cb73..f01a6514f6effb0 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -103,7 +103,7 @@ static cl::opt ClSanitizeOnOptimizerEarlyEP(
 cl::desc("Insert sanitizers on OptimizerEarlyEP."), cl::init(false));
 
 // Re-link builtin bitcodes after optimization
-static cl::opt ClRelinkBuiltinBitcodePostop(
+cl::opt ClRelinkBuiltinBitcodePostop(
 "relink-builtin-bitcode-postop", cl::Optional,
 cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false));
 }
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index a31a271ed77d1ca..e3ceb3adbcc93a8 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -57,6 +57,10 @@ using namespace llvm;
 
 #define DEBUG_TYPE "codegenaction"
 
+namespace llvm {
+extern cl::opt ClRelinkBuiltinBitcodePostop;
+}
+
 namespace clang {
 class BackendConsumer;
 class ClangDiagnosticHandler final : public DiagnosticHandler {
@@ -251,32 +255,50 @@ bool BackendConsumer::LinkInModules(llvm::Module *M, bool 
ShouldLinkFiles) {
   }
 
 CurLinkModule = LM.Module.get();
-
-// TODO: If CloneModule() is updated to support cloning of unmaterialized
-// modules, we can remove this
 bool Err;
-if (Error E = CurLinkModule->materializeAll())
-  return false;
 
 // Create a Clone to move to the linker, which preserves the original
 // linking modules, allowing them to be linked again in the future
-// TODO: Add a ShouldCleanup option to make Cloning optional. When
-// set, we can pass the original modules to the linker for cleanup
-std::unique_ptr Clone = llvm::CloneModule(*LM.Module);
+if (ClRelinkBuiltinBitcodePostop) {
+  // TODO: If CloneModule() is updated to support cloning of unmaterialized
+  // modules, we can remove this
+  if (Error E = CurLinkModule->materializeAll())
+return false;
 
-if (LM.Internalize) {
-  Err = Linker::linkModules(
+  std::unique_ptr Clone = llvm::CloneModule(*LM.Module);
+
+  if (LM.Internalize) {
+Err = Linker::linkModules(
   *M, std::move(Clone), LM.LinkFlags,
   [](llvm::Module , const llvm::StringSet<> ) {
-internalizeModule(M, [](const llvm::GlobalValue ) {
-  return !GV.hasName() || (GVS.count(GV.getName()) == 0);
-});
+  internalizeModule(M, [](const llvm::GlobalValue ) {
+return !GV.hasName() ||
+(GVS.count(GV.getName()) == 0);
+});
   });
-} else
-  Err = Linker::linkModules(*M, std::move(Clone), LM.LinkFlags);
+  } else
+Err = Linker::linkModules(*M, std::move(Clone), LM.LinkFlags);
 
-if (Err)
-  return true;
+  if (Err)
+return true;
+}
+// Otherwise we can link (and clean up) the original modules
+else {
+  if (LM.Internalize) {
+Err = Linker::linkModules(
+  *M, std::move(LM.Module), LM.LinkFlags,
+  [](llvm::Module , const llvm::StringSet<> ) {
+  internalizeModule(M, [](const llvm::GlobalValue ) {
+return !GV.hasName() ||
+(GVS.count(GV.getName()) == 0);
+});
+  });
+  } else
+Err = Linker::linkModules(*M, std::move(LM.Module), LM.LinkFlags);
+
+  if (Err)
+return true;
+}
   }
 
   return false; // success

>From d0a3664520272a174ccbb5f4986ec796c0c86883 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Thu, 16 Nov 2023 07:29:55 -0800
Subject: [PATCH 2/5] [NFC] Taking clang-format suggestions

---
 clang/lib/CodeGen/CodeGenAction.cpp | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index e3ceb3adbcc93a8..fbf53accd48d0b2 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -271,10 +271,9 @@ bool BackendConsumer::LinkInModules(llvm::Module *M, bool 
ShouldLinkFiles) {
 Err = Linker::linkModules(
   *M, 

[clang] [CodeGen] Add conditional to module cloning in bitcode linking (PR #72478)

2023-11-29 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/72478

>From 7d2ee902f1fb1dc0cd355b4b51fda32309f45ccb Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Wed, 15 Nov 2023 22:06:46 -0800
Subject: [PATCH 1/5] [CodeGen] Add conditional to module cloning in bitcode
 linking

Now that we have a commandline option dictating a second link step,
(-relink-builtin-bitcode-postop), we can condition the module
creation when linking in bitcode modules. This aims to improve
performance by avoiding unnecessary linking
---
 clang/lib/CodeGen/BackendUtil.cpp   |  2 +-
 clang/lib/CodeGen/CodeGenAction.cpp | 56 -
 2 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index a7a47d17723cb73..f01a6514f6effb0 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -103,7 +103,7 @@ static cl::opt ClSanitizeOnOptimizerEarlyEP(
 cl::desc("Insert sanitizers on OptimizerEarlyEP."), cl::init(false));
 
 // Re-link builtin bitcodes after optimization
-static cl::opt ClRelinkBuiltinBitcodePostop(
+cl::opt ClRelinkBuiltinBitcodePostop(
 "relink-builtin-bitcode-postop", cl::Optional,
 cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false));
 }
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index a31a271ed77d1ca..e3ceb3adbcc93a8 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -57,6 +57,10 @@ using namespace llvm;
 
 #define DEBUG_TYPE "codegenaction"
 
+namespace llvm {
+extern cl::opt ClRelinkBuiltinBitcodePostop;
+}
+
 namespace clang {
 class BackendConsumer;
 class ClangDiagnosticHandler final : public DiagnosticHandler {
@@ -251,32 +255,50 @@ bool BackendConsumer::LinkInModules(llvm::Module *M, bool 
ShouldLinkFiles) {
   }
 
 CurLinkModule = LM.Module.get();
-
-// TODO: If CloneModule() is updated to support cloning of unmaterialized
-// modules, we can remove this
 bool Err;
-if (Error E = CurLinkModule->materializeAll())
-  return false;
 
 // Create a Clone to move to the linker, which preserves the original
 // linking modules, allowing them to be linked again in the future
-// TODO: Add a ShouldCleanup option to make Cloning optional. When
-// set, we can pass the original modules to the linker for cleanup
-std::unique_ptr Clone = llvm::CloneModule(*LM.Module);
+if (ClRelinkBuiltinBitcodePostop) {
+  // TODO: If CloneModule() is updated to support cloning of unmaterialized
+  // modules, we can remove this
+  if (Error E = CurLinkModule->materializeAll())
+return false;
 
-if (LM.Internalize) {
-  Err = Linker::linkModules(
+  std::unique_ptr Clone = llvm::CloneModule(*LM.Module);
+
+  if (LM.Internalize) {
+Err = Linker::linkModules(
   *M, std::move(Clone), LM.LinkFlags,
   [](llvm::Module , const llvm::StringSet<> ) {
-internalizeModule(M, [](const llvm::GlobalValue ) {
-  return !GV.hasName() || (GVS.count(GV.getName()) == 0);
-});
+  internalizeModule(M, [](const llvm::GlobalValue ) {
+return !GV.hasName() ||
+(GVS.count(GV.getName()) == 0);
+});
   });
-} else
-  Err = Linker::linkModules(*M, std::move(Clone), LM.LinkFlags);
+  } else
+Err = Linker::linkModules(*M, std::move(Clone), LM.LinkFlags);
 
-if (Err)
-  return true;
+  if (Err)
+return true;
+}
+// Otherwise we can link (and clean up) the original modules
+else {
+  if (LM.Internalize) {
+Err = Linker::linkModules(
+  *M, std::move(LM.Module), LM.LinkFlags,
+  [](llvm::Module , const llvm::StringSet<> ) {
+  internalizeModule(M, [](const llvm::GlobalValue ) {
+return !GV.hasName() ||
+(GVS.count(GV.getName()) == 0);
+});
+  });
+  } else
+Err = Linker::linkModules(*M, std::move(LM.Module), LM.LinkFlags);
+
+  if (Err)
+return true;
+}
   }
 
   return false; // success

>From 9fb0b81d2d4770f8d5c23361e7fb3dc135a49355 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Thu, 16 Nov 2023 07:29:55 -0800
Subject: [PATCH 2/5] [NFC] Taking clang-format suggestions

---
 clang/lib/CodeGen/CodeGenAction.cpp | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index e3ceb3adbcc93a8..fbf53accd48d0b2 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -271,10 +271,9 @@ bool BackendConsumer::LinkInModules(llvm::Module *M, bool 
ShouldLinkFiles) {
 Err = Linker::linkModules(
   *M, 

[clang] [clang-offload-bundler] Add support for -check-input-archive (PR #73709)

2023-11-29 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/73709

>From e69976a8923b134e051dd2756233c0285d3c9880 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 28 Nov 2023 14:42:11 -0800
Subject: [PATCH 1/4] [clang-offload-bundler] Add support for
 -check-input-archive

In this patch, we add support for checking a heterogeneous archive.
We also significantly improve the clang-offload-bundler documentation.
---
 clang/docs/ClangOffloadBundler.rst| 297 +++---
 clang/include/clang/Driver/OffloadBundler.h   |   2 +-
 clang/lib/Driver/OffloadBundler.cpp   |  94 +-
 .../ClangOffloadBundler.cpp   |  19 ++
 4 files changed, 358 insertions(+), 54 deletions(-)

diff --git a/clang/docs/ClangOffloadBundler.rst 
b/clang/docs/ClangOffloadBundler.rst
index 1e21d3e7264d5c3..1fcfde011e46e2f 100644
--- a/clang/docs/ClangOffloadBundler.rst
+++ b/clang/docs/ClangOffloadBundler.rst
@@ -30,58 +30,139 @@ includes an ``init`` function that will use the runtime 
corresponding to the
 offload kind (see :ref:`clang-offload-kind-table`) to load the offload code
 objects appropriate to the devices present when the host program is executed.
 
+:program:`clang-offload-bundler` is located in
+`clang/tools/clang-offload-bundler`.
+
+.. code-block:: console
+
+  $ clang-offload-bundler -help
+  OVERVIEW: A tool to bundle several input files of the specified type 
+  referring to the same source file but different targets into a single
+  one. The resulting file can also be unbundled into different files by
+  this tool if -unbundle is provided.
+
+  USAGE: clang-offload-bundler [options]
+
+  OPTIONS:
+
+  Generic Options:
+
+--help  - Display available options (--help-hidden for 
more)
+--help-list - Display list of available options 
(--help-list-hidden for more)
+--version   - Display the version of this program
+
+  clang-offload-bundler options:
+
+--###   - Print any external commands that are to be 
executed instead of actually executing them - for testing purposes.
+--allow-missing-bundles - Create empty files if bundles are missing when 
unbundling.
+--bundle-align=   - Alignment of bundle for binary files
+--check-input-archive   - Check if input heterogeneous archive is valid in 
terms of TargetID rules.
+--inputs=   - [,...]
+--list  - List bundle IDs in the bundled file.
+--outputs=  - [,...]
+--targets=  - [-,...]
+--type= - Type of the files to be bundled/unbundled.
+  Current supported types are:
+i   - cpp-output
+ii  - c++-cpp-output
+cui - cuda/hip-output
+d   - dependency
+ll  - llvm
+bc  - llvm-bc
+s   - assembler
+o   - object
+a   - archive of bundled files
+gch - precompiled-header
+ast - clang AST file
+--unbundle  - Unbundle bundled file into several output files.
+
+Usage
+=
+
+This tool can be used as follows for bundling:
+
+::
+
+  clang-offload-bundler -targets=triple1,triple2 -type=ii 
-inputs=a.triple1.ii,a.triple2.ii -outputs=a.ii
+
+or, it can be used as follows for unbundling:
+
+::
+
+  clang-offload-bundler -targets=triple1,triple2 -type=ii 
-outputs=a.triple1.ii,a.triple2.ii -inputs=a.ii -unbundle
+
+
 Supported File Formats
 ==
-Several text and binary file formats are supported for bundling/unbundling. See
-:ref:`supported-file-formats-table` for a list of currently supported formats.
+
+Multiple text and binary file formats are supported for bundling/unbundling. 
See
+:ref:`supported-file-formats-table` for a list of currently supported input
+formats. Use the ``File Type`` column to determine the value to pass to the
+``--type`` option based on the type of input files while bundling/unbundling.
 
   .. table:: Supported File Formats
  :name: supported-file-formats-table
 
- +++-+
- | File Format| File Extension | Text/Binary |
- +++=+
- | CPP output |i   | Text|
- +++-+
- | C++ CPP output |   ii   | Text|
- +++-+
- | CUDA/HIP output|   cui  | Text|
- +++-+
- | Dependency |d   | Text|
- +++-+
- | LLVM   |   ll   | 

[clang] [clang-offload-bundler] Add support for -check-input-archive (PR #73709)

2023-11-29 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/73709

>From e69976a8923b134e051dd2756233c0285d3c9880 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 28 Nov 2023 14:42:11 -0800
Subject: [PATCH 1/3] [clang-offload-bundler] Add support for
 -check-input-archive

In this patch, we add support for checking a heterogeneous archive.
We also significantly improve the clang-offload-bundler documentation.
---
 clang/docs/ClangOffloadBundler.rst| 297 +++---
 clang/include/clang/Driver/OffloadBundler.h   |   2 +-
 clang/lib/Driver/OffloadBundler.cpp   |  94 +-
 .../ClangOffloadBundler.cpp   |  19 ++
 4 files changed, 358 insertions(+), 54 deletions(-)

diff --git a/clang/docs/ClangOffloadBundler.rst 
b/clang/docs/ClangOffloadBundler.rst
index 1e21d3e7264d5c3..1fcfde011e46e2f 100644
--- a/clang/docs/ClangOffloadBundler.rst
+++ b/clang/docs/ClangOffloadBundler.rst
@@ -30,58 +30,139 @@ includes an ``init`` function that will use the runtime 
corresponding to the
 offload kind (see :ref:`clang-offload-kind-table`) to load the offload code
 objects appropriate to the devices present when the host program is executed.
 
+:program:`clang-offload-bundler` is located in
+`clang/tools/clang-offload-bundler`.
+
+.. code-block:: console
+
+  $ clang-offload-bundler -help
+  OVERVIEW: A tool to bundle several input files of the specified type 
+  referring to the same source file but different targets into a single
+  one. The resulting file can also be unbundled into different files by
+  this tool if -unbundle is provided.
+
+  USAGE: clang-offload-bundler [options]
+
+  OPTIONS:
+
+  Generic Options:
+
+--help  - Display available options (--help-hidden for 
more)
+--help-list - Display list of available options 
(--help-list-hidden for more)
+--version   - Display the version of this program
+
+  clang-offload-bundler options:
+
+--###   - Print any external commands that are to be 
executed instead of actually executing them - for testing purposes.
+--allow-missing-bundles - Create empty files if bundles are missing when 
unbundling.
+--bundle-align=   - Alignment of bundle for binary files
+--check-input-archive   - Check if input heterogeneous archive is valid in 
terms of TargetID rules.
+--inputs=   - [,...]
+--list  - List bundle IDs in the bundled file.
+--outputs=  - [,...]
+--targets=  - [-,...]
+--type= - Type of the files to be bundled/unbundled.
+  Current supported types are:
+i   - cpp-output
+ii  - c++-cpp-output
+cui - cuda/hip-output
+d   - dependency
+ll  - llvm
+bc  - llvm-bc
+s   - assembler
+o   - object
+a   - archive of bundled files
+gch - precompiled-header
+ast - clang AST file
+--unbundle  - Unbundle bundled file into several output files.
+
+Usage
+=
+
+This tool can be used as follows for bundling:
+
+::
+
+  clang-offload-bundler -targets=triple1,triple2 -type=ii 
-inputs=a.triple1.ii,a.triple2.ii -outputs=a.ii
+
+or, it can be used as follows for unbundling:
+
+::
+
+  clang-offload-bundler -targets=triple1,triple2 -type=ii 
-outputs=a.triple1.ii,a.triple2.ii -inputs=a.ii -unbundle
+
+
 Supported File Formats
 ==
-Several text and binary file formats are supported for bundling/unbundling. See
-:ref:`supported-file-formats-table` for a list of currently supported formats.
+
+Multiple text and binary file formats are supported for bundling/unbundling. 
See
+:ref:`supported-file-formats-table` for a list of currently supported input
+formats. Use the ``File Type`` column to determine the value to pass to the
+``--type`` option based on the type of input files while bundling/unbundling.
 
   .. table:: Supported File Formats
  :name: supported-file-formats-table
 
- +++-+
- | File Format| File Extension | Text/Binary |
- +++=+
- | CPP output |i   | Text|
- +++-+
- | C++ CPP output |   ii   | Text|
- +++-+
- | CUDA/HIP output|   cui  | Text|
- +++-+
- | Dependency |d   | Text|
- +++-+
- | LLVM   |   ll   | 

[clang] [clang-offload-bundler] Add support for -check-input-archive (PR #73709)

2023-11-29 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/73709

>From e69976a8923b134e051dd2756233c0285d3c9880 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 28 Nov 2023 14:42:11 -0800
Subject: [PATCH 1/2] [clang-offload-bundler] Add support for
 -check-input-archive

In this patch, we add support for checking a heterogeneous archive.
We also significantly improve the clang-offload-bundler documentation.
---
 clang/docs/ClangOffloadBundler.rst| 297 +++---
 clang/include/clang/Driver/OffloadBundler.h   |   2 +-
 clang/lib/Driver/OffloadBundler.cpp   |  94 +-
 .../ClangOffloadBundler.cpp   |  19 ++
 4 files changed, 358 insertions(+), 54 deletions(-)

diff --git a/clang/docs/ClangOffloadBundler.rst 
b/clang/docs/ClangOffloadBundler.rst
index 1e21d3e7264d5c3..1fcfde011e46e2f 100644
--- a/clang/docs/ClangOffloadBundler.rst
+++ b/clang/docs/ClangOffloadBundler.rst
@@ -30,58 +30,139 @@ includes an ``init`` function that will use the runtime 
corresponding to the
 offload kind (see :ref:`clang-offload-kind-table`) to load the offload code
 objects appropriate to the devices present when the host program is executed.
 
+:program:`clang-offload-bundler` is located in
+`clang/tools/clang-offload-bundler`.
+
+.. code-block:: console
+
+  $ clang-offload-bundler -help
+  OVERVIEW: A tool to bundle several input files of the specified type 
+  referring to the same source file but different targets into a single
+  one. The resulting file can also be unbundled into different files by
+  this tool if -unbundle is provided.
+
+  USAGE: clang-offload-bundler [options]
+
+  OPTIONS:
+
+  Generic Options:
+
+--help  - Display available options (--help-hidden for 
more)
+--help-list - Display list of available options 
(--help-list-hidden for more)
+--version   - Display the version of this program
+
+  clang-offload-bundler options:
+
+--###   - Print any external commands that are to be 
executed instead of actually executing them - for testing purposes.
+--allow-missing-bundles - Create empty files if bundles are missing when 
unbundling.
+--bundle-align=   - Alignment of bundle for binary files
+--check-input-archive   - Check if input heterogeneous archive is valid in 
terms of TargetID rules.
+--inputs=   - [,...]
+--list  - List bundle IDs in the bundled file.
+--outputs=  - [,...]
+--targets=  - [-,...]
+--type= - Type of the files to be bundled/unbundled.
+  Current supported types are:
+i   - cpp-output
+ii  - c++-cpp-output
+cui - cuda/hip-output
+d   - dependency
+ll  - llvm
+bc  - llvm-bc
+s   - assembler
+o   - object
+a   - archive of bundled files
+gch - precompiled-header
+ast - clang AST file
+--unbundle  - Unbundle bundled file into several output files.
+
+Usage
+=
+
+This tool can be used as follows for bundling:
+
+::
+
+  clang-offload-bundler -targets=triple1,triple2 -type=ii 
-inputs=a.triple1.ii,a.triple2.ii -outputs=a.ii
+
+or, it can be used as follows for unbundling:
+
+::
+
+  clang-offload-bundler -targets=triple1,triple2 -type=ii 
-outputs=a.triple1.ii,a.triple2.ii -inputs=a.ii -unbundle
+
+
 Supported File Formats
 ==
-Several text and binary file formats are supported for bundling/unbundling. See
-:ref:`supported-file-formats-table` for a list of currently supported formats.
+
+Multiple text and binary file formats are supported for bundling/unbundling. 
See
+:ref:`supported-file-formats-table` for a list of currently supported input
+formats. Use the ``File Type`` column to determine the value to pass to the
+``--type`` option based on the type of input files while bundling/unbundling.
 
   .. table:: Supported File Formats
  :name: supported-file-formats-table
 
- +++-+
- | File Format| File Extension | Text/Binary |
- +++=+
- | CPP output |i   | Text|
- +++-+
- | C++ CPP output |   ii   | Text|
- +++-+
- | CUDA/HIP output|   cui  | Text|
- +++-+
- | Dependency |d   | Text|
- +++-+
- | LLVM   |   ll   | 

[clang] [clang-offload-bundler] Add support for -check-input-archive (PR #73709)

2023-11-28 Thread Jacob Lambert via cfe-commits

lamb-j wrote:

For context, these changes reconcile differences between the upstream 
clang-offload-bundler and the AMD Fork offload bundler 
(https://github.com/RadeonOpenCompute/llvm-project/tree/amd-stg-open)

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


[clang] [clang-offload-bundler] Add support for -check-input-archive (PR #73709)

2023-11-28 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j created 
https://github.com/llvm/llvm-project/pull/73709

In this patch, we add support for checking a heterogeneous archive. We also 
significantly improve the clang-offload-bundler documentation.

>From e69976a8923b134e051dd2756233c0285d3c9880 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 28 Nov 2023 14:42:11 -0800
Subject: [PATCH] [clang-offload-bundler] Add support for -check-input-archive

In this patch, we add support for checking a heterogeneous archive.
We also significantly improve the clang-offload-bundler documentation.
---
 clang/docs/ClangOffloadBundler.rst| 297 +++---
 clang/include/clang/Driver/OffloadBundler.h   |   2 +-
 clang/lib/Driver/OffloadBundler.cpp   |  94 +-
 .../ClangOffloadBundler.cpp   |  19 ++
 4 files changed, 358 insertions(+), 54 deletions(-)

diff --git a/clang/docs/ClangOffloadBundler.rst 
b/clang/docs/ClangOffloadBundler.rst
index 1e21d3e7264d5c3..1fcfde011e46e2f 100644
--- a/clang/docs/ClangOffloadBundler.rst
+++ b/clang/docs/ClangOffloadBundler.rst
@@ -30,58 +30,139 @@ includes an ``init`` function that will use the runtime 
corresponding to the
 offload kind (see :ref:`clang-offload-kind-table`) to load the offload code
 objects appropriate to the devices present when the host program is executed.
 
+:program:`clang-offload-bundler` is located in
+`clang/tools/clang-offload-bundler`.
+
+.. code-block:: console
+
+  $ clang-offload-bundler -help
+  OVERVIEW: A tool to bundle several input files of the specified type 
+  referring to the same source file but different targets into a single
+  one. The resulting file can also be unbundled into different files by
+  this tool if -unbundle is provided.
+
+  USAGE: clang-offload-bundler [options]
+
+  OPTIONS:
+
+  Generic Options:
+
+--help  - Display available options (--help-hidden for 
more)
+--help-list - Display list of available options 
(--help-list-hidden for more)
+--version   - Display the version of this program
+
+  clang-offload-bundler options:
+
+--###   - Print any external commands that are to be 
executed instead of actually executing them - for testing purposes.
+--allow-missing-bundles - Create empty files if bundles are missing when 
unbundling.
+--bundle-align=   - Alignment of bundle for binary files
+--check-input-archive   - Check if input heterogeneous archive is valid in 
terms of TargetID rules.
+--inputs=   - [,...]
+--list  - List bundle IDs in the bundled file.
+--outputs=  - [,...]
+--targets=  - [-,...]
+--type= - Type of the files to be bundled/unbundled.
+  Current supported types are:
+i   - cpp-output
+ii  - c++-cpp-output
+cui - cuda/hip-output
+d   - dependency
+ll  - llvm
+bc  - llvm-bc
+s   - assembler
+o   - object
+a   - archive of bundled files
+gch - precompiled-header
+ast - clang AST file
+--unbundle  - Unbundle bundled file into several output files.
+
+Usage
+=
+
+This tool can be used as follows for bundling:
+
+::
+
+  clang-offload-bundler -targets=triple1,triple2 -type=ii 
-inputs=a.triple1.ii,a.triple2.ii -outputs=a.ii
+
+or, it can be used as follows for unbundling:
+
+::
+
+  clang-offload-bundler -targets=triple1,triple2 -type=ii 
-outputs=a.triple1.ii,a.triple2.ii -inputs=a.ii -unbundle
+
+
 Supported File Formats
 ==
-Several text and binary file formats are supported for bundling/unbundling. See
-:ref:`supported-file-formats-table` for a list of currently supported formats.
+
+Multiple text and binary file formats are supported for bundling/unbundling. 
See
+:ref:`supported-file-formats-table` for a list of currently supported input
+formats. Use the ``File Type`` column to determine the value to pass to the
+``--type`` option based on the type of input files while bundling/unbundling.
 
   .. table:: Supported File Formats
  :name: supported-file-formats-table
 
- +++-+
- | File Format| File Extension | Text/Binary |
- +++=+
- | CPP output |i   | Text|
- +++-+
- | C++ CPP output |   ii   | Text|
- +++-+
- | CUDA/HIP output|   cui  | Text|
- +++-+
- | Dependency |  

[clang] [CodeGen] Add conditional to module cloning in bitcode linking (PR #72478)

2023-11-16 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/72478

>From 3a2a066eeadce6b8f3cd5645965ffe564e68fba3 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Wed, 15 Nov 2023 22:06:46 -0800
Subject: [PATCH 1/3] [CodeGen] Add conditional to module cloning in bitcode
 linking

Now that we have a commandline option dictating a second link step,
(-relink-builtin-bitcode-postop), we can condition the module
creation when linking in bitcode modules. This aims to improve
performance by avoiding unnecessary linking
---
 clang/lib/CodeGen/BackendUtil.cpp   |  2 +-
 clang/lib/CodeGen/CodeGenAction.cpp | 56 -
 2 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index a7a47d17723cb73..f01a6514f6effb0 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -103,7 +103,7 @@ static cl::opt ClSanitizeOnOptimizerEarlyEP(
 cl::desc("Insert sanitizers on OptimizerEarlyEP."), cl::init(false));
 
 // Re-link builtin bitcodes after optimization
-static cl::opt ClRelinkBuiltinBitcodePostop(
+cl::opt ClRelinkBuiltinBitcodePostop(
 "relink-builtin-bitcode-postop", cl::Optional,
 cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false));
 }
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index a31a271ed77d1ca..e3ceb3adbcc93a8 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -57,6 +57,10 @@ using namespace llvm;
 
 #define DEBUG_TYPE "codegenaction"
 
+namespace llvm {
+extern cl::opt ClRelinkBuiltinBitcodePostop;
+}
+
 namespace clang {
 class BackendConsumer;
 class ClangDiagnosticHandler final : public DiagnosticHandler {
@@ -251,32 +255,50 @@ bool BackendConsumer::LinkInModules(llvm::Module *M, bool 
ShouldLinkFiles) {
   }
 
 CurLinkModule = LM.Module.get();
-
-// TODO: If CloneModule() is updated to support cloning of unmaterialized
-// modules, we can remove this
 bool Err;
-if (Error E = CurLinkModule->materializeAll())
-  return false;
 
 // Create a Clone to move to the linker, which preserves the original
 // linking modules, allowing them to be linked again in the future
-// TODO: Add a ShouldCleanup option to make Cloning optional. When
-// set, we can pass the original modules to the linker for cleanup
-std::unique_ptr Clone = llvm::CloneModule(*LM.Module);
+if (ClRelinkBuiltinBitcodePostop) {
+  // TODO: If CloneModule() is updated to support cloning of unmaterialized
+  // modules, we can remove this
+  if (Error E = CurLinkModule->materializeAll())
+return false;
 
-if (LM.Internalize) {
-  Err = Linker::linkModules(
+  std::unique_ptr Clone = llvm::CloneModule(*LM.Module);
+
+  if (LM.Internalize) {
+Err = Linker::linkModules(
   *M, std::move(Clone), LM.LinkFlags,
   [](llvm::Module , const llvm::StringSet<> ) {
-internalizeModule(M, [](const llvm::GlobalValue ) {
-  return !GV.hasName() || (GVS.count(GV.getName()) == 0);
-});
+  internalizeModule(M, [](const llvm::GlobalValue ) {
+return !GV.hasName() ||
+(GVS.count(GV.getName()) == 0);
+});
   });
-} else
-  Err = Linker::linkModules(*M, std::move(Clone), LM.LinkFlags);
+  } else
+Err = Linker::linkModules(*M, std::move(Clone), LM.LinkFlags);
 
-if (Err)
-  return true;
+  if (Err)
+return true;
+}
+// Otherwise we can link (and clean up) the original modules
+else {
+  if (LM.Internalize) {
+Err = Linker::linkModules(
+  *M, std::move(LM.Module), LM.LinkFlags,
+  [](llvm::Module , const llvm::StringSet<> ) {
+  internalizeModule(M, [](const llvm::GlobalValue ) {
+return !GV.hasName() ||
+(GVS.count(GV.getName()) == 0);
+});
+  });
+  } else
+Err = Linker::linkModules(*M, std::move(LM.Module), LM.LinkFlags);
+
+  if (Err)
+return true;
+}
   }
 
   return false; // success

>From 5e9cd599c60334e8d5d99be0afb091d848dfc746 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Thu, 16 Nov 2023 07:29:55 -0800
Subject: [PATCH 2/3] [NFC] Taking clang-format suggestions

---
 clang/lib/CodeGen/CodeGenAction.cpp | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index e3ceb3adbcc93a8..fbf53accd48d0b2 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -271,10 +271,9 @@ bool BackendConsumer::LinkInModules(llvm::Module *M, bool 
ShouldLinkFiles) {
 Err = Linker::linkModules(
   *M, 

[clang] [CodeGen] Add conditional to module cloning in bitcode linking (PR #72478)

2023-11-16 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/72478

>From 3a2a066eeadce6b8f3cd5645965ffe564e68fba3 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Wed, 15 Nov 2023 22:06:46 -0800
Subject: [PATCH 1/2] [CodeGen] Add conditional to module cloning in bitcode
 linking

Now that we have a commandline option dictating a second link step,
(-relink-builtin-bitcode-postop), we can condition the module
creation when linking in bitcode modules. This aims to improve
performance by avoiding unnecessary linking
---
 clang/lib/CodeGen/BackendUtil.cpp   |  2 +-
 clang/lib/CodeGen/CodeGenAction.cpp | 56 -
 2 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index a7a47d17723cb73..f01a6514f6effb0 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -103,7 +103,7 @@ static cl::opt ClSanitizeOnOptimizerEarlyEP(
 cl::desc("Insert sanitizers on OptimizerEarlyEP."), cl::init(false));
 
 // Re-link builtin bitcodes after optimization
-static cl::opt ClRelinkBuiltinBitcodePostop(
+cl::opt ClRelinkBuiltinBitcodePostop(
 "relink-builtin-bitcode-postop", cl::Optional,
 cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false));
 }
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index a31a271ed77d1ca..e3ceb3adbcc93a8 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -57,6 +57,10 @@ using namespace llvm;
 
 #define DEBUG_TYPE "codegenaction"
 
+namespace llvm {
+extern cl::opt ClRelinkBuiltinBitcodePostop;
+}
+
 namespace clang {
 class BackendConsumer;
 class ClangDiagnosticHandler final : public DiagnosticHandler {
@@ -251,32 +255,50 @@ bool BackendConsumer::LinkInModules(llvm::Module *M, bool 
ShouldLinkFiles) {
   }
 
 CurLinkModule = LM.Module.get();
-
-// TODO: If CloneModule() is updated to support cloning of unmaterialized
-// modules, we can remove this
 bool Err;
-if (Error E = CurLinkModule->materializeAll())
-  return false;
 
 // Create a Clone to move to the linker, which preserves the original
 // linking modules, allowing them to be linked again in the future
-// TODO: Add a ShouldCleanup option to make Cloning optional. When
-// set, we can pass the original modules to the linker for cleanup
-std::unique_ptr Clone = llvm::CloneModule(*LM.Module);
+if (ClRelinkBuiltinBitcodePostop) {
+  // TODO: If CloneModule() is updated to support cloning of unmaterialized
+  // modules, we can remove this
+  if (Error E = CurLinkModule->materializeAll())
+return false;
 
-if (LM.Internalize) {
-  Err = Linker::linkModules(
+  std::unique_ptr Clone = llvm::CloneModule(*LM.Module);
+
+  if (LM.Internalize) {
+Err = Linker::linkModules(
   *M, std::move(Clone), LM.LinkFlags,
   [](llvm::Module , const llvm::StringSet<> ) {
-internalizeModule(M, [](const llvm::GlobalValue ) {
-  return !GV.hasName() || (GVS.count(GV.getName()) == 0);
-});
+  internalizeModule(M, [](const llvm::GlobalValue ) {
+return !GV.hasName() ||
+(GVS.count(GV.getName()) == 0);
+});
   });
-} else
-  Err = Linker::linkModules(*M, std::move(Clone), LM.LinkFlags);
+  } else
+Err = Linker::linkModules(*M, std::move(Clone), LM.LinkFlags);
 
-if (Err)
-  return true;
+  if (Err)
+return true;
+}
+// Otherwise we can link (and clean up) the original modules
+else {
+  if (LM.Internalize) {
+Err = Linker::linkModules(
+  *M, std::move(LM.Module), LM.LinkFlags,
+  [](llvm::Module , const llvm::StringSet<> ) {
+  internalizeModule(M, [](const llvm::GlobalValue ) {
+return !GV.hasName() ||
+(GVS.count(GV.getName()) == 0);
+});
+  });
+  } else
+Err = Linker::linkModules(*M, std::move(LM.Module), LM.LinkFlags);
+
+  if (Err)
+return true;
+}
   }
 
   return false; // success

>From 5e9cd599c60334e8d5d99be0afb091d848dfc746 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Thu, 16 Nov 2023 07:29:55 -0800
Subject: [PATCH 2/2] [NFC] Taking clang-format suggestions

---
 clang/lib/CodeGen/CodeGenAction.cpp | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index e3ceb3adbcc93a8..fbf53accd48d0b2 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -271,10 +271,9 @@ bool BackendConsumer::LinkInModules(llvm::Module *M, bool 
ShouldLinkFiles) {
 Err = Linker::linkModules(
   *M, 

[clang] [CodeGen] Add conditional to module cloning in bitcode linking (PR #72478)

2023-11-15 Thread Jacob Lambert via cfe-commits


@@ -251,32 +255,50 @@ bool BackendConsumer::LinkInModules(llvm::Module *M, bool 
ShouldLinkFiles) {
   }
 
 CurLinkModule = LM.Module.get();
-
-// TODO: If CloneModule() is updated to support cloning of unmaterialized
-// modules, we can remove this
 bool Err;
-if (Error E = CurLinkModule->materializeAll())
-  return false;
 
 // Create a Clone to move to the linker, which preserves the original
 // linking modules, allowing them to be linked again in the future
-// TODO: Add a ShouldCleanup option to make Cloning optional. When
-// set, we can pass the original modules to the linker for cleanup
-std::unique_ptr Clone = llvm::CloneModule(*LM.Module);
+if (ClRelinkBuiltinBitcodePostop) {

lamb-j wrote:

Open to suggestions on a cleaner way to do this. Ideally we could do something 
like the following, instead of duplicating the functionality twice:

```
std::unique_ptr LinkMod;

if (ClRelinkBuiltinBitcodePostop)
  LinkMod = Clone
else
  LinkMod = Original

// Link with LinkMod
```

But due to `llvm::Module` not having a default constructor, I haven't figured 
out a way to do something like the above. That is, creating a single variable 
that can represent both the Original and the Clone, and set it depending on the 
provided boolean.

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


[clang] [CodeGen] Implement post-opt linking option for builtin bitocdes (PR #69371)

2023-11-15 Thread Jacob Lambert via cfe-commits


@@ -48,428 +49,365 @@
 #include "llvm/Support/ToolOutputFile.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Transforms/IPO/Internalize.h"
+#include "llvm/Transforms/Utils/Cloning.h"
 
-#include 
 #include 
 using namespace clang;
 using namespace llvm;
 
 #define DEBUG_TYPE "codegenaction"
 
 namespace clang {
-  class BackendConsumer;
-  class ClangDiagnosticHandler final : public DiagnosticHandler {
-  public:
-ClangDiagnosticHandler(const CodeGenOptions , BackendConsumer *BCon)
-: CodeGenOpts(CGOpts), BackendCon(BCon) {}
+class BackendConsumer;
+class ClangDiagnosticHandler final : public DiagnosticHandler {
+public:
+  ClangDiagnosticHandler(const CodeGenOptions , BackendConsumer *BCon)
+  : CodeGenOpts(CGOpts), BackendCon(BCon) {}
 
-bool handleDiagnostics(const DiagnosticInfo ) override;
+  bool handleDiagnostics(const DiagnosticInfo ) override;
 
-bool isAnalysisRemarkEnabled(StringRef PassName) const override {
-  return CodeGenOpts.OptimizationRemarkAnalysis.patternMatches(PassName);
-}
-bool isMissedOptRemarkEnabled(StringRef PassName) const override {
-  return CodeGenOpts.OptimizationRemarkMissed.patternMatches(PassName);
-}
-bool isPassedOptRemarkEnabled(StringRef PassName) const override {
-  return CodeGenOpts.OptimizationRemark.patternMatches(PassName);
-}
+  bool isAnalysisRemarkEnabled(StringRef PassName) const override {
+return CodeGenOpts.OptimizationRemarkAnalysis.patternMatches(PassName);
+  }
+  bool isMissedOptRemarkEnabled(StringRef PassName) const override {
+return CodeGenOpts.OptimizationRemarkMissed.patternMatches(PassName);
+  }
+  bool isPassedOptRemarkEnabled(StringRef PassName) const override {
+return CodeGenOpts.OptimizationRemark.patternMatches(PassName);
+  }
 
-bool isAnyRemarkEnabled() const override {
-  return CodeGenOpts.OptimizationRemarkAnalysis.hasValidPattern() ||
- CodeGenOpts.OptimizationRemarkMissed.hasValidPattern() ||
- CodeGenOpts.OptimizationRemark.hasValidPattern();
-}
+  bool isAnyRemarkEnabled() const override {
+return CodeGenOpts.OptimizationRemarkAnalysis.hasValidPattern() ||
+   CodeGenOpts.OptimizationRemarkMissed.hasValidPattern() ||
+   CodeGenOpts.OptimizationRemark.hasValidPattern();
+  }
 
-  private:
-const CodeGenOptions 
-BackendConsumer *BackendCon;
-  };
+private:
+  const CodeGenOptions 
+  BackendConsumer *BackendCon;
+};
+
+static void reportOptRecordError(Error E, DiagnosticsEngine ,
+ const CodeGenOptions ) {
+  handleAllErrors(
+  std::move(E),
+[&](const LLVMRemarkSetupFileError ) {
+Diags.Report(diag::err_cannot_open_file)
+<< CodeGenOpts.OptRecordFile << E.message();
+  },
+[&](const LLVMRemarkSetupPatternError ) {
+Diags.Report(diag::err_drv_optimization_remark_pattern)
+<< E.message() << CodeGenOpts.OptRecordPasses;
+  },
+[&](const LLVMRemarkSetupFormatError ) {
+Diags.Report(diag::err_drv_optimization_remark_format)
+<< CodeGenOpts.OptRecordFormat;
+  });
+}
 
-  static void reportOptRecordError(Error E, DiagnosticsEngine ,
-   const CodeGenOptions ) {
-handleAllErrors(
-std::move(E),
-  [&](const LLVMRemarkSetupFileError ) {
-  Diags.Report(diag::err_cannot_open_file)
-  << CodeGenOpts.OptRecordFile << E.message();
-},
-  [&](const LLVMRemarkSetupPatternError ) {
-  Diags.Report(diag::err_drv_optimization_remark_pattern)
-  << E.message() << CodeGenOpts.OptRecordPasses;
-},
-  [&](const LLVMRemarkSetupFormatError ) {
-  Diags.Report(diag::err_drv_optimization_remark_format)
-  << CodeGenOpts.OptRecordFormat;
-});
-}
+BackendConsumer::BackendConsumer(BackendAction Action, DiagnosticsEngine 
,
+ IntrusiveRefCntPtr VFS,
+ const HeaderSearchOptions ,
+ const PreprocessorOptions ,
+ const CodeGenOptions ,
+ const TargetOptions ,
+ const LangOptions ,
+ const std::string ,
+ SmallVector LinkModules,
+ std::unique_ptr OS,
+ LLVMContext ,
+ CoverageSourceInfo *CoverageInfo)
+  : Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts),
+  CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts),
+  AsmOutStream(std::move(OS)), Context(nullptr), FS(VFS),
+  LLVMIRGeneration("irgen", "LLVM IR Generation Time"),
+  LLVMIRGenerationRefCount(0),
+  Gen(CreateLLVMCodeGen(Diags, InFile, std::move(VFS), HeaderSearchOpts,
+PPOpts, 

[clang] [CodeGen] Add conditional to module cloning in bitcode linking (PR #72478)

2023-11-15 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j created 
https://github.com/llvm/llvm-project/pull/72478

Now that we have a commandline option dictating a second link step, 
(-relink-builtin-bitcode-postop), we can condition the module creation when 
linking in bitcode modules. This aims to improve performance by avoiding 
unnecessary linking

>From 3a2a066eeadce6b8f3cd5645965ffe564e68fba3 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Wed, 15 Nov 2023 22:06:46 -0800
Subject: [PATCH] [CodeGen] Add conditional to module cloning in bitcode
 linking

Now that we have a commandline option dictating a second link step,
(-relink-builtin-bitcode-postop), we can condition the module
creation when linking in bitcode modules. This aims to improve
performance by avoiding unnecessary linking
---
 clang/lib/CodeGen/BackendUtil.cpp   |  2 +-
 clang/lib/CodeGen/CodeGenAction.cpp | 56 -
 2 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index a7a47d17723cb73..f01a6514f6effb0 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -103,7 +103,7 @@ static cl::opt ClSanitizeOnOptimizerEarlyEP(
 cl::desc("Insert sanitizers on OptimizerEarlyEP."), cl::init(false));
 
 // Re-link builtin bitcodes after optimization
-static cl::opt ClRelinkBuiltinBitcodePostop(
+cl::opt ClRelinkBuiltinBitcodePostop(
 "relink-builtin-bitcode-postop", cl::Optional,
 cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false));
 }
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index a31a271ed77d1ca..e3ceb3adbcc93a8 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -57,6 +57,10 @@ using namespace llvm;
 
 #define DEBUG_TYPE "codegenaction"
 
+namespace llvm {
+extern cl::opt ClRelinkBuiltinBitcodePostop;
+}
+
 namespace clang {
 class BackendConsumer;
 class ClangDiagnosticHandler final : public DiagnosticHandler {
@@ -251,32 +255,50 @@ bool BackendConsumer::LinkInModules(llvm::Module *M, bool 
ShouldLinkFiles) {
   }
 
 CurLinkModule = LM.Module.get();
-
-// TODO: If CloneModule() is updated to support cloning of unmaterialized
-// modules, we can remove this
 bool Err;
-if (Error E = CurLinkModule->materializeAll())
-  return false;
 
 // Create a Clone to move to the linker, which preserves the original
 // linking modules, allowing them to be linked again in the future
-// TODO: Add a ShouldCleanup option to make Cloning optional. When
-// set, we can pass the original modules to the linker for cleanup
-std::unique_ptr Clone = llvm::CloneModule(*LM.Module);
+if (ClRelinkBuiltinBitcodePostop) {
+  // TODO: If CloneModule() is updated to support cloning of unmaterialized
+  // modules, we can remove this
+  if (Error E = CurLinkModule->materializeAll())
+return false;
 
-if (LM.Internalize) {
-  Err = Linker::linkModules(
+  std::unique_ptr Clone = llvm::CloneModule(*LM.Module);
+
+  if (LM.Internalize) {
+Err = Linker::linkModules(
   *M, std::move(Clone), LM.LinkFlags,
   [](llvm::Module , const llvm::StringSet<> ) {
-internalizeModule(M, [](const llvm::GlobalValue ) {
-  return !GV.hasName() || (GVS.count(GV.getName()) == 0);
-});
+  internalizeModule(M, [](const llvm::GlobalValue ) {
+return !GV.hasName() ||
+(GVS.count(GV.getName()) == 0);
+});
   });
-} else
-  Err = Linker::linkModules(*M, std::move(Clone), LM.LinkFlags);
+  } else
+Err = Linker::linkModules(*M, std::move(Clone), LM.LinkFlags);
 
-if (Err)
-  return true;
+  if (Err)
+return true;
+}
+// Otherwise we can link (and clean up) the original modules
+else {
+  if (LM.Internalize) {
+Err = Linker::linkModules(
+  *M, std::move(LM.Module), LM.LinkFlags,
+  [](llvm::Module , const llvm::StringSet<> ) {
+  internalizeModule(M, [](const llvm::GlobalValue ) {
+return !GV.hasName() ||
+(GVS.count(GV.getName()) == 0);
+});
+  });
+  } else
+Err = Linker::linkModules(*M, std::move(LM.Module), LM.LinkFlags);
+
+  if (Err)
+return true;
+}
   }
 
   return false; // success

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Implement post-opt linking option for builtin bitocdes (PR #69371)

2023-11-15 Thread Jacob Lambert via cfe-commits


@@ -48,428 +49,365 @@
 #include "llvm/Support/ToolOutputFile.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Transforms/IPO/Internalize.h"
+#include "llvm/Transforms/Utils/Cloning.h"
 
-#include 
 #include 
 using namespace clang;
 using namespace llvm;
 
 #define DEBUG_TYPE "codegenaction"
 
 namespace clang {
-  class BackendConsumer;
-  class ClangDiagnosticHandler final : public DiagnosticHandler {
-  public:
-ClangDiagnosticHandler(const CodeGenOptions , BackendConsumer *BCon)
-: CodeGenOpts(CGOpts), BackendCon(BCon) {}
+class BackendConsumer;
+class ClangDiagnosticHandler final : public DiagnosticHandler {
+public:
+  ClangDiagnosticHandler(const CodeGenOptions , BackendConsumer *BCon)
+  : CodeGenOpts(CGOpts), BackendCon(BCon) {}
 
-bool handleDiagnostics(const DiagnosticInfo ) override;
+  bool handleDiagnostics(const DiagnosticInfo ) override;
 
-bool isAnalysisRemarkEnabled(StringRef PassName) const override {
-  return CodeGenOpts.OptimizationRemarkAnalysis.patternMatches(PassName);
-}
-bool isMissedOptRemarkEnabled(StringRef PassName) const override {
-  return CodeGenOpts.OptimizationRemarkMissed.patternMatches(PassName);
-}
-bool isPassedOptRemarkEnabled(StringRef PassName) const override {
-  return CodeGenOpts.OptimizationRemark.patternMatches(PassName);
-}
+  bool isAnalysisRemarkEnabled(StringRef PassName) const override {
+return CodeGenOpts.OptimizationRemarkAnalysis.patternMatches(PassName);
+  }
+  bool isMissedOptRemarkEnabled(StringRef PassName) const override {
+return CodeGenOpts.OptimizationRemarkMissed.patternMatches(PassName);
+  }
+  bool isPassedOptRemarkEnabled(StringRef PassName) const override {
+return CodeGenOpts.OptimizationRemark.patternMatches(PassName);
+  }
 
-bool isAnyRemarkEnabled() const override {
-  return CodeGenOpts.OptimizationRemarkAnalysis.hasValidPattern() ||
- CodeGenOpts.OptimizationRemarkMissed.hasValidPattern() ||
- CodeGenOpts.OptimizationRemark.hasValidPattern();
-}
+  bool isAnyRemarkEnabled() const override {
+return CodeGenOpts.OptimizationRemarkAnalysis.hasValidPattern() ||
+   CodeGenOpts.OptimizationRemarkMissed.hasValidPattern() ||
+   CodeGenOpts.OptimizationRemark.hasValidPattern();
+  }
 
-  private:
-const CodeGenOptions 
-BackendConsumer *BackendCon;
-  };
+private:
+  const CodeGenOptions 
+  BackendConsumer *BackendCon;
+};
+
+static void reportOptRecordError(Error E, DiagnosticsEngine ,
+ const CodeGenOptions ) {
+  handleAllErrors(
+  std::move(E),
+[&](const LLVMRemarkSetupFileError ) {
+Diags.Report(diag::err_cannot_open_file)
+<< CodeGenOpts.OptRecordFile << E.message();
+  },
+[&](const LLVMRemarkSetupPatternError ) {
+Diags.Report(diag::err_drv_optimization_remark_pattern)
+<< E.message() << CodeGenOpts.OptRecordPasses;
+  },
+[&](const LLVMRemarkSetupFormatError ) {
+Diags.Report(diag::err_drv_optimization_remark_format)
+<< CodeGenOpts.OptRecordFormat;
+  });
+}
 
-  static void reportOptRecordError(Error E, DiagnosticsEngine ,
-   const CodeGenOptions ) {
-handleAllErrors(
-std::move(E),
-  [&](const LLVMRemarkSetupFileError ) {
-  Diags.Report(diag::err_cannot_open_file)
-  << CodeGenOpts.OptRecordFile << E.message();
-},
-  [&](const LLVMRemarkSetupPatternError ) {
-  Diags.Report(diag::err_drv_optimization_remark_pattern)
-  << E.message() << CodeGenOpts.OptRecordPasses;
-},
-  [&](const LLVMRemarkSetupFormatError ) {
-  Diags.Report(diag::err_drv_optimization_remark_format)
-  << CodeGenOpts.OptRecordFormat;
-});
-}
+BackendConsumer::BackendConsumer(BackendAction Action, DiagnosticsEngine 
,
+ IntrusiveRefCntPtr VFS,
+ const HeaderSearchOptions ,
+ const PreprocessorOptions ,
+ const CodeGenOptions ,
+ const TargetOptions ,
+ const LangOptions ,
+ const std::string ,
+ SmallVector LinkModules,
+ std::unique_ptr OS,
+ LLVMContext ,
+ CoverageSourceInfo *CoverageInfo)
+  : Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts),
+  CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts),
+  AsmOutStream(std::move(OS)), Context(nullptr), FS(VFS),
+  LLVMIRGeneration("irgen", "LLVM IR Generation Time"),
+  LLVMIRGenerationRefCount(0),
+  Gen(CreateLLVMCodeGen(Diags, InFile, std::move(VFS), HeaderSearchOpts,
+PPOpts, 

[clang] [CodeGen] Implement post-opt linking option for builtin bitocdes (PR #69371)

2023-11-09 Thread Jacob Lambert via cfe-commits

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


[clang] [CodeGen] Implement post-opt linking option for builtin bitocdes (PR #69371)

2023-11-09 Thread Jacob Lambert via cfe-commits

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


[clang] [CodeGen] Implement post-opt linking option for builtin bitocdes (PR #69371)

2023-11-09 Thread Jacob Lambert via cfe-commits


@@ -113,7 +120,7 @@ class EmitAssemblyHelper {
   const CodeGenOptions 
   const clang::TargetOptions 
   const LangOptions 
-  Module *TheModule;
+  llvm::Module *TheModule;

lamb-j wrote:

Without the qualification, we get the following:

In file included from llvm-project/llvm/include/llvm/IR/ModuleSummaryIndex.h:28,
 from llvm-project/clang/include/clang/CodeGen/BackendUtil.h:13,
 from llvm-project/clang/lib/CodeGen/BackendUtil.cpp:9:
llvm-project/llvm/include/llvm/IR/Module.h:65:32: note: candidates are: ‘class 
llvm::Module’
   65 | class LLVM_EXTERNAL_VISIBILITY Module {
  |^~
In file included from llvm-project/clang/include/clang/Lex/ModuleLoader.h:18,
 from llvm-project/clang/include/clang/Frontend/ASTUnit.h:26,
 from 
llvm-project/clang/include/clang/Frontend/FrontendAction.h:23,
 from 
llvm-project/clang/include/clang/CodeGen/CodeGenAction.h:12,
 from llvm-project/clang/lib/CodeGen/BackendConsumer.h:13,
 from llvm-project/clang/lib/CodeGen/BackendUtil.cpp:10:
llvm-project/clang/include/clang/Basic/Module.h:105:18: note: 
‘class clang::Module’
  105 | class alignas(8) Module {
  |  ^~

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


[clang] [CodeGen] Implement post-opt linking option for builtin bitocdes (PR #69371)

2023-11-09 Thread Jacob Lambert via cfe-commits

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


[clang] [CodeGen] Implement post-opt linking option for builtin bitocdes (PR #69371)

2023-11-09 Thread Jacob Lambert via cfe-commits


@@ -113,7 +120,7 @@ class EmitAssemblyHelper {
   const CodeGenOptions 
   const clang::TargetOptions 
   const LangOptions 
-  Module *TheModule;
+  llvm::Module *TheModule;

lamb-j wrote:

When including the new BackendConsumer.h header file to BackendUtils.cpp, we 
were indirectly including another header several layers deep that had defined 
clang::Module. Previously this file had no references to clang::Module via any 
includes, but with the new include we were getting an "ambiguous reference to 
Module" error. This was fixed by specifying which Module class we were using in 
this file.

I don't remember exactly which nested include referenced clang::Module, I could 
track down the include path again if it's helpful though.

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


[clang] [CodeGen] Implement post-opt linking option for builtin bitocdes (PR #69371)

2023-11-08 Thread Jacob Lambert via cfe-commits

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


[clang] [CodeGen] Implement post-opt linking option for builtin bitocdes (PR #69371)

2023-11-08 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/69371

>From 0de3e4a4b460ba407da1acbcf4ef21916ded69e2 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 17 Oct 2023 12:01:15 -0700
Subject: [PATCH 1/3] [NFC] Refactor BackendConsumer class definition into new
 header

Previously the BackendConsumer class was defined in CodeGenAction.cpp.
In order to use this class and its member functions in other files
for upcoming changes, we first need to refactor the class definition
into a separate header
---
 clang/lib/CodeGen/BackendConsumer.h | 166 +++
 clang/lib/CodeGen/CodeGenAction.cpp | 643 
 2 files changed, 448 insertions(+), 361 deletions(-)
 create mode 100644 clang/lib/CodeGen/BackendConsumer.h

diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
new file mode 100644
index 000..2a4f70d5668ed6b
--- /dev/null
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -0,0 +1,166 @@
+//===--- BackendConsumer.h - LLVM BackendConsumer Header File 
-===//
+//
+// 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_LIB_CODEGEN_BACKENDCONSUMER_H
+#define LLVM_CLANG_LIB_CODEGEN_BACKENDCONSUMER_H
+
+#include "clang/CodeGen/BackendUtil.h"
+#include "clang/CodeGen/CodeGenAction.h"
+
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/Support/Timer.h"
+
+namespace llvm {
+  class DiagnosticInfoDontCall;
+}
+
+namespace clang {
+class ASTContext;
+class CodeGenAction;
+class CoverageSourceInfo;
+
+class BackendConsumer : public ASTConsumer {
+  using LinkModule = CodeGenAction::LinkModule;
+
+  virtual void anchor();
+  DiagnosticsEngine 
+  BackendAction Action;
+  const HeaderSearchOptions 
+  const CodeGenOptions 
+  const TargetOptions 
+  const LangOptions 
+  std::unique_ptr AsmOutStream;
+  ASTContext *Context;
+  IntrusiveRefCntPtr FS;
+
+  llvm::Timer LLVMIRGeneration;
+  unsigned LLVMIRGenerationRefCount;
+
+  /// True if we've finished generating IR. This prevents us from generating
+  /// additional LLVM IR after emitting output in HandleTranslationUnit. This
+  /// can happen when Clang plugins trigger additional AST deserialization.
+  bool IRGenFinished = false;
+
+  bool TimerIsEnabled = false;
+
+  std::unique_ptr Gen;
+
+  SmallVector LinkModules;
+
+  // A map from mangled names to their function's source location, used for
+  // backend diagnostics as the Clang AST may be unavailable. We actually use
+  // the mangled name's hash as the key because mangled names can be very
+  // long and take up lots of space. Using a hash can cause name collision,
+  // but that is rare and the consequences are pointing to a wrong source
+  // location which is not severe. This is a vector instead of an actual map
+  // because we optimize for time building this map rather than time
+  // retrieving an entry, as backend diagnostics are uncommon.
+  std::vector>
+ManglingFullSourceLocs;
+
+
+  // This is here so that the diagnostic printer knows the module a diagnostic
+  // refers to.
+  llvm::Module *CurLinkModule = nullptr;
+
+public:
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , const std::string ,
+  SmallVector LinkModules,
+  std::unique_ptr OS, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  // This constructor is used in installing an empty BackendConsumer
+  // to use the clang diagnostic handler for IR input files. It avoids
+  // initializing the OS field.
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , llvm::Module *Module,
+  SmallVector LinkModules, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  llvm::Module *getModule() const;
+  std::unique_ptr takeModule();
+
+  CodeGenerator *getCodeGenerator();
+
+  void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override;
+  void Initialize(ASTContext ) override;
+  bool HandleTopLevelDecl(DeclGroupRef D) override;
+  void HandleInlineFunctionDefinition(FunctionDecl *D) override;
+  void HandleInterestingDecl(DeclGroupRef D) override;
+  void HandleTranslationUnit(ASTContext ) override;
+  void 

[clang] [CodeGen] Implement post-opt linking option for builtin bitocdes (PR #69371)

2023-11-08 Thread Jacob Lambert via cfe-commits

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


[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-11-08 Thread Jacob Lambert via cfe-commits

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


[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-11-07 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/69371

>From 86535608c7e79d31260e2a358b7a00f7b747e8bd Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 17 Oct 2023 12:01:15 -0700
Subject: [PATCH 1/3] [NFC] Refactor BackendConsumer class definition into new
 header

Previously the BackendConsumer class was defined in CodeGenAction.cpp.
In order to use this class and its member functions in other files
for upcoming changes, we first need to refactor the class definition
into a separate header
---
 clang/lib/CodeGen/BackendConsumer.h | 166 +++
 clang/lib/CodeGen/CodeGenAction.cpp | 643 
 2 files changed, 448 insertions(+), 361 deletions(-)
 create mode 100644 clang/lib/CodeGen/BackendConsumer.h

diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
new file mode 100644
index 000..2a4f70d5668ed6b
--- /dev/null
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -0,0 +1,166 @@
+//===--- BackendConsumer.h - LLVM BackendConsumer Header File 
-===//
+//
+// 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_LIB_CODEGEN_BACKENDCONSUMER_H
+#define LLVM_CLANG_LIB_CODEGEN_BACKENDCONSUMER_H
+
+#include "clang/CodeGen/BackendUtil.h"
+#include "clang/CodeGen/CodeGenAction.h"
+
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/Support/Timer.h"
+
+namespace llvm {
+  class DiagnosticInfoDontCall;
+}
+
+namespace clang {
+class ASTContext;
+class CodeGenAction;
+class CoverageSourceInfo;
+
+class BackendConsumer : public ASTConsumer {
+  using LinkModule = CodeGenAction::LinkModule;
+
+  virtual void anchor();
+  DiagnosticsEngine 
+  BackendAction Action;
+  const HeaderSearchOptions 
+  const CodeGenOptions 
+  const TargetOptions 
+  const LangOptions 
+  std::unique_ptr AsmOutStream;
+  ASTContext *Context;
+  IntrusiveRefCntPtr FS;
+
+  llvm::Timer LLVMIRGeneration;
+  unsigned LLVMIRGenerationRefCount;
+
+  /// True if we've finished generating IR. This prevents us from generating
+  /// additional LLVM IR after emitting output in HandleTranslationUnit. This
+  /// can happen when Clang plugins trigger additional AST deserialization.
+  bool IRGenFinished = false;
+
+  bool TimerIsEnabled = false;
+
+  std::unique_ptr Gen;
+
+  SmallVector LinkModules;
+
+  // A map from mangled names to their function's source location, used for
+  // backend diagnostics as the Clang AST may be unavailable. We actually use
+  // the mangled name's hash as the key because mangled names can be very
+  // long and take up lots of space. Using a hash can cause name collision,
+  // but that is rare and the consequences are pointing to a wrong source
+  // location which is not severe. This is a vector instead of an actual map
+  // because we optimize for time building this map rather than time
+  // retrieving an entry, as backend diagnostics are uncommon.
+  std::vector>
+ManglingFullSourceLocs;
+
+
+  // This is here so that the diagnostic printer knows the module a diagnostic
+  // refers to.
+  llvm::Module *CurLinkModule = nullptr;
+
+public:
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , const std::string ,
+  SmallVector LinkModules,
+  std::unique_ptr OS, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  // This constructor is used in installing an empty BackendConsumer
+  // to use the clang diagnostic handler for IR input files. It avoids
+  // initializing the OS field.
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , llvm::Module *Module,
+  SmallVector LinkModules, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  llvm::Module *getModule() const;
+  std::unique_ptr takeModule();
+
+  CodeGenerator *getCodeGenerator();
+
+  void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override;
+  void Initialize(ASTContext ) override;
+  bool HandleTopLevelDecl(DeclGroupRef D) override;
+  void HandleInlineFunctionDefinition(FunctionDecl *D) override;
+  void HandleInterestingDecl(DeclGroupRef D) override;
+  void HandleTranslationUnit(ASTContext ) override;
+  void 

[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-11-06 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/69371

>From 25302c315360c166f34ab9acde2561dc7865b3bb Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 17 Oct 2023 12:01:15 -0700
Subject: [PATCH 1/3] [NFC] Refactor BackendConsumer class definition into new
 header

Previously the BackendConsumer class was defined in CodeGenAction.cpp.
In order to use this class and its member functions in other files
for upcoming changes, we first need to refactor the class definition
into a separate header
---
 clang/lib/CodeGen/BackendConsumer.h | 166 +++
 clang/lib/CodeGen/CodeGenAction.cpp | 643 
 2 files changed, 448 insertions(+), 361 deletions(-)
 create mode 100644 clang/lib/CodeGen/BackendConsumer.h

diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
new file mode 100644
index 000..2a4f70d5668ed6b
--- /dev/null
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -0,0 +1,166 @@
+//===--- BackendConsumer.h - LLVM BackendConsumer Header File 
-===//
+//
+// 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_LIB_CODEGEN_BACKENDCONSUMER_H
+#define LLVM_CLANG_LIB_CODEGEN_BACKENDCONSUMER_H
+
+#include "clang/CodeGen/BackendUtil.h"
+#include "clang/CodeGen/CodeGenAction.h"
+
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/Support/Timer.h"
+
+namespace llvm {
+  class DiagnosticInfoDontCall;
+}
+
+namespace clang {
+class ASTContext;
+class CodeGenAction;
+class CoverageSourceInfo;
+
+class BackendConsumer : public ASTConsumer {
+  using LinkModule = CodeGenAction::LinkModule;
+
+  virtual void anchor();
+  DiagnosticsEngine 
+  BackendAction Action;
+  const HeaderSearchOptions 
+  const CodeGenOptions 
+  const TargetOptions 
+  const LangOptions 
+  std::unique_ptr AsmOutStream;
+  ASTContext *Context;
+  IntrusiveRefCntPtr FS;
+
+  llvm::Timer LLVMIRGeneration;
+  unsigned LLVMIRGenerationRefCount;
+
+  /// True if we've finished generating IR. This prevents us from generating
+  /// additional LLVM IR after emitting output in HandleTranslationUnit. This
+  /// can happen when Clang plugins trigger additional AST deserialization.
+  bool IRGenFinished = false;
+
+  bool TimerIsEnabled = false;
+
+  std::unique_ptr Gen;
+
+  SmallVector LinkModules;
+
+  // A map from mangled names to their function's source location, used for
+  // backend diagnostics as the Clang AST may be unavailable. We actually use
+  // the mangled name's hash as the key because mangled names can be very
+  // long and take up lots of space. Using a hash can cause name collision,
+  // but that is rare and the consequences are pointing to a wrong source
+  // location which is not severe. This is a vector instead of an actual map
+  // because we optimize for time building this map rather than time
+  // retrieving an entry, as backend diagnostics are uncommon.
+  std::vector>
+ManglingFullSourceLocs;
+
+
+  // This is here so that the diagnostic printer knows the module a diagnostic
+  // refers to.
+  llvm::Module *CurLinkModule = nullptr;
+
+public:
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , const std::string ,
+  SmallVector LinkModules,
+  std::unique_ptr OS, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  // This constructor is used in installing an empty BackendConsumer
+  // to use the clang diagnostic handler for IR input files. It avoids
+  // initializing the OS field.
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , llvm::Module *Module,
+  SmallVector LinkModules, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  llvm::Module *getModule() const;
+  std::unique_ptr takeModule();
+
+  CodeGenerator *getCodeGenerator();
+
+  void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override;
+  void Initialize(ASTContext ) override;
+  bool HandleTopLevelDecl(DeclGroupRef D) override;
+  void HandleInlineFunctionDefinition(FunctionDecl *D) override;
+  void HandleInterestingDecl(DeclGroupRef D) override;
+  void HandleTranslationUnit(ASTContext ) override;
+  void 

[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-11-06 Thread Jacob Lambert via cfe-commits

lamb-j wrote:

> this doesn't really apply since you changed the function signature so it 
> needs to be reformatted.

I don't follow the logic there. The function signature can have a style as 
well. And I think this is actually a good example to demonstrate a reason not 
to reformat if we look at the next few lines:

Following existing style:
```
  void RunOptimizationPipeline(BackendAction Action,
  std::unique_ptr ,
  std::unique_ptr ,
  BackendConsumer *BC);
  void RunCodegenPipeline(BackendAction Action,
  std::unique_ptr ,
  std::unique_ptr );
```


Following clang format:
```
  void RunOptimizationPipeline(
  BackendAction Action, std::unique_ptr ,
  std::unique_ptr ,
  BackendConsumer *BC);
  void RunCodegenPipeline(BackendAction Action,
  std::unique_ptr ,
  std::unique_ptr );
```

To me, the first case aligns more with the spirit of the "golden rule". And if 
someone wants to reformat the whole file at a later point, that would be a good 
time to change the style for both signatures.

That said, I definitely don't want this to be a barrier to getting this patch 
in, so if you still feel like we should go with the clang-format 
recommendation, I'll change it and also update the EmitAssembly and 
EmitBackendOutput signatures which were flagged by clang-format for the same 
reasons.

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


[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-11-06 Thread Jacob Lambert via cfe-commits

lamb-j wrote:

> 
> Just do what the formatter says, not every file is 100% clang-formatted so 
> there's bits of old code that haven't been properly cleaned yet. This was the 
> same line that I thought looked wrong so it should probably be fixed. Using 
> `git clang-format HEAD~1` only formats what you've changed, so you don't need 
> to worry about spurious edits.

Isn't the standard to follow the existing style, not re-format small sections 
of code during a commit to a different style?

[Always follow the golden rule:

If you are extending, enhancing, or bug fixing already implemented code, use 
the style that is already being used so that the source is uniform and easy to 
follow.](https://llvm.org/docs/CodingStandards.html)

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


[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-11-06 Thread Jacob Lambert via cfe-commits

lamb-j wrote:

I am getting this from the formatter:

-  void RunOptimizationPipeline(BackendAction Action,
-  std::unique_ptr ,
-  std::unique_ptr ,
-  BackendConsumer *BC);
+  void RunOptimizationPipeline(
+  BackendAction Action, std::unique_ptr ,
+  std::unique_ptr , BackendConsumer *BC);

But in this case I am just following the existing style. I did notice a couple 
of other improvements from the formatter though, and I've added those changes.

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


[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-11-06 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/69371

>From 25302c315360c166f34ab9acde2561dc7865b3bb Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 17 Oct 2023 12:01:15 -0700
Subject: [PATCH 1/3] [NFC] Refactor BackendConsumer class definition into new
 header

Previously the BackendConsumer class was defined in CodeGenAction.cpp.
In order to use this class and its member functions in other files
for upcoming changes, we first need to refactor the class definition
into a separate header
---
 clang/lib/CodeGen/BackendConsumer.h | 166 +++
 clang/lib/CodeGen/CodeGenAction.cpp | 643 
 2 files changed, 448 insertions(+), 361 deletions(-)
 create mode 100644 clang/lib/CodeGen/BackendConsumer.h

diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
new file mode 100644
index 000..2a4f70d5668ed6b
--- /dev/null
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -0,0 +1,166 @@
+//===--- BackendConsumer.h - LLVM BackendConsumer Header File 
-===//
+//
+// 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_LIB_CODEGEN_BACKENDCONSUMER_H
+#define LLVM_CLANG_LIB_CODEGEN_BACKENDCONSUMER_H
+
+#include "clang/CodeGen/BackendUtil.h"
+#include "clang/CodeGen/CodeGenAction.h"
+
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/Support/Timer.h"
+
+namespace llvm {
+  class DiagnosticInfoDontCall;
+}
+
+namespace clang {
+class ASTContext;
+class CodeGenAction;
+class CoverageSourceInfo;
+
+class BackendConsumer : public ASTConsumer {
+  using LinkModule = CodeGenAction::LinkModule;
+
+  virtual void anchor();
+  DiagnosticsEngine 
+  BackendAction Action;
+  const HeaderSearchOptions 
+  const CodeGenOptions 
+  const TargetOptions 
+  const LangOptions 
+  std::unique_ptr AsmOutStream;
+  ASTContext *Context;
+  IntrusiveRefCntPtr FS;
+
+  llvm::Timer LLVMIRGeneration;
+  unsigned LLVMIRGenerationRefCount;
+
+  /// True if we've finished generating IR. This prevents us from generating
+  /// additional LLVM IR after emitting output in HandleTranslationUnit. This
+  /// can happen when Clang plugins trigger additional AST deserialization.
+  bool IRGenFinished = false;
+
+  bool TimerIsEnabled = false;
+
+  std::unique_ptr Gen;
+
+  SmallVector LinkModules;
+
+  // A map from mangled names to their function's source location, used for
+  // backend diagnostics as the Clang AST may be unavailable. We actually use
+  // the mangled name's hash as the key because mangled names can be very
+  // long and take up lots of space. Using a hash can cause name collision,
+  // but that is rare and the consequences are pointing to a wrong source
+  // location which is not severe. This is a vector instead of an actual map
+  // because we optimize for time building this map rather than time
+  // retrieving an entry, as backend diagnostics are uncommon.
+  std::vector>
+ManglingFullSourceLocs;
+
+
+  // This is here so that the diagnostic printer knows the module a diagnostic
+  // refers to.
+  llvm::Module *CurLinkModule = nullptr;
+
+public:
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , const std::string ,
+  SmallVector LinkModules,
+  std::unique_ptr OS, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  // This constructor is used in installing an empty BackendConsumer
+  // to use the clang diagnostic handler for IR input files. It avoids
+  // initializing the OS field.
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , llvm::Module *Module,
+  SmallVector LinkModules, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  llvm::Module *getModule() const;
+  std::unique_ptr takeModule();
+
+  CodeGenerator *getCodeGenerator();
+
+  void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override;
+  void Initialize(ASTContext ) override;
+  bool HandleTopLevelDecl(DeclGroupRef D) override;
+  void HandleInlineFunctionDefinition(FunctionDecl *D) override;
+  void HandleInterestingDecl(DeclGroupRef D) override;
+  void HandleTranslationUnit(ASTContext ) override;
+  void 

[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-11-06 Thread Jacob Lambert via cfe-commits


@@ -0,0 +1,29 @@
+//===-- LinkInModulesPass.cpp - Module Linking pass --- 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
+//
+//===--===//
+/// \file
+///
+/// LinkInModulesPass implementation.
+///
+//===--===//
+
+#include "LinkInModulesPass.h"
+#include "BackendConsumer.h"
+
+using namespace llvm;
+
+LinkInModulesPass::LinkInModulesPass(clang::BackendConsumer *BC,
+ bool ShouldLinkFiles) : BC(BC),
+ ShouldLinkFiles(ShouldLinkFiles) {}
+
+PreservedAnalyses LinkInModulesPass::run(Module , ModuleAnalysisManager ) 
{
+
+  if (BC != NULL && BC->LinkInModules(, ShouldLinkFiles))

lamb-j wrote:

Done

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


[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-11-06 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/69371

>From 25302c315360c166f34ab9acde2561dc7865b3bb Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 17 Oct 2023 12:01:15 -0700
Subject: [PATCH 1/3] [NFC] Refactor BackendConsumer class definition into new
 header

Previously the BackendConsumer class was defined in CodeGenAction.cpp.
In order to use this class and its member functions in other files
for upcoming changes, we first need to refactor the class definition
into a separate header
---
 clang/lib/CodeGen/BackendConsumer.h | 166 +++
 clang/lib/CodeGen/CodeGenAction.cpp | 643 
 2 files changed, 448 insertions(+), 361 deletions(-)
 create mode 100644 clang/lib/CodeGen/BackendConsumer.h

diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
new file mode 100644
index 000..2a4f70d5668ed6b
--- /dev/null
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -0,0 +1,166 @@
+//===--- BackendConsumer.h - LLVM BackendConsumer Header File 
-===//
+//
+// 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_LIB_CODEGEN_BACKENDCONSUMER_H
+#define LLVM_CLANG_LIB_CODEGEN_BACKENDCONSUMER_H
+
+#include "clang/CodeGen/BackendUtil.h"
+#include "clang/CodeGen/CodeGenAction.h"
+
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/Support/Timer.h"
+
+namespace llvm {
+  class DiagnosticInfoDontCall;
+}
+
+namespace clang {
+class ASTContext;
+class CodeGenAction;
+class CoverageSourceInfo;
+
+class BackendConsumer : public ASTConsumer {
+  using LinkModule = CodeGenAction::LinkModule;
+
+  virtual void anchor();
+  DiagnosticsEngine 
+  BackendAction Action;
+  const HeaderSearchOptions 
+  const CodeGenOptions 
+  const TargetOptions 
+  const LangOptions 
+  std::unique_ptr AsmOutStream;
+  ASTContext *Context;
+  IntrusiveRefCntPtr FS;
+
+  llvm::Timer LLVMIRGeneration;
+  unsigned LLVMIRGenerationRefCount;
+
+  /// True if we've finished generating IR. This prevents us from generating
+  /// additional LLVM IR after emitting output in HandleTranslationUnit. This
+  /// can happen when Clang plugins trigger additional AST deserialization.
+  bool IRGenFinished = false;
+
+  bool TimerIsEnabled = false;
+
+  std::unique_ptr Gen;
+
+  SmallVector LinkModules;
+
+  // A map from mangled names to their function's source location, used for
+  // backend diagnostics as the Clang AST may be unavailable. We actually use
+  // the mangled name's hash as the key because mangled names can be very
+  // long and take up lots of space. Using a hash can cause name collision,
+  // but that is rare and the consequences are pointing to a wrong source
+  // location which is not severe. This is a vector instead of an actual map
+  // because we optimize for time building this map rather than time
+  // retrieving an entry, as backend diagnostics are uncommon.
+  std::vector>
+ManglingFullSourceLocs;
+
+
+  // This is here so that the diagnostic printer knows the module a diagnostic
+  // refers to.
+  llvm::Module *CurLinkModule = nullptr;
+
+public:
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , const std::string ,
+  SmallVector LinkModules,
+  std::unique_ptr OS, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  // This constructor is used in installing an empty BackendConsumer
+  // to use the clang diagnostic handler for IR input files. It avoids
+  // initializing the OS field.
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , llvm::Module *Module,
+  SmallVector LinkModules, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  llvm::Module *getModule() const;
+  std::unique_ptr takeModule();
+
+  CodeGenerator *getCodeGenerator();
+
+  void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override;
+  void Initialize(ASTContext ) override;
+  bool HandleTopLevelDecl(DeclGroupRef D) override;
+  void HandleInlineFunctionDefinition(FunctionDecl *D) override;
+  void HandleInterestingDecl(DeclGroupRef D) override;
+  void HandleTranslationUnit(ASTContext ) override;
+  void 

[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-11-06 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/69371

>From 25302c315360c166f34ab9acde2561dc7865b3bb Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 17 Oct 2023 12:01:15 -0700
Subject: [PATCH 1/3] [NFC] Refactor BackendConsumer class definition into new
 header

Previously the BackendConsumer class was defined in CodeGenAction.cpp.
In order to use this class and its member functions in other files
for upcoming changes, we first need to refactor the class definition
into a separate header
---
 clang/lib/CodeGen/BackendConsumer.h | 166 +++
 clang/lib/CodeGen/CodeGenAction.cpp | 643 
 2 files changed, 448 insertions(+), 361 deletions(-)
 create mode 100644 clang/lib/CodeGen/BackendConsumer.h

diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
new file mode 100644
index 000..2a4f70d5668ed6b
--- /dev/null
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -0,0 +1,166 @@
+//===--- BackendConsumer.h - LLVM BackendConsumer Header File 
-===//
+//
+// 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_LIB_CODEGEN_BACKENDCONSUMER_H
+#define LLVM_CLANG_LIB_CODEGEN_BACKENDCONSUMER_H
+
+#include "clang/CodeGen/BackendUtil.h"
+#include "clang/CodeGen/CodeGenAction.h"
+
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/Support/Timer.h"
+
+namespace llvm {
+  class DiagnosticInfoDontCall;
+}
+
+namespace clang {
+class ASTContext;
+class CodeGenAction;
+class CoverageSourceInfo;
+
+class BackendConsumer : public ASTConsumer {
+  using LinkModule = CodeGenAction::LinkModule;
+
+  virtual void anchor();
+  DiagnosticsEngine 
+  BackendAction Action;
+  const HeaderSearchOptions 
+  const CodeGenOptions 
+  const TargetOptions 
+  const LangOptions 
+  std::unique_ptr AsmOutStream;
+  ASTContext *Context;
+  IntrusiveRefCntPtr FS;
+
+  llvm::Timer LLVMIRGeneration;
+  unsigned LLVMIRGenerationRefCount;
+
+  /// True if we've finished generating IR. This prevents us from generating
+  /// additional LLVM IR after emitting output in HandleTranslationUnit. This
+  /// can happen when Clang plugins trigger additional AST deserialization.
+  bool IRGenFinished = false;
+
+  bool TimerIsEnabled = false;
+
+  std::unique_ptr Gen;
+
+  SmallVector LinkModules;
+
+  // A map from mangled names to their function's source location, used for
+  // backend diagnostics as the Clang AST may be unavailable. We actually use
+  // the mangled name's hash as the key because mangled names can be very
+  // long and take up lots of space. Using a hash can cause name collision,
+  // but that is rare and the consequences are pointing to a wrong source
+  // location which is not severe. This is a vector instead of an actual map
+  // because we optimize for time building this map rather than time
+  // retrieving an entry, as backend diagnostics are uncommon.
+  std::vector>
+ManglingFullSourceLocs;
+
+
+  // This is here so that the diagnostic printer knows the module a diagnostic
+  // refers to.
+  llvm::Module *CurLinkModule = nullptr;
+
+public:
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , const std::string ,
+  SmallVector LinkModules,
+  std::unique_ptr OS, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  // This constructor is used in installing an empty BackendConsumer
+  // to use the clang diagnostic handler for IR input files. It avoids
+  // initializing the OS field.
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , llvm::Module *Module,
+  SmallVector LinkModules, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  llvm::Module *getModule() const;
+  std::unique_ptr takeModule();
+
+  CodeGenerator *getCodeGenerator();
+
+  void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override;
+  void Initialize(ASTContext ) override;
+  bool HandleTopLevelDecl(DeclGroupRef D) override;
+  void HandleInlineFunctionDefinition(FunctionDecl *D) override;
+  void HandleInterestingDecl(DeclGroupRef D) override;
+  void HandleTranslationUnit(ASTContext ) override;
+  void 

[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-11-06 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/69371

>From 25302c315360c166f34ab9acde2561dc7865b3bb Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 17 Oct 2023 12:01:15 -0700
Subject: [PATCH 1/3] [NFC] Refactor BackendConsumer class definition into new
 header

Previously the BackendConsumer class was defined in CodeGenAction.cpp.
In order to use this class and its member functions in other files
for upcoming changes, we first need to refactor the class definition
into a separate header
---
 clang/lib/CodeGen/BackendConsumer.h | 166 +++
 clang/lib/CodeGen/CodeGenAction.cpp | 643 
 2 files changed, 448 insertions(+), 361 deletions(-)
 create mode 100644 clang/lib/CodeGen/BackendConsumer.h

diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
new file mode 100644
index 000..2a4f70d5668ed6b
--- /dev/null
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -0,0 +1,166 @@
+//===--- BackendConsumer.h - LLVM BackendConsumer Header File 
-===//
+//
+// 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_LIB_CODEGEN_BACKENDCONSUMER_H
+#define LLVM_CLANG_LIB_CODEGEN_BACKENDCONSUMER_H
+
+#include "clang/CodeGen/BackendUtil.h"
+#include "clang/CodeGen/CodeGenAction.h"
+
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/Support/Timer.h"
+
+namespace llvm {
+  class DiagnosticInfoDontCall;
+}
+
+namespace clang {
+class ASTContext;
+class CodeGenAction;
+class CoverageSourceInfo;
+
+class BackendConsumer : public ASTConsumer {
+  using LinkModule = CodeGenAction::LinkModule;
+
+  virtual void anchor();
+  DiagnosticsEngine 
+  BackendAction Action;
+  const HeaderSearchOptions 
+  const CodeGenOptions 
+  const TargetOptions 
+  const LangOptions 
+  std::unique_ptr AsmOutStream;
+  ASTContext *Context;
+  IntrusiveRefCntPtr FS;
+
+  llvm::Timer LLVMIRGeneration;
+  unsigned LLVMIRGenerationRefCount;
+
+  /// True if we've finished generating IR. This prevents us from generating
+  /// additional LLVM IR after emitting output in HandleTranslationUnit. This
+  /// can happen when Clang plugins trigger additional AST deserialization.
+  bool IRGenFinished = false;
+
+  bool TimerIsEnabled = false;
+
+  std::unique_ptr Gen;
+
+  SmallVector LinkModules;
+
+  // A map from mangled names to their function's source location, used for
+  // backend diagnostics as the Clang AST may be unavailable. We actually use
+  // the mangled name's hash as the key because mangled names can be very
+  // long and take up lots of space. Using a hash can cause name collision,
+  // but that is rare and the consequences are pointing to a wrong source
+  // location which is not severe. This is a vector instead of an actual map
+  // because we optimize for time building this map rather than time
+  // retrieving an entry, as backend diagnostics are uncommon.
+  std::vector>
+ManglingFullSourceLocs;
+
+
+  // This is here so that the diagnostic printer knows the module a diagnostic
+  // refers to.
+  llvm::Module *CurLinkModule = nullptr;
+
+public:
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , const std::string ,
+  SmallVector LinkModules,
+  std::unique_ptr OS, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  // This constructor is used in installing an empty BackendConsumer
+  // to use the clang diagnostic handler for IR input files. It avoids
+  // initializing the OS field.
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , llvm::Module *Module,
+  SmallVector LinkModules, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  llvm::Module *getModule() const;
+  std::unique_ptr takeModule();
+
+  CodeGenerator *getCodeGenerator();
+
+  void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override;
+  void Initialize(ASTContext ) override;
+  bool HandleTopLevelDecl(DeclGroupRef D) override;
+  void HandleInlineFunctionDefinition(FunctionDecl *D) override;
+  void HandleInterestingDecl(DeclGroupRef D) override;
+  void HandleTranslationUnit(ASTContext ) override;
+  void 

[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-11-06 Thread Jacob Lambert via cfe-commits

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


[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-11-06 Thread Jacob Lambert via cfe-commits


@@ -48,428 +49,369 @@
 #include "llvm/Support/ToolOutputFile.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Transforms/IPO/Internalize.h"
+#include "llvm/Transforms/Utils/Cloning.h"
 
-#include 
 #include 
 using namespace clang;
 using namespace llvm;
 
 #define DEBUG_TYPE "codegenaction"
 
 namespace clang {
-  class BackendConsumer;
-  class ClangDiagnosticHandler final : public DiagnosticHandler {
-  public:
-ClangDiagnosticHandler(const CodeGenOptions , BackendConsumer *BCon)
-: CodeGenOpts(CGOpts), BackendCon(BCon) {}
+class BackendConsumer;
+class ClangDiagnosticHandler final : public DiagnosticHandler {
+public:
+  ClangDiagnosticHandler(const CodeGenOptions , BackendConsumer *BCon)
+  : CodeGenOpts(CGOpts), BackendCon(BCon) {}
 
-bool handleDiagnostics(const DiagnosticInfo ) override;
+  bool handleDiagnostics(const DiagnosticInfo ) override;
 
-bool isAnalysisRemarkEnabled(StringRef PassName) const override {
-  return CodeGenOpts.OptimizationRemarkAnalysis.patternMatches(PassName);
-}
-bool isMissedOptRemarkEnabled(StringRef PassName) const override {
-  return CodeGenOpts.OptimizationRemarkMissed.patternMatches(PassName);
-}
-bool isPassedOptRemarkEnabled(StringRef PassName) const override {
-  return CodeGenOpts.OptimizationRemark.patternMatches(PassName);
-}
+  bool isAnalysisRemarkEnabled(StringRef PassName) const override {
+return CodeGenOpts.OptimizationRemarkAnalysis.patternMatches(PassName);
+  }
+  bool isMissedOptRemarkEnabled(StringRef PassName) const override {
+return CodeGenOpts.OptimizationRemarkMissed.patternMatches(PassName);
+  }
+  bool isPassedOptRemarkEnabled(StringRef PassName) const override {
+return CodeGenOpts.OptimizationRemark.patternMatches(PassName);
+  }
 
-bool isAnyRemarkEnabled() const override {
-  return CodeGenOpts.OptimizationRemarkAnalysis.hasValidPattern() ||
- CodeGenOpts.OptimizationRemarkMissed.hasValidPattern() ||
- CodeGenOpts.OptimizationRemark.hasValidPattern();
-}
+  bool isAnyRemarkEnabled() const override {
+return CodeGenOpts.OptimizationRemarkAnalysis.hasValidPattern() ||
+   CodeGenOpts.OptimizationRemarkMissed.hasValidPattern() ||
+   CodeGenOpts.OptimizationRemark.hasValidPattern();
+  }
 
-  private:
-const CodeGenOptions 
-BackendConsumer *BackendCon;
-  };
+private:
+  const CodeGenOptions 
+  BackendConsumer *BackendCon;
+};
+
+static void reportOptRecordError(Error E, DiagnosticsEngine ,
+ const CodeGenOptions ) {
+  handleAllErrors(
+  std::move(E),
+[&](const LLVMRemarkSetupFileError ) {
+Diags.Report(diag::err_cannot_open_file)
+<< CodeGenOpts.OptRecordFile << E.message();
+  },
+[&](const LLVMRemarkSetupPatternError ) {
+Diags.Report(diag::err_drv_optimization_remark_pattern)
+<< E.message() << CodeGenOpts.OptRecordPasses;
+  },
+[&](const LLVMRemarkSetupFormatError ) {
+Diags.Report(diag::err_drv_optimization_remark_format)
+<< CodeGenOpts.OptRecordFormat;
+  });
+}
 
-  static void reportOptRecordError(Error E, DiagnosticsEngine ,
-   const CodeGenOptions ) {
-handleAllErrors(
-std::move(E),
-  [&](const LLVMRemarkSetupFileError ) {
-  Diags.Report(diag::err_cannot_open_file)
-  << CodeGenOpts.OptRecordFile << E.message();
-},
-  [&](const LLVMRemarkSetupPatternError ) {
-  Diags.Report(diag::err_drv_optimization_remark_pattern)
-  << E.message() << CodeGenOpts.OptRecordPasses;
-},
-  [&](const LLVMRemarkSetupFormatError ) {
-  Diags.Report(diag::err_drv_optimization_remark_format)
-  << CodeGenOpts.OptRecordFormat;
-});
-}
+BackendConsumer::BackendConsumer(BackendAction Action, DiagnosticsEngine 
,
+ IntrusiveRefCntPtr VFS,
+ const HeaderSearchOptions ,
+ const PreprocessorOptions ,
+ const CodeGenOptions ,
+ const TargetOptions ,
+ const LangOptions ,
+ const std::string ,
+ SmallVector LinkModules,
+ std::unique_ptr OS,
+ LLVMContext ,
+ CoverageSourceInfo *CoverageInfo)
+  : Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts),
+  CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts),
+  AsmOutStream(std::move(OS)), Context(nullptr), FS(VFS),
+  LLVMIRGeneration("irgen", "LLVM IR Generation Time"),
+  LLVMIRGenerationRefCount(0),
+  Gen(CreateLLVMCodeGen(Diags, InFile, std::move(VFS), HeaderSearchOpts,
+PPOpts, 

[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-11-06 Thread Jacob Lambert via cfe-commits


@@ -155,10 +162,10 @@ class EmitAssemblyHelper {
 return F;
   }
 
-  void
-  RunOptimizationPipeline(BackendAction Action,
+  void RunOptimizationPipeline(BackendAction Action,
   std::unique_ptr ,
-  std::unique_ptr );
+  std::unique_ptr ,
+  BackendConsumer *BC);

lamb-j wrote:

I think so? I'm using the same indentation level as the other arguments, and 
BackendConsumer needs it's own line to no not overflow the character limit. 
What looks off about it?

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


[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-11-06 Thread Jacob Lambert via cfe-commits


@@ -1035,6 +1043,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 }
   }
 
+  // Re-link against any bitcodes supplied via the -mlink-builtin-bitcode 
option
+  // Some optimizations may generate new function calls that would not have
+  // been linked pre-optimization (i.e. fused sincos calls generated by
+  // AMDGPULibCalls::fold_sincos.)
+  if (ClRelinkBuiltinBitcodePostop)

lamb-j wrote:

Also, the reason for LinkInModules pass is that we need to insert the second 
linking step into the RunOptimizationPipeline, specifically _after_ the 
AMDGPULibCalls pass, but _before_ the BitcodeWriter pass

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


[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-11-06 Thread Jacob Lambert via cfe-commits


@@ -1035,6 +1043,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 }
   }
 
+  // Re-link against any bitcodes supplied via the -mlink-builtin-bitcode 
option
+  // Some optimizations may generate new function calls that would not have
+  // been linked pre-optimization (i.e. fused sincos calls generated by
+  // AMDGPULibCalls::fold_sincos.)
+  if (ClRelinkBuiltinBitcodePostop)

lamb-j wrote:

I did look into having a file-specific option to link specific bitcodes 
post-optimization, and I think it is a good idea overall.

It is possible to come up with a specific set of bitcodes that need to be 
re-linked, based on the current optimizations we've implemented that introduce 
undefined functions. And we could then specify that set for a file-specific 
post-optimization linking.

But there are some downsides:
  - Any users would also need to know the specific set of bitcodes needed for 
post-optimization linking
  - We may need to hardcode that list in a bunch of different places, both 
within LLVM and external APIs
  - If a new optimization is implemented that expands the set of bitcodes 
needed for post-optimization linking, we'd need to go around and update any 
place that uses the file-specific options

Given that, I think the boolean relink option may serve us better for the time 
being

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


[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-10-31 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/69371

>From 25302c315360c166f34ab9acde2561dc7865b3bb Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 17 Oct 2023 12:01:15 -0700
Subject: [PATCH 1/3] [NFC] Refactor BackendConsumer class definition into new
 header

Previously the BackendConsumer class was defined in CodeGenAction.cpp.
In order to use this class and its member functions in other files
for upcoming changes, we first need to refactor the class definition
into a separate header
---
 clang/lib/CodeGen/BackendConsumer.h | 166 +++
 clang/lib/CodeGen/CodeGenAction.cpp | 643 
 2 files changed, 448 insertions(+), 361 deletions(-)
 create mode 100644 clang/lib/CodeGen/BackendConsumer.h

diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
new file mode 100644
index 000..2a4f70d5668ed6b
--- /dev/null
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -0,0 +1,166 @@
+//===--- BackendConsumer.h - LLVM BackendConsumer Header File 
-===//
+//
+// 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_LIB_CODEGEN_BACKENDCONSUMER_H
+#define LLVM_CLANG_LIB_CODEGEN_BACKENDCONSUMER_H
+
+#include "clang/CodeGen/BackendUtil.h"
+#include "clang/CodeGen/CodeGenAction.h"
+
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/Support/Timer.h"
+
+namespace llvm {
+  class DiagnosticInfoDontCall;
+}
+
+namespace clang {
+class ASTContext;
+class CodeGenAction;
+class CoverageSourceInfo;
+
+class BackendConsumer : public ASTConsumer {
+  using LinkModule = CodeGenAction::LinkModule;
+
+  virtual void anchor();
+  DiagnosticsEngine 
+  BackendAction Action;
+  const HeaderSearchOptions 
+  const CodeGenOptions 
+  const TargetOptions 
+  const LangOptions 
+  std::unique_ptr AsmOutStream;
+  ASTContext *Context;
+  IntrusiveRefCntPtr FS;
+
+  llvm::Timer LLVMIRGeneration;
+  unsigned LLVMIRGenerationRefCount;
+
+  /// True if we've finished generating IR. This prevents us from generating
+  /// additional LLVM IR after emitting output in HandleTranslationUnit. This
+  /// can happen when Clang plugins trigger additional AST deserialization.
+  bool IRGenFinished = false;
+
+  bool TimerIsEnabled = false;
+
+  std::unique_ptr Gen;
+
+  SmallVector LinkModules;
+
+  // A map from mangled names to their function's source location, used for
+  // backend diagnostics as the Clang AST may be unavailable. We actually use
+  // the mangled name's hash as the key because mangled names can be very
+  // long and take up lots of space. Using a hash can cause name collision,
+  // but that is rare and the consequences are pointing to a wrong source
+  // location which is not severe. This is a vector instead of an actual map
+  // because we optimize for time building this map rather than time
+  // retrieving an entry, as backend diagnostics are uncommon.
+  std::vector>
+ManglingFullSourceLocs;
+
+
+  // This is here so that the diagnostic printer knows the module a diagnostic
+  // refers to.
+  llvm::Module *CurLinkModule = nullptr;
+
+public:
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , const std::string ,
+  SmallVector LinkModules,
+  std::unique_ptr OS, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  // This constructor is used in installing an empty BackendConsumer
+  // to use the clang diagnostic handler for IR input files. It avoids
+  // initializing the OS field.
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , llvm::Module *Module,
+  SmallVector LinkModules, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  llvm::Module *getModule() const;
+  std::unique_ptr takeModule();
+
+  CodeGenerator *getCodeGenerator();
+
+  void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override;
+  void Initialize(ASTContext ) override;
+  bool HandleTopLevelDecl(DeclGroupRef D) override;
+  void HandleInlineFunctionDefinition(FunctionDecl *D) override;
+  void HandleInterestingDecl(DeclGroupRef D) override;
+  void HandleTranslationUnit(ASTContext ) override;
+  void 

[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-10-19 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j updated 
https://github.com/llvm/llvm-project/pull/69371

>From 25302c315360c166f34ab9acde2561dc7865b3bb Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 17 Oct 2023 12:01:15 -0700
Subject: [PATCH 1/3] [NFC] Refactor BackendConsumer class definition into new
 header

Previously the BackendConsumer class was defined in CodeGenAction.cpp.
In order to use this class and its member functions in other files
for upcoming changes, we first need to refactor the class definition
into a separate header
---
 clang/lib/CodeGen/BackendConsumer.h | 166 +++
 clang/lib/CodeGen/CodeGenAction.cpp | 643 
 2 files changed, 448 insertions(+), 361 deletions(-)
 create mode 100644 clang/lib/CodeGen/BackendConsumer.h

diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
new file mode 100644
index 000..2a4f70d5668ed6b
--- /dev/null
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -0,0 +1,166 @@
+//===--- BackendConsumer.h - LLVM BackendConsumer Header File 
-===//
+//
+// 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_LIB_CODEGEN_BACKENDCONSUMER_H
+#define LLVM_CLANG_LIB_CODEGEN_BACKENDCONSUMER_H
+
+#include "clang/CodeGen/BackendUtil.h"
+#include "clang/CodeGen/CodeGenAction.h"
+
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/Support/Timer.h"
+
+namespace llvm {
+  class DiagnosticInfoDontCall;
+}
+
+namespace clang {
+class ASTContext;
+class CodeGenAction;
+class CoverageSourceInfo;
+
+class BackendConsumer : public ASTConsumer {
+  using LinkModule = CodeGenAction::LinkModule;
+
+  virtual void anchor();
+  DiagnosticsEngine 
+  BackendAction Action;
+  const HeaderSearchOptions 
+  const CodeGenOptions 
+  const TargetOptions 
+  const LangOptions 
+  std::unique_ptr AsmOutStream;
+  ASTContext *Context;
+  IntrusiveRefCntPtr FS;
+
+  llvm::Timer LLVMIRGeneration;
+  unsigned LLVMIRGenerationRefCount;
+
+  /// True if we've finished generating IR. This prevents us from generating
+  /// additional LLVM IR after emitting output in HandleTranslationUnit. This
+  /// can happen when Clang plugins trigger additional AST deserialization.
+  bool IRGenFinished = false;
+
+  bool TimerIsEnabled = false;
+
+  std::unique_ptr Gen;
+
+  SmallVector LinkModules;
+
+  // A map from mangled names to their function's source location, used for
+  // backend diagnostics as the Clang AST may be unavailable. We actually use
+  // the mangled name's hash as the key because mangled names can be very
+  // long and take up lots of space. Using a hash can cause name collision,
+  // but that is rare and the consequences are pointing to a wrong source
+  // location which is not severe. This is a vector instead of an actual map
+  // because we optimize for time building this map rather than time
+  // retrieving an entry, as backend diagnostics are uncommon.
+  std::vector>
+ManglingFullSourceLocs;
+
+
+  // This is here so that the diagnostic printer knows the module a diagnostic
+  // refers to.
+  llvm::Module *CurLinkModule = nullptr;
+
+public:
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , const std::string ,
+  SmallVector LinkModules,
+  std::unique_ptr OS, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  // This constructor is used in installing an empty BackendConsumer
+  // to use the clang diagnostic handler for IR input files. It avoids
+  // initializing the OS field.
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , llvm::Module *Module,
+  SmallVector LinkModules, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  llvm::Module *getModule() const;
+  std::unique_ptr takeModule();
+
+  CodeGenerator *getCodeGenerator();
+
+  void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override;
+  void Initialize(ASTContext ) override;
+  bool HandleTopLevelDecl(DeclGroupRef D) override;
+  void HandleInlineFunctionDefinition(FunctionDecl *D) override;
+  void HandleInterestingDecl(DeclGroupRef D) override;
+  void HandleTranslationUnit(ASTContext ) override;
+  void 

[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-10-17 Thread Jacob Lambert via cfe-commits

lamb-j wrote:

> This approach assumes that whatever the function call was transformed into 
> also exists in the same library, which isn't necessarily true.

True, good point. But I don't think it's necessarily due to this approach, but 
more of how AMDGPULibCalls is implemented. It seems like the instruction 
folding implementations are assuming the definitions of the new functions 
they're inserting will be linked in at a later point?

Previously we were doing it via a separate _llvm-link_ call to re-link all the 
device libraries. With this approach, we're doing it as part of the clang 
optimization pipeline, and would no longer need that extra link step.

Maybe this approach could be a solution for the time being? With a longer term 
solution being to think more carefully about the legality of AMDGPULibCalls 
inserting function calls that may or may not exist? Maybe device library calls 
are the exception?



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


[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-10-17 Thread Jacob Lambert via cfe-commits

lamb-j wrote:

sincos() is just one example. There are several other cases that can trigger 
this issue. fold_rootn() generates new function calls for square and cubic 
roots, fold_pow() does a similar thing for specific powers (ex 2)

We did try disabling -llvm-prelink, and it did lead to a significant 
performance difference for a couple of key applications



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


[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

2023-10-17 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j created 
https://github.com/llvm/llvm-project/pull/69371

This set of patches updates device library linking and optimization to do the 
following:

Link
Optimize
Link (New)

This handles the edge case where optimization introduces new device library 
functions, such as a fused sincos() from separate sin() and cos() calls. The 
second link step ensures the sincos() definition is also linked in from the 
device libraries.

>From 25302c315360c166f34ab9acde2561dc7865b3bb Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 17 Oct 2023 12:01:15 -0700
Subject: [PATCH 1/3] [NFC] Refactor BackendConsumer class definition into new
 header

Previously the BackendConsumer class was defined in CodeGenAction.cpp.
In order to use this class and its member functions in other files
for upcoming changes, we first need to refactor the class definition
into a separate header
---
 clang/lib/CodeGen/BackendConsumer.h | 166 +++
 clang/lib/CodeGen/CodeGenAction.cpp | 643 
 2 files changed, 448 insertions(+), 361 deletions(-)
 create mode 100644 clang/lib/CodeGen/BackendConsumer.h

diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
new file mode 100644
index 000..2a4f70d5668ed6b
--- /dev/null
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -0,0 +1,166 @@
+//===--- BackendConsumer.h - LLVM BackendConsumer Header File 
-===//
+//
+// 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_LIB_CODEGEN_BACKENDCONSUMER_H
+#define LLVM_CLANG_LIB_CODEGEN_BACKENDCONSUMER_H
+
+#include "clang/CodeGen/BackendUtil.h"
+#include "clang/CodeGen/CodeGenAction.h"
+
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/Support/Timer.h"
+
+namespace llvm {
+  class DiagnosticInfoDontCall;
+}
+
+namespace clang {
+class ASTContext;
+class CodeGenAction;
+class CoverageSourceInfo;
+
+class BackendConsumer : public ASTConsumer {
+  using LinkModule = CodeGenAction::LinkModule;
+
+  virtual void anchor();
+  DiagnosticsEngine 
+  BackendAction Action;
+  const HeaderSearchOptions 
+  const CodeGenOptions 
+  const TargetOptions 
+  const LangOptions 
+  std::unique_ptr AsmOutStream;
+  ASTContext *Context;
+  IntrusiveRefCntPtr FS;
+
+  llvm::Timer LLVMIRGeneration;
+  unsigned LLVMIRGenerationRefCount;
+
+  /// True if we've finished generating IR. This prevents us from generating
+  /// additional LLVM IR after emitting output in HandleTranslationUnit. This
+  /// can happen when Clang plugins trigger additional AST deserialization.
+  bool IRGenFinished = false;
+
+  bool TimerIsEnabled = false;
+
+  std::unique_ptr Gen;
+
+  SmallVector LinkModules;
+
+  // A map from mangled names to their function's source location, used for
+  // backend diagnostics as the Clang AST may be unavailable. We actually use
+  // the mangled name's hash as the key because mangled names can be very
+  // long and take up lots of space. Using a hash can cause name collision,
+  // but that is rare and the consequences are pointing to a wrong source
+  // location which is not severe. This is a vector instead of an actual map
+  // because we optimize for time building this map rather than time
+  // retrieving an entry, as backend diagnostics are uncommon.
+  std::vector>
+ManglingFullSourceLocs;
+
+
+  // This is here so that the diagnostic printer knows the module a diagnostic
+  // refers to.
+  llvm::Module *CurLinkModule = nullptr;
+
+public:
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , const std::string ,
+  SmallVector LinkModules,
+  std::unique_ptr OS, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  // This constructor is used in installing an empty BackendConsumer
+  // to use the clang diagnostic handler for IR input files. It avoids
+  // initializing the OS field.
+  BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+  IntrusiveRefCntPtr VFS,
+  const HeaderSearchOptions ,
+  const PreprocessorOptions ,
+  const CodeGenOptions ,
+  const TargetOptions ,
+  const LangOptions , llvm::Module *Module,
+  SmallVector LinkModules, llvm::LLVMContext ,
+  CoverageSourceInfo *CoverageInfo = nullptr);
+
+  llvm::Module *getModule() const;
+  std::unique_ptr takeModule();
+
+  CodeGenerator *getCodeGenerator();
+
+  void 

[clang] 0661533 - [AMDGPU] Prepend --no-undefined option for linker instead of append

2023-08-23 Thread Jacob Lambert via cfe-commits

Author: Jacob Lambert
Date: 2023-08-23T12:25:01-07:00
New Revision: 0661533e4168202476d660d3b18bbe13db16cc43

URL: 
https://github.com/llvm/llvm-project/commit/0661533e4168202476d660d3b18bbe13db16cc43
DIFF: 
https://github.com/llvm/llvm-project/commit/0661533e4168202476d660d3b18bbe13db16cc43.diff

LOG: [AMDGPU] Prepend --no-undefined option for linker instead of append

Previously, for linking in amdgpu contexts, the --no-undefined was appended to 
the options passed to lld,
overriding any user-supplied options via "-Wl," or "-Xlinker". We now prepend 
--no-undefined so that
the user options are respected.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/test/Driver/amdgpu-toolchain-opencl.cl
clang/test/Driver/amdgpu-toolchain.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index d0223322b56ba4..3f08c0ef5d6f00 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -551,6 +551,9 @@ void amdgpu::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   std::string Linker = getToolChain().GetProgramPath(getShortName());
   ArgStringList CmdArgs;
+  CmdArgs.push_back("--no-undefined");
+  CmdArgs.push_back("-shared");
+
   addLinkerCompressDebugSectionsOption(getToolChain(), Args, CmdArgs);
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
@@ -560,8 +563,6 @@ void amdgpu::Linker::ConstructJob(Compilation , const 
JobAction ,
   else if (Args.hasArg(options::OPT_mcpu_EQ))
 CmdArgs.push_back(Args.MakeArgString(
 "-plugin-opt=mcpu=" + Args.getLastArgValue(options::OPT_mcpu_EQ)));
-  CmdArgs.push_back("--no-undefined");
-  CmdArgs.push_back("-shared");
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
   C.addCommand(std::make_unique(

diff  --git a/clang/test/Driver/amdgpu-toolchain-opencl.cl 
b/clang/test/Driver/amdgpu-toolchain-opencl.cl
index 1ab6b7416e65ac..12fb1e4107d15e 100644
--- a/clang/test/Driver/amdgpu-toolchain-opencl.cl
+++ b/clang/test/Driver/amdgpu-toolchain-opencl.cl
@@ -28,3 +28,7 @@
 
 // RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -mcpu=fiji 
-nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK %s
 // CHK-LINK: ld.lld{{.*}} "--no-undefined" "-shared"
+
+// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl 
-Wl,--unresolved-symbols=ignore-all -x cl -mcpu=fiji -nogpulib %s 2>&1 | 
FileCheck -check-prefix=CHK-LINK_UR %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -Xlinker 
--unresolved-symbols=ignore-all -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck 
-check-prefix=CHK-LINK_UR %s
+// CHK-LINK_UR: ld.lld{{.*}} "--no-undefined"{{.*}} 
"--unresolved-symbols=ignore-all"

diff  --git a/clang/test/Driver/amdgpu-toolchain.c 
b/clang/test/Driver/amdgpu-toolchain.c
index 67491e53709d3e..4300e7e9f66705 100644
--- a/clang/test/Driver/amdgpu-toolchain.c
+++ b/clang/test/Driver/amdgpu-toolchain.c
@@ -10,6 +10,14 @@
 
 // DWARF_VER: "-dwarf-version=5"
 
+// RUN: %clang -### --target=amdgcn--amdhsa -x assembler \
+// RUN:  -Wl,--unresolved-symbols=ignore-all %s 2>&1 | FileCheck 
-check-prefix=AS_LINK_UR %s
+// RUN: %clang -### --target=amdgcn--amdhsa -x assembler \
+// RUN:  -Xlinker --unresolved-symbols=ignore-all %s 2>&1 | FileCheck 
-check-prefix=AS_LINK_UR %s
+
+// AS_LINK_UR: "-cc1as"
+// AS_LINK_UR: ld.lld{{.*}} "--no-undefined"{{.*}} 
"--unresolved-symbols=ignore-all"
+
 // RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
 // RUN:   -L. -flto -fconvergent-functions %s 2>&1 | FileCheck 
-check-prefixes=LTO,MCPU %s
 // RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f3b9912 - [clang-offload-bundler] Fix error with regex in bundler test

2023-03-14 Thread Jacob Lambert via cfe-commits

Author: Jacob Lambert
Date: 2023-03-14T19:51:26-07:00
New Revision: f3b9912026894ecca8925c974dd7ca16b0f1e265

URL: 
https://github.com/llvm/llvm-project/commit/f3b9912026894ecca8925c974dd7ca16b0f1e265
DIFF: 
https://github.com/llvm/llvm-project/commit/f3b9912026894ecca8925c974dd7ca16b0f1e265.diff

LOG: [clang-offload-bundler] Fix error with regex in bundler test

Fix recently introduced error and further generalize
pattern matching for accepted HOST string

Added: 


Modified: 
clang/test/Driver/clang-offload-bundler.c

Removed: 




diff  --git a/clang/test/Driver/clang-offload-bundler.c 
b/clang/test/Driver/clang-offload-bundler.c
index 949748c0112f..7d0b6b27a60a 100644
--- a/clang/test/Driver/clang-offload-bundler.c
+++ b/clang/test/Driver/clang-offload-bundler.c
@@ -300,7 +300,7 @@
 
 // RUN: clang-offload-bundler -type=o 
-targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu
 -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.o -### 2>&1 \
 // RUN: | FileCheck %s -DHOST=%itanium_abi_triple -DINOBJ1=%t.o 
-DINOBJ2=%t.tgt1 -DINOBJ3=%t.tgt2 -DOUTOBJ=%t.bundle3.o --check-prefix 
CK-OBJ-CMD-INPUTS
-// CK-OBJ-CMD-INPUTS: llvm-objcopy{{(.exe)?}}" 
"--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]={{.*}}" 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=readonly,exclude" 
"--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=[[INOBJ2]]"
 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=readonly,exclude"
 "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu-=[[INOBJ3]]" 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu-=readonly,exclude"
 "--" "[[INOBJ1]]" "[[OUTOBJ]]"
+// CK-OBJ-CMD-INPUTS: llvm-objcopy{{(.exe)?}}" 
"--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST:.+]]={{.*}}" 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=readonly,exclude" 
"--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=[[INOBJ2]]"
 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=readonly,exclude"
 "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu-=[[INOBJ3]]" 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu-=readonly,exclude"
 "--" "[[INOBJ1]]" "[[OUTOBJ]]"
 
 // RUN: clang-offload-bundler -type=o 
-targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu
 -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.o
 // RUN: clang-offload-bundler -type=o -input=%t.bundle3.o -list | FileCheck 
-check-prefix=CKLST %s



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 65fb636 - [clang-offload-bundler] Fix test failures and document typo

2023-03-14 Thread Jacob Lambert via cfe-commits

Author: Jacob Lambert
Date: 2023-03-14T19:14:42-07:00
New Revision: 65fb636bd462687980935979f2f36ec992e15c84

URL: 
https://github.com/llvm/llvm-project/commit/65fb636bd462687980935979f2f36ec992e15c84
DIFF: 
https://github.com/llvm/llvm-project/commit/65fb636bd462687980935979f2f36ec992e15c84.diff

LOG: [clang-offload-bundler] Fix test failures and document typo

The recent bundler patch (e48ae0d) introduced a few errors
in two clang/Driver tests, and in the bundler documentation

Added: 


Modified: 
clang/docs/ClangOffloadBundler.rst
clang/test/Driver/clang-offload-bundler-standardize.c
clang/test/Driver/clang-offload-bundler.c

Removed: 




diff  --git a/clang/docs/ClangOffloadBundler.rst 
b/clang/docs/ClangOffloadBundler.rst
index 52981d6e1dbc..d08bf4b97781 100644
--- a/clang/docs/ClangOffloadBundler.rst
+++ b/clang/docs/ClangOffloadBundler.rst
@@ -175,7 +175,7 @@ Where:
 
 **target-triple**
 The target triple of the code object. See `Target Triple
-.
+`_.
 
 The bundler accepts target triples with or without the optional environment
 field:

diff  --git a/clang/test/Driver/clang-offload-bundler-standardize.c 
b/clang/test/Driver/clang-offload-bundler-standardize.c
index e599271342d5..6a24968c30ef 100644
--- a/clang/test/Driver/clang-offload-bundler-standardize.c
+++ b/clang/test/Driver/clang-offload-bundler-standardize.c
@@ -1,4 +1,5 @@
 // REQUIRES: x86-registered-target
+// REQUIRES: asserts
 // UNSUPPORTED: target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}}
 // REQUIRES: asserts
 

diff  --git a/clang/test/Driver/clang-offload-bundler.c 
b/clang/test/Driver/clang-offload-bundler.c
index e75af52c3b8b..949748c0112f 100644
--- a/clang/test/Driver/clang-offload-bundler.c
+++ b/clang/test/Driver/clang-offload-bundler.c
@@ -1,6 +1,5 @@
 // REQUIRES: x86-registered-target
 // UNSUPPORTED: target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}}
-// XFAIL: target={{.*-ps(4|5)}}
 
 //
 // Generate all the types of files we can bundle.
@@ -297,11 +296,11 @@
 
 // RUN: clang-offload-bundler -type=o 
-targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu
 -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.o -### 2>&1 \
 // RUN: | FileCheck %s -DHOST=%itanium_abi_triple -DINOBJ1=%t.o 
-DINOBJ2=%t.tgt1 -DINOBJ3=%t.tgt2 -DOUTOBJ=%t.bundle3.o --check-prefix 
CK-OBJ-CMD
-// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" 
"--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]-={{.*}}" 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]-=readonly,exclude" 
"--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=[[INOBJ2]]"
 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=readonly,exclude"
 "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu-=[[INOBJ3]]" 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu-=readonly,exclude"
 "--" "[[INOBJ1]]" "[[OUTOBJ]]"
+// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" 
"--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST:.+]]={{.*}}" 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=readonly,exclude" 
"--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=[[INOBJ2]]"
 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=readonly,exclude"
 "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu-=[[INOBJ3]]" 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu-=readonly,exclude"
 "--" "[[INOBJ1]]" "[[OUTOBJ]]"
 
 // RUN: clang-offload-bundler -type=o 
-targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu
 -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.o -### 2>&1 \
 // RUN: | FileCheck %s -DHOST=%itanium_abi_triple -DINOBJ1=%t.o 
-DINOBJ2=%t.tgt1 -DINOBJ3=%t.tgt2 -DOUTOBJ=%t.bundle3.o --check-prefix 
CK-OBJ-CMD-INPUTS
-// CK-OBJ-CMD-INPUTS: llvm-objcopy{{(.exe)?}}" 
"--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]-={{.*}}" 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]-=readonly,exclude" 
"--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=[[INOBJ2]]"
 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=readonly,exclude"
 "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu-=[[INOBJ3]]" 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu-=readonly,exclude"
 "--" "[[INOBJ1]]" "[[OUTOBJ]]"
+// CK-OBJ-CMD-INPUTS: llvm-objcopy{{(.exe)?}}" 
"--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]={{.*}}" 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=readonly,exclude" 
"--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=[[INOBJ2]]"
 

[clang] e48ae0d - [clang-offload-bundler] Standardize TargetID field for bundler

2023-03-14 Thread Jacob Lambert via cfe-commits

Author: Jacob Lambert
Date: 2023-03-14T14:12:31-07:00
New Revision: e48ae0dbd80d58ce8eded9e55f0b1262d52517af

URL: 
https://github.com/llvm/llvm-project/commit/e48ae0dbd80d58ce8eded9e55f0b1262d52517af
DIFF: 
https://github.com/llvm/llvm-project/commit/e48ae0dbd80d58ce8eded9e55f0b1262d52517af.diff

LOG: [clang-offload-bundler] Standardize TargetID field for bundler

The bundler accepts both of the following for the --target option:
  hip-amdgcn-amd-amdhsa-gfx900(no env field)
  hip-amdgcn-amd-amdhsa--gfx900   (blank env field)

The environment field is defined as optional for Triples
in Triple.h. However, in this patch we update the bundler to
internally standardize to include the env field. While users
aren't required to specify an env field when listing targets on
the commandline, bundles generated by the offload-bundler will
include the ABI field.

This standardization simplifies things for APIs that deal with
bundles generated by the clang-offload-bundler tool.

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

Added: 
clang/test/Driver/clang-offload-bundler-standardize.c

Modified: 
clang/docs/ClangOffloadBundler.rst
clang/lib/Driver/OffloadBundler.cpp
clang/test/Driver/clang-offload-bundler-asserts-on.c
clang/test/Driver/clang-offload-bundler.c
clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Removed: 




diff  --git a/clang/docs/ClangOffloadBundler.rst 
b/clang/docs/ClangOffloadBundler.rst
index 997948a8217e5..52981d6e1dbce 100644
--- a/clang/docs/ClangOffloadBundler.rst
+++ b/clang/docs/ClangOffloadBundler.rst
@@ -174,7 +174,20 @@ Where:
   = 
==
 
 **target-triple**
-The target triple of the code object.
+The target triple of the code object. See `Target Triple
+.
+
+The bundler accepts target triples with or without the optional environment
+field:
+
+``--``, or
+``---``
+
+However, in order to standardize outputs for tools that consume bitcode
+bundles, bundles written by the bundler internally use only the 4-field
+target triple:
+
+``---``
 
 **target-id**
   The canonical target ID of the code object. Present only if the target

diff  --git a/clang/lib/Driver/OffloadBundler.cpp 
b/clang/lib/Driver/OffloadBundler.cpp
index 0145e0311145f..de7799f1435c8 100644
--- a/clang/lib/Driver/OffloadBundler.cpp
+++ b/clang/lib/Driver/OffloadBundler.cpp
@@ -72,12 +72,22 @@ OffloadTargetInfo::OffloadTargetInfo(const StringRef Target,
   if (clang::StringToCudaArch(TripleOrGPU.second) != clang::CudaArch::UNKNOWN) 
{
 auto KindTriple = TripleOrGPU.first.split('-');
 this->OffloadKind = KindTriple.first;
-this->Triple = llvm::Triple(KindTriple.second);
+
+// Enforce optional env field to standardize bundles
+llvm::Triple t = llvm::Triple(KindTriple.second);
+this->Triple = llvm::Triple(t.getArchName(), t.getVendorName(),
+t.getOSName(), t.getEnvironmentName());
+
 this->TargetID = Target.substr(Target.find(TripleOrGPU.second));
   } else {
 auto KindTriple = TargetFeatures.first.split('-');
 this->OffloadKind = KindTriple.first;
-this->Triple = llvm::Triple(KindTriple.second);
+
+// Enforce optional env field to standardize bundles
+llvm::Triple t = llvm::Triple(KindTriple.second);
+this->Triple = llvm::Triple(t.getArchName(), t.getVendorName(),
+t.getOSName(), t.getEnvironmentName());
+
 this->TargetID = "";
   }
 }

diff  --git a/clang/test/Driver/clang-offload-bundler-asserts-on.c 
b/clang/test/Driver/clang-offload-bundler-asserts-on.c
index aceda09f7bfa1..db99e31d568b9 100644
--- a/clang/test/Driver/clang-offload-bundler-asserts-on.c
+++ b/clang/test/Driver/clang-offload-bundler-asserts-on.c
@@ -21,12 +21,12 @@
 
 // Tests to check compatibility between Bundle Entry ID formats i.e. between 
presence/absence of extra hyphen in case of missing environment field
 // RUN: clang-offload-bundler -unbundle -type=a 
-targets=openmp-amdgcn-amd-amdhsa--gfx906,openmp-amdgcn-amd-amdhsa-gfx908 
-input=%t.input-archive.a -output=%t-archive-gfx906-simple.a 
-output=%t-archive-gfx908-simple.a -debug-only=CodeObjectCompatibility 2>&1 | 
FileCheck %s -check-prefix=BUNDLECOMPATIBILITY
-// BUNDLECOMPATIBILITY: Compatible: Exact match:[CodeObject: 
openmp-amdgcn-amd-amdhsa-gfx906]   :   [Target: 
openmp-amdgcn-amd-amdhsa--gfx906]
-// BUNDLECOMPATIBILITY: Compatible: Exact match:[CodeObject: 
openmp-amdgcn-amd-amdhsa--gfx908]  :   [Target: 
openmp-amdgcn-amd-amdhsa-gfx908]
+// BUNDLECOMPATIBILITY: Compatible: Exact match:[CodeObject: 
openmp-amdgcn-amd-amdhsa--gfx906]  :   [Target: 
openmp-amdgcn-amd-amdhsa--gfx906]
+// BUNDLECOMPATIBILITY: Compatible: Exact match: 

[clang] b47d4df - Switch ABI references to env/environment

2023-03-13 Thread Jacob Lambert via cfe-commits

Author: Jacob Lambert
Date: 2023-03-13T16:19:31-07:00
New Revision: b47d4df25c696739dbbb9e373ffd8a501eabcfef

URL: 
https://github.com/llvm/llvm-project/commit/b47d4df25c696739dbbb9e373ffd8a501eabcfef
DIFF: 
https://github.com/llvm/llvm-project/commit/b47d4df25c696739dbbb9e373ffd8a501eabcfef.diff

LOG: Switch ABI references to env/environment

To be consistent with Triple.h, we update references to the
optional fourth triple field from ABI to env or enviornment

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

Added: 


Modified: 
clang/docs/CrossCompilation.rst

Removed: 




diff  --git a/clang/docs/CrossCompilation.rst b/clang/docs/CrossCompilation.rst
index 932e0525366e..3578eb3e4db0 100644
--- a/clang/docs/CrossCompilation.rst
+++ b/clang/docs/CrossCompilation.rst
@@ -77,12 +77,12 @@ match (since Clang assumes the host triple), and the 
compilation will
 go ahead, creating code for the host platform, which will break later
 on when assembling or linking.
 
-The triple has the general format ``---``, where:
+The triple has the general format ``---``, where:
  * ``arch`` = ``x86_64``, ``i386``, ``arm``, ``thumb``, ``mips``, etc.
  * ``sub`` = for ex. on ARM: ``v5``, ``v6m``, ``v7a``, ``v7m``, etc.
  * ``vendor`` = ``pc``, ``apple``, ``nvidia``, ``ibm``, etc.
  * ``sys`` = ``none``, ``linux``, ``win32``, ``darwin``, ``cuda``, etc.
- * ``abi`` = ``eabi``, ``gnu``, ``android``, ``macho``, ``elf``, etc.
+ * ``env`` = ``eabi``, ``gnu``, ``android``, ``macho``, ``elf``, etc.
 
 The sub-architecture options are available for their own architectures,
 of course, so "x86v7a" doesn't make sense. The vendor needs to be
@@ -97,8 +97,8 @@ choose ``unknown`` and the defaults will be used. If you 
choose a parameter
 that Clang doesn't know, like ``blerg``, it'll ignore and assume
 ``unknown``, which is not always desired, so be careful.
 
-Finally, the ABI option is something that will pick default CPU/FPU,
-define the specific behaviour of your code (PCS, extensions),
+Finally, the env (enviornment) option is something that will pick default
+CPU/FPU, define the specific behaviour of your code (PCS, extensions),
 and also choose the correct library calls, etc.
 
 CPU, FPU, ABI
@@ -198,6 +198,6 @@ forget to specify ``-ccc-gcc-name 
armv7l-linux-gnueabihf-gcc`` (which
 uses hard-float), Clang will pick the ``armv7l-linux-gnueabi-ld``
 (which uses soft-float) and linker errors will happen.
 
-The same is true if you're compiling for 
diff erent ABIs, like ``gnueabi``
-and ``androideabi``, and might even link and run, but produce run-time
-errors, which are much harder to track down and fix.
+The same is true if you're compiling for 
diff erent environments, like
+``gnueabi`` and ``androideabi``, and might even link and run, but produce
+run-time errors, which are much harder to track down and fix.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f9de860 - [Driver][test] Fix test by creating empty archive instead of empty file

2022-12-07 Thread Jacob Lambert via cfe-commits

Author: Jacob Lambert
Date: 2022-12-07T11:50:11-08:00
New Revision: f9de860ca4c4b5827498dc096a26d9ebdf236181

URL: 
https://github.com/llvm/llvm-project/commit/f9de860ca4c4b5827498dc096a26d9ebdf236181
DIFF: 
https://github.com/llvm/llvm-project/commit/f9de860ca4c4b5827498dc096a26d9ebdf236181.diff

LOG: [Driver][test] Fix test by creating empty archive instead of empty file

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

Added: 


Modified: 
clang/test/Driver/hip-link-bc-to-bc.hip

Removed: 




diff  --git a/clang/test/Driver/hip-link-bc-to-bc.hip 
b/clang/test/Driver/hip-link-bc-to-bc.hip
index 972822b5260c2..a428a0497933e 100644
--- a/clang/test/Driver/hip-link-bc-to-bc.hip
+++ b/clang/test/Driver/hip-link-bc-to-bc.hip
@@ -1,6 +1,4 @@
 // REQUIRES: x86-registered-target, amdgpu-registered-target
-// See issue #58711
-// XFAIL: *
 
 // Check that clang unbundles the two bitcodes and links via llvm-link
 // RUN: rm -rf %t && mkdir %t
@@ -21,7 +19,7 @@
 // BITCODE: "{{.*}}llvm-link" "-o" "bundle1-hip-amdgcn-amd-amdhsa-gfx906.bc" 
"[[B1DEV2]]" "[[B2DEV2]]"
 
 // Check that clang unbundles the bitcode and archive and links via llvm-link
-// RUN: touch %t/libhipbundle.a
+// RUN: llvm-ar rc %t/libhipbundle.a
 // RUN: touch %t/bundle.bc
 
 // RUN: %clang -### --target=x86_64-unknown-linux-gnu --offload-arch=gfx906 
--hip-link \



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6b992bc - [Driver][test] Fix test by creating empty archive instead of empty file

2022-12-05 Thread Jacob Lambert via cfe-commits

Author: Jacob Lambert
Date: 2022-12-05T15:39:09-08:00
New Revision: 6b992bcce0c5a86f57c83dd8d0ac9e63bcfc5521

URL: 
https://github.com/llvm/llvm-project/commit/6b992bcce0c5a86f57c83dd8d0ac9e63bcfc5521
DIFF: 
https://github.com/llvm/llvm-project/commit/6b992bcce0c5a86f57c83dd8d0ac9e63bcfc5521.diff

LOG: [Driver][test] Fix test by creating empty archive instead of empty file

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

Added: 


Modified: 
clang/test/Driver/hip-link-bc-to-bc.hip

Removed: 




diff  --git a/clang/test/Driver/hip-link-bc-to-bc.hip 
b/clang/test/Driver/hip-link-bc-to-bc.hip
index 972822b5260c2..ac6dcf494224b 100644
--- a/clang/test/Driver/hip-link-bc-to-bc.hip
+++ b/clang/test/Driver/hip-link-bc-to-bc.hip
@@ -1,6 +1,4 @@
 // REQUIRES: x86-registered-target, amdgpu-registered-target
-// See issue #58711
-// XFAIL: *
 
 // Check that clang unbundles the two bitcodes and links via llvm-link
 // RUN: rm -rf %t && mkdir %t
@@ -21,7 +19,7 @@
 // BITCODE: "{{.*}}llvm-link" "-o" "bundle1-hip-amdgcn-amd-amdhsa-gfx906.bc" 
"[[B1DEV2]]" "[[B2DEV2]]"
 
 // Check that clang unbundles the bitcode and archive and links via llvm-link
-// RUN: touch %t/libhipbundle.a
+// RUN: ar rc %t/libhipbundle.a
 // RUN: touch %t/bundle.bc
 
 // RUN: %clang -### --target=x86_64-unknown-linux-gnu --offload-arch=gfx906 
--hip-link \



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0f3f357 - [clang-offload-bundler] Library-ize ClangOffloadBundler

2022-07-27 Thread Jacob Lambert via cfe-commits

Author: Jacob Lambert
Date: 2022-07-27T11:54:38-07:00
New Revision: 0f3f357e26cfdb887866215b234138e66fd0c4c9

URL: 
https://github.com/llvm/llvm-project/commit/0f3f357e26cfdb887866215b234138e66fd0c4c9
DIFF: 
https://github.com/llvm/llvm-project/commit/0f3f357e26cfdb887866215b234138e66fd0c4c9.diff

LOG: [clang-offload-bundler] Library-ize ClangOffloadBundler

Lifting the core functionalities of the clang-offload-bundler into a
user-facing library/API. This will allow online and JIT compilers to
bundle and unbundle files without spawning a new process.

This patch lifts the classes and functions used to implement
the clang-offload-bundler into a separate OffloadBundler.cpp,
and defines three top-level API functions in OfflaodBundler.h.
BundleFiles()
UnbundleFiles()
UnbundleArchives()

This patch also introduces a Config class that locally stores the
previously global cl::opt options and arrays to allow users to call
the APIs in a multi-threaded context, and introduces an
OffloadBundler class to encapsulate the top-level API functions.

We also  lift the BundlerExecutable variable, which is specific
to the clang-offload-bundler tool, from the API, and replace
its use with an ObjcopyPath variable. This variable must be set
in order to internally call llvm-objcopy.

Finally, we move the API files from
clang/tools/clang-offload-bundler into clang/lib/Driver and
clang/include/clang/Driver.

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

Added: 
clang/include/clang/Driver/OffloadBundler.h
clang/lib/Driver/OffloadBundler.cpp

Modified: 
clang/lib/Driver/CMakeLists.txt
clang/tools/clang-offload-bundler/CMakeLists.txt
clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/OffloadBundler.h 
b/clang/include/clang/Driver/OffloadBundler.h
new file mode 100644
index 0..ea0631b0ddf7f
--- /dev/null
+++ b/clang/include/clang/Driver/OffloadBundler.h
@@ -0,0 +1,89 @@
+//===- OffloadBundler.h - File Bundling and Unbundling --*- 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
+//
+//===--===//
+///
+/// \file
+/// This file defines an offload bundling API that bundles 
diff erent files
+/// that relate with the same source code but 
diff erent targets into a single
+/// one. Also the implements the opposite functionality, i.e. unbundle files
+/// previous created by this API.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H
+#define LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H
+
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+
+namespace clang {
+
+class OffloadBundlerConfig {
+public:
+  bool AllowNoHost = false;
+  bool AllowMissingBundles = false;
+  bool CheckInputArchive = false;
+  bool PrintExternalCommands = false;
+  bool HipOpenmpCompatible = false;
+
+  unsigned BundleAlignment = 1;
+  unsigned HostInputIndex = ~0u;
+
+  std::string FilesType;
+  std::string ObjcopyPath;
+
+  // TODO: Convert these to llvm::SmallVector
+  std::vector TargetNames;
+  std::vector InputFileNames;
+  std::vector OutputFileNames;
+};
+
+class OffloadBundler {
+public:
+  const OffloadBundlerConfig 
+
+  // TODO: Add error checking from ClangOffloadBundler.cpp
+  OffloadBundler(const OffloadBundlerConfig ) : BundlerConfig(BC) {}
+
+  // List bundle IDs. Return true if an error was found.
+  static llvm::Error
+  ListBundleIDsInFile(llvm::StringRef InputFileName,
+  const OffloadBundlerConfig );
+
+  llvm::Error BundleFiles();
+  llvm::Error UnbundleFiles();
+  llvm::Error UnbundleArchive();
+};
+
+/// Obtain the offload kind, real machine triple, and an optional GPUArch
+/// out of the target information specified by the user.
+/// Bundle Entry ID (or, Offload Target String) has following components:
+///  * Offload Kind - Host, OpenMP, or HIP
+///  * Triple - Standard LLVM Triple
+///  * GPUArch (Optional) - Processor name, like gfx906 or sm_30
+struct OffloadTargetInfo {
+  llvm::StringRef OffloadKind;
+  llvm::Triple Triple;
+  llvm::StringRef GPUArch;
+
+  const OffloadBundlerConfig 
+
+  OffloadTargetInfo(const llvm::StringRef Target,
+const OffloadBundlerConfig );
+  bool hasHostKind() const;
+  bool isOffloadKindValid() const;
+  bool isOffloadKindCompatible(const llvm::StringRef TargetOffloadKind) const;
+  bool isTripleValid() const;
+  bool operator==(const OffloadTargetInfo ) const;
+  std::string str();
+};
+
+} // namespace clang
+
+#endif // LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H

diff  --git a/clang/lib/Driver/CMakeLists.txt 

[clang] 8348c40 - [clang-offload-bundler] Library-ize ClangOffloadBundler

2022-07-26 Thread Jacob Lambert via cfe-commits

Author: Jacob Lambert
Date: 2022-07-26T10:05:22-07:00
New Revision: 8348c4095600ec2c0beee293267832799d2ebee3

URL: 
https://github.com/llvm/llvm-project/commit/8348c4095600ec2c0beee293267832799d2ebee3
DIFF: 
https://github.com/llvm/llvm-project/commit/8348c4095600ec2c0beee293267832799d2ebee3.diff

LOG: [clang-offload-bundler] Library-ize ClangOffloadBundler

Lifting the core functionalities of the clang-offload-bundler into a
user-facing library/API. This will allow online and JIT compilers to
bundle and unbundle files without spawning a new process.

This patch lifts the classes and functions used to implement
the clang-offload-bundler into a separate OffloadBundler.cpp,
and defines three top-level API functions in OfflaodBundler.h.
BundleFiles()
UnbundleFiles()
UnbundleArchives()

This patch also introduces a Config class that locally stores the
previously global cl::opt options and arrays to allow users to call
the APIs in a multi-threaded context, and introduces an
OffloadBundler class to encapsulate the top-level API functions.

We also  lift the BundlerExecutable variable, which is specific
to the clang-offload-bundler tool, from the API, and replace
its use with an ObjcopyPath variable. This variable must be set
in order to internally call llvm-objcopy.

Finally, we move the API files from
clang/tools/clang-offload-bundler into clang/lib/Driver and
clang/include/clang/Driver.

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

Added: 
clang/include/clang/Driver/OffloadBundler.h
clang/lib/Driver/OffloadBundler.cpp

Modified: 
clang/lib/Driver/CMakeLists.txt
clang/tools/clang-offload-bundler/CMakeLists.txt
clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/OffloadBundler.h 
b/clang/include/clang/Driver/OffloadBundler.h
new file mode 100644
index 0..ea0631b0ddf7f
--- /dev/null
+++ b/clang/include/clang/Driver/OffloadBundler.h
@@ -0,0 +1,89 @@
+//===- OffloadBundler.h - File Bundling and Unbundling --*- 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
+//
+//===--===//
+///
+/// \file
+/// This file defines an offload bundling API that bundles 
diff erent files
+/// that relate with the same source code but 
diff erent targets into a single
+/// one. Also the implements the opposite functionality, i.e. unbundle files
+/// previous created by this API.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H
+#define LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H
+
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+
+namespace clang {
+
+class OffloadBundlerConfig {
+public:
+  bool AllowNoHost = false;
+  bool AllowMissingBundles = false;
+  bool CheckInputArchive = false;
+  bool PrintExternalCommands = false;
+  bool HipOpenmpCompatible = false;
+
+  unsigned BundleAlignment = 1;
+  unsigned HostInputIndex = ~0u;
+
+  std::string FilesType;
+  std::string ObjcopyPath;
+
+  // TODO: Convert these to llvm::SmallVector
+  std::vector TargetNames;
+  std::vector InputFileNames;
+  std::vector OutputFileNames;
+};
+
+class OffloadBundler {
+public:
+  const OffloadBundlerConfig 
+
+  // TODO: Add error checking from ClangOffloadBundler.cpp
+  OffloadBundler(const OffloadBundlerConfig ) : BundlerConfig(BC) {}
+
+  // List bundle IDs. Return true if an error was found.
+  static llvm::Error
+  ListBundleIDsInFile(llvm::StringRef InputFileName,
+  const OffloadBundlerConfig );
+
+  llvm::Error BundleFiles();
+  llvm::Error UnbundleFiles();
+  llvm::Error UnbundleArchive();
+};
+
+/// Obtain the offload kind, real machine triple, and an optional GPUArch
+/// out of the target information specified by the user.
+/// Bundle Entry ID (or, Offload Target String) has following components:
+///  * Offload Kind - Host, OpenMP, or HIP
+///  * Triple - Standard LLVM Triple
+///  * GPUArch (Optional) - Processor name, like gfx906 or sm_30
+struct OffloadTargetInfo {
+  llvm::StringRef OffloadKind;
+  llvm::Triple Triple;
+  llvm::StringRef GPUArch;
+
+  const OffloadBundlerConfig 
+
+  OffloadTargetInfo(const llvm::StringRef Target,
+const OffloadBundlerConfig );
+  bool hasHostKind() const;
+  bool isOffloadKindValid() const;
+  bool isOffloadKindCompatible(const llvm::StringRef TargetOffloadKind) const;
+  bool isTripleValid() const;
+  bool operator==(const OffloadTargetInfo ) const;
+  std::string str();
+};
+
+} // namespace clang
+
+#endif // LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H

diff  --git a/clang/lib/Driver/CMakeLists.txt 

[clang] afcc6ba - [clang][HIP] Updating driver to enable archive/bitcode to bitcode linking when targeting HIPAMD toolchain

2022-04-21 Thread Jacob Lambert via cfe-commits

Author: Jacob Lambert
Date: 2022-04-21T09:24:33-07:00
New Revision: afcc6baac52fcc91d1636f6803f5c230e7018016

URL: 
https://github.com/llvm/llvm-project/commit/afcc6baac52fcc91d1636f6803f5c230e7018016
DIFF: 
https://github.com/llvm/llvm-project/commit/afcc6baac52fcc91d1636f6803f5c230e7018016.diff

LOG: [clang][HIP] Updating driver to enable archive/bitcode to bitcode linking 
when targeting HIPAMD toolchain

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

Added: 
clang/test/Driver/hip-link-bc-to-bc.hip

Modified: 
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/HIPAMD.cpp
clang/lib/Driver/ToolChains/HIPAMD.h
clang/test/Driver/hip-phases.hip

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index c2f33f2970e1f..0e0d2b47bd663 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3065,7 +3065,7 @@ class OffloadingActionBuilder final {
 
   // amdgcn does not support linking of object files, therefore we skip
   // backend and assemble phases to output LLVM IR. Except for generating
-  // non-relocatable device coee, where we generate fat binary for device
+  // non-relocatable device code, where we generate fat binary for device
   // code and pass to host in Backend phase.
   if (CudaDeviceActions.empty())
 return ABRT_Success;
@@ -3074,7 +3074,7 @@ class OffloadingActionBuilder final {
   CudaDeviceActions.size() == GpuArchList.size()) &&
  "Expecting one action per GPU architecture.");
   assert(!CompileHostOnly &&
- "Not expecting CUDA actions in host-only compilation.");
+ "Not expecting HIP actions in host-only compilation.");
 
   if (!Relocatable && CurPhase == phases::Backend && !EmitLLVM &&
   !EmitAsm) {
@@ -3203,12 +3203,16 @@ class OffloadingActionBuilder final {
  "Linker inputs and GPU arch list sizes do not match.");
 
   ActionList Actions;
-  // Append a new link action for each device.
   unsigned I = 0;
+  // Append a new link action for each device.
+  // Each entry in DeviceLinkerInputs corresponds to a GPU arch.
   for (auto  : DeviceLinkerInputs) {
-// Each entry in DeviceLinkerInputs corresponds to a GPU arch.
-auto *DeviceLinkAction =
-C.MakeAction(LI, types::TY_Image);
+
+types::ID Output = Args.hasArg(options::OPT_emit_llvm)
+   ? types::TY_LLVM_BC
+   : types::TY_Image;
+
+auto *DeviceLinkAction = C.MakeAction(LI, Output);
 // Linking all inputs for the current GPU arch.
 // LI contains all the inputs for the linker.
 OffloadAction::DeviceDependences DeviceLinkDeps;
@@ -3220,6 +3224,12 @@ class OffloadingActionBuilder final {
   }
   DeviceLinkerInputs.clear();
 
+  // If emitting LLVM, do not generate final host/device compilation action
+  if (Args.hasArg(options::OPT_emit_llvm)) {
+  AL.append(Actions);
+  return;
+  }
+
   // Create a host object from all the device images by embedding them
   // in a fat binary for mixed host-device compilation. For device-only
   // compilation, creates a fat binary.
@@ -3747,7 +3757,8 @@ void Driver::handleArguments(Compilation , 
DerivedArgList ,
   phases::ID FinalPhase = getFinalPhase(Args, );
 
   if (FinalPhase == phases::Link) {
-if (Args.hasArg(options::OPT_emit_llvm))
+// Emitting LLVM while linking disabled except in HIPAMD Toolchain
+if (Args.hasArg(options::OPT_emit_llvm) && 
!Args.hasArg(options::OPT_hip_link))
   Diag(clang::diag::err_drv_emit_llvm_link);
 if (IsCLMode() && LTOMode != LTOK_None &&
 !Args.getLastArgValue(options::OPT_fuse_ld_EQ)
@@ -3932,7 +3943,10 @@ void Driver::BuildActions(Compilation , DerivedArgList 
,
   // Queue linker inputs.
   if (Phase == phases::Link) {
 assert(Phase == PL.back() && "linking must be final compilation 
step.");
-LinkerInputs.push_back(Current);
+// We don't need to generate additional link commands if emitting AMD 
bitcode
+if (!(C.getInputArgs().hasArg(options::OPT_hip_link) &&
+ (C.getInputArgs().hasArg(options::OPT_emit_llvm
+  LinkerInputs.push_back(Current);
 Current = nullptr;
 break;
   }

diff  --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp 
b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index 9f0ac6294e607..f672d2a108cc9 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -72,6 +72,36 @@ static bool shouldSkipSanitizeOption(const ToolChain ,
   return false;
 }
 
+void AMDGCN::Linker::constructLlvmLinkCommand(Compilation ,
+ const JobAction ,
+ const 

[clang] edf7e02 - [clang][NFC] Fix Typo

2022-01-28 Thread Jacob Lambert via cfe-commits

Author: Jacob Lambert
Date: 2022-01-28T11:55:46-08:00
New Revision: edf7e026a8b4df5df7febaef126888f1ce65ebf6

URL: 
https://github.com/llvm/llvm-project/commit/edf7e026a8b4df5df7febaef126888f1ce65ebf6
DIFF: 
https://github.com/llvm/llvm-project/commit/edf7e026a8b4df5df7febaef126888f1ce65ebf6.diff

LOG: [clang][NFC] Fix Typo

Added: 


Modified: 
clang/docs/ClangOffloadBundler.rst

Removed: 




diff  --git a/clang/docs/ClangOffloadBundler.rst 
b/clang/docs/ClangOffloadBundler.rst
index ac4c5b51904fc..997948a8217e5 100644
--- a/clang/docs/ClangOffloadBundler.rst
+++ b/clang/docs/ClangOffloadBundler.rst
@@ -290,7 +290,7 @@ clang-offload-bundler extracts compatible device binaries 
for a given target
 from the bundled device binaries in a heterogeneous device archive and creates
 a target specific device archive without bundling.
 
-clang-offlocad-bundler determines whether a device binary is compatible with a
+clang-offload-bundler determines whether a device binary is compatible with a
 target by comparing bundle ID's. Two bundle ID's are considered compatible if:
 
   * Their offload kind are the same



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits