LLVM: lib/LTO/LTOBackend.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

49#include

50

51using namespace llvm;

52using namespace lto;

53

54#define DEBUG_TYPE "lto-backend"

55

60};

61

65 "Do not embed"),

67 "Embed after all optimization passes"),

69 "post-merge-pre-opt",

70 "Embed post merge, but before optimizations")),

71 cl::desc("Embed LLVM bitcode in object files produced by LTO"));

72

74 "thinlto-assume-merged", cl::init(false),

75 cl::desc("Assume the input has already undergone ThinLTO function "

76 "importing and the other pre-optimization pipeline changes."));

77

78namespace llvm {

80}

81

83 errs() << "failed to open " << Path << ": " << Msg << '\n';

85 exit(1);

86}

87

91

92 std::error_code EC;

93 if (SaveTempsArgs.empty() || SaveTempsArgs.contains("resolution")) {

95 std::make_unique<raw_fd_ostream>(OutputFileName + "resolution.txt", EC,

97 if (EC) {

100 }

101 }

102

103 auto setHook = [&](std::string PathSuffix, ModuleHookFn &Hook) {

104

106 Hook = [=](unsigned Task, const Module &M) {

107

108

109 if (LinkerHook && !LinkerHook(Task, M))

110 return false;

111

112 std::string PathPrefix;

113

114

115

116 if (M.getModuleIdentifier() == "ld-temp.o" || !UseInputModulePath) {

117 PathPrefix = OutputFileName;

118 if (Task != (unsigned)-1)

119 PathPrefix += utostr(Task) + ".";

120 } else

121 PathPrefix = M.getModuleIdentifier() + ".";

122 std::string Path = PathPrefix + PathSuffix + ".bc";

123 std::error_code EC;

125

126

127 if (EC)

130 return true;

131 };

132 };

133

134 auto SaveCombinedIndex =

137 std::string Path = OutputFileName + "index.bc";

138 std::error_code EC;

140

141

142 if (EC)

145

146 Path = OutputFileName + "index.dot";

148 if (EC)

150 Index.exportToDot(OSDot, GUIDPreservedSymbols);

151 return true;

152 };

153

154 if (SaveTempsArgs.empty()) {

162 } else {

163 if (SaveTempsArgs.contains("preopt"))

165 if (SaveTempsArgs.contains("promote"))

167 if (SaveTempsArgs.contains("internalize"))

169 if (SaveTempsArgs.contains("import"))

171 if (SaveTempsArgs.contains("opt"))

173 if (SaveTempsArgs.contains("precodegen"))

175 if (SaveTempsArgs.contains("combinedindex"))

177 }

178

180}

181

182#define HANDLE_EXTENSION(Ext) \

183 llvm::PassPluginLibraryInfo get##Ext##PluginInfo();

184#include "llvm/Support/Extension.def"

185#undef HANDLE_EXTENSION

186

189#define HANDLE_EXTENSION(Ext) \

190 get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);

191#include "llvm/Support/Extension.def"

192#undef HANDLE_EXTENSION

193

194

195 for (auto &PluginFN : PassPlugins) {

200 }

201}

202

203static std::unique_ptr

205 StringRef TheTriple = M.getTargetTriple();

208 for (const std::string &A : Conf.MAttrs)

210

211 std::optionalReloc::Model RelocModel;

214 else if (M.getModuleFlag("PIC Level"))

215 RelocModel =

217

218 std::optionalCodeModel::Model CodeModel;

221 else

222 CodeModel = M.getCodeModel();

223

227

228 assert(TM && "Failed to create target machine");

229

230 if (std::optional<uint64_t> LargeDataThreshold = M.getLargeDataThreshold())

231 TM->setLargeDataThreshold(*LargeDataThreshold);

232

233 return TM;

234}

235

237 unsigned OptLevel, bool IsThinLTO,

241 std::optional PGOOpt;

259 PGOOpt = PGOOptions("", "", "", "", nullptr,

262 }

263 TM->setPGOOption(PGOOpt);

264

269

273 SI.registerCallbacks(PIC, &MAM);

275

277

278 std::unique_ptr TLII(

281 TLII->disableAllFunctions();

283

284

290 }

