14ce34bb2SArthur Eubanks //===- CountVisits.cpp ----------------------------------------------------===// 24ce34bb2SArthur Eubanks // 34ce34bb2SArthur Eubanks // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 44ce34bb2SArthur Eubanks // See https://llvm.org/LICENSE.txt for license information. 54ce34bb2SArthur Eubanks // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 64ce34bb2SArthur Eubanks // 74ce34bb2SArthur Eubanks //===----------------------------------------------------------------------===// 84ce34bb2SArthur Eubanks 94ce34bb2SArthur Eubanks #include "llvm/Transforms/Utils/CountVisits.h" 104ce34bb2SArthur Eubanks #include "llvm/ADT/Statistic.h" 11*c0866cefSNikita Popov #include "llvm/IR/Function.h" 124ce34bb2SArthur Eubanks #include "llvm/IR/PassManager.h" 134ce34bb2SArthur Eubanks 144ce34bb2SArthur Eubanks using namespace llvm; 154ce34bb2SArthur Eubanks 164ce34bb2SArthur Eubanks #define DEBUG_TYPE "count-visits" 174ce34bb2SArthur Eubanks 184ce34bb2SArthur Eubanks STATISTIC(MaxVisited, "Max number of times we visited a function"); 194ce34bb2SArthur Eubanks run(Function & F,FunctionAnalysisManager &)204ce34bb2SArthur EubanksPreservedAnalyses CountVisitsPass::run(Function &F, FunctionAnalysisManager &) { 214ce34bb2SArthur Eubanks uint32_t Count = Counts[F.getName()] + 1; 224ce34bb2SArthur Eubanks Counts[F.getName()] = Count; 234ce34bb2SArthur Eubanks if (Count > MaxVisited) 244ce34bb2SArthur Eubanks MaxVisited = Count; 254ce34bb2SArthur Eubanks return PreservedAnalyses::all(); 264ce34bb2SArthur Eubanks } 27