mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 02:33:06 +01:00
[NFC] Port InstCount pass to new pass manager
This commit is contained in:
parent
6d725be5b3
commit
2893862e92
28
include/llvm/Analysis/InstCount.h
Normal file
28
include/llvm/Analysis/InstCount.h
Normal file
@ -0,0 +1,28 @@
|
||||
//===- InstCount.h - Collects the count of all instructions -----*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This pass collects the count of all instructions and reports them
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_ANALYSIS_INSTCOUNT_H
|
||||
#define LLVM_ANALYSIS_INSTCOUNT_H
|
||||
|
||||
#include "llvm/IR/PassManager.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class Function;
|
||||
|
||||
struct InstCountPass : PassInfoMixin<InstCountPass> {
|
||||
PreservedAnalyses run(Function &F, FunctionAnalysisManager &);
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_ANALYSIS_INSTCOUNT_H
|
@ -192,7 +192,7 @@ void initializeInferAddressSpacesPass(PassRegistry&);
|
||||
void initializeInferFunctionAttrsLegacyPassPass(PassRegistry&);
|
||||
void initializeInjectTLIMappingsLegacyPass(PassRegistry &);
|
||||
void initializeInlineCostAnalysisPass(PassRegistry&);
|
||||
void initializeInstCountPass(PassRegistry&);
|
||||
void initializeInstCountLegacyPassPass(PassRegistry &);
|
||||
void initializeInstNamerPass(PassRegistry&);
|
||||
void initializeInstSimplifyLegacyPassPass(PassRegistry &);
|
||||
void initializeInstrProfilingLegacyPassPass(PassRegistry&);
|
||||
|
@ -50,7 +50,7 @@ void llvm::initializeAnalysis(PassRegistry &Registry) {
|
||||
initializeAAResultsWrapperPassPass(Registry);
|
||||
initializeGlobalsAAWrapperPassPass(Registry);
|
||||
initializeIVUsersWrapperPassPass(Registry);
|
||||
initializeInstCountPass(Registry);
|
||||
initializeInstCountLegacyPassPass(Registry);
|
||||
initializeIntervalPartitionPass(Registry);
|
||||
initializeLazyBranchProbabilityInfoPassPass(Registry);
|
||||
initializeLazyBlockFrequencyInfoPassPass(Registry);
|
||||
|
@ -10,6 +10,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Analysis/InstCount.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/Analysis/Passes.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
@ -23,57 +24,71 @@ using namespace llvm;
|
||||
|
||||
#define DEBUG_TYPE "instcount"
|
||||
|
||||
STATISTIC(TotalInsts , "Number of instructions (of all types)");
|
||||
STATISTIC(TotalInsts, "Number of instructions (of all types)");
|
||||
STATISTIC(TotalBlocks, "Number of basic blocks");
|
||||
STATISTIC(TotalFuncs , "Number of non-external functions");
|
||||
STATISTIC(TotalFuncs, "Number of non-external functions");
|
||||
|
||||
#define HANDLE_INST(N, OPCODE, CLASS) \
|
||||
STATISTIC(Num ## OPCODE ## Inst, "Number of " #OPCODE " insts");
|
||||
#define HANDLE_INST(N, OPCODE, CLASS) \
|
||||
STATISTIC(Num##OPCODE##Inst, "Number of " #OPCODE " insts");
|
||||
|
||||
#include "llvm/IR/Instruction.def"
|
||||
|
||||
namespace {
|
||||
class InstCount : public FunctionPass, public InstVisitor<InstCount> {
|
||||
friend class InstVisitor<InstCount>;
|
||||
class InstCount : public InstVisitor<InstCount> {
|
||||
friend class InstVisitor<InstCount>;
|
||||
|
||||
void visitFunction (Function &F) { ++TotalFuncs; }
|
||||
void visitBasicBlock(BasicBlock &BB) { ++TotalBlocks; }
|
||||
void visitFunction(Function &F) { ++TotalFuncs; }
|
||||
void visitBasicBlock(BasicBlock &BB) { ++TotalBlocks; }
|
||||
|
||||
#define HANDLE_INST(N, OPCODE, CLASS) \
|
||||
void visit##OPCODE(CLASS &) { ++Num##OPCODE##Inst; ++TotalInsts; }
|
||||
#define HANDLE_INST(N, OPCODE, CLASS) \
|
||||
void visit##OPCODE(CLASS &) { \
|
||||
++Num##OPCODE##Inst; \
|
||||
++TotalInsts; \
|
||||
}
|
||||
|
||||
#include "llvm/IR/Instruction.def"
|
||||
|
||||
void visitInstruction(Instruction &I) {
|
||||
errs() << "Instruction Count does not know about " << I;
|
||||
llvm_unreachable(nullptr);
|
||||
}
|
||||
public:
|
||||
static char ID; // Pass identification, replacement for typeid
|
||||
InstCount() : FunctionPass(ID) {
|
||||
initializeInstCountPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
void visitInstruction(Instruction &I) {
|
||||
errs() << "Instruction Count does not know about " << I;
|
||||
llvm_unreachable(nullptr);
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
bool runOnFunction(Function &F) override;
|
||||
PreservedAnalyses InstCountPass::run(Function &F,
|
||||
FunctionAnalysisManager &FAM) {
|
||||
LLVM_DEBUG(dbgs() << "INSTCOUNT: running on function " << F.getName()
|
||||
<< "\n");
|
||||
InstCount().visit(F);
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.setPreservesAll();
|
||||
}
|
||||
void print(raw_ostream &O, const Module *M) const override {}
|
||||
|
||||
};
|
||||
return PreservedAnalyses::all();
|
||||
}
|
||||
|
||||
char InstCount::ID = 0;
|
||||
INITIALIZE_PASS(InstCount, "instcount",
|
||||
namespace {
|
||||
class InstCountLegacyPass : public FunctionPass {
|
||||
public:
|
||||
static char ID; // Pass identification, replacement for typeid
|
||||
InstCountLegacyPass() : FunctionPass(ID) {
|
||||
initializeInstCountLegacyPassPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
bool runOnFunction(Function &F) override {
|
||||
LLVM_DEBUG(dbgs() << "INSTCOUNT: running on function " << F.getName()
|
||||
<< "\n");
|
||||
InstCount().visit(F);
|
||||
return false;
|
||||
};
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.setPreservesAll();
|
||||
}
|
||||
|
||||
void print(raw_ostream &O, const Module *M) const override {}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
char InstCountLegacyPass::ID = 0;
|
||||
INITIALIZE_PASS(InstCountLegacyPass, "instcount",
|
||||
"Counts the various types of Instructions", false, true)
|
||||
|
||||
FunctionPass *llvm::createInstCountPass() { return new InstCount(); }
|
||||
|
||||
// InstCount::run - This is the main Analysis entry point for a
|
||||
// function.
|
||||
//
|
||||
bool InstCount::runOnFunction(Function &F) {
|
||||
visit(F);
|
||||
return false;
|
||||
}
|
||||
FunctionPass *llvm::createInstCountPass() { return new InstCountLegacyPass(); }
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "llvm/Analysis/IVUsers.h"
|
||||
#include "llvm/Analysis/InlineAdvisor.h"
|
||||
#include "llvm/Analysis/InlineSizeEstimatorAnalysis.h"
|
||||
#include "llvm/Analysis/InstCount.h"
|
||||
#include "llvm/Analysis/LazyCallGraph.h"
|
||||
#include "llvm/Analysis/LazyValueInfo.h"
|
||||
#include "llvm/Analysis/LoopAccessAnalysis.h"
|
||||
|
@ -196,6 +196,7 @@ FUNCTION_PASS("make-guards-explicit", MakeGuardsExplicitPass())
|
||||
FUNCTION_PASS("post-inline-ee-instrument", EntryExitInstrumenterPass(/*PostInlining=*/true))
|
||||
FUNCTION_PASS("gvn-hoist", GVNHoistPass())
|
||||
FUNCTION_PASS("instcombine", InstCombinePass())
|
||||
FUNCTION_PASS("instcount", InstCountPass())
|
||||
FUNCTION_PASS("instsimplify", InstSimplifyPass())
|
||||
FUNCTION_PASS("invalidate<all>", InvalidateAllAnalysesPass())
|
||||
FUNCTION_PASS("irce", IRCEPass())
|
||||
|
Loading…
Reference in New Issue
Block a user