291

293 }

294

295

301

303

306

308

309 switch (OptLevel) {

310 default:

312 case 0:

314 break;

315 case 1:

317 break;

318 case 2:

320 break;

321 case 3:

323 break;

324 }

325

326

331 }

332 } else if (IsThinLTO) {

334 } else {

336 }

337

340

342 std::string PipelineStr;

347 });

348 outs() << "pipeline-passes: " << PipelineStr << '\n';

349 }

350

352}

353

355

356

357

358 return Mod.empty() && Mod.global_empty() && Mod.named_metadata_empty() &&

359 Mod.getModuleInlineAsm().empty();

360}

361

365 const std::vector<uint8_t> &CmdArgs) {

366 if (EmbedBitcode == LTOBitcodeEmbedding::EmbedPostMergePreOptimized) {

367

368

369

370

371

372

373

374

375 if (CmdArgs.empty())

377 dbgs() << "Post-(Thin)LTO merge bitcode embedding was requested, but "

378 "command line arguments are not available");

380 true, true,

381 CmdArgs);

382 }

383

384

385

386

387

389

391 ImportSummary);

392 }

394}

395

400 return;

401

402 if (EmbedBitcode == LTOBitcodeEmbedding::EmbedOptimized)

404 true,

405 false,

406 std::vector<uint8_t>());

407

408 std::unique_ptr DwoOut;

410 if (!Conf.DwoDir.empty()) {

411 std::error_code EC;

414 ": " + EC.message());

415

416 DwoFile = Conf.DwoDir;

418 TM->Options.MCOptions.SplitDwarfFile = std::string(DwoFile);

419 } else

420 TM->Options.MCOptions.SplitDwarfFile = Conf.SplitDwarfFile;

421

422 if (!DwoFile.empty()) {

423 std::error_code EC;

424 DwoOut = std::make_unique(DwoFile, EC, sys::fs::OF_None);

425 if (EC)

427 EC.message());

428 }

429

431 AddStream(Task, Mod.getModuleIdentifier());

434 std::unique_ptr &Stream = *StreamOrErr;

435 TM->Options.ObjectFilenameForDebug = Stream->ObjectPathName;

436

440

441

442

443

444

446 CodeGenPasses.add(

450 if (TM->addPassesToEmitFile(CodeGenPasses, *Stream->OS,

451 DwoOut ? &DwoOut->os() : nullptr,

454 CodeGenPasses.run(Mod);

455

456 if (DwoOut)

457 DwoOut->keep();

458}

459

462 unsigned ParallelCodeGenParallelismLevel, Module &Mod,

467 const Target *T = &TM->getTarget();

468

469 const auto HandleModulePartition =

470 [&](std::unique_ptr MPart) {

471

472

473

474

475

476

480

481

482 CodegenThreadPool.async(

487 if (!MOrErr)

489 std::unique_ptr MPartInCtx = std::move(MOrErr.get());

490

491 std::unique_ptr TM =

493

494 codegen(C, TM.get(), AddStream, ThreadId, *MPartInCtx,

495 CombinedIndex);

496 },

497

498

500 };

501

502

503 if (!TM->splitModule(Mod, ParallelCodeGenParallelismLevel,

504 HandleModulePartition)) {

505 SplitModule(Mod, ParallelCodeGenParallelismLevel, HandleModulePartition,

506 false);

507 }

508

509

510

511

512 CodegenThreadPool.wait();

513}

514

517 if (C.OverrideTriple.empty())

518 Mod.setTargetTriple(C.OverrideTriple);

519 else if (Mod.getTargetTriple().empty())

520 Mod.setTargetTriple(C.DefaultTriple);

521

522 std::string Msg;

524 if (T)

526 return T;

527}

528

530 std::unique_ptr DiagOutputFile) {

531

532

533 if (!DiagOutputFile)

535 DiagOutputFile->keep();

536 DiagOutputFile->os().flush();

538}

539

541 unsigned ParallelCodeGenParallelismLevel, Module &Mod,

544 if (!TOrErr)

546

548

