-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_store_inst.cpp
More file actions
58 lines (48 loc) · 1.81 KB
/
Copy pathget_store_inst.cpp
File metadata and controls
58 lines (48 loc) · 1.81 KB
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
//===- Hello.cpp - Example code from "Writing an LLVM Pass" ---------------===//
//
// 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 file implements two versions of the LLVM "Hello World" pass described
// in docs/WritingAnLLVMPass.html
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/Statistic.h"
#include "llvm/IR/Function.h"
#include "llvm/Pass.h"
#include "llvm/Support/raw_ostream.h"
#include <vector>
using namespace llvm;
#define DEBUG_TYPE "demo"
STATISTIC(HelloCounter, "Counts number of functions greeted");
namespace {
// Hello - The first implementation, without getAnalysisUsage.
struct Demo : public FunctionPass {
static char ID; // Pass identification, replacement for typeid
Demo() : FunctionPass(ID) {}
bool runOnFunction(Function &F) override {
// int number_of_ins = 0;
++HelloCounter;
errs() << "Demo: ";
errs().write_escaped(F.getName()) << '\n';
for(BasicBlock &BB : F)
{
for(Instruction &I : BB)
{
errs()<<" opcode of the instruction is : "<< I.getOpcodeName()<<"\n"; //This prints Opcode of all the instructions
if(I.getOpcode() == Instruction::Store) // This compares if the Opcode is "Store" then it prints the stmt
{
errs()<<"Ye kay hai"<<"\n";
}
}
//errs()<<"Number of Instructions are : "<< number_of_ins<< '\n';
}
return false;
}
};
}
char Demo::ID = 0;
static RegisterPass<Demo> X("demo", "This is a Demo pass");