]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/include/llvm/Transforms/IPO/GlobalDCE.h
MFC r355940:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / include / llvm / Transforms / IPO / GlobalDCE.h
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:
31   PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
32
33 private:
34   SmallPtrSet<GlobalValue*, 32> AliveGlobals;
35
36   /// Global -> Global that uses this global.
37   DenseMap<GlobalValue *, SmallPtrSet<GlobalValue *, 4>> GVDependencies;
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   void UpdateGVDependencies(GlobalValue &GV);
47   void MarkLive(GlobalValue &GV,
48                 SmallVectorImpl<GlobalValue *> *Updates = nullptr);
49   bool RemoveUnusedGlobalValue(GlobalValue &GV);
50
51   void ComputeDependencies(Value *V, SmallPtrSetImpl<GlobalValue *> &U);
52 };
53
54 }
55
56 #endif // LLVM_TRANSFORMS_IPO_GLOBALDCE_H