mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
The body of a function has to be re-analyzed for every call site of the function, which is very expensive and if the body is not changed would produce the same result. This takes about ~10% from swift-syntax overall build time in release configuration.
48 lines
1.6 KiB
C++
48 lines
1.6 KiB
C++
//===--- IsSelfRecursiveAnalysis.cpp --------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "swift/SILOptimizer/Analysis/IsSelfRecursiveAnalysis.h"
|
|
#include "swift/SIL/ApplySite.h"
|
|
#include "swift/SIL/SILBasicBlock.h"
|
|
#include "swift/SIL/SILFunction.h"
|
|
#include "swift/SIL/SILInstruction.h"
|
|
|
|
using namespace swift;
|
|
|
|
// Force the compiler to generate the destructor in this C++ file.
|
|
// Otherwise it can happen that it is generated in a SwiftCompilerSources module
|
|
// and that results in unresolved-symbols linker errors.
|
|
IsSelfRecursive::~IsSelfRecursive() = default;
|
|
|
|
void IsSelfRecursive::compute() {
|
|
isSelfRecursive = false;
|
|
|
|
for (auto &BB : *getFunction()) {
|
|
for (auto &I : BB) {
|
|
if (auto Apply = FullApplySite::isa(&I)) {
|
|
if (Apply.getReferencedFunctionOrNull() == f) {
|
|
isSelfRecursive = true;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// Main Entry Point
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
SILAnalysis *swift::createIsSelfRecursiveAnalysis(SILModule *) {
|
|
return new IsSelfRecursiveAnalysis();
|
|
}
|