LLVM 24.0.0git
WebAssemblyUtilities.h
Go to the documentation of this file.
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#include "llvm/ADT/StringRef.h"
21#include <algorithm>
22
23namespace llvm {
24
26class MachineFunction;
27class MachineInstr;
28class MachineOperand;
29class MCContext;
30class MCSymbolWasm;
31class MCRegisterClass;
35class MachineSDNode;
36class SDLoc;
37class SelectionDAG;
38
39namespace WebAssembly {
40
45
46/// Parse an ABI name into the corresponding enum.
48 return Name == "experimental-mv" ? WebAssemblyABI::ExperimentalMV
50}
51
52bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI);
53bool mayThrow(const MachineInstr &MI);
54
55// Exception-related function names
56extern const char *const ClangCallTerminateFn;
57extern const char *const CxaBeginCatchFn;
58extern const char *const CxaRethrowFn;
59extern const char *const StdTerminateFn;
60extern const char *const PersonalityWrapperFn;
61
62/// Returns the operand number of a callee, assuming the argument is a call
63/// instruction.
65
66/// Returns the __indirect_function_table, for use in call_indirect and in
67/// function bitcasts.
71
72/// Returns the __funcref_call_table, for use in funcref calls when lowered to
73/// table.set + call_indirect.
77
78/// Find a catch instruction from an EH pad. Returns null if no catch
79/// instruction found or the catch is in an invalid location.
81
82/// Returns the appropriate copy opcode for the given register class.
84
85/// Returns true if multivalue returns of a function can be lowered directly,
86/// i.e., not indirectly via a pointer parameter that points to the value in
87/// memory.
89
90/// Returns true if the function's return value(s) can be lowered directly,
91/// i.e., not indirectly via a pointer parameter that points to the value in
92/// memory.
93bool canLowerReturn(size_t ResultSize, const WebAssemblySubtarget *Subtarget);
94
95// Get the TLS base value for the current target
96// If using libcall thread context, calls
97// __wasm_get_tls_base, otherwise, global.get __tls_base
100 const SDValue Chain = SDValue());
101
102/// Moves the element at \p Idx of \p Range to the front, keeping the order of
103/// the other elements.
104template <typename RangeT> void moveToFront(RangeT &Range, size_t Idx) {
105 std::rotate(Range.begin(), Range.begin() + Idx, Range.begin() + Idx + 1);
106}
107
108/// Returns the virtual register defined by the ARGUMENT instruction of the
109/// swiftasync argument, or an invalid register if there is none. The argument
110/// arrives in local 0, which must hold the async context for the whole
111/// function.
113
114} // end namespace WebAssembly
115
116} // end namespace llvm
117
118#endif
return SDValue()
const AArch64Subtarget & Subtarget
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
IRTranslator LLVM IR MI
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
Context object for machine code objects.
Definition MCContext.h:83
MCRegisterClass - Base class of TargetRegisterClass.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
An SDNode that represents everything that will be needed to construct a MachineInstr.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
const char *const StdTerminateFn
const char *const CxaBeginCatchFn
bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI)
Test whether MI is a child of some other node in an expression tree.
WebAssemblyABI getABI(StringRef Name)
Parse an ABI name into the corresponding enum.
bool canLowerMultivalueReturn(const WebAssemblySubtarget *Subtarget)
Returns true if multivalue returns of a function can be lowered directly, i.e., not indirectly via a ...
const char *const CxaRethrowFn
MCSymbolWasm * getOrCreateFunctionTableSymbol(MCContext &Ctx, const WebAssemblySubtarget *Subtarget)
Returns the __indirect_function_table, for use in call_indirect and in function bitcasts.
unsigned getCopyOpcodeForRegClass(const TargetRegisterClass *RC)
Returns the appropriate copy opcode for the given register class.
void moveToFront(RangeT &Range, size_t Idx)
Moves the element at Idx of Range to the front, keeping the order of the other elements.
const MachineOperand & getCalleeOp(const MachineInstr &MI)
Returns the operand number of a callee, assuming the argument is a call instruction.
MachineInstr * findCatch(MachineBasicBlock *EHPad)
Find a catch instruction from an EH pad.
Register getSwiftAsyncArgReg(const MachineFunction &MF)
Returns the virtual register defined by the ARGUMENT instruction of the swiftasync argument,...
MCSymbolWasm * getOrCreateFuncrefCallTableSymbol(MCContext &Ctx, const WebAssemblySubtarget *Subtarget)
Returns the __funcref_call_table, for use in funcref calls when lowered to table.set + call_indirect.
const char *const PersonalityWrapperFn
bool canLowerReturn(size_t ResultSize, const WebAssemblySubtarget *Subtarget)
Returns true if the function's return value(s) can be lowered directly, i.e., not indirectly via a po...
const char *const ClangCallTerminateFn
bool mayThrow(const MachineInstr &MI)
MachineSDNode * getTLSBase(SelectionDAG &DAG, const SDLoc &DL, const WebAssemblySubtarget *Subtarget, const SDValue Chain=SDValue())
This is an optimization pass for GlobalISel generic memory operations.
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58