LLVM: include/llvm/Transforms/IPO/FunctionImport.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_TRANSFORMS_IPO_FUNCTIONIMPORT_H

10#define LLVM_TRANSFORMS_IPO_FUNCTIONIMPORT_H

11

20#include

21#include

22#include <system_error>

23#include

24

25namespace llvm {

26

28

29

30

32public:

33

34

37

38

39

41

43

45

46

48

49

50

52

53

54

56

57

58

60 };

61

62

63

79

80

81

82

83

87 std::unique_ptr>>;

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

112 public:

114

116

117

118

121

122

123

126 auto Key = std::make_pair(FromModule, GUID);

127 auto InsertResult = TheTable.try_emplace(Key, TheTable.size());

128 return makeIDPair(InsertResult.first->second);

129 }

130

131

132

133 std::optional<std::pair<ImportIDTy, ImportIDTy>>

135 auto Key = std::make_pair(FromModule, GUID);

136 auto It = TheTable.find(Key);

137 if (It != TheTable.end())

138 return makeIDPair(It->second);

139 return std::nullopt;

140 }

141

142

143

144 std::tuple<StringRef, GlobalValue::GUID, GlobalValueSummary::ImportKind>

149 auto It = TheTable.begin() + (ImportID >> 1);

150 StringRef FromModule = It->first.first;

152 return std::make_tuple(FromModule, GUID, Kind);

153 }

154

155

156 std::tuple<StringRef, GlobalValue::GUID, GlobalValueSummary::ImportKind>

158 return lookup(ImportID);

159 }

160

161 private:

162

163 static std::pair<ImportIDTy, ImportIDTy> makeIDPair(ImportIDTy Index) {

166 return std::make_pair(Def, Decl);

167 }

168

170 };

171

172

173 class SortedImportList;

174

175

176

177

178

179

180

181

182

183

184

186 public:

188

189

191

192

194

196 };

197

200

201

202

205

206

207

208

211

219

220

221

223

224 LLVM_ABI std::optionalGlobalValueSummary::ImportKind

226

227

228

229

231 auto end() const { return map_iterator(Imports.end(), std::cref(IDs)); }

232

234

235 private:

238 };

239

240

241

243 public:

246 bool(const std::pair<StringRef, GlobalValue::GUID> &,

247 const std::pair<StringRef, GlobalValue::GUID> &)>

248 Comp)

249 : IDs(ImportMap.IDs), Imports(iterator_range(ImportMap.Imports)) {

253 -> std::pair<StringRef, GlobalValue::GUID> {

254 auto Tuple = IDs.lookup(Id);

255 return std::make_pair(std::get<0>(Tuple), std::get<1>(Tuple));

256 };

258 });

259 }

260

261

262

263

265 auto end() const { return map_iterator(Imports.end(), std::cref(IDs)); }

266

267 private:

270 };

271

272

274 public:

277 : ImportIDs(), EmptyList(ImportIDs), ListsImpl(Size) {}

278

280 return ListsImpl.try_emplace(DestMod, ImportIDs).first->second;

281 }

282

284 auto It = ListsImpl.find(DestMod);

285 if (It != ListsImpl.end())

286 return It->second;

287 return EmptyList;

288 }

289

290 size_t size() const { return ListsImpl.size(); }

291

295

296 private:

300 };

301

302

303

304

306

307

309 std::function<Expected<std::unique_ptr>(StringRef Identifier)>;

310

311

313 bool ClearDSOLocalOnDeclarations)

314 : Index(Index), ModuleLoader(std::move(ModuleLoader)),

315 ClearDSOLocalOnDeclarations(ClearDSOLocalOnDeclarations) {}

316

317

319 const ImportMapTy &ImportList);

320

321private:

322

324

325

327

328

329

330 bool ClearDSOLocalOnDeclarations;

331};

332

333

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

364 isPrevailing,

367

368

369

370

372

373

374

375

376

378

379

380

381

382

383

384

385

387 ModuleSummaryIndex &Index,

388 const DenseSetGlobalValue::GUID &GUIDPreservedSymbols,

390

391

392

394 ModuleSummaryIndex &Index,

395 const DenseSetGlobalValue::GUID &GUIDPreservedSymbols,

397 bool ImportEnabled);

398

399

400

402

403

404

405

406

407

408

409

410

411

412

413

414

415

417 StringRef ModulePath,

418 const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,

419 const FunctionImporter::ImportMapTy &ImportList,

422

423

427

428

430 StringRef ModulePath,

432 function_ref<void(const std::string &)> F);

433

434

435

436

437

438

439

