-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDummyOptimizationPass.cpp
More file actions
executable file
·59 lines (52 loc) · 1.76 KB
/
DummyOptimizationPass.cpp
File metadata and controls
executable file
·59 lines (52 loc) · 1.76 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
//
// 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>
#include <vector>
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) {}
virtual bool runOnFunction(Function &F) {
//initialize analysis
staticAnalyses.push_back(new StaticAnalysis(F));
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 {
//The pure static analysis. Functional testing
OS << "STATIC ANALYSES test : \n";
for (unsigned int i = 0 ; i < staticAnalyses.size() ; i++){
OS << "Print CFG (without flow) : " << "\n";
//Check graph once. Everything flow should be empty.
staticAnalyses[i]->JSONCFG(OS);
//Run worklist algorithm
staticAnalyses[i]->runWorklist();
//Check graph again. Everything flow should say top.
OS << "\nPrint CFG (with flow) : " << "\n";
staticAnalyses[i]->JSONCFG(OS);
}
}
};
}
char DummyOptimizationPass::ID = 0;
static RegisterPass<DummyOptimizationPass> X("dummyOptimization", "Dummy Optimization Pass", false, false);