LLVM  6.0.0svn
LTOBackend.cpp
Go to the documentation of this file.
1 //===-LTOBackend.cpp - LLVM Link Time Optimizer Backend -------------------===//
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 "backend" phase of LTO, i.e. it performs
11 // optimization and code generation on a loaded module. It is generally used
12 // internally by the LTO class but can also be used independently, for example
13 // to implement a standalone ThinLTO backend.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #include "llvm/LTO/LTOBackend.h"
25 #include "llvm/IR/PassManager.h"
26 #include "llvm/IR/Verifier.h"
27 #include "llvm/LTO/LTO.h"
31 #include "llvm/Support/Error.h"
36 #include "llvm/Transforms/IPO.h"
41 
42 using namespace llvm;
43 using namespace lto;
44 
46  errs() << "failed to open " << Path << ": " << Msg << '\n';
47  errs().flush();
48  exit(1);
49 }
50 
51 Error Config::addSaveTemps(std::string OutputFileName,
52  bool UseInputModulePath) {
54 
55  std::error_code EC;
56  ResolutionFile = llvm::make_unique<raw_fd_ostream>(
57  OutputFileName + "resolution.txt", EC, sys::fs::OpenFlags::F_Text);
58  if (EC)
59  return errorCodeToError(EC);
60 
61  auto setHook = [&](std::string PathSuffix, ModuleHookFn &Hook) {
62  // Keep track of the hook provided by the linker, which also needs to run.
63  ModuleHookFn LinkerHook = Hook;
64  Hook = [=](unsigned Task, const Module &M) {
65  // If the linker's hook returned false, we need to pass that result
66  // through.
67  if (LinkerHook && !LinkerHook(Task, M))
68  return false;
69 
70  std::string PathPrefix;
71  // If this is the combined module (not a ThinLTO backend compile) or the
72  // user hasn't requested using the input module's path, emit to a file
73  // named from the provided OutputFileName with the Task ID appended.
74  if (M.getModuleIdentifier() == "ld-temp.o" || !UseInputModulePath) {
75  PathPrefix = OutputFileName + utostr(Task);
76  } else
77  PathPrefix = M.getModuleIdentifier();
78  std::string Path = PathPrefix + "." + PathSuffix + ".bc";
79  std::error_code EC;
81  // Because -save-temps is a debugging feature, we report the error
82  // directly and exit.
83  if (EC)
84  reportOpenError(Path, EC.message());
85  WriteBitcodeToFile(&M, OS, /*ShouldPreserveUseListOrder=*/false);
86  return true;
87  };
88  };
89 
90  setHook("0.preopt", PreOptModuleHook);
91  setHook("1.promote", PostPromoteModuleHook);
92  setHook("2.internalize", PostInternalizeModuleHook);
93  setHook("3.import", PostImportModuleHook);
94  setHook("4.opt", PostOptModuleHook);
95  setHook("5.precodegen", PreCodeGenModuleHook);
96 
97  CombinedIndexHook = [=](const ModuleSummaryIndex &Index) {
98  std::string Path = OutputFileName + "index.bc";
99  std::error_code EC;
101  // Because -save-temps is a debugging feature, we report the error
102  // directly and exit.
103  if (EC)
104  reportOpenError(Path, EC.message());
105  WriteIndexToFile(Index, OS);
106  return true;
107  };
108 
109  return Error::success();
110 }
111 
112 namespace {
113 
114 std::unique_ptr<TargetMachine>
115 createTargetMachine(Config &Conf, const Target *TheTarget, Module &M) {
116  StringRef TheTriple = M.getTargetTriple();
118  Features.getDefaultSubtargetFeatures(Triple(TheTriple));
119  for (const std::string &A : Conf.MAttrs)
120  Features.AddFeature(A);
121 
123  if (Conf.RelocModel)
124  RelocModel = *Conf.RelocModel;
125  else
126  RelocModel =
128 
129  return std::unique_ptr<TargetMachine>(TheTarget->createTargetMachine(
130  TheTriple, Conf.CPU, Features.getString(), Conf.Options, RelocModel,
131  Conf.CodeModel, Conf.CGOptLevel));
132 }
133 
134 static void runNewPMPasses(Config &Conf, Module &Mod, TargetMachine *TM,
135  unsigned OptLevel, bool IsThinLTO) {
136  Optional<PGOOptions> PGOOpt;
137  if (!Conf.SampleProfile.empty())
138  PGOOpt = PGOOptions("", "", Conf.SampleProfile, false, true);
139 
140  PassBuilder PB(TM, PGOOpt);
141  AAManager AA;
142 
143  // Parse a custom AA pipeline if asked to.
144  if (!PB.parseAAPipeline(AA, "default"))
145  report_fatal_error("Error parsing default AA pipeline");
146 
151 
152  // Register the AA manager first so that our version is the one used.
153  FAM.registerPass([&] { return std::move(AA); });
154 
155  // Register all the basic analyses with the managers.
156  PB.registerModuleAnalyses(MAM);
157  PB.registerCGSCCAnalyses(CGAM);
158  PB.registerFunctionAnalyses(FAM);
159  PB.registerLoopAnalyses(LAM);
160  PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
161 
163  // FIXME (davide): verify the input.
164 
166 
167  switch (OptLevel) {
168  default:
169  llvm_unreachable("Invalid optimization level");
170  case 0:
171  OL = PassBuilder::O0;
172  break;
173  case 1:
174  OL = PassBuilder::O1;
175  break;
176  case 2:
177  OL = PassBuilder::O2;
178  break;
179  case 3:
180  OL = PassBuilder::O3;
181  break;
182  }
183 
184  if (IsThinLTO)
186  else
187  MPM = PB.buildLTODefaultPipeline(OL, Conf.DebugPassManager);
188  MPM.run(Mod, MAM);
189 
190  // FIXME (davide): verify the output.
191 }
192 
193 static void runNewPMCustomPasses(Module &Mod, TargetMachine *TM,
194  std::string PipelineDesc,
195  std::string AAPipelineDesc,
196  bool DisableVerify) {
197  PassBuilder PB(TM);
198  AAManager AA;
199 
200  // Parse a custom AA pipeline if asked to.
201  if (!AAPipelineDesc.empty())
202  if (!PB.parseAAPipeline(AA, AAPipelineDesc))
203  report_fatal_error("unable to parse AA pipeline description: " +
204  AAPipelineDesc);
205 
210 
211  // Register the AA manager first so that our version is the one used.
212  FAM.registerPass([&] { return std::move(AA); });
213 
214  // Register all the basic analyses with the managers.
215  PB.registerModuleAnalyses(MAM);
216  PB.registerCGSCCAnalyses(CGAM);
217  PB.registerFunctionAnalyses(FAM);
218  PB.registerLoopAnalyses(LAM);
219  PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
220 
221  ModulePassManager MPM;
222 
223  // Always verify the input.
224  MPM.addPass(VerifierPass());
225 
226  // Now, add all the passes we've been requested to.
227  if (!PB.parsePassPipeline(MPM, PipelineDesc))
228  report_fatal_error("unable to parse pass pipeline description: " +
229  PipelineDesc);
230 
231  if (!DisableVerify)
232  MPM.addPass(VerifierPass());
233  MPM.run(Mod, MAM);
234 }
235 
236 static void runOldPMPasses(Config &Conf, Module &Mod, TargetMachine *TM,
237  bool IsThinLTO, ModuleSummaryIndex *ExportSummary,
238  const ModuleSummaryIndex *ImportSummary) {
239  legacy::PassManager passes;
241 
242  PassManagerBuilder PMB;
245  PMB.ExportSummary = ExportSummary;
246  PMB.ImportSummary = ImportSummary;
247  // Unconditionally verify input since it is not verified before this
248  // point and has unknown origin.
249  PMB.VerifyInput = true;
250  PMB.VerifyOutput = !Conf.DisableVerify;
251  PMB.LoopVectorize = true;
252  PMB.SLPVectorize = true;
253  PMB.OptLevel = Conf.OptLevel;
254  PMB.PGOSampleUse = Conf.SampleProfile;
255  if (IsThinLTO)
256  PMB.populateThinLTOPassManager(passes);
257  else
258  PMB.populateLTOPassManager(passes);
259  passes.run(Mod);
260 }
261 
262 bool opt(Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
263  bool IsThinLTO, ModuleSummaryIndex *ExportSummary,
264  const ModuleSummaryIndex *ImportSummary) {
265  // FIXME: Plumb the combined index into the new pass manager.
266  if (!Conf.OptPipeline.empty())
267  runNewPMCustomPasses(Mod, TM, Conf.OptPipeline, Conf.AAPipeline,
268  Conf.DisableVerify);
269  else if (Conf.UseNewPM)
270  runNewPMPasses(Conf, Mod, TM, Conf.OptLevel, IsThinLTO);
271  else
272  runOldPMPasses(Conf, Mod, TM, IsThinLTO, ExportSummary, ImportSummary);
273  return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
274 }
275 
276 void codegen(Config &Conf, TargetMachine *TM, AddStreamFn AddStream,
277  unsigned Task, Module &Mod) {
278  if (Conf.PreCodeGenModuleHook && !Conf.PreCodeGenModuleHook(Task, Mod))
279  return;
280 
281  auto Stream = AddStream(Task);
282  legacy::PassManager CodeGenPasses;
283  if (TM->addPassesToEmitFile(CodeGenPasses, *Stream->OS, Conf.CGFileType))
284  report_fatal_error("Failed to setup codegen");
285  CodeGenPasses.run(Mod);
286 }
287 
288 void splitCodeGen(Config &C, TargetMachine *TM, AddStreamFn AddStream,
289  unsigned ParallelCodeGenParallelismLevel,
290  std::unique_ptr<Module> Mod) {
291  ThreadPool CodegenThreadPool(ParallelCodeGenParallelismLevel);
292  unsigned ThreadCount = 0;
293  const Target *T = &TM->getTarget();
294 
295  SplitModule(
296  std::move(Mod), ParallelCodeGenParallelismLevel,
297  [&](std::unique_ptr<Module> MPart) {
298  // We want to clone the module in a new context to multi-thread the
299  // codegen. We do it by serializing partition modules to bitcode
300  // (while still on the main thread, in order to avoid data races) and
301  // spinning up new threads which deserialize the partitions into
302  // separate contexts.
303  // FIXME: Provide a more direct way to do this in LLVM.
304  SmallString<0> BC;
305  raw_svector_ostream BCOS(BC);
306  WriteBitcodeToFile(MPart.get(), BCOS);
307 
308  // Enqueue the task
309  CodegenThreadPool.async(
310  [&](const SmallString<0> &BC, unsigned ThreadId) {
311  LTOLLVMContext Ctx(C);
313  MemoryBufferRef(StringRef(BC.data(), BC.size()), "ld-temp.o"),
314  Ctx);
315  if (!MOrErr)
316  report_fatal_error("Failed to read bitcode");
317  std::unique_ptr<Module> MPartInCtx = std::move(MOrErr.get());
318 
319  std::unique_ptr<TargetMachine> TM =
320  createTargetMachine(C, T, *MPartInCtx);
321 
322  codegen(C, TM.get(), AddStream, ThreadId, *MPartInCtx);
323  },
324  // Pass BC using std::move to ensure that it get moved rather than
325  // copied into the thread's context.
326  std::move(BC), ThreadCount++);
327  },
328  false);
329 
330  // Because the inner lambda (which runs in a worker thread) captures our local
331  // variables, we need to wait for the worker threads to terminate before we
332  // can leave the function scope.
333  CodegenThreadPool.wait();
334 }
335 
336 Expected<const Target *> initAndLookupTarget(Config &C, Module &Mod) {
337  if (!C.OverrideTriple.empty())
339  else if (Mod.getTargetTriple().empty())
341 
342  std::string Msg;
344  if (!T)
345  return make_error<StringError>(Msg, inconvertibleErrorCode());
346  return T;
347 }
348 
349 }
350 
351 static void
352 finalizeOptimizationRemarks(std::unique_ptr<ToolOutputFile> DiagOutputFile) {
353  // Make sure we flush the diagnostic remarks file in case the linker doesn't
354  // call the global destructors before exiting.
355  if (!DiagOutputFile)
356  return;
357  DiagOutputFile->keep();
358  DiagOutputFile->os().flush();
359 }
360 
362  unsigned ParallelCodeGenParallelismLevel,
363  std::unique_ptr<Module> Mod,
364  ModuleSummaryIndex &CombinedIndex) {
365  Expected<const Target *> TOrErr = initAndLookupTarget(C, *Mod);
366  if (!TOrErr)
367  return TOrErr.takeError();
368 
369  std::unique_ptr<TargetMachine> TM = createTargetMachine(C, *TOrErr, *Mod);
370 
371  // Setup optimization remarks.
372  auto DiagFileOrErr = lto::setupOptimizationRemarks(
373  Mod->getContext(), C.RemarksFilename, C.RemarksWithHotness);
374  if (!DiagFileOrErr)
375  return DiagFileOrErr.takeError();
376  auto DiagnosticOutputFile = std::move(*DiagFileOrErr);
377 
378  if (!C.CodeGenOnly) {
379  if (!opt(C, TM.get(), 0, *Mod, /*IsThinLTO=*/false,
380  /*ExportSummary=*/&CombinedIndex, /*ImportSummary=*/nullptr)) {
381  finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
382  return Error::success();
383  }
384  }
385 
386  if (ParallelCodeGenParallelismLevel == 1) {
387  codegen(C, TM.get(), AddStream, 0, *Mod);
388  } else {
389  splitCodeGen(C, TM.get(), AddStream, ParallelCodeGenParallelismLevel,
390  std::move(Mod));
391  }
392  finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
393  return Error::success();
394 }
395 
396 Error lto::thinBackend(Config &Conf, unsigned Task, AddStreamFn AddStream,
397  Module &Mod, const ModuleSummaryIndex &CombinedIndex,
398  const FunctionImporter::ImportMapTy &ImportList,
399  const GVSummaryMapTy &DefinedGlobals,
401  Expected<const Target *> TOrErr = initAndLookupTarget(Conf, Mod);
402  if (!TOrErr)
403  return TOrErr.takeError();
404 
405  std::unique_ptr<TargetMachine> TM = createTargetMachine(Conf, *TOrErr, Mod);
406 
407  if (Conf.CodeGenOnly) {
408  codegen(Conf, TM.get(), AddStream, Task, Mod);
409  return Error::success();
410  }
411 
412  if (Conf.PreOptModuleHook && !Conf.PreOptModuleHook(Task, Mod))
413  return Error::success();
414 
415  renameModuleForThinLTO(Mod, CombinedIndex);
416 
417  thinLTOResolveWeakForLinkerModule(Mod, DefinedGlobals);
418 
419  if (Conf.PostPromoteModuleHook && !Conf.PostPromoteModuleHook(Task, Mod))
420  return Error::success();
421 
422  if (!DefinedGlobals.empty())
423  thinLTOInternalizeModule(Mod, DefinedGlobals);
424 
425  if (Conf.PostInternalizeModuleHook &&
426  !Conf.PostInternalizeModuleHook(Task, Mod))
427  return Error::success();
428 
429  auto ModuleLoader = [&](StringRef Identifier) {
431  "ODR Type uniquing should be enabled on the context");
432  auto I = ModuleMap.find(Identifier);
433  assert(I != ModuleMap.end());
434  return I->second.getLazyModule(Mod.getContext(),
435  /*ShouldLazyLoadMetadata=*/true,
436  /*IsImporting*/ true);
437  };
438 
439  FunctionImporter Importer(CombinedIndex, ModuleLoader);
440  if (Error Err = Importer.importFunctions(Mod, ImportList).takeError())
441  return Err;
442 
443  if (Conf.PostImportModuleHook && !Conf.PostImportModuleHook(Task, Mod))
444  return Error::success();
445 
446  if (!opt(Conf, TM.get(), Task, Mod, /*IsThinLTO=*/true,
447  /*ExportSummary=*/nullptr, /*ImportSummary=*/&CombinedIndex))
448  return Error::success();
449 
450  codegen(Conf, TM.get(), AddStream, Task, Mod);
451  return Error::success();
452 }
static void codegen(Module *M, llvm::raw_pwrite_stream &OS, function_ref< std::unique_ptr< TargetMachine >()> TMFactory, TargetMachine::CodeGenFileType FileType)
Definition: ParallelCG.cpp:29
uint64_t CallInst * C
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition: Module.h:233
Interfaces for registering analysis passes, producing common pass manager configurations, and parsing of pass pipelines.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Expected< std::unique_ptr< ToolOutputFile > > setupOptimizationRemarks(LLVMContext &Context, StringRef LTORemarksFilename, bool LTOPassRemarksWithHotness, int Count=-1)
Setup optimization remarks.
Definition: LTO.cpp:1184
std::string CPU
Definition: Config.h:39
std::string AAPipeline
Definition: Config.h:63
CodeGenOpt::Level CGOptLevel
Definition: Config.h:44
PassManagerBuilder - This class is used to set up a standard optimization sequence for languages like...
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:115
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
void getDefaultSubtargetFeatures(const Triple &Triple)
Adds the default features for the specified target triple.
This header provides classes for managing a pipeline of passes over loops in LLVM IR...
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:136
TargetMachine * createTargetMachine(StringRef TT, StringRef CPU, StringRef Features, const TargetOptions &Options, Optional< Reloc::Model > RM, Optional< CodeModel::Model > CM=None, CodeGenOpt::Level OL=CodeGenOpt::Default, bool JIT=false) const
createTargetMachine - Create a target specific machine implementation for the specified Triple...
bool ShouldDiscardValueNames
Definition: Config.h:85
std::string OverrideTriple
Setting this field will replace target triples in input files with this triple.
Definition: Config.h:67
void populateThinLTOPassManager(legacy::PassManagerBase &PM)
bool CodeGenOnly
Disable entirely the optimizer, including importing for ThinLTO.
Definition: Config.h:53
void registerModuleAnalyses(ModuleAnalysisManager &MAM)
Registers all available module analysis passes.
void SplitModule(std::unique_ptr< Module > M, unsigned N, function_ref< void(std::unique_ptr< Module > MPart)> ModuleCallback, bool PreserveLocals=false)
Splits the module M into N linkable partitions.
std::unique_ptr< raw_ostream > ResolutionFile
If this field is set, LTO will write input file paths and symbol resolutions here in llvm-lto2 comman...
Definition: Config.h:92
ImmutablePass * createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA)
Create an analysis pass wrapper around a TTI object.
ModuleSummaryIndex * ExportSummary
The module summary index to use for exporting information from the regular LTO phase, for example for the CFI and devirtualization type tests.
std::string getString() const
Returns features as a string.
const ModuleSummaryIndex * ImportSummary
The module summary index to use for importing information to the thin LTO backends, for example for the CFI and devirtualization type tests.
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:489
OptimizationLevel
LLVM-provided high-level optimization levels.
Definition: PassBuilder.h:90
Implementation of the target library information.
This class implements a map that also provides access to all stored values in a deterministic order...
Definition: MapVector.h:38
bool DebugPassManager
Whether to emit the pass manager debuggging informations.
Definition: Config.h:83
std::string PGOSampleUse
Path of the sample Profile data file.
Error takeError()
Take ownership of the stored error.
Definition: Error.h:537
static const Target * lookupTarget(const std::string &Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
Definition: PassManager.h:444
std::shared_future< void > async(Function &&F, Args &&... ArgList)
Asynchronous submission of a task to the pool.
Definition: ThreadPool.h:54
ModuleHookFn PreCodeGenModuleHook
This module hook is called before code generation.
Definition: Config.h:140
Pass * Inliner
Inliner - Specifies the inliner to use.
CombinedIndexHookFn CombinedIndexHook
Definition: Config.h:153
static void finalizeOptimizationRemarks(std::unique_ptr< ToolOutputFile > DiagOutputFile)
Definition: LTOBackend.cpp:352
std::function< std::unique_ptr< NativeObjectStream >unsigned Task)> AddStreamFn
This type defines the callback to add a native object that is generated on the fly.
Definition: LTO.h:175
void add(Pass *P) override
Add a pass to the queue of passes to run.
bool RemarksWithHotness
Whether to emit optimization remarks with hotness informations.
Definition: Config.h:80
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
std::vector< std::string > MAttrs
Definition: Config.h:41
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:237
bool parseAAPipeline(AAManager &AA, StringRef PipelineText)
Parse a textual alias analysis pipeline into the provided AA manager.
void populateLTOPassManager(legacy::PassManagerBase &PM)
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
Definition: PassManager.h:739
This class provides access to building LLVM&#39;s passes.
Definition: PassBuilder.h:56
ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level, bool DebugLogging=false)
Build an LTO default optimization pipeline to a pass manager.
std::function< bool(unsigned Task, const Module &)> ModuleHookFn
The following callbacks deal with tasks, which normally represent the entire optimization and code ge...
Definition: Config.h:118
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
void AddFeature(StringRef String, bool Enable=true)
Adds Features.
void registerLoopAnalyses(LoopAnalysisManager &LAM)
Registers all available loop analysis passes.
bool DisableVerify
Definition: Config.h:47
#define T
unsigned OptLevel
The Optimization Level - Specify the basic optimization level.
void crossRegisterProxies(LoopAnalysisManager &LAM, FunctionAnalysisManager &FAM, CGSCCAnalysisManager &CGAM, ModuleAnalysisManager &MAM)
Cross register the analysis managers through their proxies.
std::string SampleProfile
Sample PGO profile path.
Definition: Config.h:74
TargetOptions Options
Definition: Config.h:40
Optional< CodeModel::Model > CodeModel
Definition: Config.h:43
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
A ThreadPool for asynchronous parallel execution on a defined number of threads.
Definition: ThreadPool.h:36
Class to hold module path string table and global value map, and encapsulate methods for operating on...
iterator find(const KeyT &Key)
Definition: MapVector.h:144
PassManager manages ModulePassManagers.
void WriteBitcodeToFile(const Module *M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the specified raw output stream.
ModuleHookFn PreOptModuleHook
This module hook is called after linking (regular LTO) or loading (ThinLTO) the module, before modifying it.
Definition: Config.h:122
bool renameModuleForThinLTO(Module &M, const ModuleSummaryIndex &Index, SetVector< GlobalValue *> *GlobalsToImport=nullptr)
Perform in-place global value handling on the given Module for exported local functions renamed and p...
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:78
TargetLibraryInfoImpl * LibraryInfo
LibraryInfo - Specifies information about the runtime library for the optimizer.
Disable as many optimizations as possible.
Definition: PassBuilder.h:94
A manager for alias analyses.
virtual TargetIRAnalysis getTargetIRAnalysis()
Get a TargetIRAnalysis appropriate for the target.
bool UseNewPM
Use the new pass manager.
Definition: Config.h:50
unsigned OptLevel
Definition: Config.h:46
bool isODRUniquingDebugTypes() const
Whether there is a string map for uniquing debug info identifiers across the context.
void registerFunctionAnalyses(FunctionAnalysisManager &FAM)
Registers all available function analysis passes.
LTO configuration.
Definition: Config.h:36
std::string DefaultTriple
Setting this field will replace unspecified target triples in input files with this triple...
Definition: Config.h:71
Optimize for fast execution as much as possible.
Definition: PassBuilder.h:148
const Triple & getTargetTriple() const
const Target & getTarget() const
ModuleHookFn PostInternalizeModuleHook
This hook is called after internalizing the module.
Definition: Config.h:129
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
Create a verifier pass.
Definition: Verifier.h:135
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
TargetMachine::CodeGenFileType CGFileType
Definition: Config.h:45
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
std::string RemarksFilename
Optimization remarks file path.
Definition: Config.h:77
static ErrorSuccess success()
Create a success value.
Definition: Error.h:313
Optimize for fast execution as much as possible without triggering significant incremental compile ti...
Definition: PassBuilder.h:132
bool parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText, bool VerifyEachPass=true, bool DebugLogging=false)
Parse a textual pass pipeline description into a ModulePassManager.
#define LLVM_ATTRIBUTE_NORETURN
Definition: Compiler.h:206
Optional< Reloc::Model > RelocModel
Definition: Config.h:42
reference get()
Returns a reference to the stored T value.
Definition: Error.h:517
std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:174
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:224
Target - Wrapper for Target specific information.
Manages the enabling and disabling of subtarget specific features.
std::string OptPipeline
If this field is set, the set of passes run in the middle-end optimizer will be the one specified by ...
Definition: Config.h:58
void WriteIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out, const std::map< std::string, GVSummaryMapTy > *ModuleToSummariesForIndex=nullptr)
Write the specified module summary index to the given raw output stream, where it will be written in ...
virtual bool addPassesToEmitFile(PassManagerBase &, raw_pwrite_stream &, CodeGenFileType, bool=true, MachineModuleInfo *MMI=nullptr)
Add passes to the specified pass manager to get the specified file emitted.
The file should be opened in text mode on platforms that make this distinction.
Definition: FileSystem.h:769
Expected< std::unique_ptr< Module > > parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context)
Read the specified bitcode file, returning the module.
Expected< bool > importFunctions(Module &M, const ImportMapTy &ImportList)
Import functions in Module M based on the supplied import list.
Error thinBackend(Config &C, unsigned Task, AddStreamFn AddStream, Module &M, const ModuleSummaryIndex &CombinedIndex, const FunctionImporter::ImportMapTy &ImportList, const GVSummaryMapTy &DefinedGlobals, MapVector< StringRef, BitcodeModule > &ModuleMap)
Runs a ThinLTO backend.
Definition: LTOBackend.cpp:396
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:361
ModulePassManager buildThinLTODefaultPipeline(OptimizationLevel Level, bool DebugLogging=false)
Build an ThinLTO default optimization pipeline to a pass manager.
pointer data()
Return a pointer to the vector&#39;s buffer, even if empty().
Definition: SmallVector.h:143
Manages a sequence of passes over a particular unit of IR.
Definition: PassManager.h:420
A struct capturing PGO tunables.
Definition: PassBuilder.h:31
#define I(x, y, z)
Definition: MD5.cpp:58
void thinLTOInternalizeModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals)
Internalize TheModule based on the information recorded in the summaries during global summary-based ...
void setTargetTriple(StringRef T)
Set the target triple.
Definition: Module.h:269
void thinLTOResolveWeakForLinkerModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals)
Resolve WeakForLinker values in TheModule based on the information recorded in the summaries during g...
LLVM_NODISCARD bool empty() const
Definition: DenseMap.h:93
This header provides classes for managing passes over SCCs of the call graph.
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)
Registers all available CGSCC analysis passes.
ModuleHookFn PostImportModuleHook
This hook is called after importing from other modules (ThinLTO-specific).
Definition: Config.h:132
Error backend(Config &C, AddStreamFn AddStream, unsigned ParallelCodeGenParallelismLevel, std::unique_ptr< Module > M, ModuleSummaryIndex &CombinedIndex)
Runs a regular LTO backend.
Definition: LTOBackend.cpp:361
iterator end()
Definition: MapVector.h:68
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Optimize quickly without destroying debuggability.
Definition: PassBuilder.h:114
Pass * createFunctionInliningPass()
createFunctionInliningPass - Return a new pass object that uses a heuristic to inline direct function...
The function importer is automatically importing function from other modules based on the provided su...
std::unique_ptr< Module > splitCodeGen(std::unique_ptr< Module > M, ArrayRef< raw_pwrite_stream *> OSs, ArrayRef< llvm::raw_pwrite_stream *> BCOSs, const std::function< std::unique_ptr< TargetMachine >()> &TMFactory, TargetMachine::CodeGenFileType FT=TargetMachine::CGFT_ObjectFile, bool PreserveLocals=false)
Split M into OSs.size() partitions, and generate code for each.
Definition: ParallelCG.cpp:39
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
const FeatureBitset Features
ModuleHookFn PostOptModuleHook
This module hook is called after optimization is complete.
Definition: Config.h:135
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:57
PICLevel::Level getPICLevel() const
Returns the PIC level (small or large model)
Definition: Module.cpp:473
Error addSaveTemps(std::string OutputFileName, bool UseInputModulePath=false)
This is a convenience function that configures this Config object to write temporary files named afte...
Definition: LTOBackend.cpp:51
A derived class of LLVMContext that initializes itself according to a given Config object...
Definition: Config.h:188
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
hexagon cext opt
A container for analyses that lazily runs them and caches their results.
void addPass(PassT Pass)
Definition: PassManager.h:485
static LLVM_ATTRIBUTE_NORETURN void reportOpenError(StringRef Path, Twine Msg)
Definition: LTOBackend.cpp:45
This pass exposes codegen information to IR-level passes.
This header defines various interfaces for pass management in LLVM.
ModuleHookFn PostPromoteModuleHook
This hook is called after promoting any internal functions (ThinLTO-specific).
Definition: Config.h:126
void wait()
Blocking wait for all the threads to complete and the queue to be empty.
Definition: ThreadPool.cpp:72
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:73