LLVM 20.0.0git
Macros | Functions
WebAssemblyCFGStackify.cpp File Reference

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

#include "Utils/WebAssemblyTypeUtilities.h"
#include "WebAssembly.h"
#include "WebAssemblyExceptionInfo.h"
#include "WebAssemblyMachineFunctionInfo.h"
#include "WebAssemblySortRegion.h"
#include "WebAssemblySubtarget.h"
#include "WebAssemblyUtilities.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/WasmEHFuncInfo.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/Target/TargetMachine.h"

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 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 appendEndToFunction (MachineFunction &MF, const WebAssemblyInstrInfo &TII)
 

Detailed Description

This file implements a CFG stacking pass.

This pass inserts BLOCK, LOOP, and TRY 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 41 of file WebAssemblyCFGStackify.cpp.

Function Documentation

◆ appendEndToFunction()

static void appendEndToFunction ( MachineFunction MF,
const WebAssemblyInstrInfo TII 
)
static

◆ explicitlyBranchesTo()

static 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 165 of file WebAssemblyCFGStackify.cpp.

References MBB, MI, and llvm::MachineBasicBlock::terminators().

◆ getEarliestInsertPos()

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

◆ getLatestInsertPos()

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

◆ INITIALIZE_PASS()

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

Definition at line 152 of file WebAssemblyCFGStackify.cpp.

◆ STATISTIC() [1/2]

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

◆ STATISTIC() [2/2]

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

◆ unstackifyVRegsUsedInSplitBB()

static void unstackifyVRegsUsedInSplitBB ( MachineBasicBlock MBB,
MachineBasicBlock Split 
)
static