LLVM 17.0.0git
StripDeadPrototypes.cpp
Go to the documentation of this file.
1//===-- StripDeadPrototypes.cpp - Remove unused function declarations ----===//
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 pass loops over all of the functions in the input module, looking for
10// dead declarations and removes them. Dead declarations are declarations of
11// functions for which no implementation is available (i.e., declarations for
12// unused library functions).
13//
14//===----------------------------------------------------------------------===//
15
17#include "llvm/ADT/Statistic.h"
18#include "llvm/IR/Module.h"
20#include "llvm/Pass.h"
21#include "llvm/Transforms/IPO.h"
22
23using namespace llvm;
24
25#define DEBUG_TYPE "strip-dead-prototypes"
26
27STATISTIC(NumDeadPrototypes, "Number of dead prototypes removed");
28
29static bool stripDeadPrototypes(Module &M) {
30 bool MadeChange = false;
31
32 // Erase dead function prototypes.
34 // Function must be a prototype and unused.
35 if (F.isDeclaration() && F.use_empty()) {
36 F.eraseFromParent();
37 ++NumDeadPrototypes;
38 MadeChange = true;
39 }
40 }
41
42 // Erase dead global var prototypes.
43 for (GlobalVariable &GV : llvm::make_early_inc_range(M.globals())) {
44 // Global must be a prototype and unused.
45 if (GV.isDeclaration() && GV.use_empty())
46 GV.eraseFromParent();
47 }
48
49 // Return an indication of whether we changed anything or not.
50 return MadeChange;
51}
52
58}
#define F(x, y, z)
Definition: MD5.cpp:55
Module.h This file contains the declarations for the Module class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition: Statistic.h:167
static bool stripDeadPrototypes(Module &M)
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:620
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: PassManager.h:152
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: PassManager.h:155
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:158
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition: STLExtras.h:732
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)