-
Notifications
You must be signed in to change notification settings - Fork 5
Updated ReplaceIRVar.cpp #18
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
base: master
Are you sure you want to change the base?
Changes from all commits
e41fa75
5227262
137b91c
55bd3af
95b5479
04b52d5
95eb7ca
90f267e
b81918b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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)); | ||
| } | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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));
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, please :)
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
|
|
||
|
|
@@ -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()){ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have done this with the help of llvm::Constant
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.