mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This patch implements collection and dumping of statistics about SILModules, SILFunctions and memory consumption during the execution of SIL optimization pipelines. The following statistics can be collected: * For SILFunctions: the number of SIL basic blocks, the number of SIL instructions, the number of SIL instructions of a specific kind, duration of a pass * For SILModules: the number of SIL basic blocks, the number of SIL instructions, the number of SIL instructions of a specific kind, the number of SILFunctions, the amount of memory used by the compiler, duration of a pass By default, any collection of statistics is disabled to avoid affecting compile times. One can enable the collection of statistics and dumping of these statistics for the whole SILModule and/or for SILFunctions. To reduce the amount of produced data, one can set thresholds in such a way that changes in the statistics are only reported if the delta between the old and the new values are at least X%. The deltas are computed as using the following formula: Delta = (NewValue - OldValue) / OldValue Thresholds provide a simple way to perform a simple filtering of the collected statistics during the compilation. But if there is a need for a more complex analysis of collected data (e.g. aggregation by a pipeline stage or by the type of a transformation), it is often better to dump as much data as possible into a file using e.g. -sil-stats-dump-all -sil-stats-modules -sil-stats-functions and then e.g. use the helper scripts to store the collected data into a database and then perform complex queries on it. Many kinds of analysis can be then formulated pretty easily as SQL queries.
42 lines
1.5 KiB
C++
42 lines
1.5 KiB
C++
//===--- OptimizerStatsUtils.h - Utils for collecting stats --*- C++ ---*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2017 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_OPTIMIZER_STATS_UTILS_H
|
|
#define SWIFT_OPTIMIZER_STATS_UTILS_H
|
|
|
|
namespace swift {
|
|
class SILModule;
|
|
class SILTransform;
|
|
class SILPassManager;
|
|
|
|
/// Updates SILModule stats before executing the transform \p Transform.
|
|
///
|
|
/// \param M SILModule to be processed
|
|
/// \param Transform the SIL transformation that was just executed
|
|
/// \param PM the PassManager being used
|
|
void updateSILModuleStatsBeforeTransform(SILModule &M, SILTransform *Transform,
|
|
SILPassManager &PM, int PassNumber);
|
|
|
|
/// Updates SILModule stats after finishing executing the
|
|
/// transform \p Transform.
|
|
///
|
|
/// \param M SILModule to be processed
|
|
/// \param Transform the SIL transformation that was just executed
|
|
/// \param PM the PassManager being used
|
|
void updateSILModuleStatsAfterTransform(SILModule &M, SILTransform *Transform,
|
|
SILPassManager &PM, int PassNumber,
|
|
int Duration);
|
|
|
|
} // end namespace swift
|
|
|
|
#endif
|