550 if (C.CodeGenOnly) {

551 if (opt(C, TM.get(), 0, Mod, false,

552 &CombinedIndex, nullptr,

553 std::vector<uint8_t>()))

555 }

556

557 if (ParallelCodeGenParallelismLevel == 1) {

558 codegen(C, TM.get(), AddStream, 0, Mod, CombinedIndex);

559 } else {

560 splitCodeGen(C, TM.get(), AddStream, ParallelCodeGenParallelismLevel, Mod,

561 CombinedIndex);

562 }

564}

565

568 std::vector<GlobalValue*> DeadGVs;

569 for (auto &GV : Mod.global_values())

571 if (!Index.isGlobalValueLive(GVS)) {

572 DeadGVs.push_back(&GV);

574 }

575

576

577

579 GV->removeDeadConstantUsers();

580

581

582 if (GV->use_empty())

583 GV->eraseFromParent();

584 }

585}

586

592 bool CodeGenOnly, AddStreamFn IRAddStream,

593 const std::vector<uint8_t> &CmdArgs) {

595 if (!TOrErr)

597

599

600

604 Task);

605 if (!DiagFileOrErr)

606 return DiagFileOrErr.takeError();

607 auto DiagnosticOutputFile = std::move(*DiagFileOrErr);

608

609

610

611 Mod.setPartialSampleProfileRatio(CombinedIndex);

612

614 if (CodeGenOnly) {

615

616

617 codegen(Conf, TM.get(), AddStream, Task, Mod, CombinedIndex);

619 }

620

623

624 auto OptimizeAndCodegen =

626 std::unique_ptr DiagnosticOutputFile) {

627

628 if (opt(Conf, TM, Task, Mod, true,

629 nullptr, &CombinedIndex,

630 CmdArgs))

632

633

634

635

636

637 if (IRAddStream)

639

640 codegen(Conf, TM, AddStream, Task, Mod, CombinedIndex);

642 };

643

645 return OptimizeAndCodegen(Mod, TM.get(), std::move(DiagnosticOutputFile));

646

647

648

649 bool ClearDSOLocalOnDeclarations =

650 TM->getTargetTriple().isOSBinFormatELF() &&

654

656

658

661

662 if (!DefinedGlobals.empty())

664

668

669 auto ModuleLoader = [&](StringRef Identifier) {

670 assert(Mod.getContext().isODRUniquingDebugTypes() &&

671 "ODR Type uniquing should be enabled on the context");

672 if (ModuleMap) {

673 auto I = ModuleMap->find(Identifier);

675 return I->second.getLazyModule(Mod.getContext(),

676 true,

677 true);

678 }

679

682 if (!MBOrErr)

684 Twine("Error loading imported file ") + Identifier + " : ",

686

688 if (!BMOrErr)

690 Twine("Error loading imported file ") + Identifier + " : " +

693

695 BMOrErr->getLazyModule(Mod.getContext(),

696 true,

697 true);

698 if (MOrErr)

699 (*MOrErr)->setOwnedMemoryBuffer(std::move(*MBOrErr));

700 return MOrErr;

701 };

702

704 ClearDSOLocalOnDeclarations);

706 return Err;

707

708

711

714

715 return OptimizeAndCodegen(Mod, TM.get(), std::move(DiagnosticOutputFile));

716}

717

720 return BMs.begin();

721

724 if (LTOInfo && LTOInfo->IsThinLTO)

725 return &BM;

726 }

727 return nullptr;

728}

729

732 if (!BMsOrErr)

734

735

736

738 return *Bm;

739

740 return make_error("Could not find module summary",

742}

743

748 return true;

749

750

751

752 for (const auto &GlobalList : CombinedIndex) {

753

754 if (GlobalList.second.SummaryList.empty())

755 continue;

756

757 auto GUID = GlobalList.first;

758 for (const auto &Summary : GlobalList.second.SummaryList) {

759

760

761 if (Summary->modulePath() == M.getModuleIdentifier())

762 continue;

763

764 ImportList.addGUID(Summary->modulePath(), GUID, Summary->importType());

765 }

766 }

767 return true;

768}

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

This header provides classes for managing passes over SCCs of the call graph.

#define clEnumValN(ENUMVAL, FLAGNAME, DESC)

