Skip to content
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
1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

4 changes: 4 additions & 0 deletions include/Graph/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ void Graph<Node>::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);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions include/InstModel/GenericInstModel/GenericInstModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class GenericInstModel : public InstModel {
std::vector<Token *> extractToken(llvm::GlobalVariable *);
std::vector<Token *> extractToken(llvm::CallInst *);
std::vector<Token *> extractToken(llvm::Argument *, llvm::Function *);
std::vector<Token *> extractPHINodeToken(llvm::Instruction *);

std::vector<int> extractRedirections(llvm::GlobalVariable *);
template <typename GEP> Token *handleGEPUtil(GEP *, Token *);
Expand Down
1 change: 1 addition & 0 deletions include/Token/Token.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions include/Utils/ReplaceIRVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 26 additions & 3 deletions lib/InstModel/GenericInstModel/GenericInstModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ std::vector<Token *> GenericInstModel::extractToken(llvm::Instruction *Inst) {
return extractToken(GEP);
} else if (llvm::CallInst *CI = llvm::dyn_cast<llvm::CallInst>(Inst)) {
return extractToken(CI);
} else if(llvm::isa<llvm::PHINode>(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
Expand Down Expand Up @@ -60,8 +62,15 @@ std::vector<Token *> GenericInstModel::extractToken(llvm::StoreInst *Inst) {
TokenVec.push_back(
this->getTokenWrapper()->getToken(Inst->getPointerOperand()));
llvm::Value *ValOp = Inst->getValueOperand();
if (!llvm::isa<llvm::ConstantInt>(ValOp))
TokenVec.push_back(this->getTokenWrapper()->getToken(ValOp));
if (!llvm::isa<llvm::ConstantInt>(ValOp)){
if(llvm::isa<llvm::ConstantPointerNull>(ValOp)){
std::string s("NULL");
TokenVec.push_back(this->getTokenWrapper()->getToken(s,nullptr));
}
else{
TokenVec.push_back(this->getTokenWrapper()->getToken(ValOp));
}
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be written as:

  if (!llvm::isa<llvm::ConstantInt>(ValOp)) return TokenVec;      

  if (llvm::isa<llvm::ConstantPointerNull>(ValOp))
    TokenVec.push_back(this->getTokenWrapper()->getToken("NULL",nullptr));
  else
    TokenVec.push_back(this->getTokenWrapper()->getToken(ValOp));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are trying to say

if (llvm::isa<llvm::ConstantInt>(ValOp)) return TokenVec;

if (llvm::isa<llvm::ConstantPointerNull>(ValOp))
TokenVec.push_back(this->getTokenWrapper()->getToken("NULL",nullptr));
else
TokenVec.push_back(this->getTokenWrapper()->getToken(ValOp));

And if it is then I have done this. Can I do this more general way like instead of using llvm::ConstantInt that can use only for integer constant we can use llvm::Constant which is more general way to say constant because constant can be float or double also.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please :)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that there can be other places where ConstantInt is used and it will fail with floats and doubles (thanks for pointing that out). Can you please create a github issue for that?

return TokenVec;
}

Expand Down Expand Up @@ -159,19 +168,33 @@ std::vector<Token *> GenericInstModel::extractToken(llvm::CallInst *CI) {
}
return TokenVec;
}
/// extractPHINodeToken - Returns the alias objects for PHInode instruction
std::vector<Token *> GenericInstModel::extractPHINodeToken(llvm::Instruction *Inst){
std::vector<Token *> TokenVec;
TokenVec.push_back(this->getTokenWrapper()->getToken(Inst));
if(Inst->getOperand(0)->hasName()){
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use hasName; I think you are using hasName to check if it a variable or a constant? if yes, prefer checking if it is ConstantInt, like we did in the StoreInst.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done this with the help of llvm::Constant

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that will be great. Though, hasName will also work fine but it will add an explicit dependency to run instnamer or something instnamer like to get it working.

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<int>
GenericInstModel::extractRedirections(llvm::Instruction *Inst) {
std::vector<int> load{1, 2}, store{2, 1}, copy{1, 1}, assign{1, 0};
std::vector<int> load{1, 2}, store{2, 1}, copy{1, 1}, assign{1, 0}, phiNode{1,1,1};
if (llvm::isa<llvm::AllocaInst>(Inst) ||
llvm::isa<llvm::GetElementPtrInst>(Inst))
return assign;
if (llvm::isa<llvm::StoreInst>(Inst))
return store;
if (llvm::isa<llvm::LoadInst>(Inst))
return load;
if(llvm::isa<llvm::PHINode>(Inst))
return phiNode;
return copy;
}

Expand Down
7 changes: 5 additions & 2 deletions lib/Token/Token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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; }
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/Utils/CFGUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
25 changes: 17 additions & 8 deletions lib/Utils/ReplaceIRVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::string>(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 =
Expand All @@ -60,9 +71,7 @@ void ReplaceIRVar::runOnBasicBlock(llvm::BasicBlock &BB) {
(DbgDeclare->getVariable()->getName()).str());
if (llvm::Instruction *I =
llvm::dyn_cast<llvm::Instruction>(DbgDeclare->getAddress())) {
llvm::StringRef strref(this->NewName);
HashMap.insert(std::pair<std::string, std::string>(I->getName().str(),
this->NewName));
this->insert(I->getName().str());
}
}
}
Expand All @@ -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);
}
}