Skip to content
Merged
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
36 changes: 3 additions & 33 deletions llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2013,24 +2013,6 @@ bool WebAssemblyCFGStackify::fixCallUnwindMismatches(MachineFunction &MF) {
return true;
}

// Returns the single destination of try_table, if there is one. All try_table
// we generate in this pass has a single destination, i.e., a single catch
// clause.
static MachineBasicBlock *getSingleUnwindDest(const MachineInstr *TryTable) {
if (TryTable->getOperand(1).getImm() != 1)
return nullptr;
switch (TryTable->getOperand(2).getImm()) {
case wasm::WASM_OPCODE_CATCH:
case wasm::WASM_OPCODE_CATCH_REF:
return TryTable->getOperand(4).getMBB();
case wasm::WASM_OPCODE_CATCH_ALL:
case wasm::WASM_OPCODE_CATCH_ALL_REF:
return TryTable->getOperand(3).getMBB();
default:
llvm_unreachable("try_table: Invalid catch clause\n");
}
}

bool WebAssemblyCFGStackify::fixCatchUnwindMismatches(MachineFunction &MF) {
// This function is used for both the legacy EH and the standard (exnref) EH,
// and the reason we have unwind mismatches is the same for the both of them,
Expand Down Expand Up @@ -2141,25 +2123,13 @@ bool WebAssemblyCFGStackify::fixCatchUnwindMismatches(MachineFunction &MF) {

for (auto &MBB : reverse(MF)) {
for (auto &MI : reverse(MBB)) {
if (MI.getOpcode() == WebAssembly::TRY)
if (WebAssembly::isTry(MI.getOpcode())) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added braces for consistency.

EHPadStack.pop_back();
else if (MI.getOpcode() == WebAssembly::TRY_TABLE) {
// We want to exclude try_tables created in fixCallUnwindMismatches.
// Check if the try_table's unwind destination matches the EH pad stack
// top. If it is created in fixCallUnwindMismatches, it wouldn't.
if (getSingleUnwindDest(&MI) == EHPadStack.back())
EHPadStack.pop_back();
} else if (MI.getOpcode() == WebAssembly::DELEGATE)
} else if (MI.getOpcode() == WebAssembly::DELEGATE) {
EHPadStack.push_back(&MBB);
else if (WebAssembly::isCatch(MI.getOpcode())) {
} else if (WebAssembly::isCatch(MI.getOpcode())) {
auto *EHPad = &MBB;

// If the BB has a catch pseudo instruction but is not marked as an EH
// pad, it's a trampoline BB we created in fixCallUnwindMismatches. Skip
// it.
if (!EHPad->isEHPad())
continue;

// catch_all always catches an exception, so we don't need to do
// anything
if (WebAssembly::isCatchAll(MI.getOpcode())) {
Expand Down