From ed83c12e267fcbc4487773a0e93fb643fb84d557 Mon Sep 17 00:00:00 2001 From: Ajay Mohan <ajmohan@ucsd.edu> Date: Sat, 5 Dec 2015 00:28:06 +0000 Subject: [PATCH] Initial WorkList --- llvm/src/lib/CSE231/WorkList.cpp | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 llvm/src/lib/CSE231/WorkList.cpp diff --git a/llvm/src/lib/CSE231/WorkList.cpp b/llvm/src/lib/CSE231/WorkList.cpp new file mode 100644 index 0000000..7af834f --- /dev/null +++ b/llvm/src/lib/CSE231/WorkList.cpp @@ -0,0 +1,63 @@ +//The Worklist Alogrithm +//ARGS: +// Lattic_Definition class +// Function ptr +// Initial State +#include "llvm/ADT/StringMap.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/Instruction.h" +#include "llvm/Pass.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/InstIterator.h" +using namespace llvm; +namespace{ +class Edge{ + public: + BasicBlock *BB; + Instruction *IB; + bool isBlock(false); + bool isInstruction(false); +} +class CPElement{ + public: + //The variable + String variable; + //the value it holds + int value; +} + +void Worklist(Function *F) +{ + SmallVector<Edge*,256> WorkList; + + //Map of Edge(Basic Block/Instruction) to computed value + std::map<Edge*, std::set<CPElement> M; + //And its iterator + std::map<Edge*, std::set<CPElement>::iterator MI; + + //Null Element to initialize edge mappings + CPElement ElementNull = new CPElement(); + + ElementNull.variable = new String("phi"); + ElementNull.value = -1; + + //For every BasicBlock + //Add them to the Map + //And store ElementNull as their value + for(Function::iterator BB = FB->begin(), BE = FB->end(); BB != BE; ++BB) { + Edge BasicBlockEdge = new Edge(); + BasicBlockEdge.isBlock = true; + BasicBlockEdge.BB = BB; + M[BasicBlockEdge] = ElementNull + for (BasicBlock::iterator IB = BB->begin(), IE = BB->end();IB != IE; ++IB) { + //For every InstructionBlock + //Add them to the Map + //And store ElementNull as their value + Edge InstructionEdge = new Edge(); + InstructionEdge.isInstruction = true; + InstructionEdge.IB = IB; + M[InstructionEdge] = ElementNull; + } + } +} -- 1.9.1