1*fe013be4SDimitry Andric //===- CountVisits.cpp ----------------------------------------------------===// 2*fe013be4SDimitry Andric // 3*fe013be4SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*fe013be4SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*fe013be4SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*fe013be4SDimitry Andric // 7*fe013be4SDimitry Andric //===----------------------------------------------------------------------===// 8*fe013be4SDimitry Andric 9*fe013be4SDimitry Andric #include "llvm/Transforms/Utils/CountVisits.h" 10*fe013be4SDimitry Andric #include "llvm/ADT/Statistic.h" 11*fe013be4SDimitry Andric #include "llvm/IR/PassManager.h" 12*fe013be4SDimitry Andric 13*fe013be4SDimitry Andric using namespace llvm; 14*fe013be4SDimitry Andric 15*fe013be4SDimitry Andric #define DEBUG_TYPE "count-visits" 16*fe013be4SDimitry Andric 17*fe013be4SDimitry Andric STATISTIC(MaxVisited, "Max number of times we visited a function"); 18*fe013be4SDimitry Andric run(Function & F,FunctionAnalysisManager &)19*fe013be4SDimitry AndricPreservedAnalyses CountVisitsPass::run(Function &F, FunctionAnalysisManager &) { 20*fe013be4SDimitry Andric uint32_t Count = Counts[F.getName()] + 1; 21*fe013be4SDimitry Andric Counts[F.getName()] = Count; 22*fe013be4SDimitry Andric if (Count > MaxVisited) 23*fe013be4SDimitry Andric MaxVisited = Count; 24*fe013be4SDimitry Andric return PreservedAnalyses::all(); 25*fe013be4SDimitry Andric } 26