Revert " [LoongArch][ISel] Check the number of sign bits in `PatGprGpr_32` (#107432)"
[llvm-project.git] / llvm / lib / Analysis / InstCount.cpp
blobd427d3eeaa9e16879567258a5a6c05fbbeee5e14
1 //===-- InstCount.cpp - Collects the count of all instructions ------------===//
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 pass collects the count of all instructions and reports them
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Analysis/InstCount.h"
14 #include "llvm/ADT/Statistic.h"
15 #include "llvm/Analysis/Passes.h"
16 #include "llvm/IR/Function.h"
17 #include "llvm/IR/InstVisitor.h"
18 #include "llvm/Support/Debug.h"
19 #include "llvm/Support/ErrorHandling.h"
20 #include "llvm/Support/raw_ostream.h"
21 using namespace llvm;
23 #define DEBUG_TYPE "instcount"
25 STATISTIC(TotalInsts, "Number of instructions (of all types)");
26 STATISTIC(TotalBlocks, "Number of basic blocks");
27 STATISTIC(TotalFuncs, "Number of non-external functions");
29 #define HANDLE_INST(N, OPCODE, CLASS) \
30 STATISTIC(Num##OPCODE##Inst, "Number of " #OPCODE " insts");
32 #include "llvm/IR/Instruction.def"
34 namespace {
35 class InstCount : public InstVisitor<InstCount> {
36 friend class InstVisitor<InstCount>;
38 void visitFunction(Function &F) { ++TotalFuncs; }
39 void visitBasicBlock(BasicBlock &BB) { ++TotalBlocks; }
41 #define HANDLE_INST(N, OPCODE, CLASS) \
42 void visit##OPCODE(CLASS &) { \
43 ++Num##OPCODE##Inst; \
44 ++TotalInsts; \
47 #include "llvm/IR/Instruction.def"
49 void visitInstruction(Instruction &I) {
50 errs() << "Instruction Count does not know about " << I;
51 llvm_unreachable(nullptr);
54 } // namespace
56 PreservedAnalyses InstCountPass::run(Function &F,
57 FunctionAnalysisManager &FAM) {
58 LLVM_DEBUG(dbgs() << "INSTCOUNT: running on function " << F.getName()
59 << "\n");
60 InstCount().visit(F);
62 return PreservedAnalyses::all();