Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:40

0001 //===-- GlobalDCE.h - DCE unreachable internal functions ------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This transform is designed to eliminate unreachable internal globals from the
0010 // program.  It uses an aggressive algorithm, searching out globals that are
0011 // known to be alive.  After it finds all of the globals which are needed, it
0012 // deletes whatever is left over.  This allows it to delete recursive chunks of
0013 // the program which are unreachable.
0014 //
0015 //===----------------------------------------------------------------------===//
0016 
0017 #ifndef LLVM_TRANSFORMS_IPO_GLOBALDCE_H
0018 #define LLVM_TRANSFORMS_IPO_GLOBALDCE_H
0019 
0020 #include "llvm/ADT/DenseMap.h"
0021 #include "llvm/ADT/SmallSet.h"
0022 #include "llvm/IR/GlobalValue.h"
0023 #include "llvm/IR/PassManager.h"
0024 #include <unordered_map>
0025 
0026 namespace llvm {
0027 class Comdat;
0028 class Constant;
0029 class Function;
0030 class GlobalVariable;
0031 class Metadata;
0032 class Module;
0033 class Value;
0034 
0035 /// Pass to remove unused function declarations.
0036 class GlobalDCEPass : public PassInfoMixin<GlobalDCEPass> {
0037 public:
0038   GlobalDCEPass(bool InLTOPostLink = false) : InLTOPostLink(InLTOPostLink) {}
0039 
0040   PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
0041 
0042   void printPipeline(raw_ostream &OS,
0043                      function_ref<StringRef(StringRef)> MapClassName2PassName);
0044 
0045 private:
0046   bool InLTOPostLink = false;
0047 
0048   SmallPtrSet<GlobalValue*, 32> AliveGlobals;
0049 
0050   /// Global -> Global that uses this global.
0051   DenseMap<GlobalValue *, SmallPtrSet<GlobalValue *, 4>> GVDependencies;
0052 
0053   /// Constant -> Globals that use this global cache.
0054   std::unordered_map<Constant *, SmallPtrSet<GlobalValue *, 8>>
0055       ConstantDependenciesCache;
0056 
0057   /// Comdat -> Globals in that Comdat section.
0058   std::unordered_multimap<Comdat *, GlobalValue *> ComdatMembers;
0059 
0060   /// !type metadata -> set of (vtable, offset) pairs
0061   DenseMap<Metadata *, SmallSet<std::pair<GlobalVariable *, uint64_t>, 4>>
0062       TypeIdMap;
0063 
0064   // Global variables which are vtables, and which we have enough information
0065   // about to safely do dead virtual function elimination.
0066   SmallPtrSet<GlobalValue *, 32> VFESafeVTables;
0067 
0068   void UpdateGVDependencies(GlobalValue &GV);
0069   void MarkLive(GlobalValue &GV,
0070                 SmallVectorImpl<GlobalValue *> *Updates = nullptr);
0071 
0072   // Dead virtual function elimination.
0073   void AddVirtualFunctionDependencies(Module &M);
0074   void ScanVTables(Module &M);
0075   void ScanTypeCheckedLoadIntrinsics(Module &M);
0076   void ScanVTableLoad(Function *Caller, Metadata *TypeId, uint64_t CallOffset);
0077 
0078   void ComputeDependencies(Value *V, SmallPtrSetImpl<GlobalValue *> &U);
0079 };
0080 
0081 }
0082 
0083 #endif // LLVM_TRANSFORMS_IPO_GLOBALDCE_H