From d39de453997d852448db9c1dd5425de7d9bd4058 Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Fri, 28 Oct 2016 02:39:38 +0000 Subject: [PATCH] [ThinLTO] Create AliasSummary when building index Summary: Previously we were creating the alias summary on the fly while writing the summary to bitcode. This moves the creation of these summaries to the module summary index builder where we build the rest of the summary index. This is going to be necessary for setting the NoRename flag for values possibly used in inline asm or module level asm. Reviewers: mehdi_amini Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D26049 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285379 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ModuleSummaryAnalysis.cpp | 30 ++++++++++++++++++++------ lib/Bitcode/Writer/BitcodeWriter.cpp | 4 +++- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/Analysis/ModuleSummaryAnalysis.cpp b/lib/Analysis/ModuleSummaryAnalysis.cpp index c107deb0a6e..f13ae844442 100644 --- a/lib/Analysis/ModuleSummaryAnalysis.cpp +++ b/lib/Analysis/ModuleSummaryAnalysis.cpp @@ -78,10 +78,9 @@ static CalleeInfo::HotnessType getHotness(uint64_t ProfileCount, static void computeFunctionSummary(ModuleSummaryIndex &Index, const Module &M, const Function &F, BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI) { - // Summary not currently supported for anonymous functions, they must - // be renamed. - if (!F.hasName()) - return; + // Summary not currently supported for anonymous functions, they should + // have been named. + assert(F.hasName()); unsigned NumInsts = 0; // Map from callee ValueId to profile count. Used to accumulate profile @@ -111,9 +110,11 @@ static void computeFunctionSummary(ModuleSummaryIndex &Index, const Module &M, } // Check if this is a direct call to a known function. if (CalledFunction) { - // Skip nameless and intrinsics. - if (!CalledFunction->hasName() || CalledFunction->isIntrinsic()) + // Skip intrinsics. + if (CalledFunction->isIntrinsic()) continue; + // We should have named any anonymous globals + assert(CalledFunction->hasName()); auto ScaledCount = BFI ? BFI->getBlockProfileCount(&BB) : None; // Use the original CalledValue, in case it was an alias. We want // to record the call edge to the alias in that case. Eventually @@ -166,6 +167,17 @@ static void computeVariableSummary(ModuleSummaryIndex &Index, Index.addGlobalValueSummary(V.getName(), std::move(GVarSummary)); } +static void computeAliasSummary(ModuleSummaryIndex &Index, + const GlobalAlias &A) { + GlobalValueSummary::GVFlags Flags(A); + std::unique_ptr AS = llvm::make_unique(Flags); + auto *Aliasee = A.getBaseObject(); + auto *AliaseeSummary = Index.getGlobalValueSummary(*Aliasee); + assert(AliaseeSummary && "Alias expects aliasee summary to be parsed"); + AS->setAliasee(AliaseeSummary); + Index.addGlobalValueSummary(A.getName(), std::move(AS)); +} + ModuleSummaryIndex llvm::buildModuleSummaryIndex( const Module &M, std::function GetBFICallback, @@ -204,6 +216,12 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex( continue; computeVariableSummary(Index, G); } + + // Compute summaries for all aliases defined in module, and save in the + // index. + for (const GlobalAlias &A : M.aliases()) + computeAliasSummary(Index, A); + return Index; } diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 2972688992f..62008c42d3d 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -3434,7 +3434,9 @@ void ModuleBitcodeWriter::writePerModuleGlobalValueSummary() { auto AliasId = VE.getValueID(&A); auto AliaseeId = VE.getValueID(Aliasee); NameVals.push_back(AliasId); - NameVals.push_back(getEncodedGVSummaryFlags(A)); + auto *Summary = Index->getGlobalValueSummary(A); + AliasSummary *AS = cast(Summary); + NameVals.push_back(getEncodedGVSummaryFlags(AS->flags())); NameVals.push_back(AliaseeId); Stream.EmitRecord(bitc::FS_ALIAS, NameVals, FSAliasAbbrev); NameVals.clear(); -- 2.49.0