From 985f7585633b541cc2ccdba2e347c8fb97e056c4 Mon Sep 17 00:00:00 2001 From: ayush-qubit Date: Sun, 11 Apr 2021 18:50:12 +0530 Subject: [PATCH 01/14] Added PHINode support --- include/Token/TokenWrapper.h | 21 +++++++++++++++++- lib/Token/TokenWrapper.cpp | 43 ++++++++++++++++++++---------------- lib/Utils/ReplaceIRVar.cpp | 9 ++++++-- 3 files changed, 51 insertions(+), 22 deletions(-) diff --git a/include/Token/TokenWrapper.h b/include/Token/TokenWrapper.h index 03186f6..365dc7d 100644 --- a/include/Token/TokenWrapper.h +++ b/include/Token/TokenWrapper.h @@ -42,9 +42,11 @@ class TokenWrapper { std::vector extractToken(llvm::GlobalVariable *); std::vector extractToken(llvm::CallInst *); std::vector extractToken(llvm::Argument *, llvm::Function *); + std::vector extractPHINodeToken(llvm::Instruction *); template std::pair extractStatementType(Ty *); - + + std::vector extractPHINodeStatementType(llvm::Instruction *); template Token *handleGEPUtil(GEP *, Token *); ~TokenWrapper(); @@ -52,4 +54,21 @@ class TokenWrapper { } // namespace spatial +namespace spatial{ + /// extractStatementType - Returns the relative level of redirection based of + /// LHS and RHS on the statement + template + std::pair TokenWrapper::extractStatementType(Ty *Inst) { + if (llvm::isa(Inst) || + llvm::isa(Inst) || + llvm::isa(Inst)) + return {1, 0}; + if (llvm::isa(Inst)) + return {2, 1}; + if (llvm::isa(Inst)) + return {1, 2}; + return {1, 1}; + } +} + #endif diff --git a/lib/Token/TokenWrapper.cpp b/lib/Token/TokenWrapper.cpp index 3ffe459..1827223 100644 --- a/lib/Token/TokenWrapper.cpp +++ b/lib/Token/TokenWrapper.cpp @@ -123,7 +123,9 @@ std::vector TokenWrapper::extractToken(llvm::Instruction *Inst) { return extractToken(GEP); } else if (llvm::CallInst *CI = llvm::dyn_cast(Inst)) { return extractToken(CI); - } else { + } else if(llvm::isa(Inst)){ + return extractPHINodeToken(Inst); + }else { // Direct support to some instructions may not be useful example // CallInst, as it is more useful to generate alias object for call // arguments on the fly @@ -248,25 +250,28 @@ std::vector TokenWrapper::extractToken(llvm::CallInst *CI) { return TokenVec; } -/// extractStatementType - Returns the relative level of redirection based of -/// LHS and RHS on the statement -template -std::pair TokenWrapper::extractStatementType(Ty *Inst) { - if (llvm::isa(Inst) || - llvm::isa(Inst) || - llvm::isa(Inst)) - return {1, 0}; - if (llvm::isa(Inst)) - return {2, 1}; - if (llvm::isa(Inst)) - return {1, 2}; - return {1, 1}; +/// extractPHINodeToken - Returns aliases for the PHINode instruction +std::vector TokenWrapper::extractPHINodeToken(llvm::Instruction *Inst){ + std::vector TokenVec; + Token *PhiNode = this->getToken(Inst); + TokenVec.push_back(PhiNode); + if(Inst->getOperand(0)->hasName()){ + TokenVec.push_back(this->getToken(Inst->getOperand(0))); + } + if(Inst->getOperand(1)->hasName()){ + TokenVec.push_back(this->getToken(Inst->getOperand(1))); + } + return TokenVec; +} + +/// extractPHINodeStetementType - Returns relative level of redirection based on LHS and RHS +/// for PHINode instruction. +std::vector TokenWrapper::extractPHINodeStatementType(llvm::Instruction *Inst){ + if(llvm::isa(Inst)){ + return {1,1,1}; + } + return {}; } -template std::pair -TokenWrapper::extractStatementType(llvm::Instruction *); -template std::pair -TokenWrapper::extractStatementType( - llvm::GlobalVariable *); /// handleGEPUtil - Returns the extended field value for a GEP template Token *TokenWrapper::handleGEPUtil(GEP *G, Token *Ptr) { diff --git a/lib/Utils/ReplaceIRVar.cpp b/lib/Utils/ReplaceIRVar.cpp index 5f3a097..bdafc1e 100644 --- a/lib/Utils/ReplaceIRVar.cpp +++ b/lib/Utils/ReplaceIRVar.cpp @@ -60,9 +60,14 @@ void ReplaceIRVar::runOnBasicBlock(llvm::BasicBlock &BB) { (DbgDeclare->getVariable()->getName()).str()); if (llvm::Instruction *I = llvm::dyn_cast(DbgDeclare->getAddress())) { - llvm::StringRef strref(this->NewName); - HashMap.insert(std::pair(I->getName().str(), + std::string Name = I->getName().str(); + if(HashMap.find(Name) != HashMap.end()){ + HashMap[Name] = this->NewName; + } + else{ + HashMap.insert(std::pair(I->getName().str(), this->NewName)); + } } } } From b9703458508097f64159f1fa230cf0e7e2a3180b Mon Sep 17 00:00:00 2001 From: ayush-qubit Date: Thu, 15 Apr 2021 19:39:02 +0530 Subject: [PATCH 02/14] Added NULL Pointer --- include/Graph/Graph.h | 9 +++++++-- include/Token/Token.h | 1 + include/Token/TokenWrapper.h | 3 ++- lib/Token/Token.cpp | 9 +++++++++ lib/Token/TokenWrapper.cpp | 11 +++++++++-- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/include/Graph/Graph.h b/include/Graph/Graph.h index b19c1a4..19d1b5d 100644 --- a/include/Graph/Graph.h +++ b/include/Graph/Graph.h @@ -55,8 +55,13 @@ void Graph::insert(Node *Src, Node *Dest, int Left, int Right) { } } else if (Left == 2 && Right == 1) { for (auto Src : this->getPointee(Src)) { - for (auto Dest : this->getPointee(Dest)) { - this->insert(Src, Dest); + if(Dest->isNull()){ + this->insert(Src,Dest); + } + else if(!Src->isNull()){ + for (auto Dest : this->getPointee(Dest)) { + this->insert(Src, Dest); + } } } } else if (Left == 1 && Right == 0) { diff --git a/include/Token/Token.h b/include/Token/Token.h index 35eba16..effde62 100644 --- a/include/Token/Token.h +++ b/include/Token/Token.h @@ -62,6 +62,7 @@ class Token { bool isGlobalVar() const; bool isAllocaOrArgOrGlobal() const; bool sameFunc(llvm::Function *Func) const; + bool isNull(); std::string getHash() const; bool operator<(const Token &TheToken) const; diff --git a/include/Token/TokenWrapper.h b/include/Token/TokenWrapper.h index 365dc7d..27425b5 100644 --- a/include/Token/TokenWrapper.h +++ b/include/Token/TokenWrapper.h @@ -63,8 +63,9 @@ namespace spatial{ llvm::isa(Inst) || llvm::isa(Inst)) return {1, 0}; - if (llvm::isa(Inst)) + if (llvm::isa(Inst)){ return {2, 1}; + } if (llvm::isa(Inst)) return {1, 2}; return {1, 1}; diff --git a/lib/Token/Token.cpp b/lib/Token/Token.cpp index d49f188..b1c33a4 100644 --- a/lib/Token/Token.cpp +++ b/lib/Token/Token.cpp @@ -196,6 +196,15 @@ bool Token::isArg() const { return this->Kind == 2; } /// isField - Returns true if alias is a field bool Token::isField() const { return this->Index != ""; } +bool Token::isNull(){ + if(this->Kind == 3 && this->name == "NULL"){ + return true; + } + else{ + return false; + } +} + /// isAllocaOrArgOrGlobal - Returns true if the alias is global, an argument or /// alloca bool Token::isAllocaOrArgOrGlobal() const { diff --git a/lib/Token/TokenWrapper.cpp b/lib/Token/TokenWrapper.cpp index 1827223..8533f18 100644 --- a/lib/Token/TokenWrapper.cpp +++ b/lib/Token/TokenWrapper.cpp @@ -154,8 +154,15 @@ std::vector TokenWrapper::extractToken(llvm::StoreInst *Inst) { std::vector TokenVec; TokenVec.push_back(this->getToken(Inst->getPointerOperand())); llvm::Value *ValOp = Inst->getValueOperand(); - if (!llvm::isa(ValOp)) - TokenVec.push_back(this->getToken(ValOp)); + // if (!llvm::isa(ValOp)) + // TokenVec.push_back(this->getToken(ValOp)); + if(llvm::ConstantPointerNull *Constant = llvm::dyn_cast(ValOp)){ + std::string s("NULL"); + TokenVec.push_back(this->getToken(s,Inst->getParent()->getParent())); + } + else if(!llvm::isa(ValOp)){ + TokenVec.push_back(this->getToken(ValOp)); + } return TokenVec; } From 37b297980f51ea049dde82bbd464ee05be6d0c23 Mon Sep 17 00:00:00 2001 From: ayush-qubit Date: Mon, 19 Apr 2021 18:04:51 +0530 Subject: [PATCH 03/14] Update ReplaceIRVar --- include/Utils/ReplaceIRVar.h | 1 + lib/Token/Token.cpp | 9 +-------- lib/Token/TokenWrapper.cpp | 8 ++++---- lib/Utils/ReplaceIRVar.cpp | 20 ++++++++++++-------- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/include/Utils/ReplaceIRVar.h b/include/Utils/ReplaceIRVar.h index cd6ddd7..3f401f3 100644 --- a/include/Utils/ReplaceIRVar.h +++ b/include/Utils/ReplaceIRVar.h @@ -23,6 +23,7 @@ class ReplaceIRVar { void init(llvm::BasicBlock &BB); void init(llvm::Module &M); void format(std::string First, std::string Second); + void insert(std::string); public: ReplaceIRVar(); diff --git a/lib/Token/Token.cpp b/lib/Token/Token.cpp index b1c33a4..f5d4197 100644 --- a/lib/Token/Token.cpp +++ b/lib/Token/Token.cpp @@ -196,14 +196,7 @@ bool Token::isArg() const { return this->Kind == 2; } /// isField - Returns true if alias is a field bool Token::isField() const { return this->Index != ""; } -bool Token::isNull(){ - if(this->Kind == 3 && this->name == "NULL"){ - return true; - } - else{ - return false; - } -} +bool Token::isNull() { return this->Kind == 3 && this->name == "NULL"; } /// isAllocaOrArgOrGlobal - Returns true if the alias is global, an argument or /// alloca diff --git a/lib/Token/TokenWrapper.cpp b/lib/Token/TokenWrapper.cpp index 8533f18..9f26061 100644 --- a/lib/Token/TokenWrapper.cpp +++ b/lib/Token/TokenWrapper.cpp @@ -156,9 +156,10 @@ std::vector TokenWrapper::extractToken(llvm::StoreInst *Inst) { llvm::Value *ValOp = Inst->getValueOperand(); // if (!llvm::isa(ValOp)) // TokenVec.push_back(this->getToken(ValOp)); - if(llvm::ConstantPointerNull *Constant = llvm::dyn_cast(ValOp)){ + // llvm::ConstantPointerNull *Constant = llvm::dyn_cast(ValOp) + if(llvm::isa(ValOp)){ std::string s("NULL"); - TokenVec.push_back(this->getToken(s,Inst->getParent()->getParent())); + TokenVec.push_back(this->getToken(s,nullptr)); } else if(!llvm::isa(ValOp)){ TokenVec.push_back(this->getToken(ValOp)); @@ -260,8 +261,7 @@ std::vector TokenWrapper::extractToken(llvm::CallInst *CI) { /// extractPHINodeToken - Returns aliases for the PHINode instruction std::vector TokenWrapper::extractPHINodeToken(llvm::Instruction *Inst){ std::vector TokenVec; - Token *PhiNode = this->getToken(Inst); - TokenVec.push_back(PhiNode); + TokenVec.push_back(this->getToken(Inst)); if(Inst->getOperand(0)->hasName()){ TokenVec.push_back(this->getToken(Inst->getOperand(0))); } diff --git a/lib/Utils/ReplaceIRVar.cpp b/lib/Utils/ReplaceIRVar.cpp index bdafc1e..bec91e9 100644 --- a/lib/Utils/ReplaceIRVar.cpp +++ b/lib/Utils/ReplaceIRVar.cpp @@ -41,6 +41,17 @@ void ReplaceIRVar::init(llvm::Module &M) { } } +/// insert IR Name and Source Name mapping +void ReplaceIRVar::insert(std::string Name){ + if(HashMap.find(Name) != HashMap.end()){ + HashMap[Name] = this->NewName; + } + else{ + HashMap.insert(std::pair(Name, + this->NewName)); + } +} + /// replace IR variable to Actual Variable for the Function passed as parameter void ReplaceIRVar::runOnFunction(llvm::Function &F) { this->init(F); @@ -60,14 +71,7 @@ void ReplaceIRVar::runOnBasicBlock(llvm::BasicBlock &BB) { (DbgDeclare->getVariable()->getName()).str()); if (llvm::Instruction *I = llvm::dyn_cast(DbgDeclare->getAddress())) { - std::string Name = I->getName().str(); - if(HashMap.find(Name) != HashMap.end()){ - HashMap[Name] = this->NewName; - } - else{ - HashMap.insert(std::pair(I->getName().str(), - this->NewName)); - } + this->insert(I->getName().str()); } } } From 1633165e0cf5feba4747df76dc06b72cc25eef8e Mon Sep 17 00:00:00 2001 From: ayush-qubit Date: Wed, 28 Apr 2021 21:58:05 +0530 Subject: [PATCH 04/14] Update ReplaceIRVar --- include/Utils/ReplaceIRVar.h | 6 +++--- lib/Utils/CFGUtils.cpp | 2 +- lib/Utils/ReplaceIRVar.cpp | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/Utils/ReplaceIRVar.h b/include/Utils/ReplaceIRVar.h index 3f401f3..55bdba4 100644 --- a/include/Utils/ReplaceIRVar.h +++ b/include/Utils/ReplaceIRVar.h @@ -27,8 +27,8 @@ class ReplaceIRVar { public: ReplaceIRVar(); - void runOnFunction(llvm::Function &F); - void runOnBasicBlock(llvm::BasicBlock &BB); - void runOnModule(llvm::Module &M); + void run(llvm::Function &F); + void run(llvm::BasicBlock &BB); + void run(llvm::Module &M); }; #endif \ No newline at end of file diff --git a/lib/Utils/CFGUtils.cpp b/lib/Utils/CFGUtils.cpp index ed14675..737c0ce 100644 --- a/lib/Utils/CFGUtils.cpp +++ b/lib/Utils/CFGUtils.cpp @@ -13,7 +13,7 @@ namespace spatial { /// InstNamer - sets name to the SSA temporaries void InstNamer(llvm::Function &F) { ReplaceIRVar Replace; - Replace.runOnFunction(F); + Replace.run(F); } bool SkipFunction(llvm::Function &F) { diff --git a/lib/Utils/ReplaceIRVar.cpp b/lib/Utils/ReplaceIRVar.cpp index bec91e9..cbc9b58 100644 --- a/lib/Utils/ReplaceIRVar.cpp +++ b/lib/Utils/ReplaceIRVar.cpp @@ -53,16 +53,16 @@ void ReplaceIRVar::insert(std::string Name){ } /// replace IR variable to Actual Variable for the Function passed as parameter -void ReplaceIRVar::runOnFunction(llvm::Function &F) { +void ReplaceIRVar::run(llvm::Function &F) { this->init(F); for (llvm::BasicBlock &BB : F) { - this->runOnBasicBlock(BB); + this->run(BB); } } /// replace IR variable to Actual Variable for the Basic Block passed as /// parameter -void ReplaceIRVar::runOnBasicBlock(llvm::BasicBlock &BB) { +void ReplaceIRVar::run(llvm::BasicBlock &BB) { this->init(BB); for (llvm::Instruction &I : BB) { if (const llvm::DbgDeclareInst *DbgDeclare = @@ -84,9 +84,9 @@ void ReplaceIRVar::runOnBasicBlock(llvm::BasicBlock &BB) { } /// replace IR variable to Actual Variable for the Module passed as parameter -void ReplaceIRVar::runOnModule(llvm::Module &M) { +void ReplaceIRVar::run(llvm::Module &M) { this->init(M); for (llvm::Function &F : M) { - this->runOnFunction(F); + this->run(F); } } From d9e62d3fe893c38ff22bfa2cef0660f1af3c5020 Mon Sep 17 00:00:00 2001 From: ayush-qubit Date: Thu, 29 Apr 2021 19:49:57 +0530 Subject: [PATCH 05/14] Added comment --- include/Token/Token.h | 2 +- lib/Token/Token.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/Token/Token.h b/include/Token/Token.h index effde62..6937eff 100644 --- a/include/Token/Token.h +++ b/include/Token/Token.h @@ -62,7 +62,7 @@ class Token { bool isGlobalVar() const; bool isAllocaOrArgOrGlobal() const; bool sameFunc(llvm::Function *Func) const; - bool isNull(); + bool isNull() const; std::string getHash() const; bool operator<(const Token &TheToken) const; diff --git a/lib/Token/Token.cpp b/lib/Token/Token.cpp index f5d4197..c4402cb 100644 --- a/lib/Token/Token.cpp +++ b/lib/Token/Token.cpp @@ -196,7 +196,8 @@ bool Token::isArg() const { return this->Kind == 2; } /// isField - Returns true if alias is a field bool Token::isField() const { return this->Index != ""; } -bool Token::isNull() { return this->Kind == 3 && this->name == "NULL"; } +///isNull - Returns true if alias is NULL +bool Token::isNull() const { return this->Kind == 3 && this->name == "NULL"; } /// isAllocaOrArgOrGlobal - Returns true if the alias is global, an argument or /// alloca From e41fa757ec37d8bf741b1f8f371f658a3f8d46be Mon Sep 17 00:00:00 2001 From: ayush-qubit Date: Sun, 11 Apr 2021 18:50:12 +0530 Subject: [PATCH 06/14] Added PHINode support --- lib/Utils/ReplaceIRVar.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Utils/ReplaceIRVar.cpp b/lib/Utils/ReplaceIRVar.cpp index 5f3a097..bdafc1e 100644 --- a/lib/Utils/ReplaceIRVar.cpp +++ b/lib/Utils/ReplaceIRVar.cpp @@ -60,9 +60,14 @@ void ReplaceIRVar::runOnBasicBlock(llvm::BasicBlock &BB) { (DbgDeclare->getVariable()->getName()).str()); if (llvm::Instruction *I = llvm::dyn_cast(DbgDeclare->getAddress())) { - llvm::StringRef strref(this->NewName); - HashMap.insert(std::pair(I->getName().str(), + std::string Name = I->getName().str(); + if(HashMap.find(Name) != HashMap.end()){ + HashMap[Name] = this->NewName; + } + else{ + HashMap.insert(std::pair(I->getName().str(), this->NewName)); + } } } } From 5227262b62dd2bd616b0d69d29f7cf8d46c95c4b Mon Sep 17 00:00:00 2001 From: ayush-qubit Date: Thu, 15 Apr 2021 19:39:02 +0530 Subject: [PATCH 07/14] Added NULL Pointer --- lib/Token/Token.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/Token/Token.cpp b/lib/Token/Token.cpp index 862ab27..dff58da 100644 --- a/lib/Token/Token.cpp +++ b/lib/Token/Token.cpp @@ -198,6 +198,15 @@ bool Token::isArg() const { return this->Kind == 2; } /// isField - Returns true if alias is a field bool Token::isField() const { return this->Index != ""; } +bool Token::isNull(){ + if(this->Kind == 3 && this->name == "NULL"){ + return true; + } + else{ + return false; + } +} + /// isAllocaOrArgOrGlobal - Returns true if the alias is global, an argument or /// alloca bool Token::isAllocaOrArgOrGlobal() const { From 137b91c33da79d59e15b5c02db420ef0690d5e37 Mon Sep 17 00:00:00 2001 From: ayush-qubit Date: Mon, 19 Apr 2021 18:04:51 +0530 Subject: [PATCH 08/14] Update ReplaceIRVar --- include/Utils/ReplaceIRVar.h | 1 + lib/Token/Token.cpp | 9 +-------- lib/Utils/ReplaceIRVar.cpp | 20 ++++++++++++-------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/include/Utils/ReplaceIRVar.h b/include/Utils/ReplaceIRVar.h index cd6ddd7..3f401f3 100644 --- a/include/Utils/ReplaceIRVar.h +++ b/include/Utils/ReplaceIRVar.h @@ -23,6 +23,7 @@ class ReplaceIRVar { void init(llvm::BasicBlock &BB); void init(llvm::Module &M); void format(std::string First, std::string Second); + void insert(std::string); public: ReplaceIRVar(); diff --git a/lib/Token/Token.cpp b/lib/Token/Token.cpp index dff58da..1a8d26c 100644 --- a/lib/Token/Token.cpp +++ b/lib/Token/Token.cpp @@ -198,14 +198,7 @@ bool Token::isArg() const { return this->Kind == 2; } /// isField - Returns true if alias is a field bool Token::isField() const { return this->Index != ""; } -bool Token::isNull(){ - if(this->Kind == 3 && this->name == "NULL"){ - return true; - } - else{ - return false; - } -} +bool Token::isNull() { return this->Kind == 3 && this->name == "NULL"; } /// isAllocaOrArgOrGlobal - Returns true if the alias is global, an argument or /// alloca diff --git a/lib/Utils/ReplaceIRVar.cpp b/lib/Utils/ReplaceIRVar.cpp index bdafc1e..bec91e9 100644 --- a/lib/Utils/ReplaceIRVar.cpp +++ b/lib/Utils/ReplaceIRVar.cpp @@ -41,6 +41,17 @@ void ReplaceIRVar::init(llvm::Module &M) { } } +/// insert IR Name and Source Name mapping +void ReplaceIRVar::insert(std::string Name){ + if(HashMap.find(Name) != HashMap.end()){ + HashMap[Name] = this->NewName; + } + else{ + HashMap.insert(std::pair(Name, + this->NewName)); + } +} + /// replace IR variable to Actual Variable for the Function passed as parameter void ReplaceIRVar::runOnFunction(llvm::Function &F) { this->init(F); @@ -60,14 +71,7 @@ void ReplaceIRVar::runOnBasicBlock(llvm::BasicBlock &BB) { (DbgDeclare->getVariable()->getName()).str()); if (llvm::Instruction *I = llvm::dyn_cast(DbgDeclare->getAddress())) { - std::string Name = I->getName().str(); - if(HashMap.find(Name) != HashMap.end()){ - HashMap[Name] = this->NewName; - } - else{ - HashMap.insert(std::pair(I->getName().str(), - this->NewName)); - } + this->insert(I->getName().str()); } } } From 55bd3af9b764145cd6c2f5add9db86525e4611a8 Mon Sep 17 00:00:00 2001 From: ayush-qubit Date: Wed, 28 Apr 2021 21:58:05 +0530 Subject: [PATCH 09/14] Update ReplaceIRVar --- include/Utils/ReplaceIRVar.h | 6 +++--- lib/Utils/CFGUtils.cpp | 2 +- lib/Utils/ReplaceIRVar.cpp | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/Utils/ReplaceIRVar.h b/include/Utils/ReplaceIRVar.h index 3f401f3..55bdba4 100644 --- a/include/Utils/ReplaceIRVar.h +++ b/include/Utils/ReplaceIRVar.h @@ -27,8 +27,8 @@ class ReplaceIRVar { public: ReplaceIRVar(); - void runOnFunction(llvm::Function &F); - void runOnBasicBlock(llvm::BasicBlock &BB); - void runOnModule(llvm::Module &M); + void run(llvm::Function &F); + void run(llvm::BasicBlock &BB); + void run(llvm::Module &M); }; #endif \ No newline at end of file diff --git a/lib/Utils/CFGUtils.cpp b/lib/Utils/CFGUtils.cpp index ed14675..737c0ce 100644 --- a/lib/Utils/CFGUtils.cpp +++ b/lib/Utils/CFGUtils.cpp @@ -13,7 +13,7 @@ namespace spatial { /// InstNamer - sets name to the SSA temporaries void InstNamer(llvm::Function &F) { ReplaceIRVar Replace; - Replace.runOnFunction(F); + Replace.run(F); } bool SkipFunction(llvm::Function &F) { diff --git a/lib/Utils/ReplaceIRVar.cpp b/lib/Utils/ReplaceIRVar.cpp index bec91e9..cbc9b58 100644 --- a/lib/Utils/ReplaceIRVar.cpp +++ b/lib/Utils/ReplaceIRVar.cpp @@ -53,16 +53,16 @@ void ReplaceIRVar::insert(std::string Name){ } /// replace IR variable to Actual Variable for the Function passed as parameter -void ReplaceIRVar::runOnFunction(llvm::Function &F) { +void ReplaceIRVar::run(llvm::Function &F) { this->init(F); for (llvm::BasicBlock &BB : F) { - this->runOnBasicBlock(BB); + this->run(BB); } } /// replace IR variable to Actual Variable for the Basic Block passed as /// parameter -void ReplaceIRVar::runOnBasicBlock(llvm::BasicBlock &BB) { +void ReplaceIRVar::run(llvm::BasicBlock &BB) { this->init(BB); for (llvm::Instruction &I : BB) { if (const llvm::DbgDeclareInst *DbgDeclare = @@ -84,9 +84,9 @@ void ReplaceIRVar::runOnBasicBlock(llvm::BasicBlock &BB) { } /// replace IR variable to Actual Variable for the Module passed as parameter -void ReplaceIRVar::runOnModule(llvm::Module &M) { +void ReplaceIRVar::run(llvm::Module &M) { this->init(M); for (llvm::Function &F : M) { - this->runOnFunction(F); + this->run(F); } } From 95b547916f22510854f09eea04a06c2cd70effc7 Mon Sep 17 00:00:00 2001 From: ayush-qubit Date: Thu, 29 Apr 2021 19:49:57 +0530 Subject: [PATCH 10/14] Added comment --- lib/Token/Token.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Token/Token.cpp b/lib/Token/Token.cpp index 1a8d26c..d00b456 100644 --- a/lib/Token/Token.cpp +++ b/lib/Token/Token.cpp @@ -198,7 +198,8 @@ bool Token::isArg() const { return this->Kind == 2; } /// isField - Returns true if alias is a field bool Token::isField() const { return this->Index != ""; } -bool Token::isNull() { return this->Kind == 3 && this->name == "NULL"; } +///isNull - Returns true if alias is NULL +bool Token::isNull() const { return this->Kind == 3 && this->name == "NULL"; } /// isAllocaOrArgOrGlobal - Returns true if the alias is global, an argument or /// alloca From 04b52d55af3ea83b414b1dc7e13d69c8c7aaf058 Mon Sep 17 00:00:00 2001 From: ayush-qubit <37446683+ayush-qubit@users.noreply.github.com> Date: Fri, 4 Jun 2021 17:40:20 +0530 Subject: [PATCH 11/14] Added NULL support and PHInode support --- .gitignore | 4 ++- include/Graph/Graph.h | 4 +++ .../GenericInstModel/GenericInstModel.h | 1 + include/Token/Token.h | 1 + .../GenericInstModel/GenericInstModel.cpp | 29 +++++++++++++++++-- lib/Token/Token.cpp | 4 +-- 6 files changed, 37 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index d163863..0e27f6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -build/ \ No newline at end of file +build/ +.vscode/ +.github/ \ No newline at end of file diff --git a/include/Graph/Graph.h b/include/Graph/Graph.h index 27e3046..acc4532 100644 --- a/include/Graph/Graph.h +++ b/include/Graph/Graph.h @@ -67,6 +67,10 @@ void Graph::insert(Node *Src, Node *Dest, int Left, int Right) { this->insert(Src, DestDest); } } + } else if(Left == 2 && Right == 0){ + for(auto Src : this->getPointee(Src)){ + this->insert(Src,Dest); + } } } diff --git a/include/InstModel/GenericInstModel/GenericInstModel.h b/include/InstModel/GenericInstModel/GenericInstModel.h index 45a4d21..4629066 100644 --- a/include/InstModel/GenericInstModel/GenericInstModel.h +++ b/include/InstModel/GenericInstModel/GenericInstModel.h @@ -32,6 +32,7 @@ class GenericInstModel : public InstModel { std::vector extractToken(llvm::GlobalVariable *); std::vector extractToken(llvm::CallInst *); std::vector extractToken(llvm::Argument *, llvm::Function *); + std::vector extractPHINodeToken(llvm::Instruction *); std::vector extractRedirections(llvm::GlobalVariable *); template Token *handleGEPUtil(GEP *, Token *); diff --git a/include/Token/Token.h b/include/Token/Token.h index 4baf33f..25095e7 100644 --- a/include/Token/Token.h +++ b/include/Token/Token.h @@ -63,6 +63,7 @@ class Token { bool isAllocaOrArgOrGlobal() const; bool sameFunc(llvm::Function *Func) const; bool isBasePointerType() const; + bool isNull() const; std::string getHash() const; bool operator<(const Token &TheToken) const; diff --git a/lib/InstModel/GenericInstModel/GenericInstModel.cpp b/lib/InstModel/GenericInstModel/GenericInstModel.cpp index d7c492d..fa06c32 100644 --- a/lib/InstModel/GenericInstModel/GenericInstModel.cpp +++ b/lib/InstModel/GenericInstModel/GenericInstModel.cpp @@ -29,6 +29,8 @@ std::vector GenericInstModel::extractToken(llvm::Instruction *Inst) { return extractToken(GEP); } else if (llvm::CallInst *CI = llvm::dyn_cast(Inst)) { return extractToken(CI); + } else if(llvm::isa(Inst)){ + return extractPHINodeToken(Inst); } else { // Direct support to some instructions may not be useful example // CallInst, as it is more useful to generate alias object for call @@ -60,8 +62,15 @@ std::vector GenericInstModel::extractToken(llvm::StoreInst *Inst) { TokenVec.push_back( this->getTokenWrapper()->getToken(Inst->getPointerOperand())); llvm::Value *ValOp = Inst->getValueOperand(); - if (!llvm::isa(ValOp)) - TokenVec.push_back(this->getTokenWrapper()->getToken(ValOp)); + if (!llvm::isa(ValOp)){ + if(llvm::isa(ValOp)){ + std::string s("NULL"); + TokenVec.push_back(this->getTokenWrapper()->getToken(s,nullptr)); + } + else{ + TokenVec.push_back(this->getTokenWrapper()->getToken(ValOp)); + } + } return TokenVec; } @@ -160,11 +169,23 @@ std::vector GenericInstModel::extractToken(llvm::CallInst *CI) { return TokenVec; } +std::vector GenericInstModel::extractPHINodeToken(llvm::Instruction *Inst){ + std::vector TokenVec; + TokenVec.push_back(this->getTokenWrapper()->getToken(Inst)); + if(Inst->getOperand(0)->hasName()){ + TokenVec.push_back(this->getTokenWrapper()->getToken(Inst->getOperand(0))); + } + if(Inst->getOperand(1)->hasName()){ + TokenVec.push_back(this->getTokenWrapper()->getToken(Inst->getOperand(1))); + } + return TokenVec; +} + /// extractRedirections - Returns the relative level of redirection based of /// LHS and RHS on the statement std::vector GenericInstModel::extractRedirections(llvm::Instruction *Inst) { - std::vector load{1, 2}, store{2, 1}, copy{1, 1}, assign{1, 0}; + std::vector load{1, 2}, store{2, 1}, copy{1, 1}, assign{1, 0}, phiNode{1,1,1}; if (llvm::isa(Inst) || llvm::isa(Inst)) return assign; @@ -172,6 +193,8 @@ GenericInstModel::extractRedirections(llvm::Instruction *Inst) { return store; if (llvm::isa(Inst)) return load; + if(llvm::isa(Inst)) + return phiNode; return copy; } diff --git a/lib/Token/Token.cpp b/lib/Token/Token.cpp index d00b456..72c92b7 100644 --- a/lib/Token/Token.cpp +++ b/lib/Token/Token.cpp @@ -168,7 +168,7 @@ llvm::StringRef Token::getName() const { /// getMemTypeName - Returns the memory type name std::string Token::getMemTypeName() const { std::string MemTyName = ""; - if (!this->isMem()) + if (!this->isMem() || this->isNull()) return MemTyName; llvm::raw_string_ostream RSO(MemTyName); this->Ty->print(RSO); @@ -187,7 +187,7 @@ std::string Token::getFunctionName() const { std::string Token::getFieldIndex() const { return this->Index; } /// isMem - Returns true if the alias denotes a location in heap -bool Token::isMem() const { return this->Kind == 1; } +bool Token::isMem() const { return this->Kind == 1 || this->isNull(); } /// isGlobalVar - Returns true if the alias is global bool Token::isGlobalVar() const { return this->IsGlobal; } From 95eb7ca7ed6b9fdf86fa743d4377e25410b9d64a Mon Sep 17 00:00:00 2001 From: ayush-qubit <37446683+ayush-qubit@users.noreply.github.com> Date: Fri, 4 Jun 2021 17:52:52 +0530 Subject: [PATCH 12/14] Update GenericModel.cpp --- lib/InstModel/GenericInstModel/GenericInstModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/InstModel/GenericInstModel/GenericInstModel.cpp b/lib/InstModel/GenericInstModel/GenericInstModel.cpp index fa06c32..fd1b78c 100644 --- a/lib/InstModel/GenericInstModel/GenericInstModel.cpp +++ b/lib/InstModel/GenericInstModel/GenericInstModel.cpp @@ -168,7 +168,7 @@ std::vector GenericInstModel::extractToken(llvm::CallInst *CI) { } return TokenVec; } - +/// extractPHINodeToken - Returns the alias objects for PHInode instruction std::vector GenericInstModel::extractPHINodeToken(llvm::Instruction *Inst){ std::vector TokenVec; TokenVec.push_back(this->getTokenWrapper()->getToken(Inst)); From de23f06a0545a8e0dc5a47a4244d58985430fe26 Mon Sep 17 00:00:00 2001 From: ayush-qubit <37446683+ayush-qubit@users.noreply.github.com> Date: Fri, 4 Jun 2021 21:32:33 +0530 Subject: [PATCH 13/14] Update Graph.h --- include/Graph/Graph.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Graph/Graph.h b/include/Graph/Graph.h index acc4532..a0abb19 100644 --- a/include/Graph/Graph.h +++ b/include/Graph/Graph.h @@ -68,8 +68,8 @@ void Graph::insert(Node *Src, Node *Dest, int Left, int Right) { } } } else if(Left == 2 && Right == 0){ - for(auto Src : this->getPointee(Src)){ - this->insert(Src,Dest); + for(auto S : this->getPointee(Src)){ + this->insert(S,Dest); } } } From e711e9722b21d0b38c0ea834a063354452ea9bf3 Mon Sep 17 00:00:00 2001 From: ayush-qubit <37446683+ayush-qubit@users.noreply.github.com> Date: Mon, 21 Jun 2021 20:24:53 +0530 Subject: [PATCH 14/14] Delete .gitignore --- .gitignore | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 0e27f6a..0000000 --- a/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -build/ -.vscode/ -.github/ \ No newline at end of file