Skip to content

Cleanup lpd #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: mlbridge-lib
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@ using namespace llvm;
void DependenceDistanceMutation::Mutate_InstList(
InstructionListType StoreInstList, LLVMContext &Context) {
for (auto S : StoreInstList) {
// errs() << "StoreInstList: " << *S << "\n";

for (auto i = S->op_begin(), e = S->op_end(); i != e; ++i) {
if (dyn_cast<Instruction>(&(**i))) {
Instruction *OP = dyn_cast<Instruction>(&(**i));
// errs() << "OP: " << *OP << "\n";
if (isa<GetElementPtrInst>(OP)) {
auto array_OP = dyn_cast<GetElementPtrInst>(OP);
// errs() << "Number of indices: " << array_OP->getNumOperands() << "\n";
// errs() << "Name: " << OP->getName() << "\n";


bool flag_Name = 0;
for (auto n : NameList) {
if (n == OP->getName()) {
Expand All @@ -43,27 +39,19 @@ void DependenceDistanceMutation::Mutate_InstList(

if (flag_Name == 0) {
NameList.push_back(OP->getName());
// errs() << "Name3: " << OP->getName() << "\n";

unsigned op_i = array_OP->getNumOperands() - 1;
// for (unsigned op_i = 1; op_i < array_OP->getNumOperands(); ++op_i)
// {
auto array_index = dyn_cast<Instruction>(array_OP->getOperand(op_i));
// errs() << "op_i: " << *array_index << "\n";

// Create new "add" instruction
IRBuilder<> builder(array_OP);
auto *OP_type = array_OP->getOperand(op_i)->getType();
Value *Right = ConstantInt::get(Type::getInt64Ty(Context), mutate);
// errs() << "aaaaaaaaaaa: " << *OP_type << " : " << *Right->getType()
// << "\n";
Value *Result = builder.CreateAdd(array_OP->getOperand(op_i), Right);
errs() << "bbbbbbbbbbbbbbbbbb: " << *Result << "\n";

array_OP->setOperand(op_i, Result);
}

// }
}
}
// errs() << "\n";
Expand Down Expand Up @@ -221,27 +209,16 @@ bool DependenceDistanceMutation::runOnFunction(Function &F) {
break;
}
if (flag_MergedList == 0) {
// errs() << "StoreInstList: " << *S << "\n";
MergedInstList.push_back(S);
}
}
else {
// errs() << "StoreInstList: " << *S << "\n";
MergedInstList.push_back(S);
}
}
}

Mutate_InstList(MergedInstList, Context);


// Mutate all instruction inside StoreInstList
// errs() << "aaaaaaaaaaaaaaaaaaaa\n";
// Mutate_InstList(StoreInstList, Context);

// Mutate all instruction inside WAWInstList
// errs() << "bbbbbbbbbbbbbbbbbbbbb\n";
// Mutate_InstList(WAWInstList, Context);
}
}
return false;
Expand Down
44 changes: 3 additions & 41 deletions llvm/lib/Transforms/Scalar/IR2Vec-LOF/IR2Vec-SCC/IR2Vec-SCC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,6 @@ void RDGWrapperPass::Print_IR2Vec_File(DataDependenceGraph &G,
if (tgtNode->NodeLabel != "") {
if ((*E).isMemoryDependence()) {
md++;
// errs() << NodeNumber.find(N)->second << " -> "
// << NodeNumber.find(&E->getTargetNode())->second << " :
// "
// << (*E).getKind() << " : " << (*E).getEdgeWeight() <<
// "\n";

File << NodeNumber.find(N)->second << " -> "
<< NodeNumber.find(&E->getTargetNode())->second
<< "[label=\"" << (*E).getKind() << ": "
Expand Down Expand Up @@ -200,9 +194,6 @@ void RDGWrapperPass::addMCACalls(Loop *L, int loopID) const {
bool RDGWrapperPass::runOnFunction(Function &F) { return computeRDG(F); }

bool RDGWrapperPass::computeRDG(Function &F) {
// errs()<<"Inside RDGWrapperPass:\n";
// F.dump();

DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();

Expand Down Expand Up @@ -289,17 +280,11 @@ void RDGWrapperPass::canonicalizeLoopsWithLoads(
auto dest = tuples[1];
auto insv = tuples[2];
auto inst = dyn_cast<Instruction>(insv);
// errs() << "inst: ";
// inst->dump();
auto ldInst = new LoadInst(dest, "");
ldInst->insertBefore(inst);
for (unsigned i = 0; i < inst->getNumOperands(); i++) {
if (inst->getOperand(i) == src) {
inst->setOperand(i, ldInst);
// errs() << "Operand set successfully - ";
// inst->dump();
// errs() << "===\n";
// inst->getParent()->dump();
break;
}
}
Expand Down Expand Up @@ -342,11 +327,6 @@ void RDGWrapperPass::populateDOTData(DataDependenceGraph &G,
continue;

auto Vec = instVecMap.find(II)->second;
// errs() << "Vec[" << II << "] = ";
// for (unsigned I = 0; I < DIM; ++I)
// errs() << Vec[I] << " ";
// errs() << "\n";
// errs() << "End\n";
if (!Found) {
NodeVec = Vec;
Found = true;
Expand All @@ -356,13 +336,7 @@ void RDGWrapperPass::populateDOTData(DataDependenceGraph &G,
}
}
// rdg.NodeRepresentations[stoi(N->NodeLabel.substr(1)) - 1] = NodeVec;
// errs() << "Nodevecd : ---\n";
// for(unsigned I = 0; I < DIM; ++I)
// {
// errs() << NodeVec[I] << " ";
// }
// errs() << "\n";
// errs() << "End\n";

NodeNumber.insert(std::make_pair(N, N->NodeLabel));
}
LLVM_DEBUG(errs() << "**before adjlist filling\n");
Expand Down Expand Up @@ -412,26 +386,18 @@ RDGData RDGWrapperPass::computeRDGForFunction(Function &F) {
int loopNum = 0;
for (LoopInfo::iterator i = LI->begin(), e = LI->end(); i != e; ++i) {
Loop *L = *i;
// L->dump();
// errs() << " came lo line 376\n";
for (auto il = df_begin(L), el = df_end(L); il != el; ++il) {
if (il->getSubLoops().size() > 0) {
// errs() << "IR2Vec-SCC.cpp : line 377\n";
continue;
}

// for (auto i : il->blocks()) {
// i->dump();
// }


// Append Memory Dependence Edges with weights into Graph
loopNum++;
auto *LAA = &getAnalysis<LoopAccessLegacyAnalysis>();
const LoopAccessInfo &LAI = LAA->getInfo(*il);
auto RDGraph = RDG(*AA, *SE, *LI, DI, LAI, ORE);
// errs() << "Function Name: " << F.getName() <<"\n";
// errs() << "**** LOOP No. :" << loopNum << "\n";


auto SCC_Graph = RDGraph.computeRDGForInnerLoop(**il);

if (SCC_Graph == nullptr) {
Expand All @@ -458,7 +424,6 @@ RDGData RDGWrapperPass::computeRDGForFunction(Function &F) {
std::string SCC_Filename = "S_" + s2 + "_F" +
std::to_string(FunctionNumber) + "_L" +
std::to_string(loopNum) + ".dot";
// "S_" + s3 + "_F_" + s4 + "_L" + std::to_string(loopNum) + ".dot";

LLVM_DEBUG(errs() << "Writing " + SCC_Filename + "\n");
RDGraph.PrintDotFile_LAI(SCCGraph, SCC_Filename, s1);
Expand All @@ -468,13 +433,10 @@ RDGData RDGWrapperPass::computeRDGForFunction(Function &F) {
content.assign((std::istreambuf_iterator<char>(ifs)),
(std::istreambuf_iterator<char>()));

// errs() << "String: " << content << "\n";

// Print Input File
std::string Input_Filename = "I_" + s2 + "_F" +
std::to_string(FunctionNumber) + "_L" +
std::to_string(loopNum) + ".dot";
// "I_" + s3 + "_F_" + s4 + "_L" + std::to_string(loopNum) + ".dot";

LLVM_DEBUG(errs() << "Writing " + Input_Filename + "\n");
Print_IR2Vec_File(SCCGraph, Input_Filename, s2, loopNum);
Expand Down
17 changes: 1 addition & 16 deletions llvm/lib/Transforms/Scalar/IR2Vec-LOF/LoopCost/LoopCost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ bool LoopCost::runOnFunction(Function &F) {
if (F.getName() != funcName)
return false;

errs() << "Function Name: " << F.getName() << "\n";
// auto *AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
auto *LI = &getAnalysis<LoopInfoWrapperPass>(F).getLoopInfo();
auto *LAA = &getAnalysis<LoopAccessLegacyAnalysis>(F);
Expand Down Expand Up @@ -183,12 +182,8 @@ bool LoopCost::runOnFunction(Function &F) {
}
}

errs() << "loop ID: " << L->getLoopID() << "\n";
L->dump();
dbgs() << "VF: " << VF << "\n";
dbgs() << "IF: " << IF << "\n";
dbgs() << "TC: " << TripCount << "\n";


Loop *InstCostLoop = nullptr;
if (VecLoop)
InstCostLoop = VecLoop;
Expand All @@ -206,7 +201,6 @@ bool LoopCost::runOnFunction(Function &F) {
}

LoopCost = LoopCost * (TripCount / (VF * IF));
dbgs() << "Loop cost with only instructions: " << LoopCost << "\n";

for (auto BB : L->getBlocks()) {
for (auto &I : *BB) {
Expand All @@ -219,21 +213,15 @@ bool LoopCost::runOnFunction(Function &F) {
// const LoopAccessInfo &LAI_WR = LAA->getInfo(L);
// const LoopAccessInfo &LAI_RAR = LAA->getInfo(L, 1);

errs() << "aaaaaaaaaaaaaaaaaaaaa\n";
Locality CL(TTI);
int64_t CacheMisses = CL.computeLocalityCost(L, TripCount, SE, DI);
LoopCost = LoopCost * (TripCount / (VF * IF));
dbgs() << "Loop cost with only instructions: " << LoopCost << "\n";
uint64_t TotalMemAccess =
NumMemInsts * ((TripCount == 1000) ? TripCount : TripCount * (VF * IF));
dbgs() << "Total memory accesses : " << NumMemInsts << " * " << TripCount
<< " = " << TotalMemAccess << "\n";
uint64_t CacheCost =
CacheMisses * (0.7 * MemoryInstCost) +
(TotalMemAccess - CacheMisses) * (0.3 * MemoryInstCost);
dbgs() << "Cache cost: " << CacheCost << "\n";
uint64_t TotalLoopCost = LoopCost + CacheCost;
dbgs() << "TotalLoopCost for Loop: " << TotalLoopCost << "\n";

this->loop_cost= TotalLoopCost;
}
Expand Down Expand Up @@ -297,7 +285,6 @@ void LoopCost::GetInnerLoops(Loop *L, SmallVectorImpl<Loop *> &InnerLoops) {
}

uint64_t LoopCost::getLoopCost() {
errs() << "function Name: " << funcName << " loop ID: " << loopID << " loop Cost: " << this->loop_cost << "\n";
return this->loop_cost;
}
// Registering the pass
Expand Down Expand Up @@ -381,7 +368,6 @@ int64_t Locality::computeLocalityCost(Loop *L, unsigned TripCount,
}
}

// errs() << "Src:" << *SrcI << " --> Dst:" << *DstI << "\n";
}
}
}
Expand Down Expand Up @@ -451,7 +437,6 @@ int64_t Locality::computeLocalityCost(Loop *L, unsigned TripCount,
}
}
}
errs() << "Total cache misses : " << Locality_Cost << "\n";
return Locality_Cost;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
// #include <llvm/IR/LegacyPassManager.h>
// #include "llvm/IR/PassManager.h"
// #include "llvm/Analysis/CFG.h"
#include "llvm/Analysis/LoopAccessAnalysis.h"
#include "llvm/Analysis/LoopAnalysisManager.h"
#include "llvm/InitializePasses.h"
Expand Down Expand Up @@ -239,12 +236,9 @@ Loop *LoopDistribution::cloneLoop(Loop *L, LoopInfo *LI, DominatorTree *DT,
// it was empty.
assert(&*oldPreheader->begin() == oldPreheader->getTerminator() &&
"preheader not empty");
// errs() << "here1- before cloning\n";
Loop *newLoop =
cloneLoopWithPreheader(L->getLoopPreheader(), L->getLoopPreheader(), L,
VMap, Twine("new-"), LI, DT, newLoopBlocks);
// errs() << "here2- after cloning\n";


// VMap can contain mappings at instruction level or BB level
// The code below obtains VMap at instruction level from BB level
Expand Down
Loading