1//===-- GlobalDCE.h - DCE unreachable internal functions ------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This transform is designed to eliminate unreachable internal globals from the 11// program. It uses an aggressive algorithm, searching out globals that are 12// known to be alive. After it finds all of the globals which are needed, it 13// deletes whatever is left over. This allows it to delete recursive chunks of 14// the program which are unreachable. 15// 16//===----------------------------------------------------------------------===// 17 18#ifndef LLVM_TRANSFORMS_IPO_GLOBALDCE_H 19#define LLVM_TRANSFORMS_IPO_GLOBALDCE_H 20 21#include "llvm/IR/Module.h" 22#include "llvm/IR/PassManager.h" 23#include <unordered_map> 24 25namespace llvm { 26 27/// Pass to remove unused function declarations. 28class GlobalDCEPass : public PassInfoMixin<GlobalDCEPass> { 29public: 30 PreservedAnalyses run(Module &M, ModuleAnalysisManager &); 31 32private: 33 SmallPtrSet<GlobalValue*, 32> AliveGlobals; 34 SmallPtrSet<Constant *, 8> SeenConstants; 35 std::unordered_multimap<Comdat *, GlobalValue *> ComdatMembers; 36 37 /// Mark the specific global value as needed, and 38 /// recursively mark anything that it uses as also needed. 39 void GlobalIsNeeded(GlobalValue *GV); 40 void MarkUsedGlobalsAsNeeded(Constant *C); 41 bool RemoveUnusedGlobalValue(GlobalValue &GV); 42}; 43 44} 45 46#endif // LLVM_TRANSFORMS_IPO_GLOBALDCE_H 47