Commit c28e27be2b9649c39970d0e8b731be2b99ed7a29

Authored by Ajay Mohan
1 parent ed83c12e26
Exists in master

Reduce Compile Errors

Showing 1 changed file with 20 additions and 15 deletions Inline Diff

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