This header defines various interfaces for pass management in LLVM.

static cl::opt< bool > ThinLTOAssumeMerged("thinlto-assume-merged", cl::init(false), cl::desc("Assume the input has already undergone ThinLTO function " "importing and the other pre-optimization pipeline changes."))

static void reportOpenError(StringRef Path, Twine Msg)

@ EmbedPostMergePreOptimized

static cl::opt< LTOBitcodeEmbedding > EmbedBitcode("lto-embed-bitcode", cl::init(LTOBitcodeEmbedding::DoNotEmbed), cl::values(clEnumValN(LTOBitcodeEmbedding::DoNotEmbed, "none", "Do not embed"), clEnumValN(LTOBitcodeEmbedding::EmbedOptimized, "optimized", "Embed after all optimization passes"), clEnumValN(LTOBitcodeEmbedding::EmbedPostMergePreOptimized, "post-merge-pre-opt", "Embed post merge, but before optimizations")), cl::desc("Embed LLVM bitcode in object files produced by LTO"))

static void splitCodeGen(const Config &C, TargetMachine *TM, AddStreamFn AddStream, unsigned ParallelCodeGenParallelismLevel, Module &Mod, const ModuleSummaryIndex &CombinedIndex)

static void dropDeadSymbols(Module &Mod, const GVSummaryMapTy &DefinedGlobals, const ModuleSummaryIndex &Index)

static Expected< const Target * > initAndLookupTarget(const Config &C, Module &Mod)

static void codegen(const Config &Conf, TargetMachine *TM, AddStreamFn AddStream, unsigned Task, Module &Mod, const ModuleSummaryIndex &CombinedIndex)

static bool isEmptyModule(const Module &Mod)

static void RegisterPassPlugins(ArrayRef< std::string > PassPlugins, PassBuilder &PB)

static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM, unsigned OptLevel, bool IsThinLTO, ModuleSummaryIndex *ExportSummary, const ModuleSummaryIndex *ImportSummary)

This header provides classes for managing a pipeline of passes over loops in LLVM IR.

This is the interface to build a ModuleSummaryIndex for a module.

static std::unique_ptr< TargetMachine > createTargetMachine(Function *F, CodeGenOptLevel OptLevel)

Create the TargetMachine object to query the backend for optimization preferences.

CGSCCAnalysisManager CGAM

FunctionAnalysisManager FAM

ModuleAnalysisManager MAM

PassInstrumentationCallbacks PIC

PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

This header defines a class that provides bookkeeping for all standard (i.e in-tree) pass instrumenta...

static cl::opt< int > ThreadCount("threads", cl::init(0))

Defines the virtual file system interface vfs::FileSystem.

static const char PassName[]

A manager for alias analyses.

A container for analyses that lazily runs them and caches their results.

bool registerPass(PassBuilderT &&PassBuilder)

Register an analysis pass with the manager.

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

size_t size() const

size - Get the array size.

Represents a module in a bitcode file.

ValueT lookup(const_arg_type_t< KeyT > Val) const

lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...

Implements a dense probed hash-table based set.

Represents either an error or a value T.

std::error_code getError() const

Lightweight error class with error context and mandatory checking.

static ErrorSuccess success()

Create a success value.

Tagged union holding either a T or a Error.

Error takeError()

Take ownership of the stored error.

reference get()

Returns a reference to the stored T value.

The map maintains the list of imports.

void addGUID(StringRef FromModule, GlobalValue::GUID GUID, GlobalValueSummary::ImportKind ImportKind)

The function importer is automatically importing function from other modules based on the provided su...

Expected< bool > importFunctions(Module &M, const ImportMapTy &ImportList)

Import functions in Module M based on the supplied import list.

Function and variable summary information to aid decisions and implementation of importing.

This class implements a map that also provides access to all stored values in a deterministic order.

iterator find(const KeyT &Key)

static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)

Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...

Class to hold module path string table and global value map, and encapsulate methods for operating on...

bool withWholeProgramVisibility() const

A Module instance is used to store all the information related to an LLVM module.

MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...

static const OptimizationLevel O3

Optimize for fast execution as much as possible.

