LLVM: include/llvm/Analysis/CallGraph.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45#ifndef LLVM_ANALYSIS_CALLGRAPH_H

46#define LLVM_ANALYSIS_CALLGRAPH_H

47

53#include

54#include

55#include

56#include

57#include

58

59namespace llvm {

60

61template struct GraphTraits;

66

67

68

69

70

71

74

75 using FunctionMapTy =

76 std::map<const Function *, std::unique_ptr>;

77

78

79 FunctionMapTy FunctionMap;

80

81

82

84

85

86

87 std::unique_ptr CallsExternalNode;

88

89public:

93

96

97 using iterator = FunctionMapTy::iterator;

99

100

102

104 ModuleAnalysisManager::Invalidator &);

105

110

111

114 assert(I != FunctionMap.end() && "Function not in callgraph!");

115 return I->second.get();

116 }

117

118

121 assert(I != FunctionMap.end() && "Function not in callgraph!");

122 return I->second.get();

123 }

124

125

126

128

130 return CallsExternalNode.get();

131 }

132

133

134

135

136

137

138

139

140

141

142

143

145

146

147

149

150

152

153

154

156};

157

158

159

160

161

163public:

164

165

166

167

168

169

170

171

172

173

175

176public:

178

179

181

184

186 assert(NumReferences == 0 && "Node deleted while references remain");

187 }

188

189 using iterator = std::vector::iterator;

191

192

194

196 inline iterator end() { return CalledFunctions.end(); }

199 inline bool empty() const { return CalledFunctions.empty(); }

200 inline unsigned size() const { return (unsigned)CalledFunctions.size(); }

201

202

203

205

206

208 assert(i < CalledFunctions.size() && "Invalid index");

209 return CalledFunctions[i].second;

210 }

211

212

215

216

217

218

219

220

221

222

224 while (!CalledFunctions.empty()) {

225 CalledFunctions.back().second->DropRef();

226 CalledFunctions.pop_back();

227 }

228 }

229

230

232 assert(CalledFunctions.empty() &&

233 "Cannot steal callsite information if I already have some");

234 std::swap(CalledFunctions, N->CalledFunctions);

235 }

236

237

239 CalledFunctions.emplace_back(Call ? std::optional(Call)

240 : std::optional(),

241 M);

242 M->AddRef();

243 }

244

246 I->second->DropRef();

247 *I = CalledFunctions.back();

248 CalledFunctions.pop_back();

249 }

250

251

252

254

255

256

257

258

261

262private:

264

267

268 std::vector CalledFunctions;

269

270

271

272 unsigned NumReferences = 0;

273

274 void DropRef() { --NumReferences; }

275 void AddRef() { ++NumReferences; }

276

277

278 void allReferencesDropped() { NumReferences = 0; }

279};

280

281

282

283

284

285

288

290

291public:

292

294

295

296

297

299};

300

301

304

305public:

307

309

311};

312

313

315 : public PassInfoMixin {

317

318public:

320

322

324};

325

326

327

328

329

330

331

332

334 std::unique_ptr G;

335

336public:

337 static char ID;

338

341

342

343

346

349

350

352

357

358

360 return (*G)[F];

361 }

362

363

365

366

367

369 return G->getExternalCallingNode();

370 }

371

373 return G->getCallsExternalNode();

374 }

375

376

377

378

379

380

381

382

383

384

385

386

388 return G->removeFunctionFromModule(CGN);

389 }

390

391

392

394 return G->getOrInsertFunction(F);

395 }

396

397

398

399

400

401 void getAnalysisUsage(AnalysisUsage &AU) const override;

402 bool runOnModule(Module &M) override;

404

406 void dump() const;

407};

408

409

410

411

412

413

414

415

434

439

442

446

450

454

456 return N->begin();

457 }

459

461};

462

463template <>

466 std::pair<const Function *const, std::unique_ptr>;

467

471

473 return P.second.get();

474 }

475

476

479

483

487};

488

489template <>

493 std::pair<const Function *const, std::unique_ptr>;

494

498

500 return P.second.get();

501 }

502

503

506

510

514};

515

516}

517

518#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

This header defines various interfaces for pass management in LLVM.

Represent the analysis usage information of a pass.

Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...

An analysis pass to compute the CallGraph for a Module.

Definition CallGraph.h:286

CallGraph Result

A formulaic type to inform clients of the result type.

Definition CallGraph.h:293

CallGraph run(Module &M, ModuleAnalysisManager &)

Compute the CallGraph for the module M.

Definition CallGraph.h:298

A node in the call graph for a module.

Definition CallGraph.h:162

friend class CallGraph

Definition CallGraph.h:263

LLVM_ABI void print(raw_ostream &OS) const

std::vector< CallRecord >::const_iterator const_iterator

Definition CallGraph.h:190

