LLVM 24.0.0git
GlobalDCE.h
Go to the documentation of this file.
1//===-- GlobalDCE.h - DCE unreachable internal functions ------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This transform is designed to eliminate unreachable internal globals from the
10// program. It uses an aggressive algorithm, searching out globals that are
11// known to be alive. After it finds all of the globals which are needed, it
12// deletes whatever is left over. This allows it to delete recursive chunks of
13// the program which are unreachable.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_TRANSFORMS_IPO_GLOBALDCE_H
18#define LLVM_TRANSFORMS_IPO_GLOBALDCE_H
19
20#include "llvm/ADT/DenseMap.h"
21#include "llvm/ADT/SetVector.h"
22#include "llvm/ADT/SmallSet.h"
23#include "llvm/IR/GlobalValue.h"
24#include "llvm/IR/PassManager.h"
26#include <unordered_map>
27
28namespace llvm {
29class Comdat;
30class Constant;
31class Function;
32class GlobalVariable;
33class Metadata;
34class Module;
35class Value;
36class ModulePass;
37
38/// Pass to remove unused function declarations.
39class GlobalDCEPass : public OptionalPassInfoMixin<GlobalDCEPass> {
40public:
41 GlobalDCEPass(bool InLTOPostLink = false) : InLTOPostLink(InLTOPostLink) {}
42
44
45 LLVM_ABI void
47 function_ref<StringRef(StringRef)> MapClassName2PassName);
48
49private:
50 bool InLTOPostLink = false;
51
53
54 /// Global -> Global that uses this global.
56
57 /// Function -> (vtable, virtual function) pairs. Maps a function to the
58 /// virtual functions that it may call and their vtables. This is used to only
59 /// mark a virtual function as live when both the caller and the vtable are
60 /// live.
63 VFuncDependencies;
64
65 /// Vtable -> virtual functions that are live once the vtable is live.
66 /// If the vtable never becomes live, the virtual function is not kept
67 /// alive by this entry.
69
70 /// Constant -> Globals that use this global cache.
72
73 /// Comdat -> Globals in that Comdat section.
74 std::unordered_multimap<Comdat *, GlobalValue *> ComdatMembers;
75
76 /// !type metadata -> set of (vtable, offset) pairs
78 TypeIdMap;
79
80 // Global variables which are vtables, and which we have enough information
81 // about to safely do dead virtual function elimination.
82 SmallPtrSet<GlobalValue *, 32> VFESafeVTables;
83
84 void UpdateGVDependencies(GlobalValue &GV);
85 void MarkLive(GlobalValue &GV,
86 SmallVectorImpl<GlobalValue *> *Updates = nullptr);
87
88 // Dead virtual function elimination.
89 void AddVirtualFunctionDependencies(Module &M);
90 void ScanVTables(Module &M);
91 void ScanTypeCheckedLoadIntrinsics(Module &M);
92 void ScanVTableLoad(Function *Caller, Metadata *TypeId, uint64_t CallOffset);
93
94 void ComputeDependencies(Value *V, SmallPtrSetImpl<GlobalValue *> &U);
95};
96
98}
99
100#endif // LLVM_TRANSFORMS_IPO_GLOBALDCE_H
uint64_t uint64_t
#define LLVM_ABI
Definition Compiler.h:211
This file defines the DenseMap class.
This header defines various interfaces for pass management in LLVM.
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallSet class.
This is an important base class in LLVM.
Definition Constant.h:44
LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
GlobalDCEPass(bool InLTOPostLink=false)
Definition GlobalDCE.h:41
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
Root of the metadata hierarchy.
Definition Metadata.h:64
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition Pass.h:253
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
Definition SetVector.h:346
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LLVM Value Representation.
Definition Value.h:75
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI ModulePass * createGlobalDCEPass()
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
A CRTP mix-in for passes that can be skipped.