static const OptimizationLevel O0

Disable as many optimizations as possible.

static const OptimizationLevel O2

Optimize for fast execution as much as possible without triggering significant incremental compile ti...

static const OptimizationLevel O1

Optimize quickly without destroying debuggability.

This class provides access to building LLVM's passes.

Error parseAAPipeline(AAManager &AA, StringRef PipelineText)

Parse a textual alias analysis pipeline into the provided AA manager.

void registerLoopAnalyses(LoopAnalysisManager &LAM)

Registers all available loop analysis passes.

void crossRegisterProxies(LoopAnalysisManager &LAM, FunctionAnalysisManager &FAM, CGSCCAnalysisManager &CGAM, ModuleAnalysisManager &MAM, MachineFunctionAnalysisManager *MFAM=nullptr)

Cross register the analysis managers through their proxies.

Error parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText)

Parse a textual pass pipeline description into a ModulePassManager.

ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level, ModuleSummaryIndex *ExportSummary)

Build an LTO default optimization pipeline to a pass manager.

ModulePassManager buildThinLTODefaultPipeline(OptimizationLevel Level, const ModuleSummaryIndex *ImportSummary)

Build a ThinLTO default optimization pipeline to a pass manager.

void registerModuleAnalyses(ModuleAnalysisManager &MAM)

Registers all available module analysis passes.

void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)

Registers all available CGSCC analysis passes.

void registerFunctionAnalyses(FunctionAnalysisManager &FAM)

Registers all available function analysis passes.

void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)

LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same_v< PassT, PassManager > > addPass(PassT &&Pass)

PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)

Run all of the passes in this manager over the given unit of IR.

static Expected< PassPlugin > Load(const std::string &Filename)

Attempts to load a pass plugin from a given file.

void registerPassBuilderCallbacks(PassBuilder &PB) const

Invoke the PassBuilder callback registration.

A non-threaded implementation.

void wait() override

Blocking wait for all the tasks to execute first.

SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...

StringRef str() const

Explicit conversion to StringRef.

This class provides an interface to register all the standard pass instrumentations and manages their...

StringRef - Represent a constant reference to a string, i.e.

Manages the enabling and disabling of subtarget specific features.

void getDefaultSubtargetFeatures(const Triple &Triple)

Adds the default features for the specified target triple.

std::string getString() const

Returns features as a string.

void AddFeature(StringRef String, bool Enable=true)

Adds Features.

Analysis pass providing the TargetLibraryInfo.

Implementation of the target library information.

Primary interface to the complete machine description for the target machine.

Target - Wrapper for Target specific information.

TargetMachine * createTargetMachine(StringRef TT, StringRef CPU, StringRef Features, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM=std::nullopt, CodeGenOptLevel OL=CodeGenOptLevel::Default, bool JIT=false) const

createTargetMachine - Create a target specific machine implementation for the specified Triple.

auto async(Function &&F, Args &&...ArgList)

Asynchronous submission of a task to the pool.

Triple - Helper class for working with autoconf configuration names.

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

bool contains(const_arg_type_t< ValueT > V) const

Check if the set contains the given element.

PassManager manages ModulePassManagers.

void add(Pass *P) override

Add a pass to the queue of passes to run.

bool run(Module &M)

run - Execute all of the passes scheduled for execution.

A raw_ostream that writes to a file descriptor.

A raw_ostream that writes to an std::string.

A raw_ostream that writes to an SmallVector or SmallString.

Interfaces for registering analysis passes, producing common pass manager configurations,...

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

@ C

The default llvm calling convention, compatible with C.

void saveModuleForTwoRounds(const Module &TheModule, unsigned Task, AddStreamFn AddStream)

Save TheModule before the first codegen round.

ValuesClass values(OptsTy... Options)

Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...

initializer< Ty > init(const Ty &Val)

BitcodeModule * findThinLTOModule(MutableArrayRef< BitcodeModule > BMs)

Returns the BitcodeModule that is ThinLTO.

Error backend(const Config &C, AddStreamFn AddStream, unsigned ParallelCodeGenParallelismLevel, Module &M, ModuleSummaryIndex &CombinedIndex)

