================ @@ -34,12 +40,223 @@ static cl::opt<bool> ClEnableVFE("enable-vfe", cl::Hidden, cl::init(true), cl::desc("Enable virtual function elimination")); +static cl::opt<std::string> ClReadSummary( + "globaldce-read-summary", + cl::desc("Read summary from given bitcode before running pass"), + cl::Hidden); + STATISTIC(NumAliases , "Number of global aliases removed"); STATISTIC(NumFunctions, "Number of functions removed"); STATISTIC(NumIFuncs, "Number of indirect functions removed"); STATISTIC(NumVariables, "Number of global variables removed"); STATISTIC(NumVFuncs, "Number of virtual functions removed"); +namespace llvm { + +// Returning a representative summary for the vtable, also set isSafe. +static const GlobalVarSummary * +getVTableFuncsForTId(const TypeIdOffsetVtableInfo &P, bool &isSafe) { + // Find a representative copy of the vtable initializer. + const GlobalVarSummary *VS = nullptr; + bool LocalFound = false; + for (auto &S : P.VTableVI.getSummaryList()) { + if (GlobalValue::isLocalLinkage(S->linkage())) { + if (LocalFound) { + isSafe = false; + return nullptr; + } + LocalFound = true; + } + auto *CurVS = cast<GlobalVarSummary>(S->getBaseObject()); + // Ignore if vTableFuncs is empty and vtable is available_externally. + if (!CurVS->vTableFuncs().empty() || + !GlobalValue::isAvailableExternallyLinkage(S->linkage())) { + VS = CurVS; + if (VS->getVCallVisibility() == GlobalObject::VCallVisibilityPublic) { + isSafe = false; + return VS; + } + } + } + + if (!VS) { + isSafe = false; + return nullptr; + } + if (!VS->isLive()) { + isSafe = true; + return nullptr; + } + isSafe = true; + return VS; +} + +static void collectSafeVTables( + ModuleSummaryIndex &Summary, + DenseMap<GlobalValue::GUID, std::vector<StringRef>> &NameByGUID, + std::map<ValueInfo, std::vector<VirtFuncOffset>> &VFESafeVTablesAndFns) { + // Update VFESafeVTablesAndFns with information from summary. + for (auto &P : Summary.typeIdCompatibleVtableMap()) { + NameByGUID[GlobalValue::getGUID(P.first)].push_back(P.first); + LLVM_DEBUG(dbgs() << "TId " << GlobalValue::getGUID(P.first) << " " + << P.first << "\n"); + } + llvm::errs() << "VFEThinLTO number of TIds: " << NameByGUID.size() << "\n"; + + // VFESafeVTablesAndFns: map from VI for vTable to VI for vfunc ---------------- teresajohnson wrote:
This comment seems to be in the wrong place, can you add a description of the below data structure (and describe VFESafeVTablesAndFns somewhere too, maybe where it is defined?) https://github.com/llvm/llvm-project/pull/69735 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits