Repository navigation
Expand file tree
/
Copy pathDummyOptimizationPass.cpp.orig
More file actions
executable file
·76 lines (67 loc) · 2.37 KB
/
Copy pathDummyOptimizationPass.cpp.orig
File metadata and controls
executable file
·76 lines (67 loc) · 2.37 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// DummyOptimizationPass.cpp
//
//
// Created by Jules Testard on 22/05/2014.
//
//
#include "llvm/Pass.h"
#include "Variable.h"
#include "StaticAnalysis.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/InstIterator.h"
#include <string>
<<<<<<< HEAD
#include <stdio.h>
=======
#include <vector>
>>>>>>> 7085824504d61e45e9bcf276226d61d173e866cf
using namespace llvm;
using namespace std;
/**
* BUGS FOUND AND FIXED :
* - Avoid static members for the passes. This generates a linking error when making the shared object.
* - raw_ostream& object does not like to be fed a std::endl symbol. Prefer to user "\n".
*
*/
namespace {
struct DummyOptimizationPass : public FunctionPass {
static char ID;
vector<StaticAnalysis *>staticAnalyses;
DummyOptimizationPass() : FunctionPass(ID) {}
<<<<<<< HEAD
virtual bool runOnModule(Module &M) {
=======
virtual bool runOnFunction(Function &F) {
//initialize analysis
staticAnalyses.push_back(new StaticAnalysis(F));
>>>>>>> 7085824504d61e45e9bcf276226d61d173e866cf
return false;
}
//The dummy optimization does not modify the code, but performs various analyses and outputs their result here
void print(raw_ostream &OS, const Module*) const {
// ========== TESTING ==============
//Test that variable class is properly linked (test can be removed later).
string example = "example";
Variable v(example);
OS << "VARIABLE test : ";
OS << "I created a new variable with name : " << v.GetName() << "\n";
//The pure static analysis. Functional testing
OS << "STATIC ANALYSES test : \n";
for (unsigned int i = 0 ; i < staticAnalyses.size() ; i++){
OS << "Function Name : " << staticAnalyses[i]->getFunctionName() << "\n";
OS << "First Instruction Name : " << staticAnalyses[i]->getCFG()->succs[0]->inst->getName().str() << "\n";
OS << "Print CFG : " << "\n";
//Check graph once. Everything flow should be empty.
staticAnalyses[i]->JSONCFG(OS);
//Run worklist algorithm
staticAnalyses.back()->runWorklist();
//Check graph again. Everything flow should say top.
staticAnalyses[i]->JSONCFG(OS);
}
}
};
}
char DummyOptimizationPass::ID = 0;
static RegisterPass<DummyOptimizationPass> X("dummyOptimization", "Dummy Optimization Pass", false, false);