LLVM  14.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/SmallSet.h"
22 #include "llvm/IR/Module.h"
23 #include "llvm/IR/PassManager.h"
24 #include <unordered_map>
25 
26 namespace llvm {
27 
28 /// Pass to remove unused function declarations.
29 class GlobalDCEPass : public PassInfoMixin<GlobalDCEPass> {
30 public:
32 
33 private:
34  SmallPtrSet<GlobalValue*, 32> AliveGlobals;
35 
36  /// Global -> Global that uses this global.
38 
39  /// Constant -> Globals that use this global cache.
40  std::unordered_map<Constant *, SmallPtrSet<GlobalValue *, 8>>
41  ConstantDependenciesCache;
42 
43  /// Comdat -> Globals in that Comdat section.
44  std::unordered_multimap<Comdat *, GlobalValue *> ComdatMembers;
45 
46  /// !type metadata -> set of (vtable, offset) pairs
48  TypeIdMap;
49 
50  // Global variables which are vtables, and which we have enough information
51  // about to safely do dead virtual function elimination.
52  SmallPtrSet<GlobalValue *, 32> VFESafeVTables;
53 
54  void UpdateGVDependencies(GlobalValue &GV);
55  void MarkLive(GlobalValue &GV,
56  SmallVectorImpl<GlobalValue *> *Updates = nullptr);
57  bool RemoveUnusedGlobalValue(GlobalValue &GV);
58 
59  // Dead virtual function elimination.
60  void AddVirtualFunctionDependencies(Module &M);
61  void ScanVTables(Module &M);
62  void ScanTypeCheckedLoadIntrinsics(Module &M);
63  void ScanVTableLoad(Function *Caller, Metadata *TypeId, uint64_t CallOffset);
64 
65  void ComputeDependencies(Value *V, SmallPtrSetImpl<GlobalValue *> &U);
66 };
67 
68 }
69 
70 #endif // LLVM_TRANSFORMS_IPO_GLOBALDCE_H
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::PassInfoMixin
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:374
llvm::Function
Definition: Function.h:61
DenseMap.h
Module.h
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:449
llvm::Metadata
Root of the metadata hierarchy.
Definition: Metadata.h:62
llvm::GlobalValue
Definition: GlobalValue.h:44
uint64_t
llvm::DenseMap
Definition: DenseMap.h:714
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::GlobalDCEPass
Pass to remove unused function declarations.
Definition: GlobalDCE.h:29
PassManager.h
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:43
llvm::SmallPtrSetImpl
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:343
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
llvm::GlobalDCEPass::run
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
Definition: GlobalDCE.cpp:289
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
SmallSet.h