xref: /freebsd-src/contrib/llvm-project/llvm/lib/Transforms/Utils/CountVisits.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
106c3fb27SDimitry Andric //===- CountVisits.cpp ----------------------------------------------------===//
206c3fb27SDimitry Andric //
306c3fb27SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
406c3fb27SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
506c3fb27SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
606c3fb27SDimitry Andric //
706c3fb27SDimitry Andric //===----------------------------------------------------------------------===//
806c3fb27SDimitry Andric 
906c3fb27SDimitry Andric #include "llvm/Transforms/Utils/CountVisits.h"
1006c3fb27SDimitry Andric #include "llvm/ADT/Statistic.h"
11*0fca6ea1SDimitry Andric #include "llvm/IR/Function.h"
1206c3fb27SDimitry Andric #include "llvm/IR/PassManager.h"
1306c3fb27SDimitry Andric 
1406c3fb27SDimitry Andric using namespace llvm;
1506c3fb27SDimitry Andric 
1606c3fb27SDimitry Andric #define DEBUG_TYPE "count-visits"
1706c3fb27SDimitry Andric 
1806c3fb27SDimitry Andric STATISTIC(MaxVisited, "Max number of times we visited a function");
1906c3fb27SDimitry Andric 
2006c3fb27SDimitry Andric PreservedAnalyses CountVisitsPass::run(Function &F, FunctionAnalysisManager &) {
2106c3fb27SDimitry Andric   uint32_t Count = Counts[F.getName()] + 1;
2206c3fb27SDimitry Andric   Counts[F.getName()] = Count;
2306c3fb27SDimitry Andric   if (Count > MaxVisited)
2406c3fb27SDimitry Andric     MaxVisited = Count;
2506c3fb27SDimitry Andric   return PreservedAnalyses::all();
2606c3fb27SDimitry Andric }
27