Runs a regular LTO backend.

Error finalizeOptimizationRemarks(std::unique_ptr< ToolOutputFile > DiagOutputFile)

bool initImportList(const Module &M, const ModuleSummaryIndex &CombinedIndex, FunctionImporter::ImportMapTy &ImportList)

Distributed ThinLTO: collect the referenced modules based on module summary and initialize ImportList...

Expected< std::unique_ptr< ToolOutputFile > > setupLLVMOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename, StringRef RemarksPasses, StringRef RemarksFormat, bool RemarksWithHotness, std::optional< uint64_t > RemarksHotnessThreshold=0, int Count=-1)

Setup optimization remarks.

bool opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod, bool IsThinLTO, ModuleSummaryIndex *ExportSummary, const ModuleSummaryIndex *ImportSummary, const std::vector< uint8_t > &CmdArgs)

Runs middle-end LTO optimizations on Mod.

Error thinBackend(const Config &C, unsigned Task, AddStreamFn AddStream, Module &M, const ModuleSummaryIndex &CombinedIndex, const FunctionImporter::ImportMapTy &ImportList, const GVSummaryMapTy &DefinedGlobals, MapVector< StringRef, BitcodeModule > *ModuleMap, bool CodeGenOnly, AddStreamFn IRAddStream=nullptr, const std::vector< uint8_t > &CmdArgs=std::vector< uint8_t >())

Runs a ThinLTO backend.

void updateMemProfAttributes(Module &Mod, const ModuleSummaryIndex &Index)

Updates MemProf attributes (and metadata) based on whether the index has recorded that we are linking...

@ OF_Text

The file should be opened in text mode on platforms like z/OS that make this distinction.

@ OF_TextWithCRLF

The file should be opened in text mode and use a carriage linefeed '\r '.

std::error_code create_directories(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)

Create all the non-existent directories in path.

void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")

Append to path.

IntrusiveRefCntPtr< FileSystem > getRealFileSystem()

Gets an vfs::FileSystem for the 'real' file system, as seen by the operating system.

This is an optimization pass for GlobalISel generic memory operations.

ThreadPoolStrategy heavyweight_hardware_concurrency(unsigned ThreadCount=0)

Returns a thread strategy for tasks requiring significant memory or other resources.

Expected< std::unique_ptr< Module > > parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context, ParserCallbacks Callbacks={})

Read the specified bitcode file, returning the module.

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.

std::error_code inconvertibleErrorCode()

The value returned by this function can be returned from convertToErrorCode for Error values where no...

raw_fd_ostream & outs()

This returns a reference to a raw_fd_ostream for standard output.

std::function< Expected< std::unique_ptr< CachedFileStream > >(unsigned Task, const Twine &ModuleName)> AddStreamFn

This type defines the callback to add a file that is generated on the fly.

bool convertToDeclaration(GlobalValue &GV)

Converts value GV to declaration, or replaces with a declaration if it is an alias.

void renameModuleForThinLTO(Module &M, const ModuleSummaryIndex &Index, bool ClearDSOLocalOnDeclarations, SetVector< GlobalValue * > *GlobalsToImport=nullptr)

Perform in-place global value handling on the given Module for exported local functions renamed and p...

void writeIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out, const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex=nullptr, const GVSummaryPtrSet *DecSummaries=nullptr)

Write the specified module summary index to the given raw output stream, where it will be written in ...

void embedBitcodeInModule(Module &M, MemoryBufferRef Buf, bool EmbedBitcode, bool EmbedCmdline, const std::vector< uint8_t > &CmdArgs)

If EmbedBitcode is set, save a copy of the llvm IR as data in the __LLVM,__bitcode section (....

void SplitModule(Module &M, unsigned N, function_ref< void(std::unique_ptr< Module > MPart)> ModuleCallback, bool PreserveLocals=false, bool RoundRobin=false)

Splits the module M into N linkable partitions.

void updatePublicTypeTestCalls(Module &M, bool WholeProgramVisibilityEnabledInLTO)

raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

void report_fatal_error(Error Err, bool gen_crash_diag=true)

Report a serious error, calling any installed error handler.

Expected< std::vector< BitcodeModule > > getBitcodeModuleList(MemoryBufferRef Buffer)

Returns a list of modules in the specified bitcode buffer.

cl::opt< bool > NoPGOWarnMismatch

raw_fd_ostream & errs()

This returns a reference to a raw_ostream for standard error.

@ Mod

The access may modify the value stored in memory.

void thinLTOInternalizeModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals)

