diff --git a/.gitignore b/.gitignore deleted file mode 100644 index d163863..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -build/ \ No newline at end of file diff --git a/include/Graph/Graph.h b/include/Graph/Graph.h index 27e3046..a0abb19 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 S : this->getPointee(Src)){ + this->insert(S,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/include/Utils/ReplaceIRVar.h b/include/Utils/ReplaceIRVar.h index cd6ddd7..55bdba4 100644 --- a/include/Utils/ReplaceIRVar.h +++ b/include/Utils/ReplaceIRVar.h @@ -23,11 +23,12 @@ 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(); - 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/InstModel/GenericInstModel/GenericInstModel.cpp b/lib/InstModel/GenericInstModel/GenericInstModel.cpp index d7c492d..fd1b78c 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; } @@ -159,12 +168,24 @@ 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)); + 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 862ab27..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; } @@ -198,6 +198,9 @@ bool Token::isArg() const { return this->Kind == 2; } /// isField - Returns true if alias is a field bool Token::isField() const { return this->Index != ""; } +///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 bool Token::isAllocaOrArgOrGlobal() const { 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 5f3a097..cbc9b58 100644 --- a/lib/Utils/ReplaceIRVar.cpp +++ b/lib/Utils/ReplaceIRVar.cpp @@ -41,17 +41,28 @@ 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) { +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 = @@ -60,9 +71,7 @@ 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(), - this->NewName)); + this->insert(I->getName().str()); } } } @@ -75,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); } }