[PATCH] D123026: [clang][NFC] Extract the EmitAssemblyHelper::emitLTOSummary method

Pavel Samolysov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 4 05:56:40 PDT 2022


psamolysov-intel created this revision.
psamolysov-intel added reviewers: tejohnson, ddunbar, tobiasvk, tobiasvk_caf, paulkirth, greened.
psamolysov-intel added a project: clang.
Herald added subscribers: ormris, inglorion.
Herald added a project: All.
psamolysov-intel requested review of this revision.
Herald added a subscriber: cfe-commits.

The code to check if the LTO summary should be emitted and to add the
corresponding module flags was duplicated in the
'EmitAssemblyHelper::EmitAssemblyWithLegacyPassManager' and
'EmitAssemblyHelper::RunOptimizationPipeline' methods.

      

In order to eliminate these code duplications, the
'EmitAssemblyHelper::emitLTOSummary' method has been extracted. The method
returns a bool value, the value is true if the module summary should be emitted.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123026

Files:
  clang/lib/CodeGen/BackendUtil.cpp


Index: clang/lib/CodeGen/BackendUtil.cpp
===================================================================
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -164,6 +164,25 @@
                           std::unique_ptr<raw_pwrite_stream> &OS,
                           std::unique_ptr<llvm::ToolOutputFile> &DwoOS);
 
+  /// Emit a module summary by default for Regular LTO except for ld64
+  /// targets.
+  ///
+  /// \return True if the module summary should be emitted.
+  bool emitLTOSummary() {
+    bool EmitLTOSummary =
+        (CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
+         TargetTriple.getVendor() != llvm::Triple::Apple);
+    if (EmitLTOSummary) {
+      if (!TheModule->getModuleFlag("ThinLTO"))
+        TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
+      if (!TheModule->getModuleFlag("EnableSplitLTOUnit"))
+        TheModule->addModuleFlag(Module::Error, "EnableSplitLTOUnit",
+                                 uint32_t(1));
+    }
+
+    return EmitLTOSummary;
+  }
+
 public:
   EmitAssemblyHelper(DiagnosticsEngine &_Diags,
                      const HeaderSearchOptions &HeaderSearchOpts,
@@ -1052,19 +1071,7 @@
       PerModulePasses.add(createWriteThinLTOBitcodePass(
           *OS, ThinLinkOS ? &ThinLinkOS->os() : nullptr));
     } else {
-      // Emit a module summary by default for Regular LTO except for ld64
-      // targets
-      bool EmitLTOSummary =
-          (CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
-           TargetTriple.getVendor() != llvm::Triple::Apple);
-      if (EmitLTOSummary) {
-        if (!TheModule->getModuleFlag("ThinLTO"))
-          TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
-        if (!TheModule->getModuleFlag("EnableSplitLTOUnit"))
-          TheModule->addModuleFlag(Module::Error, "EnableSplitLTOUnit",
-                                   uint32_t(1));
-      }
-
+      bool EmitLTOSummary = emitLTOSummary();
       PerModulePasses.add(createBitcodeWriterPass(
           *OS, CodeGenOpts.EmitLLVMUseLists, EmitLTOSummary));
     }
@@ -1468,18 +1475,7 @@
       MPM.addPass(ThinLTOBitcodeWriterPass(*OS, ThinLinkOS ? &ThinLinkOS->os()
                                                            : nullptr));
     } else {
-      // Emit a module summary by default for Regular LTO except for ld64
-      // targets
-      bool EmitLTOSummary =
-          (CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
-           TargetTriple.getVendor() != llvm::Triple::Apple);
-      if (EmitLTOSummary) {
-        if (!TheModule->getModuleFlag("ThinLTO"))
-          TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
-        if (!TheModule->getModuleFlag("EnableSplitLTOUnit"))
-          TheModule->addModuleFlag(Module::Error, "EnableSplitLTOUnit",
-                                   uint32_t(1));
-      }
+      bool EmitLTOSummary = emitLTOSummary();
       MPM.addPass(
           BitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists, EmitLTOSummary));
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123026.420152.patch
Type: text/x-patch
Size: 3081 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220404/f47ece31/attachment-0001.bin>


More information about the cfe-commits mailing list