std::vector< CallRecord > CalledFunctionsVector

Definition CallGraph.h:177

bool empty() const

Definition CallGraph.h:199

iterator begin()

Definition CallGraph.h:195

CallGraphNode(const CallGraphNode &)=delete

void addCalledFunction(CallBase *Call, CallGraphNode *M)

Adds a function to the list of functions called by this one.

Definition CallGraph.h:238

CallGraphNode(CallGraph *CG, Function *F)

Creates a node for the specified function.

Definition CallGraph.h:180

LLVM_ABI void replaceCallEdge(CallBase &Call, CallBase &NewCall, CallGraphNode *NewNode)

Replaces the edge in the node for the specified call site with a new one.

const_iterator end() const

Definition CallGraph.h:198

CallGraphNode * operator[](unsigned i) const

Returns the i'th called function.

Definition CallGraph.h:207

LLVM_ABI void dump() const

Print out this call graph node.

iterator end()

Definition CallGraph.h:196

void stealCalledFunctionsFrom(CallGraphNode *N)

Moves all the callee information from N to this node.

Definition CallGraph.h:231

~CallGraphNode()

Definition CallGraph.h:185

Function * getFunction() const

Returns the function that this call graph node represents.

Definition CallGraph.h:193

const_iterator begin() const

Definition CallGraph.h:197

LLVM_ABI void removeOneAbstractEdgeTo(CallGraphNode *Callee)

Removes one edge associated with a null callsite from this node to the specified callee function.

void removeAllCalledFunctions()

Removes all edges from this CallGraphNode to any functions it calls.

Definition CallGraph.h:223

std::vector< CallRecord >::iterator iterator

Definition CallGraph.h:189

unsigned getNumReferences() const

Returns the number of other CallGraphNodes in this CallGraph that reference this node in their callee...

Definition CallGraph.h:204

unsigned size() const

Definition CallGraph.h:200

CallGraphNode & operator=(const CallGraphNode &)=delete

void removeCallEdge(iterator I)

Definition CallGraph.h:245

std::pair< std::optional< WeakTrackingVH >, CallGraphNode * > CallRecord

A pair of the calling instruction (a call or invoke) and the call graph node being called.

Definition CallGraph.h:174

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

static bool isRequired()

Definition CallGraph.h:310

CallGraphPrinterPass(raw_ostream &OS)

Definition CallGraph.h:306

CallGraphSCCsPrinterPass(raw_ostream &OS)

Definition CallGraph.h:319

static bool isRequired()

Definition CallGraph.h:323

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

CallGraph::const_iterator const_iterator

Definition CallGraph.h:348

const CallGraph & getCallGraph() const

The internal CallGraph around which the rest of this interface is wrapped.

Definition CallGraph.h:344

const_iterator begin() const

Definition CallGraph.h:355

CallGraphNode * getCallsExternalNode() const

Definition CallGraph.h:372

const_iterator end() const

Definition CallGraph.h:356

const CallGraphNode * operator[](const Function *F) const

Returns the call graph node for the provided function.

Definition CallGraph.h:359

iterator end()

Definition CallGraph.h:354

CallGraphNode * operator[](const Function *F)

Returns the call graph node for the provided function.

Definition CallGraph.h:364

CallGraph::iterator iterator

Definition CallGraph.h:347

static char ID

Definition CallGraph.h:337

iterator begin()

Definition CallGraph.h:353

Module & getModule() const

Returns the module the call graph corresponds to.

Definition CallGraph.h:351

CallGraphNode * getOrInsertFunction(const Function *F)

Similar to operator[], but this will insert a new CallGraphNode for F if one does not already exist.

Definition CallGraph.h:393

CallGraphNode * getExternalCallingNode() const

Returns the CallGraphNode which is used to represent undetermined calls into the callgraph.

Definition CallGraph.h:368

~CallGraphWrapperPass() override

void releaseMemory() override

releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...

Function * removeFunctionFromModule(CallGraphNode *CGN)

Unlink the function from this module, returning it.

Definition CallGraph.h:387

CallGraph & getCallGraph()

Definition CallGraph.h:345

The basic data container for the call graph of a Module of IR.

Definition CallGraph.h:72

LLVM_ABI Function * removeFunctionFromModule(CallGraphNode *CGN)

Unlink the function from this module, returning it.

LLVM_ABI void print(raw_ostream &OS) const

const CallGraphNode * operator[](const Function *F) const

Returns the call graph node for the provided function.

Definition CallGraph.h:112

LLVM_ABI void dump() const

LLVM_ABI void populateCallGraphNode(CallGraphNode *CGN)

Populate CGN based on the calls inside the associated function.

LLVM_ABI void addToCallGraph(Function *F)

Add a function to the call graph, and link the node to all of the functions that it calls.

