[PATCH] D96456: [ThinLTO] Add Config::OptPassBuilderHook

Vitaly Buka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 10 14:50:02 PST 2021


vitalybuka created this revision.
Herald added subscribers: steven_wu, hiraditya, inglorion.
vitalybuka requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Clang needs to register sanitizer at OptimizerLastEPCallback.
Nowever those callbacs are executed on the ThinLTOPostLink and we had
no way to configure that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96456

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/LTO/Config.h
  llvm/lib/LTO/LTOBackend.cpp


Index: llvm/lib/LTO/LTOBackend.cpp
===================================================================
--- llvm/lib/LTO/LTOBackend.cpp
+++ llvm/lib/LTO/LTOBackend.cpp
@@ -324,6 +324,9 @@
   PB.registerLoopAnalyses(LAM);
   PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
 
+  if (Conf.OptPassBuilderHook)
+    Conf.OptPassBuilderHook(PB);
+
   ModulePassManager MPM;
 
   // Always verify the input.
Index: llvm/include/llvm/LTO/Config.h
===================================================================
--- llvm/include/llvm/LTO/Config.h
+++ llvm/include/llvm/LTO/Config.h
@@ -50,6 +50,8 @@
   std::vector<std::string> PassPlugins;
   /// For adding passes that run right before codegen.
   std::function<void(legacy::PassManager &)> PreCodeGenPassesHook;
+  /// For adding passes that run by opt.
+  std::function<void(PassBuilder &)> OptPassBuilderHook;
   Optional<Reloc::Model> RelocModel = Reloc::PIC_;
   Optional<CodeModel::Model> CodeModel = None;
   CodeGenOpt::Level CGOptLevel = CodeGenOpt::Default;
Index: clang/lib/CodeGen/BackendUtil.cpp
===================================================================
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1544,6 +1544,10 @@
     Conf.CGFileType = getCodeGenFileType(Action);
     break;
   }
+  Triple TargetTriple(M->getTargetTriple());
+  Conf.OptPassBuilderHook = [&](PassBuilder &PB) {
+    addSanitizers(TargetTriple, CGOpts, LOpts, PB);
+  };
   if (Error E =
           thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
                       ModuleToDefinedGVSummaries[M->getModuleIdentifier()],


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96456.322831.patch
Type: text/x-patch
Size: 1615 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210210/5d7ff606/attachment-0001.bin>


More information about the cfe-commits mailing list