LLVM  8.0.1
GlobalDCE.h
Go to the documentation of this file.
1 //===-- GlobalDCE.h - DCE unreachable internal functions ------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This transform is designed to eliminate unreachable internal globals from the
11 // program. It uses an aggressive algorithm, searching out globals that are
12 // known to be alive. After it finds all of the globals which are needed, it
13 // deletes whatever is left over. This allows it to delete recursive chunks of
14 // the program which are unreachable.
15 //
16 //===----------------------------------------------------------------------===//
17 
18 #ifndef LLVM_TRANSFORMS_IPO_GLOBALDCE_H
19 #define LLVM_TRANSFORMS_IPO_GLOBALDCE_H
20 
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/SmallSet.h"
23 #include "llvm/IR/Module.h"
24 #include "llvm/IR/PassManager.h"
25 #include <unordered_map>
26 
27 namespace llvm {
28 
29 /// Pass to remove unused function declarations.
30 class GlobalDCEPass : public PassInfoMixin<GlobalDCEPass> {
31 public:
33 
34 private:
35  SmallPtrSet<GlobalValue*, 32> AliveGlobals;
36 
37  /// Global -> Global that uses this global.
39 
40  /// Constant -> Globals that use this global cache.
41  std::unordered_map<Constant *, SmallPtrSet<GlobalValue *, 8>>
42  ConstantDependenciesCache;
43 
44  /// Comdat -> Globals in that Comdat section.
45  std::unordered_multimap<Comdat *, GlobalValue *> ComdatMembers;
46 
47  void UpdateGVDependencies(GlobalValue &GV);
48  void MarkLive(GlobalValue &GV,
49  SmallVectorImpl<GlobalValue *> *Updates = nullptr);
50  bool RemoveUnusedGlobalValue(GlobalValue &GV);
51 
52  void ComputeDependencies(Value *V, SmallPtrSetImpl<GlobalValue *> &U);
53 };
54 
55 }
56 
57 #endif // LLVM_TRANSFORMS_IPO_GLOBALDCE_H
This class represents lattice values for constants.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:344
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:366
Pass to remove unused function declarations.
Definition: GlobalDCE.h:30
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:154
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:418
Module.h This file contains the declarations for the Module class.
LLVM Value Representation.
Definition: Value.h:73
A container for analyses that lazily runs them and caches their results.
This header defines various interfaces for pass management in LLVM.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
Definition: GlobalDCE.cpp:142