• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- WebAssemblyUtilities - WebAssembly Utility Functions ---*- C++ -*-====//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// This file contains the declaration of the WebAssembly-specific
12 /// utility functions.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYUTILITIES_H
17 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYUTILITIES_H
18 
19 #include "llvm/CodeGen/MachineBasicBlock.h"
20 
21 namespace llvm {
22 
23 class WebAssemblyFunctionInfo;
24 
25 namespace WebAssembly {
26 
27 bool isArgument(const MachineInstr &MI);
28 bool isCopy(const MachineInstr &MI);
29 bool isTee(const MachineInstr &MI);
30 bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI);
31 bool isCallDirect(const MachineInstr &MI);
32 bool isCallIndirect(const MachineInstr &MI);
33 bool isMarker(const MachineInstr &MI);
34 bool isThrow(const MachineInstr &MI);
35 bool isRethrow(const MachineInstr &MI);
36 bool isCatch(const MachineInstr &MI);
37 bool mayThrow(const MachineInstr &MI);
38 
39 /// Returns the operand number of a callee, assuming the argument is a call
40 /// instruction.
41 unsigned getCalleeOpNo(const MachineInstr &MI);
42 
43 /// Returns if the given BB is a single BB terminate pad which starts with a
44 /// 'catch' instruction.
45 bool isCatchTerminatePad(const MachineBasicBlock &MBB);
46 /// Returns if the given BB is a single BB terminate pad which starts with a
47 /// 'catch_all' insrtruction.
48 bool isCatchAllTerminatePad(const MachineBasicBlock &MBB);
49 
50 // Exception-related function names
51 extern const char *const ClangCallTerminateFn;
52 extern const char *const CxaBeginCatchFn;
53 extern const char *const CxaRethrowFn;
54 extern const char *const StdTerminateFn;
55 extern const char *const PersonalityWrapperFn;
56 
57 /// Return the "bottom" block of an entity, which can be either a MachineLoop or
58 /// WebAssemblyException. This differs from MachineLoop::getBottomBlock in that
59 /// it works even if the entity is discontiguous.
getBottom(const T * Unit)60 template <typename T> MachineBasicBlock *getBottom(const T *Unit) {
61   MachineBasicBlock *Bottom = Unit->getHeader();
62   for (MachineBasicBlock *MBB : Unit->blocks())
63     if (MBB->getNumber() > Bottom->getNumber())
64       Bottom = MBB;
65   return Bottom;
66 }
67 
68 } // end namespace WebAssembly
69 
70 } // end namespace llvm
71 
72 #endif
73