Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
Show First 20 Lines • Show All 228 Lines • ▼ Show 20 Lines | |||||
static bool isNonVolatileStore(const Instruction *I) { | static bool isNonVolatileStore(const Instruction *I) { | ||||
if (const auto *SI = dyn_cast<StoreInst>(I)) | if (const auto *SI = dyn_cast<StoreInst>(I)) | ||||
return !SI->isVolatile(); | return !SI->isVolatile(); | ||||
return false; | return false; | ||||
} | } | ||||
// Returns true if `F` must be an unreachable function. | |||||
static bool mustBeUnreachableFunction(const Function &F) { | |||||
if (!F.empty()) { | |||||
const BasicBlock &entryBlock = F.getEntryBlock(); | |||||
if (!entryBlock.empty()) { | |||||
const Instruction *inst = &(*entryBlock.rbegin()); | |||||
if (inst->getOpcode() == Instruction::Unreachable) { | |||||
// TODO(mingmingl): delete | |||||
errs() << "unreachable function: "; | |||||
F.dump(); | |||||
errs() << "\n"; | |||||
return true; | |||||
} | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
static void computeFunctionSummary( | static void computeFunctionSummary( | ||||
ModuleSummaryIndex &Index, const Module &M, const Function &F, | ModuleSummaryIndex &Index, const Module &M, const Function &F, | ||||
BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI, DominatorTree &DT, | BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI, DominatorTree &DT, | ||||
bool HasLocalsInUsedOrAsm, DenseSet<GlobalValue::GUID> &CantBePromoted, | bool HasLocalsInUsedOrAsm, DenseSet<GlobalValue::GUID> &CantBePromoted, | ||||
bool IsThinLTO, | bool IsThinLTO, | ||||
std::function<const StackSafetyInfo *(const Function &F)> GetSSICallback) { | std::function<const StackSafetyInfo *(const Function &F)> GetSSICallback) { | ||||
// Summary not currently supported for anonymous functions, they should | // Summary not currently supported for anonymous functions, they should | ||||
// have been named. | // have been named. | ||||
▲ Show 20 Lines • Show All 247 Lines • ▼ Show 20 Lines | static void computeFunctionSummary( | ||||
std::vector<FunctionSummary::ParamAccess> ParamAccesses; | std::vector<FunctionSummary::ParamAccess> ParamAccesses; | ||||
if (auto *SSI = GetSSICallback(F)) | if (auto *SSI = GetSSICallback(F)) | ||||
ParamAccesses = SSI->getParamAccesses(Index); | ParamAccesses = SSI->getParamAccesses(Index); | ||||
auto FuncSummary = std::make_unique<FunctionSummary>( | auto FuncSummary = std::make_unique<FunctionSummary>( | ||||
Flags, NumInsts, FunFlags, /*EntryCount=*/0, std::move(Refs), | Flags, NumInsts, FunFlags, /*EntryCount=*/0, std::move(Refs), | ||||
CallGraphEdges.takeVector(), TypeTests.takeVector(), | CallGraphEdges.takeVector(), TypeTests.takeVector(), | ||||
TypeTestAssumeVCalls.takeVector(), TypeCheckedLoadVCalls.takeVector(), | TypeTestAssumeVCalls.takeVector(), TypeCheckedLoadVCalls.takeVector(), | ||||
TypeTestAssumeConstVCalls.takeVector(), | TypeTestAssumeConstVCalls.takeVector(), | ||||
TypeCheckedLoadConstVCalls.takeVector(), std::move(ParamAccesses)); | TypeCheckedLoadConstVCalls.takeVector(), std::move(ParamAccesses), | ||||
mustBeUnreachableFunction(F)); | |||||
if (NonRenamableLocal) | if (NonRenamableLocal) | ||||
CantBePromoted.insert(F.getGUID()); | CantBePromoted.insert(F.getGUID()); | ||||
errs() << "Going to add F " << F.getName() | |||||
<< " to global value summary and its unreachable mark is " | |||||
<< FuncSummary->isUnreachableFunction() << "\n"; | |||||
Index.addGlobalValueSummary(F, std::move(FuncSummary)); | Index.addGlobalValueSummary(F, std::move(FuncSummary)); | ||||
} | } | ||||
/// Find function pointers referenced within the given vtable initializer | /// Find function pointers referenced within the given vtable initializer | ||||
/// (or subset of an initializer) \p I. The starting offset of \p I within | /// (or subset of an initializer) \p I. The starting offset of \p I within | ||||
/// the vtable initializer is \p StartingOffset. Any discovered function | /// the vtable initializer is \p StartingOffset. Any discovered function | ||||
/// pointers are added to \p VTableFuncs along with their cumulative offset | /// pointers are added to \p VTableFuncs along with their cumulative offset | ||||
/// within the initializer. | /// within the initializer. | ||||
▲ Show 20 Lines • Show All 229 Lines • ▼ Show 20 Lines | ModuleSymbolTable::CollectAsmSymbols( | ||||
/* HasUnknownCall */ true}, | /* HasUnknownCall */ true}, | ||||
/*EntryCount=*/0, ArrayRef<ValueInfo>{}, | /*EntryCount=*/0, ArrayRef<ValueInfo>{}, | ||||
ArrayRef<FunctionSummary::EdgeTy>{}, | ArrayRef<FunctionSummary::EdgeTy>{}, | ||||
ArrayRef<GlobalValue::GUID>{}, | ArrayRef<GlobalValue::GUID>{}, | ||||
ArrayRef<FunctionSummary::VFuncId>{}, | ArrayRef<FunctionSummary::VFuncId>{}, | ||||
ArrayRef<FunctionSummary::VFuncId>{}, | ArrayRef<FunctionSummary::VFuncId>{}, | ||||
ArrayRef<FunctionSummary::ConstVCall>{}, | ArrayRef<FunctionSummary::ConstVCall>{}, | ||||
ArrayRef<FunctionSummary::ConstVCall>{}, | ArrayRef<FunctionSummary::ConstVCall>{}, | ||||
ArrayRef<FunctionSummary::ParamAccess>{}); | ArrayRef<FunctionSummary::ParamAccess>{}, false); | ||||
Index.addGlobalValueSummary(*GV, std::move(Summary)); | Index.addGlobalValueSummary(*GV, std::move(Summary)); | ||||
} else { | } else { | ||||
std::unique_ptr<GlobalVarSummary> Summary = | std::unique_ptr<GlobalVarSummary> Summary = | ||||
std::make_unique<GlobalVarSummary>( | std::make_unique<GlobalVarSummary>( | ||||
GVFlags, | GVFlags, | ||||
GlobalVarSummary::GVarFlags( | GlobalVarSummary::GVarFlags( | ||||
false, false, cast<GlobalVariable>(GV)->isConstant(), | false, false, cast<GlobalVariable>(GV)->isConstant(), | ||||
GlobalObject::VCallVisibilityPublic), | GlobalObject::VCallVisibilityPublic), | ||||
▲ Show 20 Lines • Show All 200 Lines • Show Last 20 Lines |