Internalize TheModule based on the information recorded in the summaries during global summary-based ...

cl::opt< bool > PrintPipelinePasses

Common option used by multiple tools to print pipeline passes.

ImmutablePass * createImmutableModuleSummaryIndexWrapperPass(const ModuleSummaryIndex *Index)

const char * toString(DWARFSectionKind Kind)

Error errorCodeToError(std::error_code EC)

Helper for converting an std::error_code to a Error.

void thinLTOFinalizeInModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals, bool PropagateAttrs)

Based on the information recorded in the summaries during global summary-based analysis:

A struct capturing PGO tunables.

This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...

StringRef getPassNameForClassName(StringRef ClassName)

Get the pass name for a given pass class name.

static const Target * lookupTarget(StringRef Triple, std::string &Error)

lookupTarget - Lookup a target based on a target triple.

std::function< bool(unsigned Task, const Module &)> ModuleHookFn

The following callbacks deal with tasks, which normally represent the entire optimization and code ge...

bool DebugPassManager

Whether to emit the pass manager debuggging informations.

bool AddFSDiscriminator

Add FSAFDO discriminators.

std::optional< uint64_t > RemarksHotnessThreshold

The minimum hotness value a diagnostic needs in order to be included in optimization diagnostics.

Error addSaveTemps(std::string OutputFileName, bool UseInputModulePath=false, const DenseSet< StringRef > &SaveTempsArgs={})

This is a convenience function that configures this Config object to write temporary files named afte...

ModuleHookFn PreOptModuleHook

This module hook is called after linking (regular LTO) or loading (ThinLTO) the module,...

CombinedIndexHookFn CombinedIndexHook

std::optional< CodeModel::Model > CodeModel

std::function< void(legacy::PassManager &)> PreCodeGenPassesHook

For adding passes that run right before codegen.

std::vector< std::string > MAttrs

CodeGenOptLevel CGOptLevel

PipelineTuningOptions PTO

Tunable parameters for passes in the default pipelines.

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...

std::string DwoDir

The directory to store .dwo files.

std::string RemarksFilename

Optimization remarks file path.

ModuleHookFn PostPromoteModuleHook

This hook is called after promoting any internal functions (ThinLTO-specific).

std::string ProfileRemapping

Name remapping file for profile data.

std::string SplitDwarfFile

The name for the split debug info file used for the DW_AT_[GNU_]dwo_name attribute in the skeleton CU...

std::string SplitDwarfOutput

The path to write a .dwo file to.

ModuleHookFn PostOptModuleHook

This module hook is called after optimization is complete.

std::string RemarksPasses

Optimization remarks pass filter.

std::string OptPipeline

If this field is set, the set of passes run in the middle-end optimizer will be the one specified by ...

bool RunCSIRInstr

Run PGO context sensitive IR instrumentation.

ModuleHookFn PostInternalizeModuleHook

This hook is called after internalizing the module.

ModuleHookFn PostImportModuleHook

This hook is called after importing from other modules (ThinLTO-specific).

bool RemarksWithHotness

Whether to emit optimization remarks with hotness informations.

std::vector< std::string > PassPlugins

std::string CSIRProfile

Context Sensitive PGO profile path.

ModuleHookFn PreCodeGenModuleHook

This module hook is called before code generation.

std::optional< Reloc::Model > RelocModel

bool ShouldDiscardValueNames

bool PGOWarnMismatch

Turn on/off the warning about a hash mismatch in the PGO profile data.

CodeGenFileType CGFileType

bool Freestanding

Flag to indicate that the optimizer should not assume builtins are present on the target.

std::string SampleProfile

Sample PGO profile path.

std::string RemarksFormat

The format used for serializing remarks (default: YAML).

A derived class of LLVMContext that initializes itself according to a given Config object.