LLVM  6.0.0svn
Macros | Functions
WebAssemblyCFGStackify.cpp File Reference

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

#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
#include "WebAssembly.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/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

static bool ExplicitlyBranchesTo (MachineBasicBlock *Pred, MachineBasicBlock *MBB)
 Test whether Pred has any terminators explicitly branching to MBB, as opposed to falling through. More...
 
static void PlaceBlockMarker (MachineBasicBlock &MBB, MachineFunction &MF, SmallVectorImpl< MachineBasicBlock *> &ScopeTops, DenseMap< const MachineInstr *, MachineInstr *> &BlockTops, DenseMap< const MachineInstr *, MachineInstr *> &LoopTops, const WebAssemblyInstrInfo &TII, const MachineLoopInfo &MLI, MachineDominatorTree &MDT, WebAssemblyFunctionInfo &MFI)
 Insert a BLOCK marker for branches to MBB (if needed). More...
 
static void PlaceLoopMarker (MachineBasicBlock &MBB, MachineFunction &MF, SmallVectorImpl< MachineBasicBlock *> &ScopeTops, DenseMap< const MachineInstr *, MachineInstr *> &LoopTops, const WebAssemblyInstrInfo &TII, const MachineLoopInfo &MLI)
 Insert a LOOP marker for a loop starting at MBB (if it's a loop header). More...
 
static unsigned GetDepth (const SmallVectorImpl< const MachineBasicBlock *> &Stack, const MachineBasicBlock *MBB)
 
static void FixEndsAtEndOfFunction (MachineFunction &MF, const WebAssemblyFunctionInfo &MFI, DenseMap< const MachineInstr *, MachineInstr *> &BlockTops, DenseMap< const MachineInstr *, MachineInstr *> &LoopTops)
 In normal assembly languages, when the end of a function is unreachable, because the function ends in an infinite loop or a noreturn call or similar, it isn't necessary to worry about the function return type at the end of the function, because it's never reached. More...
 
static void AppendEndToFunction (MachineFunction &MF, const WebAssemblyInstrInfo &TII)
 
static void PlaceMarkers (MachineFunction &MF, const MachineLoopInfo &MLI, const WebAssemblyInstrInfo &TII, MachineDominatorTree &MDT, WebAssemblyFunctionInfo &MFI)
 Insert LOOP and BLOCK markers at appropriate places. More...
 

Detailed Description

This file implements a CFG stacking pass.

This pass inserts BLOCK and LOOP 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.

Definition in file WebAssemblyCFGStackify.cpp.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "wasm-cfg-stackify"

Definition at line 36 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 69 of file WebAssemblyCFGStackify.cpp.

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

Referenced by PlaceBlockMarker().

◆ FixEndsAtEndOfFunction()

static void FixEndsAtEndOfFunction ( MachineFunction MF,
const WebAssemblyFunctionInfo MFI,
DenseMap< const MachineInstr *, MachineInstr *> &  BlockTops,
DenseMap< const MachineInstr *, MachineInstr *> &  LoopTops 
)
static

In normal assembly languages, when the end of a function is unreachable, because the function ends in an infinite loop or a noreturn call or similar, it isn't necessary to worry about the function return type at the end of the function, because it's never reached.

However, in WebAssembly, blocks that end at the function end need to have a return type signature that matches the function signature, even though it's unreachable. This function checks for such cases and fixes up the signatures.

Definition at line 232 of file WebAssemblyCFGStackify.cpp.

References assert(), llvm::bitc::END_BLOCK, llvm::MVT::f32, llvm::WebAssembly::F32, llvm::WebAssembly::F32x4, llvm::MVT::f64, llvm::WebAssembly::F64, llvm::WebAssemblyFunctionInfo::getResults(), llvm::WebAssembly::I16x8, llvm::MVT::i32, llvm::WebAssembly::I32, llvm::WebAssembly::I32x4, llvm::MVT::i64, llvm::WebAssembly::I64, llvm::WebAssembly::I8x16, llvm_unreachable, MI, llvm::reverse(), llvm::MVT::v16i8, llvm::MVT::v4f32, llvm::MVT::v4i32, and llvm::MVT::v8i16.

Referenced by PlaceMarkers().

◆ GetDepth()

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

◆ PlaceBlockMarker()

static void PlaceBlockMarker ( MachineBasicBlock MBB,
MachineFunction MF,
SmallVectorImpl< MachineBasicBlock *> &  ScopeTops,
DenseMap< const MachineInstr *, MachineInstr *> &  BlockTops,
DenseMap< const MachineInstr *, MachineInstr *> &  LoopTops,
const WebAssemblyInstrInfo TII,
const MachineLoopInfo MLI,
MachineDominatorTree MDT,
WebAssemblyFunctionInfo MFI 
)
static

◆ PlaceLoopMarker()

static void PlaceLoopMarker ( MachineBasicBlock MBB,
MachineFunction MF,
SmallVectorImpl< MachineBasicBlock *> &  ScopeTops,
DenseMap< const MachineInstr *, MachineInstr *> &  LoopTops,
const WebAssemblyInstrInfo TII,
const MachineLoopInfo MLI 
)
static

◆ PlaceMarkers()

static void PlaceMarkers ( MachineFunction MF,
const MachineLoopInfo MLI,
const WebAssemblyInstrInfo TII,
MachineDominatorTree MDT,
WebAssemblyFunctionInfo MFI 
)
static