LLVM  8.0.1
Macros | Functions
WebAssemblyCFGStackify.cpp File Reference

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

#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
#include "WebAssembly.h"
#include "WebAssemblyExceptionInfo.h"
#include "WebAssemblyMachineFunctionInfo.h"
#include "WebAssemblySubtarget.h"
#include "WebAssemblyUtilities.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/WasmEHFuncInfo.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
Include dependency graph for WebAssemblyCFGStackify.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "wasm-cfg-stackify"
 

Functions

 INITIALIZE_PASS (WebAssemblyCFGStackify, DEBUG_TYPE, "Insert BLOCK and LOOP 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. More...
 
static MachineBasicBlock::iterator GetEarliestInsertPos (MachineBasicBlock *MBB, const SmallPtrSet< const MachineInstr *, 4 > &BeforeSet, const SmallPtrSet< const MachineInstr *, 4 > &AfterSet)
 
static MachineBasicBlock::iterator GetLatestInsertPos (MachineBasicBlock *MBB, const SmallPtrSet< const MachineInstr *, 4 > &BeforeSet, const SmallPtrSet< const MachineInstr *, 4 > &AfterSet)
 
static unsigned GetDepth (const SmallVectorImpl< const MachineBasicBlock *> &Stack, const MachineBasicBlock *MBB)
 
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 43 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 111 of file WebAssemblyCFGStackify.cpp.

References llvm::WebAssembly::isRethrow(), MI, and llvm::MachineBasicBlock::terminators().

◆ GetDepth()

static unsigned GetDepth ( const SmallVectorImpl< const MachineBasicBlock *> &  Stack,
const MachineBasicBlock MBB 
)
static

◆ GetEarliestInsertPos()

static MachineBasicBlock::iterator GetEarliestInsertPos ( MachineBasicBlock MBB,
const SmallPtrSet< const MachineInstr *, 4 > &  BeforeSet,
const SmallPtrSet< const MachineInstr *, 4 > &  AfterSet 
)
static

◆ GetLatestInsertPos()

static MachineBasicBlock::iterator GetLatestInsertPos ( MachineBasicBlock MBB,
const SmallPtrSet< const MachineInstr *, 4 > &  BeforeSet,
const SmallPtrSet< const MachineInstr *, 4 > &  AfterSet 
)
static

◆ INITIALIZE_PASS()

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

Definition at line 98 of file WebAssemblyCFGStackify.cpp.