const_iterator begin() const

Definition CallGraph.h:108

iterator end()

Definition CallGraph.h:107

LLVM_ABI CallGraphNode * getOrInsertFunction(const Function *F)

Similar to operator[], but this will insert a new CallGraphNode for F if one does not already exist.

iterator begin()

Definition CallGraph.h:106

LLVM_ABI bool invalidate(Module &, const PreservedAnalyses &PA, ModuleAnalysisManager::Invalidator &)

FunctionMapTy::const_iterator const_iterator

Definition CallGraph.h:98

CallGraphNode * getCallsExternalNode() const

Definition CallGraph.h:129

Module & getModule() const

Returns the module the call graph corresponds to.

Definition CallGraph.h:101

FunctionMapTy::iterator iterator

Definition CallGraph.h:97

CallGraphNode * getExternalCallingNode() const

Returns the CallGraphNode which is used to represent undetermined calls into the callgraph.

Definition CallGraph.h:127

LLVM_ABI CallGraph(Module &M)

CallGraphNode * operator[](const Function *F)

Returns the call graph node for the provided function.

Definition CallGraph.h:119

const_iterator end() const

Definition CallGraph.h:109

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 class implements an extremely fast bulk output stream that can only output to a stream.

This is an optimization pass for GlobalISel generic memory operations.

AnalysisManager< Module > ModuleAnalysisManager

Convenience typedef for the Module analysis manager.

void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)

Implement std::swap in terms of BitVector swap.

A CRTP mix-in that provides informational APIs needed for analysis passes.

A special type used by analysis passes to provide an address that identifies that particular analysis...

CallGraphNode * NodeRef

Definition CallGraph.h:417

static NodeRef getEntryNode(CallGraphNode *CGN)

Definition CallGraph.h:420

mapped_iterator< CallGraphNode::iterator, decltype(&CGNGetValue)> ChildIteratorType

Definition CallGraph.h:423

static ChildIteratorType child_end(NodeRef N)

Definition CallGraph.h:430

static CallGraphNode * CGNGetValue(CGNPairTy P)

Definition CallGraph.h:421

CallGraphNode::CallRecord CGNPairTy

Definition CallGraph.h:418

static ChildIteratorType child_begin(NodeRef N)

Definition CallGraph.h:426

std::pair< const Function *const, std::unique_ptr< CallGraphNode > > PairTy

Definition CallGraph.h:465

static CallGraphNode * CGGetValuePtr(const PairTy &P)

Definition CallGraph.h:472

static nodes_iterator nodes_begin(CallGraph *CG)

Definition CallGraph.h:480

static nodes_iterator nodes_end(CallGraph *CG)

Definition CallGraph.h:484

mapped_iterator< CallGraph::iterator, decltype(&CGGetValuePtr)> nodes_iterator

Definition CallGraph.h:477

static NodeRef getEntryNode(CallGraph *CGN)

Definition CallGraph.h:468

static ChildIteratorType child_begin(NodeRef N)

Definition CallGraph.h:447

static ChildEdgeIteratorType child_edge_begin(NodeRef N)

Definition CallGraph.h:455

const CallGraphNode::CallRecord & EdgeRef

Definition CallGraph.h:438

CallGraphNode::CallRecord CGNPairTy

Definition CallGraph.h:437

mapped_iterator< CallGraphNode::const_iterator, decltype(&CGNGetValue)> ChildIteratorType

Definition CallGraph.h:443

static NodeRef edge_dest(EdgeRef E)

Definition CallGraph.h:460

static ChildIteratorType child_end(NodeRef N)

Definition CallGraph.h:451

const CallGraphNode * NodeRef

Definition CallGraph.h:436

static ChildEdgeIteratorType child_edge_end(NodeRef N)

Definition CallGraph.h:458

static NodeRef getEntryNode(const CallGraphNode *CGN)

Definition CallGraph.h:440

CallGraphNode::const_iterator ChildEdgeIteratorType

Definition CallGraph.h:445

static const CallGraphNode * CGNGetValue(CGNPairTy P)

Definition CallGraph.h:441

static NodeRef getEntryNode(const CallGraph *CGN)

Definition CallGraph.h:495

static nodes_iterator nodes_begin(const CallGraph *CG)

Definition CallGraph.h:507

static const CallGraphNode * CGGetValuePtr(const PairTy &P)

Definition CallGraph.h:499

static nodes_iterator nodes_end(const CallGraph *CG)

Definition CallGraph.h:511

mapped_iterator< CallGraph::const_iterator, decltype(&CGGetValuePtr)> nodes_iterator

Definition CallGraph.h:504

std::pair< const Function *const, std::unique_ptr< CallGraphNode > > PairTy

Definition CallGraph.h:492

typename CallGraph *::UnknownGraphTypeError NodeRef

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