|
LLVM
7.0.0
|
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"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 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... | |
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.
| #define DEBUG_TYPE "wasm-cfg-stackify" |
Definition at line 36 of file WebAssemblyCFGStackify.cpp.
|
static |
Definition at line 284 of file WebAssemblyCFGStackify.cpp.
References llvm::MachineFunction::back(), llvm::BuildMI(), llvm::MachineBasicBlock::end(), and llvm::MachineBasicBlock::findPrevDebugLoc().
Referenced by PlaceMarkers().
|
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 73 of file WebAssemblyCFGStackify.cpp.
References MI, and llvm::MachineBasicBlock::terminators().
Referenced by PlaceBlockMarker().
|
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 240 of file WebAssemblyCFGStackify.cpp.
References assert(), llvm::bitc::END_BLOCK, llvm::MVT::ExceptRef, llvm::WebAssembly::ExceptRef, 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().
|
static |
Definition at line 221 of file WebAssemblyCFGStackify.cpp.
References assert(), llvm::Depth, llvm::reverse(), llvm::SmallVectorBase::size(), and X.
Referenced by PlaceMarkers().
| INITIALIZE_PASS | ( | WebAssemblyCFGStackify | , |
| DEBUG_TYPE | , | ||
| "Insert BLOCK and LOOP markers for WebAssembly scopes" | , | ||
| false | , | ||
| false | |||
| ) |
Definition at line 60 of file WebAssemblyCFGStackify.cpp.
|
static |
Insert a BLOCK marker for branches to MBB (if needed).
Definition at line 83 of file WebAssemblyCFGStackify.cpp.
References assert(), llvm::MachineBasicBlock::begin(), llvm::BuildMI(), E, llvm::MachineBasicBlock::end(), llvm::bitc::END_BLOCK, ExplicitlyBranchesTo(), llvm::MachineBasicBlock::findDebugLoc(), llvm::MachineDominatorTree::findNearestCommonDominator(), llvm::MachineFunction::front(), llvm::WebAssembly::getBottom(), llvm::MachineBasicBlock::getFirstTerminator(), llvm::MachineLoopInfo::getLoopFor(), llvm::MachineBasicBlock::getNumber(), I, llvm::WebAssembly::isChild(), llvm::AMDGPUISD::LOOP, llvm::MachineBasicBlock::predecessors(), and llvm::WebAssembly::Void.
Referenced by PlaceMarkers().
|
static |
Insert a LOOP marker for a loop starting at MBB (if it's a loop header).
Definition at line 174 of file WebAssemblyCFGStackify.cpp.
References llvm::MachineBasicBlock::addSuccessor(), llvm::MachineBasicBlock::begin(), llvm::BuildMI(), llvm::MachineFunction::CreateMachineBasicBlock(), llvm::MachineBasicBlock::end(), llvm::MachineFunction::end(), llvm::MachineBasicBlock::findDebugLoc(), llvm::WebAssembly::getBottom(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::MachineLoopInfo::getLoopFor(), llvm::AMDGPUISD::LOOP, llvm::MachineBasicBlock::pred_rbegin(), llvm::MachineFunction::push_back(), and llvm::WebAssembly::Void.
Referenced by PlaceMarkers().
|
static |
Insert LOOP and BLOCK markers at appropriate places.
Definition at line 293 of file WebAssemblyCFGStackify.cpp.
References AppendEndToFunction(), assert(), llvm::SmallVectorTemplateCommon< T >::back(), llvm::MachineOperand::CreateImm(), llvm::dbgs(), llvm::SmallVectorBase::empty(), llvm::bitc::END_BLOCK, FixEndsAtEndOfFunction(), GetDepth(), llvm::MachineFunction::getInfo(), llvm::MachineFunction::getName(), llvm::MachineBasicBlock::getNumber(), llvm::MachineFunction::getNumBlockIDs(), getParent(), llvm::MachineFunction::getRegInfo(), llvm::MachineFunction::getSubtarget(), llvm::MachineRegisterInfo::invalidateLiveness(), LLVM_DEBUG, llvm::AMDGPUISD::LOOP, MI, PlaceBlockMarker(), PlaceLoopMarker(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::pop_back(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::reverse(), and TII.
1.8.13