LLVM  5.0.0
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(Module &Mod, TargetMachine *TM, unsigned OptLevel,
135  bool IsThinLTO) {
136  PassBuilder PB(TM);
137  AAManager AA;
138 
139  // Parse a custom AA pipeline if asked to.
140  assert(PB.parseAAPipeline(AA, "default"));
141 
146 
147  // Register the AA manager first so that our version is the one used.
148  FAM.registerPass([&] { return std::move(AA); });
149 
150  // Register all the basic analyses with the managers.
151  PB.registerModuleAnalyses(MAM);
152  PB.registerCGSCCAnalyses(CGAM);
153  PB.registerFunctionAnalyses(FAM);
154  PB.registerLoopAnalyses(LAM);
155  PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
156 
157  ModulePassManager MPM;
158  // FIXME (davide): verify the input.
159 
161 
162  switch (OptLevel) {
163  default:
164  llvm_unreachable("Invalid optimization level");
165  case 0:
166  OL = PassBuilder::O0;
167  break;
168  case 1:
169  OL = PassBuilder::O1;
170  break;
171  case 2:
172  OL = PassBuilder::O2;
173  break;
174  case 3:
175  OL = PassBuilder::O3;
176  break;
177  }
178 
179  if (IsThinLTO)
180  MPM = PB.buildThinLTODefaultPipeline(OL, false /* DebugLogging */);
181  else
182  MPM = PB.buildLTODefaultPipeline(OL, false /* DebugLogging */);
183  MPM.run(Mod, MAM);
184 
185  // FIXME (davide): verify the output.
186 }
187 
188 static void runNewPMCustomPasses(Module &Mod, TargetMachine *TM,
189  std::string PipelineDesc,
190  std::string AAPipelineDesc,
191  bool DisableVerify) {
192  PassBuilder PB(TM);
193  AAManager AA;
194 
195  // Parse a custom AA pipeline if asked to.
196  if (!AAPipelineDesc.empty())
197  if (!PB.parseAAPipeline(AA, AAPipelineDesc))
198  report_fatal_error("unable to parse AA pipeline description: " +
199  AAPipelineDesc);
200 
205 
206  // Register the AA manager first so that our version is the one used.
207  FAM.registerPass([&] { return std::move(AA); });
208 
209  // Register all the basic analyses with the managers.
210  PB.registerModuleAnalyses(MAM);
211  PB.registerCGSCCAnalyses(CGAM);
212  PB.registerFunctionAnalyses(FAM);
213  PB.registerLoopAnalyses(LAM);
214  PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
215 
216  ModulePassManager MPM;
217 
218  // Always verify the input.
219  MPM.addPass(VerifierPass());
220 
221  // Now, add all the passes we've been requested to.
222  if (!PB.parsePassPipeline(MPM, PipelineDesc))
223  report_fatal_error("unable to parse pass pipeline description: " +
224  PipelineDesc);
225 
226  if (!DisableVerify)
227  MPM.addPass(VerifierPass());
228  MPM.run(Mod, MAM);
229 }
230 
231 static void runOldPMPasses(Config &Conf, Module &Mod, TargetMachine *TM,
232  bool IsThinLTO, ModuleSummaryIndex *ExportSummary,
233  const ModuleSummaryIndex *ImportSummary) {
234  legacy::PassManager passes;
236 
237  PassManagerBuilder PMB;
240  PMB.ExportSummary = ExportSummary;
241  PMB.ImportSummary = ImportSummary;
242  // Unconditionally verify input since it is not verified before this
243  // point and has unknown origin.
244  PMB.VerifyInput = true;
245  PMB.VerifyOutput = !Conf.DisableVerify;
246  PMB.LoopVectorize = true;
247  PMB.SLPVectorize = true;
248  PMB.OptLevel = Conf.OptLevel;
249  PMB.PGOSampleUse = Conf.SampleProfile;
250  if (IsThinLTO)
251  PMB.populateThinLTOPassManager(passes);
252  else
253  PMB.populateLTOPassManager(passes);
254  passes.run(Mod);
255 }
256 
257 bool opt(Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
258  bool IsThinLTO, ModuleSummaryIndex *ExportSummary,
259  const ModuleSummaryIndex *ImportSummary) {
260  // FIXME: Plumb the combined index into the new pass manager.
261  if (!Conf.OptPipeline.empty())
262  runNewPMCustomPasses(Mod, TM, Conf.OptPipeline, Conf.AAPipeline,
263  Conf.DisableVerify);
264  else if (Conf.UseNewPM)
265  runNewPMPasses(Mod, TM, Conf.OptLevel, IsThinLTO);
266  else
267  runOldPMPasses(Conf, Mod, TM, IsThinLTO, ExportSummary, ImportSummary);
268  return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
269 }
270 
271 void codegen(Config &Conf, TargetMachine *TM, AddStreamFn AddStream,
272  unsigned Task, Module &Mod) {
273  if (Conf.PreCodeGenModuleHook && !Conf.PreCodeGenModuleHook(Task, Mod))
274  return;
275 
276  auto Stream = AddStream(Task);
277  legacy::PassManager CodeGenPasses;
278  if (TM->addPassesToEmitFile(CodeGenPasses, *Stream->OS, Conf.CGFileType))
279  report_fatal_error("Failed to setup codegen");
280  CodeGenPasses.run(Mod);
281 }
282 
283 void splitCodeGen(Config &C, TargetMachine *TM, AddStreamFn AddStream,
284  unsigned ParallelCodeGenParallelismLevel,
285  std::unique_ptr<Module> Mod) {
286  ThreadPool CodegenThreadPool(ParallelCodeGenParallelismLevel);
287  unsigned ThreadCount = 0;
288  const Target *T = &TM->getTarget();
289 
290  SplitModule(
291  std::move(Mod), ParallelCodeGenParallelismLevel,
292  [&](std::unique_ptr<Module> MPart) {
293  // We want to clone the module in a new context to multi-thread the
294  // codegen. We do it by serializing partition modules to bitcode
295  // (while still on the main thread, in order to avoid data races) and
296  // spinning up new threads which deserialize the partitions into
297  // separate contexts.
298  // FIXME: Provide a more direct way to do this in LLVM.
299  SmallString<0> BC;
300  raw_svector_ostream BCOS(BC);
301  WriteBitcodeToFile(MPart.get(), BCOS);
302 
303  // Enqueue the task
304  CodegenThreadPool.async(
305  [&](const SmallString<0> &BC, unsigned ThreadId) {
306  LTOLLVMContext Ctx(C);
308  MemoryBufferRef(StringRef(BC.data(), BC.size()), "ld-temp.o"),
309  Ctx);
310  if (!MOrErr)
311  report_fatal_error("Failed to read bitcode");
312  std::unique_ptr<Module> MPartInCtx = std::move(MOrErr.get());
313 
314  std::unique_ptr<TargetMachine> TM =
315  createTargetMachine(C, T, *MPartInCtx);
316 
317  codegen(C, TM.get(), AddStream, ThreadId, *MPartInCtx);
318  },
319  // Pass BC using std::move to ensure that it get moved rather than
320  // copied into the thread's context.
321  std::move(BC), ThreadCount++);
322  },
323  false);
324 
325  // Because the inner lambda (which runs in a worker thread) captures our local
326  // variables, we need to wait for the worker threads to terminate before we
327  // can leave the function scope.
328  CodegenThreadPool.wait();
329 }
330 
331 Expected<const Target *> initAndLookupTarget(Config &C, Module &Mod) {
332  if (!C.OverrideTriple.empty())
334  else if (Mod.getTargetTriple().empty())
336 
337  std::string Msg;
338  const Target *T = TargetRegistry::lookupTarget(Mod.getTargetTriple(), Msg);
339  if (!T)
340  return make_error<StringError>(Msg, inconvertibleErrorCode());
341  return T;
342 }
343 
344 }
345 
346 static void
347 finalizeOptimizationRemarks(std::unique_ptr<tool_output_file> DiagOutputFile) {
348  // Make sure we flush the diagnostic remarks file in case the linker doesn't
349  // call the global destructors before exiting.
350  if (!DiagOutputFile)
351  return;
352  DiagOutputFile->keep();
353  DiagOutputFile->os().flush();
354 }
355 
357  unsigned ParallelCodeGenParallelismLevel,
358  std::unique_ptr<Module> Mod,
359  ModuleSummaryIndex &CombinedIndex) {
360  Expected<const Target *> TOrErr = initAndLookupTarget(C, *Mod);
361  if (!TOrErr)
362  return TOrErr.takeError();
363 
364  std::unique_ptr<TargetMachine> TM = createTargetMachine(C, *TOrErr, *Mod);
365 
366  // Setup optimization remarks.
367  auto DiagFileOrErr = lto::setupOptimizationRemarks(
368  Mod->getContext(), C.RemarksFilename, C.RemarksWithHotness);
369  if (!DiagFileOrErr)
370  return DiagFileOrErr.takeError();
371  auto DiagnosticOutputFile = std::move(*DiagFileOrErr);
372 
373  if (!C.CodeGenOnly) {
374  if (!opt(C, TM.get(), 0, *Mod, /*IsThinLTO=*/false,
375  /*ExportSummary=*/&CombinedIndex, /*ImportSummary=*/nullptr)) {
376  finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
377  return Error::success();
378  }
379  }
380 
381  if (ParallelCodeGenParallelismLevel == 1) {
382  codegen(C, TM.get(), AddStream, 0, *Mod);
383  } else {
384  splitCodeGen(C, TM.get(), AddStream, ParallelCodeGenParallelismLevel,
385  std::move(Mod));
386  }
387  finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
388  return Error::success();
389 }
390 
391 Error lto::thinBackend(Config &Conf, unsigned Task, AddStreamFn AddStream,
392  Module &Mod, const ModuleSummaryIndex &CombinedIndex,
393  const FunctionImporter::ImportMapTy &ImportList,
394  const GVSummaryMapTy &DefinedGlobals,
396  Expected<const Target *> TOrErr = initAndLookupTarget(Conf, Mod);
397  if (!TOrErr)
398  return TOrErr.takeError();
399 
400  std::unique_ptr<TargetMachine> TM = createTargetMachine(Conf, *TOrErr, Mod);
401 
402  if (Conf.CodeGenOnly) {
403  codegen(Conf, TM.get(), AddStream, Task, Mod);
404  return Error::success();
405  }
406 
407  if (Conf.PreOptModuleHook && !Conf.PreOptModuleHook(Task, Mod))
408  return Error::success();
409 
410  renameModuleForThinLTO(Mod, CombinedIndex);
411 
412  thinLTOResolveWeakForLinkerModule(Mod, DefinedGlobals);
413 
414  if (Conf.PostPromoteModuleHook && !Conf.PostPromoteModuleHook(Task, Mod))
415  return Error::success();
416 
417  if (!DefinedGlobals.empty())
418  thinLTOInternalizeModule(Mod, DefinedGlobals);
419 
420  if (Conf.PostInternalizeModuleHook &&
421  !Conf.PostInternalizeModuleHook(Task, Mod))
422  return Error::success();
423 
424  auto ModuleLoader = [&](StringRef Identifier) {
426  "ODR Type uniquing should be enabled on the context");
427  auto I = ModuleMap.find(Identifier);
428  assert(I != ModuleMap.end());
429  return I->second.getLazyModule(Mod.getContext(),
430  /*ShouldLazyLoadMetadata=*/true,
431  /*IsImporting*/ true);
432  };
433 
434  FunctionImporter Importer(CombinedIndex, ModuleLoader);
435  if (Error Err = Importer.importFunctions(Mod, ImportList).takeError())
436  return Err;
437 
438  if (Conf.PostImportModuleHook && !Conf.PostImportModuleHook(Task, Mod))
439  return Error::success();
440 
441  if (!opt(Conf, TM.get(), Task, Mod, /*IsThinLTO=*/true,
442  /*ExportSummary=*/nullptr, /*ImportSummary=*/&CombinedIndex))
443  return Error::success();
444 
445  codegen(Conf, TM.get(), AddStream, Task, Mod);
446  return Error::success();
447 }
static void codegen(Module *M, llvm::raw_pwrite_stream &OS, function_ref< std::unique_ptr< TargetMachine >()> TMFactory, TargetMachine::CodeGenFileType FileType)
Definition: ParallelCG.cpp:29
Interfaces for registering analysis passes, producing common pass manager configurations, and parsing of pass pipelines.
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
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
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:103
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
bool ShouldDiscardValueNames
Definition: Config.h:82
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 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:89
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.
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:490
OptimizationLevel
LLVM-provided high-level optimization levels.
Definition: PassBuilder.h:66
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
std::string PGOSampleUse
Path of the sample Profile data file.
Error takeError()
Take ownership of the stored error.
Definition: Error.h:764
static const Target * lookupTarget(const std::string &Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition: Module.h:233
ModuleHookFn PreCodeGenModuleHook
This module hook is called before code generation.
Definition: Config.h:137
Pass * Inliner
Inliner - Specifies the inliner to use.
CombinedIndexHookFn CombinedIndexHook
Definition: Config.h:150
const Triple & getTargetTriple() const
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:174
void add(Pass *P) override
Add a pass to the queue of passes to run.
bool isODRUniquingDebugTypes() const
Whether there is a string map for uniquing debug info identifiers across the context.
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
void populateLTOPassManager(legacy::PassManagerBase &PM)
This class provides access to building LLVM's passes.
Definition: PassBuilder.h:44
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:115
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
void AddFeature(StringRef String, bool Enable=true)
Adds Features.
bool DisableVerify
Definition: Config.h:47
#define T
unsigned OptLevel
The Optimization Level - Specify the basic optimization level.
std::string SampleProfile
Sample PGO profile path.
Definition: Config.h:74
TargetOptions Options
Definition: Config.h:40
static std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:160
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:137
virtual bool addPassesToEmitFile(PassManagerBase &, raw_pwrite_stream &, CodeGenFileType, bool=true, AnalysisID=nullptr, AnalysisID=nullptr, AnalysisID=nullptr, AnalysisID=nullptr)
Add passes to the specified pass manager to get the specified file emitted.
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:119
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:78
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
Definition: PassManager.h:739
TargetLibraryInfoImpl * LibraryInfo
LibraryInfo - Specifies information about the runtime library for the optimizer.
Disable as many optimizations as possible.
Definition: PassBuilder.h:70
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
#define A
Definition: LargeTest.cpp:12
unsigned OptLevel
Definition: Config.h:46
amode opt
Expected< std::unique_ptr< tool_output_file > > setupOptimizationRemarks(LLVMContext &Context, StringRef LTORemarksFilename, bool LTOPassRemarksWithHotness, int Count=-1)
Setup optimization remarks.
Definition: LTO.cpp:1117
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:124
ModuleHookFn PostInternalizeModuleHook
This hook is called after internalizing the module.
Definition: Config.h:126
cl::opt< Reloc::Model > RelocModel("relocation-model", cl::desc("Choose relocation model"), cl::values(clEnumValN(Reloc::Static,"static","Non-relocatable code"), clEnumValN(Reloc::PIC_,"pic","Fully relocatable, position independent code"), clEnumValN(Reloc::DynamicNoPIC,"dynamic-no-pic","Relocatable external references, non-relocatable code"), clEnumValN(Reloc::ROPI,"ropi","Code and read-only data relocatable, accessed PC-relative"), clEnumValN(Reloc::RWPI,"rwpi","Read-write data relocatable, accessed relative to static base"), clEnumValN(Reloc::ROPI_RWPI,"ropi-rwpi","Combination of ropi and rwpi")))
std::string getString() const
Returns features as a string.
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
Create a verifier pass.
Definition: Verifier.h:135
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:311
PICLevel::Level getPICLevel() const
Returns the PIC level (small or large model)
Definition: Module.cpp:473
TargetMachine * createTargetMachine(StringRef TT, StringRef CPU, StringRef Features, const TargetOptions &Options, Optional< Reloc::Model > RM, CodeModel::Model CM=CodeModel::Default, CodeGenOpt::Level OL=CodeGenOpt::Default) const
createTargetMachine - Create a target specific machine implementation for the specified Triple...
Optimize for fast execution as much as possible without triggering significant incremental compile ti...
Definition: PassBuilder.h:108
#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:744
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:220
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 ...
The file should be opened in text mode on platforms that make this distinction.
Definition: FileSystem.h:708
llvm_unreachable("Unknown RegBank!")
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:391
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:357
pointer data()
Return a pointer to the vector's buffer, even if empty().
Definition: SmallVector.h:142
Manages a sequence of passes over a particular unit of IR.
Definition: PassManager.h:420
#define C
Definition: LargeTest.cpp:25
#define I(x, y, z)
Definition: MD5.cpp:58
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:135
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
CodeModel::Model CodeModel
Definition: Config.h:43
void thinLTOResolveWeakForLinkerModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals)
Resolve WeakForLinker values in TheModule based on the information recorded in the summaries during g...
This header provides classes for managing passes over SCCs of the call graph.
LLVM_NODISCARD bool empty() const
Definition: DenseMap.h:84
ModuleHookFn PostImportModuleHook
This hook is called after importing from other modules (ThinLTO-specific).
Definition: Config.h:129
Error backend(Config &C, AddStreamFn AddStream, unsigned ParallelCodeGenParallelismLevel, std::unique_ptr< Module > M, ModuleSummaryIndex &CombinedIndex)
Runs a regular LTO backend.
Definition: LTOBackend.cpp:356
iterator end()
Definition: MapVector.h:61
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Optimize quickly without destroying debuggability.
Definition: PassBuilder.h:90
Pass * createFunctionInliningPass()
createFunctionInliningPass - Return a new pass object that uses a heuristic to inline direct function...
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...
The function importer is automatically importing function from other modules based on the provided su...
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:132
const Target & getTarget() const
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:56
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:175
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
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:123
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
static void finalizeOptimizationRemarks(std::unique_ptr< tool_output_file > DiagOutputFile)
Definition: LTOBackend.cpp:347
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:237
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:73