LLVM 22.0.0git
WebAssemblyCFGStackify.cpp File Reference

This file implements a CFG stacking pass. More...

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "wasm-cfg-stackify"

Functions

 STATISTIC (NumCallUnwindMismatches, "Number of call unwind mismatches found")
 STATISTIC (NumCatchUnwindMismatches, "Number of catch unwind mismatches found")
 INITIALIZE_PASS (WebAssemblyCFGStackify, DEBUG_TYPE, "Insert BLOCK/LOOP/TRY/TRY_TABLE markers for WebAssembly scopes", false, false) FunctionPass *llvm
static bool explicitlyBranchesTo (MachineBasicBlock *Pred, MachineBasicBlock *MBB)
 Test whether Pred has any terminators explicitly branching to MBB, as opposed to falling through.
template<typename Container>
static MachineBasicBlock::iterator getEarliestInsertPos (MachineBasicBlock *MBB, const Container &BeforeSet, const Container &AfterSet)
template<typename Container>
static MachineBasicBlock::iterator getLatestInsertPos (MachineBasicBlock *MBB, const Container &BeforeSet, const Container &AfterSet)
static void unstackifyVRegsUsedInSplitBB (MachineBasicBlock &MBB, MachineBasicBlock &Split)
static void splitEndLoopBB (MachineBasicBlock *EndTryTableBB)
static MachineBasicBlockgetSingleUnwindDest (const MachineInstr *TryTable)
static void appendEndToFunction (MachineFunction &MF, const WebAssemblyInstrInfo &TII)
static void addUnreachableAfterTryTables (MachineFunction &MF, const WebAssemblyInstrInfo &TII)

Detailed Description

This file implements a CFG stacking pass.

This pass inserts BLOCK, LOOP, TRY, and TRY_TABLE markers to mark the start of scopes, since scope boundaries serve as the labels for WebAssembly's control transfers.

This is sufficient to convert arbitrary CFGs into a form that works on WebAssembly, provided that all loops are single-entry.

In case we use exceptions, this pass also fixes mismatches in unwind destinations created during transforming CFG into wasm structured format.

Definition in file WebAssemblyCFGStackify.cpp.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "wasm-cfg-stackify"

Definition at line 43 of file WebAssemblyCFGStackify.cpp.

Function Documentation

◆ addUnreachableAfterTryTables()

◆ appendEndToFunction()

◆ explicitlyBranchesTo()

bool explicitlyBranchesTo ( MachineBasicBlock * Pred,
MachineBasicBlock * MBB )
static

Test whether Pred has any terminators explicitly branching to MBB, as opposed to falling through.

Note that it's possible (eg. in unoptimized code) for a branch instruction to both branch to a block and fallthrough to it, so we check the actual branch operands to see if there are any explicit mentions.

Definition at line 194 of file WebAssemblyCFGStackify.cpp.

References MBB, and MI.

◆ getEarliestInsertPos()

template<typename Container>
MachineBasicBlock::iterator getEarliestInsertPos ( MachineBasicBlock * MBB,
const Container & BeforeSet,
const Container & AfterSet )
static

Definition at line 210 of file WebAssemblyCFGStackify.cpp.

References assert(), E(), and MBB.

◆ getLatestInsertPos()

template<typename Container>
MachineBasicBlock::iterator getLatestInsertPos ( MachineBasicBlock * MBB,
const Container & BeforeSet,
const Container & AfterSet )
static

Definition at line 234 of file WebAssemblyCFGStackify.cpp.

References assert(), E(), and MBB.

◆ getSingleUnwindDest()

◆ INITIALIZE_PASS()

INITIALIZE_PASS ( WebAssemblyCFGStackify ,
DEBUG_TYPE ,
"Insert BLOCK/LOOP/TRY/TRY_TABLE markers for WebAssembly scopes" ,
false ,
false  )

Definition at line 180 of file WebAssemblyCFGStackify.cpp.

References llvm::createWebAssemblyCFGStackify(), and DEBUG_TYPE.

◆ splitEndLoopBB()

◆ STATISTIC() [1/2]

STATISTIC ( NumCallUnwindMismatches ,
"Number of call unwind mismatches found"  )

◆ STATISTIC() [2/2]

STATISTIC ( NumCatchUnwindMismatches ,
"Number of catch unwind mismatches found"  )

◆ unstackifyVRegsUsedInSplitBB()