Home | History | Annotate | Line # | Download | only in Utils
      1 //===-- WebAssemblyUtilities - WebAssembly Utility Functions ---*- C++ -*-====//
      2 //
      3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
      4 // See https://llvm.org/LICENSE.txt for license information.
      5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
      6 //
      7 //===----------------------------------------------------------------------===//
      8 ///
      9 /// \file
     10 /// This file contains the declaration of the WebAssembly-specific
     11 /// utility functions.
     12 ///
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_UTILS_WEBASSEMBLYUTILITIES_H
     16 #define LLVM_LIB_TARGET_WEBASSEMBLY_UTILS_WEBASSEMBLYUTILITIES_H
     17 
     18 namespace llvm {
     19 
     20 class MachineBasicBlock;
     21 class MachineInstr;
     22 class MachineOperand;
     23 class MCContext;
     24 class MCSymbolWasm;
     25 class StringRef;
     26 class WebAssemblyFunctionInfo;
     27 class WebAssemblySubtarget;
     28 
     29 namespace WebAssembly {
     30 
     31 enum WasmAddressSpace : unsigned {
     32   // Default address space, for pointers to linear memory (stack, heap, data).
     33   WASM_ADDRESS_SPACE_DEFAULT = 0,
     34   // A non-integral address space for pointers to named objects outside of
     35   // linear memory: WebAssembly globals or WebAssembly locals.  Loads and stores
     36   // to these pointers are lowered to global.get / global.set or local.get /
     37   // local.set, as appropriate.
     38   WASM_ADDRESS_SPACE_WASM_VAR = 1
     39 };
     40 
     41 inline bool isDefaultAddressSpace(unsigned AS) {
     42   return AS == WASM_ADDRESS_SPACE_DEFAULT;
     43 }
     44 inline bool isWasmVarAddressSpace(unsigned AS) {
     45   return AS == WASM_ADDRESS_SPACE_WASM_VAR;
     46 }
     47 inline bool isValidAddressSpace(unsigned AS) {
     48   return isDefaultAddressSpace(AS) || isWasmVarAddressSpace(AS);
     49 }
     50 
     51 bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI);
     52 bool mayThrow(const MachineInstr &MI);
     53 
     54 // Exception-related function names
     55 extern const char *const ClangCallTerminateFn;
     56 extern const char *const CxaBeginCatchFn;
     57 extern const char *const CxaRethrowFn;
     58 extern const char *const StdTerminateFn;
     59 extern const char *const PersonalityWrapperFn;
     60 
     61 /// Returns the operand number of a callee, assuming the argument is a call
     62 /// instruction.
     63 const MachineOperand &getCalleeOp(const MachineInstr &MI);
     64 
     65 /// Returns the __indirect_function_table, for use in call_indirect and in
     66 /// function bitcasts.
     67 MCSymbolWasm *
     68 getOrCreateFunctionTableSymbol(MCContext &Ctx,
     69                                const WebAssemblySubtarget *Subtarget);
     70 
     71 /// Find a catch instruction from an EH pad. Returns null if no catch
     72 /// instruction found or the catch is in an invalid location.
     73 MachineInstr *findCatch(MachineBasicBlock *EHPad);
     74 
     75 } // end namespace WebAssembly
     76 
     77 } // end namespace llvm
     78 
     79 #endif
     80