LLVM 20.0.0git
LastRunTrackingAnalysis.cpp
Go to the documentation of this file.
1//===- LastRunTrackingAnalysis.cpp - Avoid running redundant pass -*- C++ -*-=//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
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
11// the pass.
12//
13//===----------------------------------------------------------------------===//
14
16#include "llvm/ADT/Statistic.h"
18
19using namespace llvm;
20
21#define DEBUG_TYPE "last-run-tracking"
22STATISTIC(NumSkippedPasses, "Number of skipped passes");
23STATISTIC(NumLRTQueries, "Number of LastRunTracking queries");
24
25static cl::opt<bool>
26 DisableLastRunTracking("disable-last-run-tracking", cl::Hidden,
27 cl::desc("Disable last run tracking"),
28 cl::init(false));
29
30bool LastRunTrackingInfo::shouldSkipImpl(PassID ID, OptionPtr Ptr) const {
32 return false;
33 ++NumLRTQueries;
34 auto Iter = TrackedPasses.find(ID);
35 if (Iter == TrackedPasses.end())
36 return false;
37 if (!Iter->second || Iter->second(Ptr)) {
38 ++NumSkippedPasses;
39 return true;
40 }
41 return false;
42}
43
44void LastRunTrackingInfo::updateImpl(PassID ID, bool Changed,
45 CompatibilityCheckFn CheckFn) {
46 if (Changed)
47 TrackedPasses.clear();
48 TrackedPasses[ID] = std::move(CheckFn);
49}
50
51AnalysisKey LastRunTrackingAnalysis::Key;
static cl::opt< bool > DisableLastRunTracking("disable-last-run-tracking", cl::Hidden, cl::desc("Disable last run tracking"), cl::init(false))
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition: Statistic.h:166
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:156
iterator end()
Definition: DenseMap.h:84
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28