mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-17 15:38:40 +00:00
Simplify code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4886 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b91b657e02
commit
149a5203a9
@ -2,88 +2,28 @@
|
|||||||
//
|
//
|
||||||
// This pass collects the count of all instructions and reports them
|
// This pass collects the count of all instructions and reports them
|
||||||
//
|
//
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/iMemory.h"
|
|
||||||
#include "llvm/iTerminators.h"
|
|
||||||
#include "llvm/iPHINode.h"
|
|
||||||
#include "llvm/iOther.h"
|
|
||||||
#include "llvm/iOperators.h"
|
|
||||||
#include "llvm/Support/InstVisitor.h"
|
#include "llvm/Support/InstVisitor.h"
|
||||||
#include "llvm/Support/InstIterator.h"
|
|
||||||
#include "llvm/Support/InstIterator.h"
|
|
||||||
#include "Support/Statistic.h"
|
#include "Support/Statistic.h"
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
static Statistic<> NumReturnInst("instcount","Number of ReturnInsts");
|
#define HANDLE_INST(N, OPCODE, CLASS) \
|
||||||
static Statistic<> NumBranchInst("instcount", "Number of BranchInsts");
|
Statistic<> Num##OPCODE##Inst("instcount", "Number of " #OPCODE " insts");
|
||||||
static Statistic<> NumPHINode("instcount", "Number of PHINodes");
|
|
||||||
static Statistic<> NumCastInst("instcount", "Number of CastInsts");
|
|
||||||
static Statistic<> NumCallInst("instcount", "Number of CallInsts");
|
|
||||||
static Statistic<> NumMallocInst("instcount", "Number of MallocInsts");
|
|
||||||
static Statistic<> NumAllocaInst("instcount", "Number of AllocaInsts");
|
|
||||||
static Statistic<> NumFreeInst("instcount", "Number of FreeInsts");
|
|
||||||
static Statistic<> NumLoadInst("instcount", "Number of LoadInsts");
|
|
||||||
static Statistic<> NumStoreInst("instcount", "Number of StoreInsts");
|
|
||||||
static Statistic<> NumGetElementPtrInst("instcount",
|
|
||||||
"Number of GetElementPtrInsts");
|
|
||||||
|
|
||||||
static Statistic<> NumSwitchInst("instcount", "Number of SwitchInsts");
|
#include "llvm/Instruction.def"
|
||||||
static Statistic<> NumInvokeInst("instcount", "Number of InvokeInsts");
|
|
||||||
static Statistic<> NumBinaryOperator("instcount",
|
|
||||||
"Total Number of BinaryOperators");
|
|
||||||
|
|
||||||
static Statistic<> NumShiftInst("instcount", " Total Number of ShiftInsts");
|
|
||||||
static Statistic<> NumShlInst("instcount", "Number of Left ShiftInsts");
|
|
||||||
|
|
||||||
static Statistic<> NumShrInst("instcount", "Number of Right ShiftInsts");
|
|
||||||
|
|
||||||
|
|
||||||
static Statistic<> NumAddInst("instcount", "Number of AddInsts");
|
|
||||||
static Statistic<> NumSubInst("instcount", "Number of SubInsts");
|
|
||||||
static Statistic<> NumMulInst("instcount", "Number of MulInsts");
|
|
||||||
static Statistic<> NumDivInst("instcount", "Number of DivInsts");
|
|
||||||
static Statistic<> NumRemInst("instcount", "Number of RemInsts");
|
|
||||||
static Statistic<> NumAndInst("instcount", "Number of AndInsts");
|
|
||||||
static Statistic<> NumOrInst("instcount", "Number of OrInsts");
|
|
||||||
static Statistic<> NumXorInst("instcount", "Number of XorInsts");
|
|
||||||
static Statistic<> NumSetCondInst("instcount", "Total Number of SetCondInsts");
|
|
||||||
static Statistic<> NumSetEQInst("instcount", "Number of SetEQInsts");
|
|
||||||
static Statistic<> NumSetNEInst("instcount", "Number of SetNEInsts");
|
|
||||||
static Statistic<> NumSetLEInst("instcount", "Number of SetLEInsts");
|
|
||||||
static Statistic<> NumSetGEInst("instcount", "Number of SetGEInsts");
|
|
||||||
static Statistic<> NumSetLTInst("instcount", "Number of SetLTInsts");
|
|
||||||
static Statistic<> NumSetGTInst("instcount", "Number of SetGTInsts");
|
|
||||||
|
|
||||||
class InstCount : public Pass, public InstVisitor<InstCount> {
|
class InstCount : public Pass, public InstVisitor<InstCount> {
|
||||||
private:
|
friend class InstVisitor<InstCount>;
|
||||||
friend class InstVisitor<InstCount>;
|
|
||||||
|
|
||||||
|
#define HANDLE_INST(N, OPCODE, CLASS) \
|
||||||
|
void visit##OPCODE(CLASS &) { Num##OPCODE##Inst++; }
|
||||||
|
|
||||||
void visitBinaryOperator(BinaryOperator &I);
|
#include "llvm/Instruction.def"
|
||||||
void visitShiftInst(ShiftInst &I);
|
|
||||||
void visitSetCondInst(SetCondInst &I);
|
|
||||||
|
|
||||||
inline void visitSwitchInst(SwitchInst &I) { NumSwitchInst++; }
|
void visitInstruction(Instruction &I) {
|
||||||
inline void visitInvokeInst(InvokeInst &I) { NumInvokeInst++; }
|
|
||||||
inline void visitReturnInst(ReturnInst &I) { NumReturnInst++; }
|
|
||||||
inline void visitBranchInst(BranchInst &I) { NumBranchInst++; }
|
|
||||||
inline void visitPHINode(PHINode &I) { NumPHINode++; }
|
|
||||||
inline void visitCastInst (CastInst &I) { NumCastInst++; }
|
|
||||||
inline void visitCallInst (CallInst &I) { NumCallInst++; }
|
|
||||||
inline void visitMallocInst(MallocInst &I) { NumMallocInst++; }
|
|
||||||
inline void visitAllocaInst(AllocaInst &I) { NumAllocaInst++; }
|
|
||||||
inline void visitFreeInst (FreeInst &I) { NumFreeInst++; }
|
|
||||||
inline void visitLoadInst (LoadInst &I) { NumLoadInst++; }
|
|
||||||
inline void visitStoreInst (StoreInst &I) { NumStoreInst++; }
|
|
||||||
inline void visitGetElementPtrInst(GetElementPtrInst &I) {
|
|
||||||
NumGetElementPtrInst++; }
|
|
||||||
|
|
||||||
inline void visitInstruction(Instruction &I) {
|
|
||||||
std::cerr << "Instruction Count does not know about " << I;
|
std::cerr << "Instruction Count does not know about " << I;
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
@ -93,63 +33,18 @@ namespace {
|
|||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
AU.setPreservesAll();
|
AU.setPreservesAll();
|
||||||
}
|
}
|
||||||
|
virtual void print(std::ostream &O, Module *M) const {}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
RegisterAnalysis<InstCount> X("instcount",
|
RegisterAnalysis<InstCount> X("instcount",
|
||||||
"Counts the various types of Instructions");
|
"Counts the various types of Instructions");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// createInstCountPass - The public interface to this file...
|
|
||||||
Pass *createInstCountPass() { return new InstCount(); }
|
|
||||||
|
|
||||||
|
|
||||||
// InstCount::run - This is the main Analysis entry point for a
|
// InstCount::run - This is the main Analysis entry point for a
|
||||||
// function.
|
// function.
|
||||||
//
|
//
|
||||||
bool InstCount::run(Module &M) {
|
bool InstCount::run(Module &M) {
|
||||||
for (Module::iterator mI = M.begin(), mE = M.end(); mI != mE; ++mI)
|
visit(M);
|
||||||
for (inst_iterator I = inst_begin(*mI), E = inst_end(*mI); I != E; ++I)
|
|
||||||
visit(*I);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void InstCount::visitBinaryOperator(BinaryOperator &I) {
|
|
||||||
NumBinaryOperator++;
|
|
||||||
switch (I.getOpcode()) {
|
|
||||||
case Instruction::Add: NumAddInst++; break;
|
|
||||||
case Instruction::Sub: NumSubInst++; break;
|
|
||||||
case Instruction::Mul: NumMulInst++; break;
|
|
||||||
case Instruction::Div: NumDivInst++; break;
|
|
||||||
case Instruction::Rem: NumRemInst++; break;
|
|
||||||
case Instruction::And: NumAndInst++; break;
|
|
||||||
case Instruction::Or: NumOrInst++; break;
|
|
||||||
case Instruction::Xor: NumXorInst++; break;
|
|
||||||
default : std::cerr<< " Wrong binary operator \n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void InstCount::visitSetCondInst(SetCondInst &I) {
|
|
||||||
NumBinaryOperator++;
|
|
||||||
NumSetCondInst++;
|
|
||||||
switch (I.getOpcode()) {
|
|
||||||
case Instruction::SetEQ: NumSetEQInst++; break;
|
|
||||||
case Instruction::SetNE: NumSetNEInst++; break;
|
|
||||||
case Instruction::SetLE: NumSetLEInst++; break;
|
|
||||||
case Instruction::SetGE: NumSetGEInst++; break;
|
|
||||||
case Instruction::SetLT: NumSetLTInst++; break;
|
|
||||||
case Instruction::SetGT: NumSetGTInst++; break;
|
|
||||||
default : std::cerr<< " Wrong SetCond Inst \n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void InstCount::visitShiftInst(ShiftInst &I) {
|
|
||||||
NumShiftInst++;
|
|
||||||
switch (I.getOpcode()) {
|
|
||||||
case Instruction::Shl: NumShlInst++; break;
|
|
||||||
case Instruction::Shr: NumShrInst++; break;
|
|
||||||
default : std::cerr<< " Wrong ShiftInst \n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user