Skip to content

[caller-analysis] Extract CallerAnalysis::FunctionInfo's definition o… #17741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 39 additions & 41 deletions include/swift/SILOptimizer/Analysis/CallerAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,49 +40,9 @@ namespace swift {
/// In addition of caller information this analysis also provides information
/// about partial applies of a function.
class CallerAnalysis : public SILAnalysis {

public:
class FunctionInfo;

/// NOTE: this can be extended to contain the callsites of the function.
class FunctionInfo {
friend class CallerAnalysis;

/// A list of all the functions this function calls or partially applies.
llvm::SetVector<SILFunction *> Callees;
/// A list of all the callers this function has.
llvm::SmallSet<SILFunction *, 4> Callers;

/// The number of partial applied arguments of this function.
///
/// Specifically, it stores the minimum number of partial applied arguments
/// of each function which contain one or multiple partial_applys of this
/// function.
/// This is a little bit off-topic because a partial_apply is not really
/// a "call" of this function.
llvm::DenseMap<SILFunction *, int> PartialAppliers;

public:
/// Returns true if this function has at least one caller.
bool hasCaller() const {
return !Callers.empty();
}

/// Returns non zero if this function is partially applied anywhere.
///
/// The return value is the minimum number of partially applied arguments.
/// Usually all partial applies of a function partially apply the same
/// number of arguments anyway.
int getMinPartialAppliedArgs() const {
int minArgs = 0;
for (auto Iter : PartialAppliers) {
int numArgs = Iter.second;
if (minArgs == 0 || numArgs < minArgs)
minArgs = numArgs;
}
return minArgs;
}
};

private:
/// Current module we are analyzing.
SILModule &Mod;
Expand Down Expand Up @@ -167,6 +127,44 @@ class CallerAnalysis : public SILAnalysis {
}
};

/// NOTE: this can be extended to contain the callsites of the function.
class CallerAnalysis::FunctionInfo {
friend class CallerAnalysis;

/// A list of all the functions this function calls or partially applies.
llvm::SetVector<SILFunction *> Callees;
/// A list of all the callers this function has.
llvm::SmallSet<SILFunction *, 4> Callers;

/// The number of partial applied arguments of this function.
///
/// Specifically, it stores the minimum number of partial applied arguments
/// of each function which contain one or multiple partial_applys of this
/// function.
/// This is a little bit off-topic because a partial_apply is not really
/// a "call" of this function.
llvm::DenseMap<SILFunction *, int> PartialAppliers;

public:
/// Returns true if this function has at least one caller.
bool hasCaller() const { return !Callers.empty(); }

/// Returns non zero if this function is partially applied anywhere.
///
/// The return value is the minimum number of partially applied arguments.
/// Usually all partial applies of a function partially apply the same
/// number of arguments anyway.
int getMinPartialAppliedArgs() const {
int minArgs = 0;
for (auto Iter : PartialAppliers) {
int numArgs = Iter.second;
if (minArgs == 0 || numArgs < minArgs)
minArgs = numArgs;
}
return minArgs;
}
};

} // end namespace swift

#endif