f37d0a9fa449af02bd925b5e4ca7557dc4cff2da
[oota-llvm.git] / lib / LTO / LTOCodeGenerator.cpp
1 //===-LTOCodeGenerator.cpp - LLVM Link Time Optimizer ---------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the Link Time Optimization library. This library is
11 // intended to be used by linker to optimize code at link time.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/LTO/LTOCodeGenerator.h"
16 #include "llvm/ADT/StringExtras.h"
17 #include "llvm/Analysis/Passes.h"
18 #include "llvm/Analysis/TargetLibraryInfo.h"
19 #include "llvm/Analysis/TargetTransformInfo.h"
20 #include "llvm/Bitcode/ReaderWriter.h"
21 #include "llvm/CodeGen/RuntimeLibcalls.h"
22 #include "llvm/Config/config.h"
23 #include "llvm/IR/Constants.h"
24 #include "llvm/IR/DataLayout.h"
25 #include "llvm/IR/DerivedTypes.h"
26 #include "llvm/IR/DiagnosticInfo.h"
27 #include "llvm/IR/DiagnosticPrinter.h"
28 #include "llvm/IR/LLVMContext.h"
29 #include "llvm/IR/Mangler.h"
30 #include "llvm/IR/Module.h"
31 #include "llvm/IR/Verifier.h"
32 #include "llvm/InitializePasses.h"
33 #include "llvm/LTO/LTOModule.h"
34 #include "llvm/Linker/Linker.h"
35 #include "llvm/MC/MCAsmInfo.h"
36 #include "llvm/MC/MCContext.h"
37 #include "llvm/MC/SubtargetFeature.h"
38 #include "llvm/PassManager.h"
39 #include "llvm/Support/CommandLine.h"
40 #include "llvm/Support/FileSystem.h"
41 #include "llvm/Support/FormattedStream.h"
42 #include "llvm/Support/Host.h"
43 #include "llvm/Support/MemoryBuffer.h"
44 #include "llvm/Support/Signals.h"
45 #include "llvm/Support/TargetRegistry.h"
46 #include "llvm/Support/TargetSelect.h"
47 #include "llvm/Support/ToolOutputFile.h"
48 #include "llvm/Support/raw_ostream.h"
49 #include "llvm/Target/TargetLowering.h"
50 #include "llvm/Target/TargetOptions.h"
51 #include "llvm/Target/TargetRegisterInfo.h"
52 #include "llvm/Target/TargetSubtargetInfo.h"
53 #include "llvm/Transforms/IPO.h"
54 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
55 #include "llvm/Transforms/ObjCARC.h"
56 #include <system_error>
57 using namespace llvm;
58
59 const char* LTOCodeGenerator::getVersionString() {
60 #ifdef LLVM_VERSION_INFO
61   return PACKAGE_NAME " version " PACKAGE_VERSION ", " LLVM_VERSION_INFO;
62 #else
63   return PACKAGE_NAME " version " PACKAGE_VERSION;
64 #endif
65 }
66
67 LTOCodeGenerator::LTOCodeGenerator()
68     : Context(getGlobalContext()), IRLinker(new Module("ld-temp.o", Context)) {
69   initialize();
70 }
71
72 LTOCodeGenerator::LTOCodeGenerator(std::unique_ptr<LLVMContext> Context)
73     : OwnedContext(std::move(Context)), Context(*OwnedContext),
74       IRLinker(new Module("ld-temp.o", *OwnedContext)) {
75   initialize();
76 }
77
78 void LTOCodeGenerator::initialize() {
79   TargetMach = nullptr;
80   EmitDwarfDebugInfo = false;
81   ScopeRestrictionsDone = false;
82   CodeModel = LTO_CODEGEN_PIC_MODEL_DEFAULT;
83   DiagHandler = nullptr;
84   DiagContext = nullptr;
85
86   initializeLTOPasses();
87 }
88
89 LTOCodeGenerator::~LTOCodeGenerator() {
90   delete TargetMach;
91   TargetMach = nullptr;
92
93   IRLinker.deleteModule();
94
95   for (std::vector<char *>::iterator I = CodegenOptions.begin(),
96                                      E = CodegenOptions.end();
97        I != E; ++I)
98     free(*I);
99 }
100
101 // Initialize LTO passes. Please keep this funciton in sync with
102 // PassManagerBuilder::populateLTOPassManager(), and make sure all LTO
103 // passes are initialized.
104 void LTOCodeGenerator::initializeLTOPasses() {
105   PassRegistry &R = *PassRegistry::getPassRegistry();
106
107   initializeInternalizePassPass(R);
108   initializeIPSCCPPass(R);
109   initializeGlobalOptPass(R);
110   initializeConstantMergePass(R);
111   initializeDAHPass(R);
112   initializeInstructionCombiningPassPass(R);
113   initializeSimpleInlinerPass(R);
114   initializePruneEHPass(R);
115   initializeGlobalDCEPass(R);
116   initializeArgPromotionPass(R);
117   initializeJumpThreadingPass(R);
118   initializeSROAPass(R);
119   initializeSROA_DTPass(R);
120   initializeSROA_SSAUpPass(R);
121   initializeFunctionAttrsPass(R);
122   initializeGlobalsModRefPass(R);
123   initializeLICMPass(R);
124   initializeMergedLoadStoreMotionPass(R);
125   initializeGVNPass(R);
126   initializeMemCpyOptPass(R);
127   initializeDCEPass(R);
128   initializeCFGSimplifyPassPass(R);
129 }
130
131 bool LTOCodeGenerator::addModule(LTOModule *mod) {
132   assert(&mod->getModule().getContext() == &Context &&
133          "Expected module in same context");
134
135   bool ret = IRLinker.linkInModule(&mod->getModule());
136
137   const std::vector<const char*> &undefs = mod->getAsmUndefinedRefs();
138   for (int i = 0, e = undefs.size(); i != e; ++i)
139     AsmUndefinedRefs[undefs[i]] = 1;
140
141   return !ret;
142 }
143
144 void LTOCodeGenerator::setTargetOptions(TargetOptions options) {
145   Options = options;
146 }
147
148 void LTOCodeGenerator::setDebugInfo(lto_debug_model debug) {
149   switch (debug) {
150   case LTO_DEBUG_MODEL_NONE:
151     EmitDwarfDebugInfo = false;
152     return;
153
154   case LTO_DEBUG_MODEL_DWARF:
155     EmitDwarfDebugInfo = true;
156     return;
157   }
158   llvm_unreachable("Unknown debug format!");
159 }
160
161 void LTOCodeGenerator::setCodePICModel(lto_codegen_model model) {
162   switch (model) {
163   case LTO_CODEGEN_PIC_MODEL_STATIC:
164   case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
165   case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
166   case LTO_CODEGEN_PIC_MODEL_DEFAULT:
167     CodeModel = model;
168     return;
169   }
170   llvm_unreachable("Unknown PIC model!");
171 }
172
173 bool LTOCodeGenerator::writeMergedModules(const char *path,
174                                           std::string &errMsg) {
175   if (!determineTarget(errMsg))
176     return false;
177
178   // mark which symbols can not be internalized
179   applyScopeRestrictions();
180
181   // create output file
182   std::error_code EC;
183   tool_output_file Out(path, EC, sys::fs::F_None);
184   if (EC) {
185     errMsg = "could not open bitcode file for writing: ";
186     errMsg += path;
187     return false;
188   }
189
190   // write bitcode to it
191   WriteBitcodeToFile(IRLinker.getModule(), Out.os());
192   Out.os().close();
193
194   if (Out.os().has_error()) {
195     errMsg = "could not write bitcode file: ";
196     errMsg += path;
197     Out.os().clear_error();
198     return false;
199   }
200
201   Out.keep();
202   return true;
203 }
204
205 bool LTOCodeGenerator::compileOptimizedToFile(const char **name,
206                                               std::string &errMsg) {
207   // make unique temp .o file to put generated object file
208   SmallString<128> Filename;
209   int FD;
210   std::error_code EC =
211       sys::fs::createTemporaryFile("lto-llvm", "o", FD, Filename);
212   if (EC) {
213     errMsg = EC.message();
214     return false;
215   }
216
217   // generate object file
218   tool_output_file objFile(Filename.c_str(), FD);
219
220   bool genResult = compileOptimized(objFile.os(), errMsg);
221   objFile.os().close();
222   if (objFile.os().has_error()) {
223     objFile.os().clear_error();
224     sys::fs::remove(Twine(Filename));
225     return false;
226   }
227
228   objFile.keep();
229   if (!genResult) {
230     sys::fs::remove(Twine(Filename));
231     return false;
232   }
233
234   NativeObjectPath = Filename.c_str();
235   *name = NativeObjectPath.c_str();
236   return true;
237 }
238
239 const void *LTOCodeGenerator::compileOptimized(size_t *length,
240                                                std::string &errMsg) {
241   const char *name;
242   if (!compileOptimizedToFile(&name, errMsg))
243     return nullptr;
244
245   // read .o file into memory buffer
246   ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
247       MemoryBuffer::getFile(name, -1, false);
248   if (std::error_code EC = BufferOrErr.getError()) {
249     errMsg = EC.message();
250     sys::fs::remove(NativeObjectPath);
251     return nullptr;
252   }
253   NativeObjectFile = std::move(*BufferOrErr);
254
255   // remove temp files
256   sys::fs::remove(NativeObjectPath);
257
258   // return buffer, unless error
259   if (!NativeObjectFile)
260     return nullptr;
261   *length = NativeObjectFile->getBufferSize();
262   return NativeObjectFile->getBufferStart();
263 }
264
265
266 bool LTOCodeGenerator::compile_to_file(const char **name,
267                                        bool disableOpt,
268                                        bool disableInline,
269                                        bool disableGVNLoadPRE,
270                                        bool disableVectorization,
271                                        std::string &errMsg) {
272   if (!optimize(disableOpt, disableInline, disableGVNLoadPRE,
273                 disableVectorization, errMsg))
274     return false;
275
276   return compileOptimizedToFile(name, errMsg);
277 }
278
279 const void* LTOCodeGenerator::compile(size_t *length,
280                                       bool disableOpt,
281                                       bool disableInline,
282                                       bool disableGVNLoadPRE,
283                                       bool disableVectorization,
284                                       std::string &errMsg) {
285   if (!optimize(disableOpt, disableInline, disableGVNLoadPRE,
286                 disableVectorization, errMsg))
287     return nullptr;
288
289   return compileOptimized(length, errMsg);
290 }
291
292 bool LTOCodeGenerator::determineTarget(std::string &errMsg) {
293   if (TargetMach)
294     return true;
295
296   std::string TripleStr = IRLinker.getModule()->getTargetTriple();
297   if (TripleStr.empty())
298     TripleStr = sys::getDefaultTargetTriple();
299   llvm::Triple Triple(TripleStr);
300
301   // create target machine from info for merged modules
302   const Target *march = TargetRegistry::lookupTarget(TripleStr, errMsg);
303   if (!march)
304     return false;
305
306   // The relocation model is actually a static member of TargetMachine and
307   // needs to be set before the TargetMachine is instantiated.
308   Reloc::Model RelocModel = Reloc::Default;
309   switch (CodeModel) {
310   case LTO_CODEGEN_PIC_MODEL_STATIC:
311     RelocModel = Reloc::Static;
312     break;
313   case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
314     RelocModel = Reloc::PIC_;
315     break;
316   case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
317     RelocModel = Reloc::DynamicNoPIC;
318     break;
319   case LTO_CODEGEN_PIC_MODEL_DEFAULT:
320     // RelocModel is already the default, so leave it that way.
321     break;
322   }
323
324   // Construct LTOModule, hand over ownership of module and target. Use MAttr as
325   // the default set of features.
326   SubtargetFeatures Features(MAttr);
327   Features.getDefaultSubtargetFeatures(Triple);
328   std::string FeatureStr = Features.getString();
329   // Set a default CPU for Darwin triples.
330   if (MCpu.empty() && Triple.isOSDarwin()) {
331     if (Triple.getArch() == llvm::Triple::x86_64)
332       MCpu = "core2";
333     else if (Triple.getArch() == llvm::Triple::x86)
334       MCpu = "yonah";
335     else if (Triple.getArch() == llvm::Triple::aarch64)
336       MCpu = "cyclone";
337   }
338
339   TargetMach = march->createTargetMachine(TripleStr, MCpu, FeatureStr, Options,
340                                           RelocModel, CodeModel::Default,
341                                           CodeGenOpt::Aggressive);
342   return true;
343 }
344
345 void LTOCodeGenerator::
346 applyRestriction(GlobalValue &GV,
347                  ArrayRef<StringRef> Libcalls,
348                  std::vector<const char*> &MustPreserveList,
349                  SmallPtrSetImpl<GlobalValue*> &AsmUsed,
350                  Mangler &Mangler) {
351   // There are no restrictions to apply to declarations.
352   if (GV.isDeclaration())
353     return;
354
355   // There is nothing more restrictive than private linkage.
356   if (GV.hasPrivateLinkage())
357     return;
358
359   SmallString<64> Buffer;
360   TargetMach->getNameWithPrefix(Buffer, &GV, Mangler);
361
362   if (MustPreserveSymbols.count(Buffer))
363     MustPreserveList.push_back(GV.getName().data());
364   if (AsmUndefinedRefs.count(Buffer))
365     AsmUsed.insert(&GV);
366
367   // Conservatively append user-supplied runtime library functions to
368   // llvm.compiler.used.  These could be internalized and deleted by
369   // optimizations like -globalopt, causing problems when later optimizations
370   // add new library calls (e.g., llvm.memset => memset and printf => puts).
371   // Leave it to the linker to remove any dead code (e.g. with -dead_strip).
372   if (isa<Function>(GV) &&
373       std::binary_search(Libcalls.begin(), Libcalls.end(), GV.getName()))
374     AsmUsed.insert(&GV);
375 }
376
377 static void findUsedValues(GlobalVariable *LLVMUsed,
378                            SmallPtrSetImpl<GlobalValue*> &UsedValues) {
379   if (!LLVMUsed) return;
380
381   ConstantArray *Inits = cast<ConstantArray>(LLVMUsed->getInitializer());
382   for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i)
383     if (GlobalValue *GV =
384         dyn_cast<GlobalValue>(Inits->getOperand(i)->stripPointerCasts()))
385       UsedValues.insert(GV);
386 }
387
388 // Collect names of runtime library functions. User-defined functions with the
389 // same names are added to llvm.compiler.used to prevent them from being
390 // deleted by optimizations.
391 static void accumulateAndSortLibcalls(std::vector<StringRef> &Libcalls,
392                                       const TargetLibraryInfo& TLI,
393                                       const Module &Mod,
394                                       const TargetMachine &TM) {
395   // TargetLibraryInfo has info on C runtime library calls on the current
396   // target.
397   for (unsigned I = 0, E = static_cast<unsigned>(LibFunc::NumLibFuncs);
398        I != E; ++I) {
399     LibFunc::Func F = static_cast<LibFunc::Func>(I);
400     if (TLI.has(F))
401       Libcalls.push_back(TLI.getName(F));
402   }
403
404   SmallPtrSet<const TargetLowering *, 1> TLSet;
405
406   for (const Function &F : Mod) {
407     const TargetLowering *Lowering =
408         TM.getSubtargetImpl(F)->getTargetLowering();
409
410     if (Lowering && TLSet.insert(Lowering).second)
411       // TargetLowering has info on library calls that CodeGen expects to be
412       // available, both from the C runtime and compiler-rt.
413       for (unsigned I = 0, E = static_cast<unsigned>(RTLIB::UNKNOWN_LIBCALL);
414            I != E; ++I)
415         if (const char *Name =
416                 Lowering->getLibcallName(static_cast<RTLIB::Libcall>(I)))
417           Libcalls.push_back(Name);
418   }
419
420   array_pod_sort(Libcalls.begin(), Libcalls.end());
421   Libcalls.erase(std::unique(Libcalls.begin(), Libcalls.end()),
422                  Libcalls.end());
423 }
424
425 void LTOCodeGenerator::applyScopeRestrictions() {
426   if (ScopeRestrictionsDone)
427     return;
428   Module *mergedModule = IRLinker.getModule();
429
430   // Start off with a verification pass.
431   PassManager passes;
432   passes.add(createVerifierPass());
433   passes.add(createDebugInfoVerifierPass());
434
435   // mark which symbols can not be internalized
436   Mangler Mangler(TargetMach->getDataLayout());
437   std::vector<const char*> MustPreserveList;
438   SmallPtrSet<GlobalValue*, 8> AsmUsed;
439   std::vector<StringRef> Libcalls;
440   TargetLibraryInfoImpl TLII(Triple(TargetMach->getTargetTriple()));
441   TargetLibraryInfo TLI(TLII);
442
443   accumulateAndSortLibcalls(Libcalls, TLI, *mergedModule, *TargetMach);
444
445   for (Module::iterator f = mergedModule->begin(),
446          e = mergedModule->end(); f != e; ++f)
447     applyRestriction(*f, Libcalls, MustPreserveList, AsmUsed, Mangler);
448   for (Module::global_iterator v = mergedModule->global_begin(),
449          e = mergedModule->global_end(); v !=  e; ++v)
450     applyRestriction(*v, Libcalls, MustPreserveList, AsmUsed, Mangler);
451   for (Module::alias_iterator a = mergedModule->alias_begin(),
452          e = mergedModule->alias_end(); a != e; ++a)
453     applyRestriction(*a, Libcalls, MustPreserveList, AsmUsed, Mangler);
454
455   GlobalVariable *LLVMCompilerUsed =
456     mergedModule->getGlobalVariable("llvm.compiler.used");
457   findUsedValues(LLVMCompilerUsed, AsmUsed);
458   if (LLVMCompilerUsed)
459     LLVMCompilerUsed->eraseFromParent();
460
461   if (!AsmUsed.empty()) {
462     llvm::Type *i8PTy = llvm::Type::getInt8PtrTy(Context);
463     std::vector<Constant*> asmUsed2;
464     for (auto *GV : AsmUsed) {
465       Constant *c = ConstantExpr::getBitCast(GV, i8PTy);
466       asmUsed2.push_back(c);
467     }
468
469     llvm::ArrayType *ATy = llvm::ArrayType::get(i8PTy, asmUsed2.size());
470     LLVMCompilerUsed =
471       new llvm::GlobalVariable(*mergedModule, ATy, false,
472                                llvm::GlobalValue::AppendingLinkage,
473                                llvm::ConstantArray::get(ATy, asmUsed2),
474                                "llvm.compiler.used");
475
476     LLVMCompilerUsed->setSection("llvm.metadata");
477   }
478
479   passes.add(createInternalizePass(MustPreserveList));
480
481   // apply scope restrictions
482   passes.run(*mergedModule);
483
484   ScopeRestrictionsDone = true;
485 }
486
487 /// Optimize merged modules using various IPO passes
488 bool LTOCodeGenerator::optimize(bool DisableOpt,
489                                 bool DisableInline,
490                                 bool DisableGVNLoadPRE,
491                                 bool DisableVectorization,
492                                 std::string &errMsg) {
493   if (!this->determineTarget(errMsg))
494     return false;
495
496   Module *mergedModule = IRLinker.getModule();
497
498   // Mark which symbols can not be internalized
499   this->applyScopeRestrictions();
500
501   // Instantiate the pass manager to organize the passes.
502   PassManager passes;
503
504   // Add an appropriate DataLayout instance for this module...
505   mergedModule->setDataLayout(TargetMach->getDataLayout());
506
507   passes.add(new DataLayoutPass());
508   passes.add(
509       createTargetTransformInfoWrapperPass(TargetMach->getTargetIRAnalysis()));
510
511   Triple TargetTriple(TargetMach->getTargetTriple());
512   PassManagerBuilder PMB;
513   PMB.DisableGVNLoadPRE = DisableGVNLoadPRE;
514   PMB.LoopVectorize = !DisableVectorization;
515   PMB.SLPVectorize = !DisableVectorization;
516   if (!DisableInline)
517     PMB.Inliner = createFunctionInliningPass();
518   PMB.LibraryInfo = new TargetLibraryInfoImpl(TargetTriple);
519   if (DisableOpt)
520     PMB.OptLevel = 0;
521   PMB.VerifyInput = true;
522   PMB.VerifyOutput = true;
523
524   PMB.populateLTOPassManager(passes);
525
526   // Run our queue of passes all at once now, efficiently.
527   passes.run(*mergedModule);
528
529   return true;
530 }
531
532 bool LTOCodeGenerator::compileOptimized(raw_ostream &out, std::string &errMsg) {
533   if (!this->determineTarget(errMsg))
534     return false;
535
536   Module *mergedModule = IRLinker.getModule();
537
538   // Mark which symbols can not be internalized
539   this->applyScopeRestrictions();
540
541   PassManager codeGenPasses;
542
543   codeGenPasses.add(new DataLayoutPass());
544
545   formatted_raw_ostream Out(out);
546
547   // If the bitcode files contain ARC code and were compiled with optimization,
548   // the ObjCARCContractPass must be run, so do it unconditionally here.
549   codeGenPasses.add(createObjCARCContractPass());
550
551   if (TargetMach->addPassesToEmitFile(codeGenPasses, Out,
552                                       TargetMachine::CGFT_ObjectFile)) {
553     errMsg = "target file type not supported";
554     return false;
555   }
556
557   // Run the code generator, and write assembly file
558   codeGenPasses.run(*mergedModule);
559
560   return true;
561 }
562
563 /// setCodeGenDebugOptions - Set codegen debugging options to aid in debugging
564 /// LTO problems.
565 void LTOCodeGenerator::setCodeGenDebugOptions(const char *options) {
566   for (std::pair<StringRef, StringRef> o = getToken(options);
567        !o.first.empty(); o = getToken(o.second)) {
568     // ParseCommandLineOptions() expects argv[0] to be program name. Lazily add
569     // that.
570     if (CodegenOptions.empty())
571       CodegenOptions.push_back(strdup("libLLVMLTO"));
572     CodegenOptions.push_back(strdup(o.first.str().c_str()));
573   }
574 }
575
576 void LTOCodeGenerator::parseCodeGenDebugOptions() {
577   // if options were requested, set them
578   if (!CodegenOptions.empty())
579     cl::ParseCommandLineOptions(CodegenOptions.size(),
580                                 const_cast<char **>(&CodegenOptions[0]));
581 }
582
583 void LTOCodeGenerator::DiagnosticHandler(const DiagnosticInfo &DI,
584                                          void *Context) {
585   ((LTOCodeGenerator *)Context)->DiagnosticHandler2(DI);
586 }
587
588 void LTOCodeGenerator::DiagnosticHandler2(const DiagnosticInfo &DI) {
589   // Map the LLVM internal diagnostic severity to the LTO diagnostic severity.
590   lto_codegen_diagnostic_severity_t Severity;
591   switch (DI.getSeverity()) {
592   case DS_Error:
593     Severity = LTO_DS_ERROR;
594     break;
595   case DS_Warning:
596     Severity = LTO_DS_WARNING;
597     break;
598   case DS_Remark:
599     Severity = LTO_DS_REMARK;
600     break;
601   case DS_Note:
602     Severity = LTO_DS_NOTE;
603     break;
604   }
605   // Create the string that will be reported to the external diagnostic handler.
606   std::string MsgStorage;
607   raw_string_ostream Stream(MsgStorage);
608   DiagnosticPrinterRawOStream DP(Stream);
609   DI.print(DP);
610   Stream.flush();
611
612   // If this method has been called it means someone has set up an external
613   // diagnostic handler. Assert on that.
614   assert(DiagHandler && "Invalid diagnostic handler");
615   (*DiagHandler)(Severity, MsgStorage.c_str(), DiagContext);
616 }
617
618 void
619 LTOCodeGenerator::setDiagnosticHandler(lto_diagnostic_handler_t DiagHandler,
620                                        void *Ctxt) {
621   this->DiagHandler = DiagHandler;
622   this->DiagContext = Ctxt;
623   if (!DiagHandler)
624     return Context.setDiagnosticHandler(nullptr, nullptr);
625   // Register the LTOCodeGenerator stub in the LLVMContext to forward the
626   // diagnostic to the external DiagHandler.
627   Context.setDiagnosticHandler(LTOCodeGenerator::DiagnosticHandler, this,
628                                /* RespectFilters */ true);
629 }