xref: /aosp_15_r20/external/llvm/lib/Transforms/IPO/GlobalDCE.cpp (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===-- GlobalDCE.cpp - DCE unreachable internal functions ----------------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This transform is designed to eliminate unreachable internal globals from the
11*9880d681SAndroid Build Coastguard Worker // program.  It uses an aggressive algorithm, searching out globals that are
12*9880d681SAndroid Build Coastguard Worker // known to be alive.  After it finds all of the globals which are needed, it
13*9880d681SAndroid Build Coastguard Worker // deletes whatever is left over.  This allows it to delete recursive chunks of
14*9880d681SAndroid Build Coastguard Worker // the program which are unreachable.
15*9880d681SAndroid Build Coastguard Worker //
16*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
17*9880d681SAndroid Build Coastguard Worker 
18*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/IPO/GlobalDCE.h"
19*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/SmallPtrSet.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/Statistic.h"
21*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/Constants.h"
22*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/Instructions.h"
23*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/Module.h"
24*9880d681SAndroid Build Coastguard Worker #include "llvm/Pass.h"
25*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/IPO.h"
26*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/Utils/CtorUtils.h"
27*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/Utils/GlobalStatus.h"
28*9880d681SAndroid Build Coastguard Worker #include <unordered_map>
29*9880d681SAndroid Build Coastguard Worker using namespace llvm;
30*9880d681SAndroid Build Coastguard Worker 
31*9880d681SAndroid Build Coastguard Worker #define DEBUG_TYPE "globaldce"
32*9880d681SAndroid Build Coastguard Worker 
33*9880d681SAndroid Build Coastguard Worker STATISTIC(NumAliases  , "Number of global aliases removed");
34*9880d681SAndroid Build Coastguard Worker STATISTIC(NumFunctions, "Number of functions removed");
35*9880d681SAndroid Build Coastguard Worker STATISTIC(NumIFuncs,    "Number of indirect functions removed");
36*9880d681SAndroid Build Coastguard Worker STATISTIC(NumVariables, "Number of global variables removed");
37*9880d681SAndroid Build Coastguard Worker 
38*9880d681SAndroid Build Coastguard Worker namespace {
39*9880d681SAndroid Build Coastguard Worker   class GlobalDCELegacyPass : public ModulePass {
40*9880d681SAndroid Build Coastguard Worker   public:
41*9880d681SAndroid Build Coastguard Worker     static char ID; // Pass identification, replacement for typeid
GlobalDCELegacyPass()42*9880d681SAndroid Build Coastguard Worker     GlobalDCELegacyPass() : ModulePass(ID) {
43*9880d681SAndroid Build Coastguard Worker       initializeGlobalDCELegacyPassPass(*PassRegistry::getPassRegistry());
44*9880d681SAndroid Build Coastguard Worker     }
45*9880d681SAndroid Build Coastguard Worker 
46*9880d681SAndroid Build Coastguard Worker     // run - Do the GlobalDCE pass on the specified module, optionally updating
47*9880d681SAndroid Build Coastguard Worker     // the specified callgraph to reflect the changes.
48*9880d681SAndroid Build Coastguard Worker     //
runOnModule(Module & M)49*9880d681SAndroid Build Coastguard Worker     bool runOnModule(Module &M) override {
50*9880d681SAndroid Build Coastguard Worker       if (skipModule(M))
51*9880d681SAndroid Build Coastguard Worker         return false;
52*9880d681SAndroid Build Coastguard Worker 
53*9880d681SAndroid Build Coastguard Worker       ModuleAnalysisManager DummyMAM;
54*9880d681SAndroid Build Coastguard Worker       auto PA = Impl.run(M, DummyMAM);
55*9880d681SAndroid Build Coastguard Worker       return !PA.areAllPreserved();
56*9880d681SAndroid Build Coastguard Worker     }
57*9880d681SAndroid Build Coastguard Worker 
58*9880d681SAndroid Build Coastguard Worker   private:
59*9880d681SAndroid Build Coastguard Worker     GlobalDCEPass Impl;
60*9880d681SAndroid Build Coastguard Worker   };
61*9880d681SAndroid Build Coastguard Worker }
62*9880d681SAndroid Build Coastguard Worker 
63*9880d681SAndroid Build Coastguard Worker char GlobalDCELegacyPass::ID = 0;
64*9880d681SAndroid Build Coastguard Worker INITIALIZE_PASS(GlobalDCELegacyPass, "globaldce",
65*9880d681SAndroid Build Coastguard Worker                 "Dead Global Elimination", false, false)
66*9880d681SAndroid Build Coastguard Worker 
67*9880d681SAndroid Build Coastguard Worker // Public interface to the GlobalDCEPass.
createGlobalDCEPass()68*9880d681SAndroid Build Coastguard Worker ModulePass *llvm::createGlobalDCEPass() {
69*9880d681SAndroid Build Coastguard Worker   return new GlobalDCELegacyPass();
70*9880d681SAndroid Build Coastguard Worker }
71*9880d681SAndroid Build Coastguard Worker 
72*9880d681SAndroid Build Coastguard Worker /// Returns true if F contains only a single "ret" instruction.
isEmptyFunction(Function * F)73*9880d681SAndroid Build Coastguard Worker static bool isEmptyFunction(Function *F) {
74*9880d681SAndroid Build Coastguard Worker   BasicBlock &Entry = F->getEntryBlock();
75*9880d681SAndroid Build Coastguard Worker   if (Entry.size() != 1 || !isa<ReturnInst>(Entry.front()))
76*9880d681SAndroid Build Coastguard Worker     return false;
77*9880d681SAndroid Build Coastguard Worker   ReturnInst &RI = cast<ReturnInst>(Entry.front());
78*9880d681SAndroid Build Coastguard Worker   return RI.getReturnValue() == nullptr;
79*9880d681SAndroid Build Coastguard Worker }
80*9880d681SAndroid Build Coastguard Worker 
run(Module & M,ModuleAnalysisManager &)81*9880d681SAndroid Build Coastguard Worker PreservedAnalyses GlobalDCEPass::run(Module &M, ModuleAnalysisManager &) {
82*9880d681SAndroid Build Coastguard Worker   bool Changed = false;
83*9880d681SAndroid Build Coastguard Worker 
84*9880d681SAndroid Build Coastguard Worker   // Remove empty functions from the global ctors list.
85*9880d681SAndroid Build Coastguard Worker   Changed |= optimizeGlobalCtorsList(M, isEmptyFunction);
86*9880d681SAndroid Build Coastguard Worker 
87*9880d681SAndroid Build Coastguard Worker   // Collect the set of members for each comdat.
88*9880d681SAndroid Build Coastguard Worker   for (Function &F : M)
89*9880d681SAndroid Build Coastguard Worker     if (Comdat *C = F.getComdat())
90*9880d681SAndroid Build Coastguard Worker       ComdatMembers.insert(std::make_pair(C, &F));
91*9880d681SAndroid Build Coastguard Worker   for (GlobalVariable &GV : M.globals())
92*9880d681SAndroid Build Coastguard Worker     if (Comdat *C = GV.getComdat())
93*9880d681SAndroid Build Coastguard Worker       ComdatMembers.insert(std::make_pair(C, &GV));
94*9880d681SAndroid Build Coastguard Worker   for (GlobalAlias &GA : M.aliases())
95*9880d681SAndroid Build Coastguard Worker     if (Comdat *C = GA.getComdat())
96*9880d681SAndroid Build Coastguard Worker       ComdatMembers.insert(std::make_pair(C, &GA));
97*9880d681SAndroid Build Coastguard Worker 
98*9880d681SAndroid Build Coastguard Worker   // Loop over the module, adding globals which are obviously necessary.
99*9880d681SAndroid Build Coastguard Worker   for (GlobalObject &GO : M.global_objects()) {
100*9880d681SAndroid Build Coastguard Worker     Changed |= RemoveUnusedGlobalValue(GO);
101*9880d681SAndroid Build Coastguard Worker     // Functions with external linkage are needed if they have a body.
102*9880d681SAndroid Build Coastguard Worker     // Externally visible & appending globals are needed, if they have an
103*9880d681SAndroid Build Coastguard Worker     // initializer.
104*9880d681SAndroid Build Coastguard Worker     if (!GO.isDeclaration() && !GO.hasAvailableExternallyLinkage())
105*9880d681SAndroid Build Coastguard Worker       if (!GO.isDiscardableIfUnused())
106*9880d681SAndroid Build Coastguard Worker         GlobalIsNeeded(&GO);
107*9880d681SAndroid Build Coastguard Worker   }
108*9880d681SAndroid Build Coastguard Worker 
109*9880d681SAndroid Build Coastguard Worker   for (GlobalAlias &GA : M.aliases()) {
110*9880d681SAndroid Build Coastguard Worker     Changed |= RemoveUnusedGlobalValue(GA);
111*9880d681SAndroid Build Coastguard Worker     // Externally visible aliases are needed.
112*9880d681SAndroid Build Coastguard Worker     if (!GA.isDiscardableIfUnused())
113*9880d681SAndroid Build Coastguard Worker       GlobalIsNeeded(&GA);
114*9880d681SAndroid Build Coastguard Worker   }
115*9880d681SAndroid Build Coastguard Worker 
116*9880d681SAndroid Build Coastguard Worker   for (GlobalIFunc &GIF : M.ifuncs()) {
117*9880d681SAndroid Build Coastguard Worker     Changed |= RemoveUnusedGlobalValue(GIF);
118*9880d681SAndroid Build Coastguard Worker     // Externally visible ifuncs are needed.
119*9880d681SAndroid Build Coastguard Worker     if (!GIF.isDiscardableIfUnused())
120*9880d681SAndroid Build Coastguard Worker       GlobalIsNeeded(&GIF);
121*9880d681SAndroid Build Coastguard Worker   }
122*9880d681SAndroid Build Coastguard Worker 
123*9880d681SAndroid Build Coastguard Worker   // Now that all globals which are needed are in the AliveGlobals set, we loop
124*9880d681SAndroid Build Coastguard Worker   // through the program, deleting those which are not alive.
125*9880d681SAndroid Build Coastguard Worker   //
126*9880d681SAndroid Build Coastguard Worker 
127*9880d681SAndroid Build Coastguard Worker   // The first pass is to drop initializers of global variables which are dead.
128*9880d681SAndroid Build Coastguard Worker   std::vector<GlobalVariable *> DeadGlobalVars; // Keep track of dead globals
129*9880d681SAndroid Build Coastguard Worker   for (GlobalVariable &GV : M.globals())
130*9880d681SAndroid Build Coastguard Worker     if (!AliveGlobals.count(&GV)) {
131*9880d681SAndroid Build Coastguard Worker       DeadGlobalVars.push_back(&GV);         // Keep track of dead globals
132*9880d681SAndroid Build Coastguard Worker       if (GV.hasInitializer()) {
133*9880d681SAndroid Build Coastguard Worker         Constant *Init = GV.getInitializer();
134*9880d681SAndroid Build Coastguard Worker         GV.setInitializer(nullptr);
135*9880d681SAndroid Build Coastguard Worker         if (isSafeToDestroyConstant(Init))
136*9880d681SAndroid Build Coastguard Worker           Init->destroyConstant();
137*9880d681SAndroid Build Coastguard Worker       }
138*9880d681SAndroid Build Coastguard Worker     }
139*9880d681SAndroid Build Coastguard Worker 
140*9880d681SAndroid Build Coastguard Worker   // The second pass drops the bodies of functions which are dead...
141*9880d681SAndroid Build Coastguard Worker   std::vector<Function *> DeadFunctions;
142*9880d681SAndroid Build Coastguard Worker   for (Function &F : M)
143*9880d681SAndroid Build Coastguard Worker     if (!AliveGlobals.count(&F)) {
144*9880d681SAndroid Build Coastguard Worker       DeadFunctions.push_back(&F);         // Keep track of dead globals
145*9880d681SAndroid Build Coastguard Worker       if (!F.isDeclaration())
146*9880d681SAndroid Build Coastguard Worker         F.deleteBody();
147*9880d681SAndroid Build Coastguard Worker     }
148*9880d681SAndroid Build Coastguard Worker 
149*9880d681SAndroid Build Coastguard Worker   // The third pass drops targets of aliases which are dead...
150*9880d681SAndroid Build Coastguard Worker   std::vector<GlobalAlias*> DeadAliases;
151*9880d681SAndroid Build Coastguard Worker   for (GlobalAlias &GA : M.aliases())
152*9880d681SAndroid Build Coastguard Worker     if (!AliveGlobals.count(&GA)) {
153*9880d681SAndroid Build Coastguard Worker       DeadAliases.push_back(&GA);
154*9880d681SAndroid Build Coastguard Worker       GA.setAliasee(nullptr);
155*9880d681SAndroid Build Coastguard Worker     }
156*9880d681SAndroid Build Coastguard Worker 
157*9880d681SAndroid Build Coastguard Worker   // The third pass drops targets of ifuncs which are dead...
158*9880d681SAndroid Build Coastguard Worker   std::vector<GlobalIFunc*> DeadIFuncs;
159*9880d681SAndroid Build Coastguard Worker   for (GlobalIFunc &GIF : M.ifuncs())
160*9880d681SAndroid Build Coastguard Worker     if (!AliveGlobals.count(&GIF)) {
161*9880d681SAndroid Build Coastguard Worker       DeadIFuncs.push_back(&GIF);
162*9880d681SAndroid Build Coastguard Worker       GIF.setResolver(nullptr);
163*9880d681SAndroid Build Coastguard Worker     }
164*9880d681SAndroid Build Coastguard Worker 
165*9880d681SAndroid Build Coastguard Worker   if (!DeadFunctions.empty()) {
166*9880d681SAndroid Build Coastguard Worker     // Now that all interferences have been dropped, delete the actual objects
167*9880d681SAndroid Build Coastguard Worker     // themselves.
168*9880d681SAndroid Build Coastguard Worker     for (Function *F : DeadFunctions) {
169*9880d681SAndroid Build Coastguard Worker       RemoveUnusedGlobalValue(*F);
170*9880d681SAndroid Build Coastguard Worker       M.getFunctionList().erase(F);
171*9880d681SAndroid Build Coastguard Worker     }
172*9880d681SAndroid Build Coastguard Worker     NumFunctions += DeadFunctions.size();
173*9880d681SAndroid Build Coastguard Worker     Changed = true;
174*9880d681SAndroid Build Coastguard Worker   }
175*9880d681SAndroid Build Coastguard Worker 
176*9880d681SAndroid Build Coastguard Worker   if (!DeadGlobalVars.empty()) {
177*9880d681SAndroid Build Coastguard Worker     for (GlobalVariable *GV : DeadGlobalVars) {
178*9880d681SAndroid Build Coastguard Worker       RemoveUnusedGlobalValue(*GV);
179*9880d681SAndroid Build Coastguard Worker       M.getGlobalList().erase(GV);
180*9880d681SAndroid Build Coastguard Worker     }
181*9880d681SAndroid Build Coastguard Worker     NumVariables += DeadGlobalVars.size();
182*9880d681SAndroid Build Coastguard Worker     Changed = true;
183*9880d681SAndroid Build Coastguard Worker   }
184*9880d681SAndroid Build Coastguard Worker 
185*9880d681SAndroid Build Coastguard Worker   // Now delete any dead aliases.
186*9880d681SAndroid Build Coastguard Worker   if (!DeadAliases.empty()) {
187*9880d681SAndroid Build Coastguard Worker     for (GlobalAlias *GA : DeadAliases) {
188*9880d681SAndroid Build Coastguard Worker       RemoveUnusedGlobalValue(*GA);
189*9880d681SAndroid Build Coastguard Worker       M.getAliasList().erase(GA);
190*9880d681SAndroid Build Coastguard Worker     }
191*9880d681SAndroid Build Coastguard Worker     NumAliases += DeadAliases.size();
192*9880d681SAndroid Build Coastguard Worker     Changed = true;
193*9880d681SAndroid Build Coastguard Worker   }
194*9880d681SAndroid Build Coastguard Worker 
195*9880d681SAndroid Build Coastguard Worker   // Now delete any dead aliases.
196*9880d681SAndroid Build Coastguard Worker   if (!DeadIFuncs.empty()) {
197*9880d681SAndroid Build Coastguard Worker     for (GlobalIFunc *GIF : DeadIFuncs) {
198*9880d681SAndroid Build Coastguard Worker       RemoveUnusedGlobalValue(*GIF);
199*9880d681SAndroid Build Coastguard Worker       M.getIFuncList().erase(GIF);
200*9880d681SAndroid Build Coastguard Worker     }
201*9880d681SAndroid Build Coastguard Worker     NumIFuncs += DeadIFuncs.size();
202*9880d681SAndroid Build Coastguard Worker     Changed = true;
203*9880d681SAndroid Build Coastguard Worker   }
204*9880d681SAndroid Build Coastguard Worker 
205*9880d681SAndroid Build Coastguard Worker   // Make sure that all memory is released
206*9880d681SAndroid Build Coastguard Worker   AliveGlobals.clear();
207*9880d681SAndroid Build Coastguard Worker   SeenConstants.clear();
208*9880d681SAndroid Build Coastguard Worker   ComdatMembers.clear();
209*9880d681SAndroid Build Coastguard Worker 
210*9880d681SAndroid Build Coastguard Worker   if (Changed)
211*9880d681SAndroid Build Coastguard Worker     return PreservedAnalyses::none();
212*9880d681SAndroid Build Coastguard Worker   return PreservedAnalyses::all();
213*9880d681SAndroid Build Coastguard Worker }
214*9880d681SAndroid Build Coastguard Worker 
215*9880d681SAndroid Build Coastguard Worker /// GlobalIsNeeded - the specific global value as needed, and
216*9880d681SAndroid Build Coastguard Worker /// recursively mark anything that it uses as also needed.
GlobalIsNeeded(GlobalValue * G)217*9880d681SAndroid Build Coastguard Worker void GlobalDCEPass::GlobalIsNeeded(GlobalValue *G) {
218*9880d681SAndroid Build Coastguard Worker   // If the global is already in the set, no need to reprocess it.
219*9880d681SAndroid Build Coastguard Worker   if (!AliveGlobals.insert(G).second)
220*9880d681SAndroid Build Coastguard Worker     return;
221*9880d681SAndroid Build Coastguard Worker 
222*9880d681SAndroid Build Coastguard Worker   if (Comdat *C = G->getComdat()) {
223*9880d681SAndroid Build Coastguard Worker     for (auto &&CM : make_range(ComdatMembers.equal_range(C)))
224*9880d681SAndroid Build Coastguard Worker       GlobalIsNeeded(CM.second);
225*9880d681SAndroid Build Coastguard Worker   }
226*9880d681SAndroid Build Coastguard Worker 
227*9880d681SAndroid Build Coastguard Worker   if (GlobalVariable *GV = dyn_cast<GlobalVariable>(G)) {
228*9880d681SAndroid Build Coastguard Worker     // If this is a global variable, we must make sure to add any global values
229*9880d681SAndroid Build Coastguard Worker     // referenced by the initializer to the alive set.
230*9880d681SAndroid Build Coastguard Worker     if (GV->hasInitializer())
231*9880d681SAndroid Build Coastguard Worker       MarkUsedGlobalsAsNeeded(GV->getInitializer());
232*9880d681SAndroid Build Coastguard Worker   } else if (GlobalIndirectSymbol *GIS = dyn_cast<GlobalIndirectSymbol>(G)) {
233*9880d681SAndroid Build Coastguard Worker     // The target of a global alias or ifunc is needed.
234*9880d681SAndroid Build Coastguard Worker     MarkUsedGlobalsAsNeeded(GIS->getIndirectSymbol());
235*9880d681SAndroid Build Coastguard Worker   } else {
236*9880d681SAndroid Build Coastguard Worker     // Otherwise this must be a function object.  We have to scan the body of
237*9880d681SAndroid Build Coastguard Worker     // the function looking for constants and global values which are used as
238*9880d681SAndroid Build Coastguard Worker     // operands.  Any operands of these types must be processed to ensure that
239*9880d681SAndroid Build Coastguard Worker     // any globals used will be marked as needed.
240*9880d681SAndroid Build Coastguard Worker     Function *F = cast<Function>(G);
241*9880d681SAndroid Build Coastguard Worker 
242*9880d681SAndroid Build Coastguard Worker     for (Use &U : F->operands())
243*9880d681SAndroid Build Coastguard Worker       MarkUsedGlobalsAsNeeded(cast<Constant>(U.get()));
244*9880d681SAndroid Build Coastguard Worker 
245*9880d681SAndroid Build Coastguard Worker     for (BasicBlock &BB : *F)
246*9880d681SAndroid Build Coastguard Worker       for (Instruction &I : BB)
247*9880d681SAndroid Build Coastguard Worker         for (Use &U : I.operands())
248*9880d681SAndroid Build Coastguard Worker           if (GlobalValue *GV = dyn_cast<GlobalValue>(U))
249*9880d681SAndroid Build Coastguard Worker             GlobalIsNeeded(GV);
250*9880d681SAndroid Build Coastguard Worker           else if (Constant *C = dyn_cast<Constant>(U))
251*9880d681SAndroid Build Coastguard Worker             MarkUsedGlobalsAsNeeded(C);
252*9880d681SAndroid Build Coastguard Worker   }
253*9880d681SAndroid Build Coastguard Worker }
254*9880d681SAndroid Build Coastguard Worker 
MarkUsedGlobalsAsNeeded(Constant * C)255*9880d681SAndroid Build Coastguard Worker void GlobalDCEPass::MarkUsedGlobalsAsNeeded(Constant *C) {
256*9880d681SAndroid Build Coastguard Worker   if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
257*9880d681SAndroid Build Coastguard Worker     return GlobalIsNeeded(GV);
258*9880d681SAndroid Build Coastguard Worker 
259*9880d681SAndroid Build Coastguard Worker   // Loop over all of the operands of the constant, adding any globals they
260*9880d681SAndroid Build Coastguard Worker   // use to the list of needed globals.
261*9880d681SAndroid Build Coastguard Worker   for (Use &U : C->operands()) {
262*9880d681SAndroid Build Coastguard Worker     // If we've already processed this constant there's no need to do it again.
263*9880d681SAndroid Build Coastguard Worker     Constant *Op = dyn_cast<Constant>(U);
264*9880d681SAndroid Build Coastguard Worker     if (Op && SeenConstants.insert(Op).second)
265*9880d681SAndroid Build Coastguard Worker       MarkUsedGlobalsAsNeeded(Op);
266*9880d681SAndroid Build Coastguard Worker   }
267*9880d681SAndroid Build Coastguard Worker }
268*9880d681SAndroid Build Coastguard Worker 
269*9880d681SAndroid Build Coastguard Worker // RemoveUnusedGlobalValue - Loop over all of the uses of the specified
270*9880d681SAndroid Build Coastguard Worker // GlobalValue, looking for the constant pointer ref that may be pointing to it.
271*9880d681SAndroid Build Coastguard Worker // If found, check to see if the constant pointer ref is safe to destroy, and if
272*9880d681SAndroid Build Coastguard Worker // so, nuke it.  This will reduce the reference count on the global value, which
273*9880d681SAndroid Build Coastguard Worker // might make it deader.
274*9880d681SAndroid Build Coastguard Worker //
RemoveUnusedGlobalValue(GlobalValue & GV)275*9880d681SAndroid Build Coastguard Worker bool GlobalDCEPass::RemoveUnusedGlobalValue(GlobalValue &GV) {
276*9880d681SAndroid Build Coastguard Worker   if (GV.use_empty())
277*9880d681SAndroid Build Coastguard Worker     return false;
278*9880d681SAndroid Build Coastguard Worker   GV.removeDeadConstantUsers();
279*9880d681SAndroid Build Coastguard Worker   return GV.use_empty();
280*9880d681SAndroid Build Coastguard Worker }
281