xref: /freebsd/contrib/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
15f757f3fSDimitry Andric //===-- WebAssemblyUtilities - WebAssembly Utility Functions ---*- C++ -*-====//
25f757f3fSDimitry Andric //
35f757f3fSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f757f3fSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f757f3fSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65f757f3fSDimitry Andric //
75f757f3fSDimitry Andric //===----------------------------------------------------------------------===//
85f757f3fSDimitry Andric ///
95f757f3fSDimitry Andric /// \file
105f757f3fSDimitry Andric /// This file contains the declaration of the WebAssembly-specific
115f757f3fSDimitry Andric /// utility functions.
125f757f3fSDimitry Andric ///
135f757f3fSDimitry Andric //===----------------------------------------------------------------------===//
145f757f3fSDimitry Andric 
155f757f3fSDimitry Andric #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_UTILS_WEBASSEMBLYUTILITIES_H
165f757f3fSDimitry Andric #define LLVM_LIB_TARGET_WEBASSEMBLY_UTILS_WEBASSEMBLYUTILITIES_H
175f757f3fSDimitry Andric 
185f757f3fSDimitry Andric #include "llvm/Support/CommandLine.h"
195f757f3fSDimitry Andric 
205f757f3fSDimitry Andric namespace llvm {
215f757f3fSDimitry Andric 
225f757f3fSDimitry Andric class MachineBasicBlock;
235f757f3fSDimitry Andric class MachineInstr;
245f757f3fSDimitry Andric class MachineOperand;
255f757f3fSDimitry Andric class MCContext;
265f757f3fSDimitry Andric class MCSymbolWasm;
275f757f3fSDimitry Andric class TargetRegisterClass;
285f757f3fSDimitry Andric class WebAssemblyFunctionInfo;
295f757f3fSDimitry Andric class WebAssemblySubtarget;
305f757f3fSDimitry Andric 
315f757f3fSDimitry Andric namespace WebAssembly {
325f757f3fSDimitry Andric 
335f757f3fSDimitry Andric bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI);
345f757f3fSDimitry Andric bool mayThrow(const MachineInstr &MI);
355f757f3fSDimitry Andric 
365f757f3fSDimitry Andric // Exception-related function names
375f757f3fSDimitry Andric extern const char *const ClangCallTerminateFn;
385f757f3fSDimitry Andric extern const char *const CxaBeginCatchFn;
395f757f3fSDimitry Andric extern const char *const CxaRethrowFn;
405f757f3fSDimitry Andric extern const char *const StdTerminateFn;
415f757f3fSDimitry Andric extern const char *const PersonalityWrapperFn;
425f757f3fSDimitry Andric 
435f757f3fSDimitry Andric /// Returns the operand number of a callee, assuming the argument is a call
445f757f3fSDimitry Andric /// instruction.
455f757f3fSDimitry Andric const MachineOperand &getCalleeOp(const MachineInstr &MI);
465f757f3fSDimitry Andric 
475f757f3fSDimitry Andric /// Returns the __indirect_function_table, for use in call_indirect and in
485f757f3fSDimitry Andric /// function bitcasts.
495f757f3fSDimitry Andric MCSymbolWasm *
505f757f3fSDimitry Andric getOrCreateFunctionTableSymbol(MCContext &Ctx,
515f757f3fSDimitry Andric                                const WebAssemblySubtarget *Subtarget);
525f757f3fSDimitry Andric 
535f757f3fSDimitry Andric /// Returns the __funcref_call_table, for use in funcref calls when lowered to
545f757f3fSDimitry Andric /// table.set + call_indirect.
555f757f3fSDimitry Andric MCSymbolWasm *
565f757f3fSDimitry Andric getOrCreateFuncrefCallTableSymbol(MCContext &Ctx,
575f757f3fSDimitry Andric                                   const WebAssemblySubtarget *Subtarget);
585f757f3fSDimitry Andric 
595f757f3fSDimitry Andric /// Find a catch instruction from an EH pad. Returns null if no catch
605f757f3fSDimitry Andric /// instruction found or the catch is in an invalid location.
615f757f3fSDimitry Andric MachineInstr *findCatch(MachineBasicBlock *EHPad);
625f757f3fSDimitry Andric 
635f757f3fSDimitry Andric /// Returns the appropriate copy opcode for the given register class.
645f757f3fSDimitry Andric unsigned getCopyOpcodeForRegClass(const TargetRegisterClass *RC);
655f757f3fSDimitry Andric 
66*0fca6ea1SDimitry Andric /// Returns true if multivalue returns of a function can be lowered directly,
67*0fca6ea1SDimitry Andric /// i.e., not indirectly via a pointer parameter that points to the value in
68*0fca6ea1SDimitry Andric /// memory.
69*0fca6ea1SDimitry Andric bool canLowerMultivalueReturn(const WebAssemblySubtarget *Subtarget);
70*0fca6ea1SDimitry Andric 
71*0fca6ea1SDimitry Andric /// Returns true if the function's return value(s) can be lowered directly,
72*0fca6ea1SDimitry Andric /// i.e., not indirectly via a pointer parameter that points to the value in
73*0fca6ea1SDimitry Andric /// memory.
74*0fca6ea1SDimitry Andric bool canLowerReturn(size_t ResultSize, const WebAssemblySubtarget *Subtarget);
75*0fca6ea1SDimitry Andric 
765f757f3fSDimitry Andric } // end namespace WebAssembly
775f757f3fSDimitry Andric 
785f757f3fSDimitry Andric } // end namespace llvm
795f757f3fSDimitry Andric 
805f757f3fSDimitry Andric #endif
81