443

444

445

448

449}

450

451#endif

This file defines the DenseSet and SmallDenseSet classes.

This header defines various interfaces for pass management in LLVM.

Machine Check Debug Module

static cl::opt< std::string > OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"), cl::init("-"))

This file implements a map that provides insertion order iteration.

static cl::opt< bool > PropagateAttrs("propagate-attrs", cl::init(true), cl::Hidden, cl::desc("Propagate attributes in index"))

ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...

static int Lookup(ArrayRef< TableEntry > Table, unsigned Opcode)

DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator

Implements a dense probed hash-table based set.

Tagged union holding either a T or a Error.

The function importing pass.

Definition FunctionImport.h:334

LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)

Definition FunctionImport.h:111

uint32_t ImportIDTy

Definition FunctionImport.h:113

std::pair< ImportIDTy, ImportIDTy > createImportIDs(StringRef FromModule, GlobalValue::GUID GUID)

Definition FunctionImport.h:124

ImportIDTable(const ImportIDTable &)=delete

ImportIDTable & operator=(const ImportIDTable &)=delete

std::tuple< StringRef, GlobalValue::GUID, GlobalValueSummary::ImportKind > lookup(ImportIDTy ImportID) const

Definition FunctionImport.h:145

std::optional< std::pair< ImportIDTy, ImportIDTy > > getImportIDs(StringRef FromModule, GlobalValue::GUID GUID)

Definition FunctionImport.h:134

std::tuple< StringRef, GlobalValue::GUID, GlobalValueSummary::ImportKind > operator()(ImportIDTable::ImportIDTy ImportID) const

Definition FunctionImport.h:157

Definition FunctionImport.h:273

const_iterator begin() const

Definition FunctionImport.h:293

ImportListsTy()

Definition FunctionImport.h:275

const ImportMapTy & lookup(StringRef DestMod) const

Definition FunctionImport.h:283

const_iterator end() const

Definition FunctionImport.h:294

DenseMap< StringRef, ImportMapTy >::const_iterator const_iterator

Definition FunctionImport.h:292

size_t size() const

Definition FunctionImport.h:290

ImportMapTy & operator[](StringRef DestMod)

Definition FunctionImport.h:279

ImportListsTy(size_t Size)

Definition FunctionImport.h:276

The map maintains the list of imports.

Definition FunctionImport.h:185

AddDefinitionStatus

Definition FunctionImport.h:187

@ Inserted

Definition FunctionImport.h:193

@ ChangedToDefinition

Definition FunctionImport.h:195

@ NoChange

Definition FunctionImport.h:190

LLVM_ABI AddDefinitionStatus addDefinition(StringRef FromModule, GlobalValue::GUID GUID)

auto begin() const

Definition FunctionImport.h:230

ImportMapTy(ImportIDTable &IDs)

Definition FunctionImport.h:199

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

Definition FunctionImport.h:212

LLVM_ABI SmallVector< StringRef, 0 > getSourceModules() const

LLVM_ABI std::optional< GlobalValueSummary::ImportKind > getImportType(StringRef FromModule, GlobalValue::GUID GUID) const

LLVM_ABI void maybeAddDeclaration(StringRef FromModule, GlobalValue::GUID GUID)

friend class SortedImportList

Definition FunctionImport.h:233

auto end() const

Definition FunctionImport.h:231

auto begin() const

Definition FunctionImport.h:264

SortedImportList(const ImportMapTy &ImportMap, llvm::function_ref< bool(const std::pair< StringRef, GlobalValue::GUID > &, const std::pair< StringRef, GlobalValue::GUID > &)> Comp)

Definition FunctionImport.h:244

auto end() const

Definition FunctionImport.h:265

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

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

DenseMap< GlobalValue::GUID, std::tuple< unsigned, const GlobalValueSummary *, std::unique_ptr< ImportFailureInfo > > > ImportThresholdsTy

Map of callee GUID considered for import into a given module to a pair consisting of the largest thre...

Definition FunctionImport.h:84

FunctionImporter(const ModuleSummaryIndex &Index, ModuleLoaderTy ModuleLoader, bool ClearDSOLocalOnDeclarations)

Create a Function Importer.

Definition FunctionImport.h:312

ImportFailureReason

The different reasons selectCallee will chose not to import a candidate.

Definition FunctionImport.h:35

@ NoInline

Definition FunctionImport.h:59

@ None

Definition FunctionImport.h:36

@ LocalLinkageNotInModule

Definition FunctionImport.h:51

@ TooLarge

Definition FunctionImport.h:44

@ NotLive

