-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobalVarPass.cpp
More file actions
48 lines (38 loc) · 1.18 KB
/
Copy pathGlobalVarPass.cpp
File metadata and controls
48 lines (38 loc) · 1.18 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
#include "llvm/Pass.h"
#include "llvm/IR/Module.h"
//#include "llvm/Support/raw_ostream.h"
#include "llvm/Analysis/Passes.h"
//#include "llvm/Analysis/PassSupport.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
using namespace llvm;
#define DEBUG_TYPE "globalvarpass"
STATISTIC(NumGlobalVars, "Number of Global Variables referred to (number present)");
STATISTIC(GlobalVarUsage, "Number of Global Variable References (usages)");
namespace {
class GlobalVar : public ModulePass {
public:
static char ID;
GlobalVar() : ModulePass(ID) {
initializeGlobalVarPass(*PassRegistry::getPassRegistry());
}
bool runOnModule(Module &M) override {
for (auto &Global : M.getGlobalList()) {
//errs() << "Testing: ";
//errs().write_escaped(M.getModuleIdentifier()) << '\n';
NumGlobalVars++;
if (auto *v = dyn_cast<Value>(&Global)) {
GlobalVarUsage += v->getNumUses();
}
}
return false;
}
};
}
char GlobalVar::ID = 0;
INITIALIZE_PASS(GlobalVar, "globalvarpass",
"Counts the various types of Instructions", false, true)
ModulePass *llvm::createGlobalVarPass() {
return new GlobalVar();
}