1 //===- CountVisits.cpp ----------------------------------------------------===//
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 #include "llvm/Transforms/Utils/CountVisits.h"
10 #include "llvm/ADT/Statistic.h"
11 #include "llvm/IR/PassManager.h"
12 
13 using namespace llvm;
14 
15 #define DEBUG_TYPE "count-visits"
16 
17 STATISTIC(MaxVisited, "Max number of times we visited a function");
18 
19 PreservedAnalyses CountVisitsPass::run(Function &F, FunctionAnalysisManager &) {
20   uint32_t Count = Counts[F.getName()] + 1;
21   Counts[F.getName()] = Count;
22   if (Count > MaxVisited)
23     MaxVisited = Count;
24   return PreservedAnalyses::all();
25 }
26