-
Notifications
You must be signed in to change notification settings - Fork 15
/
ValueNumbering.cpp
72 lines (63 loc) · 2.56 KB
/
ValueNumbering.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "llvm/Pass.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Instruction.h"
#include <string>
using namespace llvm;
using namespace std;
#define DEBUG_TYPE "ValueNumbering"
using namespace llvm;
namespace {
struct ValueNumbering : public FunctionPass {
string func_name = "test";
static char ID;
ValueNumbering() : FunctionPass(ID) {}
bool runOnFunction(Function &F) override {
errs() << "ValueNumbering: " << F.getName() << "\n";
if (F.getName() != func_name) return false;
for (auto& basic_block : F)
{
for (auto& inst : basic_block)
{
errs() << inst << "\n";
if(inst.getOpcode() == Instruction::Load){
errs() << "This is Load"<<"\n";
}
if(inst.getOpcode() == Instruction::Store){
errs() << "This is Store"<<"\n";
}
if (inst.isBinaryOp())
{
errs() << "Op Code:" << inst.getOpcodeName()<<"\n";
if(inst.getOpcode() == Instruction::Add){
errs() << "This is Addition"<<"\n";
}
if(inst.getOpcode() == Instruction::Add){
errs() << "This is Addition"<<"\n";
}
if(inst.getOpcode() == Instruction::Mul){
errs() << "This is Multiplication"<<"\n";
}
// see other classes, Instruction::Sub, Instruction::UDiv, Instruction::SDiv
// errs() << "Operand(0)" << (*inst.getOperand(0))<<"\n";
auto* ptr = dyn_cast<User>(&inst);
//errs() << "\t" << *ptr << "\n";
for (auto it = ptr->op_begin(); it != ptr->op_end(); ++it) {
errs() << "\t" << *(*it) << "\n";
// if ((*it)->hasName())
// errs() << (*it)->getName() << "\n";
}
} // end if
} // end for inst
} // end for block
return false;
} // end runOnFunction
}; // end of struct ValueNumbering
} // end of anonymous namespace
char ValueNumbering::ID = 0;
static RegisterPass<ValueNumbering> X("ValueNumbering", "ValueNumbering Pass",
false /* Only looks at CFG */,
false /* Analysis Pass */);