1 //===- LastRunTrackingAnalysis.cpp - Avoid running redundant pass -*- C++ -*-=//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This is an analysis pass to track a set of passes that have been run, so that
10 // we can avoid running a pass again if there is no change since the last run of
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Analysis/LastRunTrackingAnalysis.h"
16 #include "llvm/ADT/Statistic.h"
17 #include "llvm/Support/CommandLine.h"
21 #define DEBUG_TYPE "last-run-tracking"
22 STATISTIC(NumSkippedPasses
, "Number of skipped passes");
23 STATISTIC(NumLRTQueries
, "Number of LastRunTracking queries");
26 DisableLastRunTracking("disable-last-run-tracking", cl::Hidden
,
27 cl::desc("Disable last run tracking"),
30 bool LastRunTrackingInfo::shouldSkipImpl(PassID ID
, OptionPtr Ptr
) const {
31 if (DisableLastRunTracking
)
34 auto Iter
= TrackedPasses
.find(ID
);
35 if (Iter
== TrackedPasses
.end())
37 if (!Iter
->second
|| Iter
->second(Ptr
)) {
44 void LastRunTrackingInfo::updateImpl(PassID ID
, bool Changed
,
45 CompatibilityCheckFn CheckFn
) {
47 TrackedPasses
.clear();
48 TrackedPasses
[ID
] = std::move(CheckFn
);
51 AnalysisKey
LastRunTrackingAnalysis::Key
;