Commit ed83c12e267fcbc4487773a0e93fb643fb84d557

Authored by Ajay Mohan
1 parent 3c0f7cc60d
Exists in master

Initial WorkList

Showing 1 changed file with 63 additions and 0 deletions Inline Diff

llvm/src/lib/CSE231/WorkList.cpp View file @ ed83c12
File was created 1 //The Worklist Alogrithm
2 //ARGS:
3 // Lattic_Definition class
4 // Function ptr
5 // Initial State
6 #include "llvm/ADT/StringMap.h"
7 #include "llvm/IR/Function.h"
8 #include "llvm/IR/Module.h"
9 #include "llvm/IR/Instruction.h"
10 #include "llvm/Pass.h"
11 #include "llvm/Support/raw_ostream.h"
12 #include "llvm/Support/InstIterator.h"
13 using namespace llvm;
14 namespace{
15 class Edge{
16 public:
17 BasicBlock *BB;
18 Instruction *IB;
19 bool isBlock(false);
20 bool isInstruction(false);
21 }
22 class CPElement{
23 public:
24 //The variable
25 String variable;
26 //the value it holds
27 int value;
28 }
29
30 void Worklist(Function *F)
31 {
32 SmallVector<Edge*,256> WorkList;
33
34 //Map of Edge(Basic Block/Instruction) to computed value
35 std::map<Edge*, std::set<CPElement> M;
36 //And its iterator
37 std::map<Edge*, std::set<CPElement>::iterator MI;
38
39 //Null Element to initialize edge mappings
40 CPElement ElementNull = new CPElement();
41
42 ElementNull.variable = new String("phi");
43 ElementNull.value = -1;
44
45 //For every BasicBlock
46 //Add them to the Map
47 //And store ElementNull as their value
48 for(Function::iterator BB = FB->begin(), BE = FB->end(); BB != BE; ++BB) {
49 Edge BasicBlockEdge = new Edge();
50 BasicBlockEdge.isBlock = true;
51 BasicBlockEdge.BB = BB;
52 M[BasicBlockEdge] = ElementNull
53 for (BasicBlock::iterator IB = BB->begin(), IE = BB->end();IB != IE; ++IB) {
54 //For every InstructionBlock
55 //Add them to the Map
56 //And store ElementNull as their value
57 Edge InstructionEdge = new Edge();
58 InstructionEdge.isInstruction = true;