Skip to content

[SandboxIR] Implement UnreachableInst #101856

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

Merged

Conversation

wizardengineer
Copy link
Contributor

This patch implements the UnreachableInst instruction in SandboxIR. Mirroring llvm::UnreachableInst.

cc: @vporpo

Copy link

github-actions bot commented Aug 4, 2024

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.
Please turn off Keep my email addresses private setting in your account.
See LLVM Discourse for more information.

Copy link
Contributor

@vporpo vporpo left a comment

Choose a reason for hiding this comment

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

Hmm does the test actually pass?

For the instruction to be created as a sanbdoxir::UnreachableInst we need to add the following code in Value *Context::getOrCreateValueInternal(llvm::Value *LLVMV, llvm::User *U):

  case llvm::Instruction::Unreachable: {
    auto *LLVMUnreachable = cast<llvm::UnreachableInst>(LLVMV);
    It->second = std::unique_ptr<UnreachableInst>(new UnreachableInst(LLVMUnreachable, *this));
    return It->second.get();
  }

@wizardengineer
Copy link
Contributor Author

wizardengineer commented Aug 4, 2024

Hmm does the test actually pass?

For the instruction to be created as a sanbdoxir::UnreachableInst we need to add the following code in Value *Context::getOrCreateValueInternal(llvm::Value *LLVMV, llvm::User *U):

  case llvm::Instruction::Unreachable: {
    auto *LLVMUnreachable = cast<llvm::UnreachableInst>(LLVMV);
    It->second = std::unique_ptr<UnreachableInst>(new UnreachableInst(LLVMUnreachable, *this));
    return It->second.get();
  }

Good catch. Interestingly, the test did pass, but I'm not entirely sure why, if the code you sent me is required. It might be a case of "it works on my computer.", where I'm getting a faulty pass. I made sure to add it.

Copy link

github-actions bot commented Aug 4, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@wizardengineer
Copy link
Contributor Author

wizardengineer commented Aug 5, 2024

@vporpo is it okay for you to merge this or is there more changes you need me to make?

@wizardengineer
Copy link
Contributor Author

wizardengineer commented Aug 7, 2024

@vporpo Apologies for the inconvenience and wait, didn't mean to aruptly commit those recent changes. I'm just now seeing your comment about wanting to see the backtrace.

Backtrace
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
  * frame #0: 0x0000000100099950 SandboxIRTests`llvm::sandboxir::Instruction::getPrevNode() const + 20
    frame #1: 0x000000010009bf54 SandboxIRTests`llvm::sandboxir::UnreachableInst::create(llvm::sandboxir::Instruction*, llvm::sandboxir::Context&) + 36
    frame #2: 0x0000000100033c40 SandboxIRTests`SandboxIRTest_UnreachableInst_Test::TestBody() + 772
    frame #3: 0x0000000100206114 SandboxIRTests`testing::Test::Run() + 528
    frame #4: 0x0000000100206fa0 SandboxIRTests`testing::TestInfo::Run() + 608
    frame #5: 0x0000000100207be8 SandboxIRTests`testing::TestSuite::Run() + 988
    frame #6: 0x0000000100216098 SandboxIRTests`testing::internal::UnitTestImpl::RunAllTests() + 2220
    frame #7: 0x0000000100215774 SandboxIRTests`testing::UnitTest::Run() + 124
    frame #8: 0x00000001001f8170 SandboxIRTests`main + 148
    frame #9: 0x000000018adea0e0 dyld`start + 2360

Copy link
Contributor

@vporpo vporpo left a comment

Choose a reason for hiding this comment

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

I think I figured out what the problem was. I have updated the comments. To summarize, just drop ret void and change the code to InsertBefore UI, and the test should pass.

Copy link
Contributor

@vporpo vporpo left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for the patch!

@vporpo vporpo merged commit e546430 into llvm:main Aug 7, 2024
7 checks passed
@wizardengineer wizardengineer deleted the _SandboxIR_Implement_UnreachableInst branch March 9, 2025 20:22
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.

2 participants