LLVM 20.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"
24#include <unordered_map>
25
26namespace llvm {
27class Comdat;
28class Constant;
29class Function;
30class GlobalVariable;
31class Metadata;
32class Module;
33class Value;
34
35/// Pass to remove unused function declarations.
36class GlobalDCEPass : public PassInfoMixin<GlobalDCEPass> {
37public:
38 GlobalDCEPass(bool InLTOPostLink = false) : InLTOPostLink(InLTOPostLink) {}
39
41
43 function_ref<StringRef(StringRef)> MapClassName2PassName);
44
45private:
46 bool InLTOPostLink = false;
47
49
50 /// Global -> Global that uses this global.
52
53 /// Constant -> Globals that use this global cache.
54 std::unordered_map<Constant *, SmallPtrSet<GlobalValue *, 8>>
55 ConstantDependenciesCache;
56
57 /// Comdat -> Globals in that Comdat section.
58 std::unordered_multimap<Comdat *, GlobalValue *> ComdatMembers;
59
60 /// !type metadata -> set of (vtable, offset) pairs
62 TypeIdMap;
63
64 // Global variables which are vtables, and which we have enough information
65 // about to safely do dead virtual function elimination.
66 SmallPtrSet<GlobalValue *, 32> VFESafeVTables;
67
68 void UpdateGVDependencies(GlobalValue &GV);
69 void MarkLive(GlobalValue &GV,
70 SmallVectorImpl<GlobalValue *> *Updates = nullptr);
71
72 // Dead virtual function elimination.
73 void AddVirtualFunctionDependencies(Module &M);
74 void ScanVTables(Module &M);
75 void ScanTypeCheckedLoadIntrinsics(Module &M);
76 void ScanVTableLoad(Function *Caller, Metadata *TypeId, uint64_t CallOffset);
77
78 void ComputeDependencies(Value *V, SmallPtrSetImpl<GlobalValue *> &U);
79};
80
81}
82
83#endif // LLVM_TRANSFORMS_IPO_GLOBALDCE_H
dxil translate DXIL Translate Metadata
This file defines the DenseMap class.
This header defines various interfaces for pass management in LLVM.
Machine Check Debug Module
raw_pwrite_stream & OS
This file defines the SmallSet class.
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
Pass to remove unused function declarations.
Definition: GlobalDCE.h:36
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition: GlobalDCE.cpp:420
GlobalDCEPass(bool InLTOPostLink=false)
Definition: GlobalDCE.h:38
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
Definition: GlobalDCE.cpp:249
Root of the metadata hierarchy.
Definition: Metadata.h:62
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:363
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:519
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
LLVM Value Representation.
Definition: Value.h:74
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:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:69