mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
We really only need the analysis to tell whether a function has caller inside the module or not. We do not need to know the callsites. Remove them for now to make the analysis more memory efficient. Add a note to indicate it can be extended.
59 lines
2.1 KiB
C++
59 lines
2.1 KiB
C++
//===--- CallerAnalysis.cpp - Determine callsites to a function ----------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "swift/SILOptimizer/Analysis/CallerAnalysis.h"
|
|
|
|
#include "swift/Basic/Fallthrough.h"
|
|
#include "swift/SIL/SILModule.h"
|
|
#include "swift/SILOptimizer/Utils/Local.h"
|
|
|
|
using namespace swift;
|
|
|
|
void CallerAnalysis::processFunctionCallSites(SILFunction *F) {
|
|
// Scan the whole module and search Apply sites.
|
|
for (auto &BB : *F) {
|
|
for (auto &II : BB) {
|
|
if (auto Apply = FullApplySite::isa(&II)) {
|
|
SILFunction *CalleeFn = Apply.getCalleeFunction();
|
|
if (!CalleeFn)
|
|
continue;
|
|
|
|
// Update the callee information for this function.
|
|
CallerAnalysisFunctionInfo &CallerInfo
|
|
= CallInfo.FindAndConstruct(F).second;
|
|
CallerInfo.Callees.insert(CalleeFn);
|
|
|
|
// Update the callsite information for the callee.
|
|
CallerAnalysisFunctionInfo &CalleeInfo
|
|
= CallInfo.FindAndConstruct(CalleeFn).second;
|
|
CalleeInfo.Callers.insert(F);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void CallerAnalysis::invalidateExistingCalleeRelation(SILFunction *F) {
|
|
CallerAnalysisFunctionInfo &CallerInfo = CallInfo.FindAndConstruct(F).second;
|
|
for (auto Callee : CallerInfo.Callees) {
|
|
CallerAnalysisFunctionInfo &CalleeInfo
|
|
= CallInfo.FindAndConstruct(Callee).second;
|
|
CalleeInfo.Callers.remove(F);
|
|
}
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// Main Entry Point
|
|
//===----------------------------------------------------------------------===//
|
|
SILAnalysis *swift::createCallerAnalysis(SILModule *M) {
|
|
return new CallerAnalysis(M);
|
|
}
|