LLVM 22.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/GlobalValue.h"
23#include "llvm/IR/PassManager.h"
25#include <unordered_map>
26
27namespace llvm {
28class Comdat;
29class Constant;
30class Function;
31class GlobalVariable;
32class Metadata;
33class Module;
34class Value;
35class ModulePass;
36
37/// Pass to remove unused function declarations.
38class GlobalDCEPass : public PassInfoMixin<GlobalDCEPass> {
39public:
40 GlobalDCEPass(bool InLTOPostLink = false) : InLTOPostLink(InLTOPostLink) {}
41
43
44 LLVM_ABI void
46 function_ref<StringRef(StringRef)> MapClassName2PassName);
47
48private:
49 bool InLTOPostLink = false;
50
52
53 /// Global -> Global that uses this global.
55
56 /// Constant -> Globals that use this global cache.
57 std::unordered_map<Constant *, SmallPtrSet<GlobalValue *, 8>>
58 ConstantDependenciesCache;
59
60 /// Comdat -> Globals in that Comdat section.
61 std::unordered_multimap<Comdat *, GlobalValue *> ComdatMembers;
62
63 /// !type metadata -> set of (vtable, offset) pairs
65 TypeIdMap;
66
67 // Global variables which are vtables, and which we have enough information
68 // about to safely do dead virtual function elimination.
69 SmallPtrSet<GlobalValue *, 32> VFESafeVTables;
70
71 void UpdateGVDependencies(GlobalValue &GV);
72 void MarkLive(GlobalValue &GV,
73 SmallVectorImpl<GlobalValue *> *Updates = nullptr);
74
75 // Dead virtual function elimination.
76 void AddVirtualFunctionDependencies(Module &M);
77 void ScanVTables(Module &M);
78 void ScanTypeCheckedLoadIntrinsics(Module &M);
79 void ScanVTableLoad(Function *Caller, Metadata *TypeId, uint64_t CallOffset);
80
81 void ComputeDependencies(Value *V, SmallPtrSetImpl<GlobalValue *> &U);
82};
83
85}
86
87#endif // LLVM_TRANSFORMS_IPO_GLOBALDCE_H
#define LLVM_ABI
Definition Compiler.h:213
This file defines the DenseMap class.
This header defines various interfaces for pass management in LLVM.
This file defines the SmallSet class.
This is an important base class in LLVM.
Definition Constant.h:43
LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
GlobalDCEPass(bool InLTOPostLink=false)
Definition GlobalDCE.h:40
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
Root of the metadata hierarchy.
Definition Metadata.h:63
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition Pass.h:255
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
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.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
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 to automatically provide informational APIs needed for passes.
Definition PassManager.h:70