forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCallerAnalysis.cpp
58 lines (50 loc) · 2.12 KB
/
CallerAnalysis.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//===--- 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);
}