Definition FunctionImport.h:42

@ NotEligible

Definition FunctionImport.h:55

@ GlobalVar

Definition FunctionImport.h:40

@ InterposableLinkage

Definition FunctionImport.h:47

DenseSet< ValueInfo > ExportSetTy

The set contains an entry for every global value that the module exports.

Definition FunctionImport.h:305

std::function< Expected< std::unique_ptr< Module > >(StringRef Identifier)> ModuleLoaderTy

A function of this type is used to load modules referenced by the index.

Definition FunctionImport.h:308

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

uint64_t GUID

Declare a type to represent a global unique identifier for a global value.

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

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

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

A set of analyses that are preserved following a run of a transformation pass.

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

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

An efficient, type-erasing, non-owning reference to a callable.

A range adaptor for a pair of iterators.

This is an optimization pass for GlobalISel generic memory operations.

std::unordered_set< GlobalValueSummary * > GVSummaryPtrSet

A set of global value summary pointers.

DenseMap< GlobalValue::GUID, GlobalValueSummary * > GVSummaryMapTy

Map of global value GUID to its summary, used to identify values defined in a particular module,...

mapped_iterator< ItTy, FuncTy > map_iterator(ItTy I, FuncTy F)

LLVM_ABI bool convertToDeclaration(GlobalValue &GV)

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

LLVM_ABI void ComputeCrossModuleImport(const ModuleSummaryIndex &Index, const DenseMap< StringRef, GVSummaryMapTy > &ModuleToDefinedGVSummaries, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing, FunctionImporter::ImportListsTy &ImportLists, DenseMap< StringRef, FunctionImporter::ExportSetTy > &ExportLists)

Compute all the imports and exports for every module in the Index.

void sort(IteratorTy Start, IteratorTy End)

LLVM_ABI void computeDeadSymbolsAndUpdateIndirectCalls(ModuleSummaryIndex &Index, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols, function_ref< PrevailingType(GlobalValue::GUID)> isPrevailing)

Compute all the symbols that are "dead": i.e these that can't be reached in the graph from any of the...

std::map< std::string, GVSummaryMapTy, std::less<> > ModuleToSummariesForIndexTy

Map of a module name to the GUIDs and summaries we will import from that module.

LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key

LLVM_ABI void updateIndirectCalls(ModuleSummaryIndex &Index)

Update call edges for indirect calls to local functions added from SamplePGO when needed.

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

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

LLVM_ABI void gatherImportedSummariesForModule(StringRef ModulePath, const DenseMap< StringRef, GVSummaryMapTy > &ModuleToDefinedGVSummaries, const FunctionImporter::ImportMapTy &ImportList, ModuleToSummariesForIndexTy &ModuleToSummariesForIndex, GVSummaryPtrSet &DecSummaries)

Compute the set of summaries needed for a ThinLTO backend compilation of ModulePath.

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

LLVM_ABI void processImportsFiles(StringRef ModulePath, const ModuleToSummariesForIndexTy &ModuleToSummariesForIndex, function_ref< void(const std::string &)> F)

Call F passing each of the files module ModulePath will import from.

PrevailingType

PrevailingType enum used as a return type of callback passed to computeDeadSymbolsAndUpdateIndirectCa...

Definition FunctionImport.h:371

@ Yes

Definition FunctionImport.h:371

LLVM_ABI void computeDeadSymbolsWithConstProp(ModuleSummaryIndex &Index, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols, function_ref< PrevailingType(GlobalValue::GUID)> isPrevailing, bool ImportEnabled)

Compute dead symbols and run constant propagation in combined index after that.

LLVM_ABI Error EmitImportsFiles(StringRef ModulePath, StringRef OutputFilename, const ModuleToSummariesForIndexTy &ModuleToSummariesForIndex)

Emit into OutputFilename the files module ModulePath will import from.

AnalysisManager< Module > ModuleAnalysisManager

Convenience typedef for the Module analysis manager.

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

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

Implement std::hash so that hash_code can be used in STL containers.

ImportFailureInfo(ValueInfo VI, CalleeInfo::HotnessType MaxHotness, ImportFailureReason Reason, unsigned Attempts)

Definition FunctionImport.h:75

CalleeInfo::HotnessType MaxHotness

Definition FunctionImport.h:69

ImportFailureReason Reason

Definition FunctionImport.h:72

ValueInfo VI

Definition FunctionImport.h:67

unsigned Attempts

Definition FunctionImport.h:74

A CRTP mix-in to automatically provide informational APIs needed for passes.

Struct that holds a reference to a particular GUID in a global value summary.