-
Notifications
You must be signed in to change notification settings - Fork 11.5k
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
[SandboxIR] Implement BranchInst #100063
[SandboxIR] Implement BranchInst #100063
Conversation
This patch implements sandboxir::BranchInst which mirrors llvm::BranchInst. BranchInst::swapSuccessors() relies on User::swapOperandsInternal() so this patch also adds Use::swap() and the corresponding tracking code and test.
bool isUnconditional() const { | ||
return cast<llvm::BranchInst>(Val)->isUnconditional(); | ||
} | ||
bool isConditional() const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy-paste?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I need both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of these function exist in llvm::BranchInst
, so since we are trying to create a similar API I guess we should keep both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore that, I was too fast.
} | ||
Value *getCondition() const; | ||
void setCondition(Value *V) { setOperand(0, V); } | ||
unsigned getNumSuccessors() const { return 1 + isConditional(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
number + bool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return isConditional() ? 2 : 1;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I could have casted it to unsigned first, but this is how it's done in llvm::BranchInst::getNumSuccessors()
so I just copied it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am just afraid some compiler, including future Clang will complain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't worry too much about it, it's legal c++. Casting bool to int gives us 0 or 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore me again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's always good to point out things that look strange or potentially wrong, so thanks for the comments.
Context &Ctx); | ||
static BranchInst *create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd, | ||
Context &Ctx); | ||
static BranchInst *create(BasicBlock *IfTrue, BasicBlock *IfFalse, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't IfFalse == nullptr be the one that creates the instruction with only the true branch? That way you save creating two functions or put it as a default parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that would make sense, but I guess it is not as explicit as having a separate function. This is how it's done in llvm::BranchInst
so I just created a similar API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly different from other instruction adds like ReturnInst and includes tracking, approving it.
Context &Ctx); | ||
static BranchInst *create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd, | ||
Context &Ctx); | ||
static BranchInst *create(BasicBlock *IfTrue, BasicBlock *IfFalse, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/2/builds/2919 Here is the relevant piece of the build log for the reference:
|
Reverted: c312a1a the death tests need to be enabled only for the DEBUG build. |
Reapplied: c444548 |
This patch implements sandboxir::BranchInst which mirrors llvm::BranchInst. BranchInst::swapSuccessors() relies on User::swapOperandsInternal() so this patch also adds Use::swap() and the corresponding tracking code and test.
Summary: This reverts commit 3993da2. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251030
Summary: This reverts commit c312a1a. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251151
This patch implements sandboxir::BranchInst which mirrors llvm::BranchInst.
BranchInst::swapSuccessors() relies on User::swapOperandsInternal() so this patch also adds Use::swap() and the corresponding tracking code and test.