LLVM  4.0.0
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/IR/Module.h"
22 #include "llvm/IR/PassManager.h"
23 #include <unordered_map>
24 
25 namespace llvm {
26 
27 /// Pass to remove unused function declarations.
28 class GlobalDCEPass : public PassInfoMixin<GlobalDCEPass> {
29 public:
31 
32 private:
33  SmallPtrSet<GlobalValue*, 32> AliveGlobals;
34  SmallPtrSet<Constant *, 8> SeenConstants;
35  std::unordered_multimap<Comdat *, GlobalValue *> ComdatMembers;
36 
37  /// Mark the specific global value as needed, and
38  /// recursively mark anything that it uses as also needed.
39  void GlobalIsNeeded(GlobalValue *GV);
40  void MarkUsedGlobalsAsNeeded(Constant *C);
41  bool RemoveUnusedGlobalValue(GlobalValue &GV);
42 };
43 
44 }
45 
46 #endif // LLVM_TRANSFORMS_IPO_GLOBALDCE_H
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:52
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:311
Pass to remove unused function declarations.
Definition: GlobalDCE.h:28
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:107
This is an important base class in LLVM.
Definition: Constant.h:42
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:425
Module.h This file contains the declarations for the Module class.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
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:81