Skip to content
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

Merged
merged 1 commit into from
Jul 23, 2024
Merged

[SandboxIR] Implement BranchInst #100063

merged 1 commit into from
Jul 23, 2024

Conversation

vporpo
Copy link
Contributor

@vporpo vporpo commented Jul 23, 2024

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.

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 {
Copy link
Member

Choose a reason for hiding this comment

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

Copy-paste?

Copy link
Member

Choose a reason for hiding this comment

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

Do I need both?

Copy link
Contributor Author

@vporpo vporpo Jul 23, 2024

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.

Copy link
Member

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(); }
Copy link
Member

Choose a reason for hiding this comment

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

number + bool?

Copy link
Member

@tschuett tschuett Jul 23, 2024

Choose a reason for hiding this comment

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

return isConditional() ? 2 : 1;

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Ignore me again.

Copy link
Contributor Author

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,
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good!

Copy link
Member

@tmsri tmsri left a 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,
Copy link
Member

Choose a reason for hiding this comment

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

Sounds good!

@vporpo vporpo merged commit 3993da2 into llvm:main Jul 23, 2024
8 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 23, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-win-fast running on as-builder-3 while building llvm at step 7 "test-build-unified-tree-check-llvm-unit".

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:

Step 7 (test-build-unified-tree-check-llvm-unit) failure: test (failure)
******************** TEST 'LLVM-Unit :: SandboxIR/./SandboxIRTests.exe/9/19' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\build\unittests\SandboxIR\.\SandboxIRTests.exe-LLVM-Unit-13192-9-19.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=19 GTEST_SHARD_INDEX=9 C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\build\unittests\SandboxIR\.\SandboxIRTests.exe
--

Script:
--
C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\build\unittests\SandboxIR\.\SandboxIRTests.exe --gtest_filter=SandboxIRTest.BranchInst
--
C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\llvm\unittests\SandboxIR\SandboxIRTest.cpp(688): error: Death test: Br->getCondition()
    Result: failed to die.
 Error msg:
[  DEATH   ] 

C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\llvm\unittests\SandboxIR\SandboxIRTest.cpp(700): error: Death test: Br->getCondition()
    Result: failed to die.
 Error msg:
[  DEATH   ] 


C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\llvm\unittests\SandboxIR\SandboxIRTest.cpp:688
Death test: Br->getCondition()
    Result: failed to die.
 Error msg:
[  DEATH   ] 

C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\llvm\unittests\SandboxIR\SandboxIRTest.cpp:700
Death test: Br->getCondition()
    Result: failed to die.
 Error msg:
[  DEATH   ] 



********************


vporpo added a commit that referenced this pull request Jul 23, 2024
@vporpo
Copy link
Contributor Author

vporpo commented Jul 23, 2024

Reverted: c312a1a the death tests need to be enabled only for the DEBUG build.

vporpo added a commit that referenced this pull request Jul 23, 2024
@vporpo
Copy link
Contributor Author

vporpo commented Jul 23, 2024

Reapplied: c444548

yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
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.
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
Summary: This reverts commit 3993da2.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60251030
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
Summary: This reverts commit c312a1a.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60251151
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants