48 cl::desc(
"WebAssembly: output stack registers in"
49 " instruction output for test purposes only."),
55 const auto *BaseObject =
Global->getAliaseeObject();
60 "wasm_var address space symbol must resolve to a "
65 return !GV->isConstant();
73 const TargetMachine &TM = Printer.TM;
74 const Function &CurrentFunc = Printer.MF->getFunction();
76 auto *WasmSym =
static_cast<MCSymbolWasm *
>(Printer.getSymbol(&
Global));
81 !WasmSym->getType()) {
82 std::optional<bool> Mutable =
84 if (!Mutable.has_value())
104 bool InvokeDetected =
false;
105 auto *WasmSym = Printer.getMCSymbolForFunction(
F, Signature, InvokeDetected);
106 WasmSym->setSignature(Signature);
111MCSymbol *WebAssemblyMCInstLower::GetExternalSymbolSymbol(
121 switch (TargetFlags) {
146 const auto *WasmSym =
static_cast<const MCSymbolWasm *
>(Sym);
149 if (WasmSym->isFunction())
151 if (WasmSym->isGlobal())
153 if (WasmSym->isTag())
155 if (WasmSym->isTable())
165MCOperand WebAssemblyMCInstLower::lowerTypeIndexOperand(
168 auto Signature = Ctx.createWasmSignature();
169 Signature->Returns = std::move(Returns);
170 Signature->Params = std::move(Params);
172 static_cast<MCSymbolWasm *
>(Printer.createTempSymbol(
"typeindex"));
173 Sym->setSignature(Signature);
181WebAssemblyMCInstLower::lowerEncodedFunctionSignature(
const APInt &Sig)
const {
188 auto GetWord = [&
Idx, &Sig]() {
197 int NReturns = GetWord() ^ 0x7ffffff;
198 for (
int I = 0;
I < NReturns;
I++) {
201 int NParams = GetWord();
202 for (
int I = 0;
I < NParams;
I++) {
205 return lowerTypeIndexOperand(std::move(Returns), std::move(Params));
212 Type *RetTy =
F.getReturnType();
223 unsigned NumVariadicDefs =
MI->getNumExplicitDefs() -
Desc.getNumDefs();
231 for (
unsigned I = 0, E =
MI->getNumOperands();
I != E; ++
I) {
256 unsigned DescIndex =
I - NumVariadicDefs;
257 assert(DescIndex <
Desc.NumOperands &&
"unexpected CImmediate operand");
261 "unexpected CImmediate operand");
267 unsigned DescIndex =
I - NumVariadicDefs;
268 if (DescIndex <
Desc.NumOperands) {
280 MI->getParent()->getParent()->getRegInfo();
296 if (
MI->getOpcode() == WebAssembly::RET_CALL_INDIRECT)
299 MCOp = lowerTypeIndexOperand(std::move(Returns), std::move(Params));
323 MCOp = lowerTypeIndexOperand(std::move(Returns),
334 const uint64_t BitPattern =
335 Imm->getValueAPF().bitcastToAPInt().getZExtValue();
336 if (
Imm->getType()->isFloatTy())
338 else if (
Imm->getType()->isDoubleTy())
345 MCOp = lowerSymbolOperand(
346 MO, GetGlobalAddressSymbol(*MO.
getGlobal(),
MI->getDebugLoc()));
349 MCOp = lowerSymbolOperand(MO, GetExternalSymbolSymbol(MO));
353 "WebAssembly does not use target flags on MCSymbol");
363 else if (
Desc.variadicOpsAreDefs())
381 if (
MI->isDebugInstr() ||
MI->isLabel() ||
MI->isInlineAsm())
387 assert(StackOpcode != -1 &&
"Failed to stackify instruction");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the declarations for the subclasses of Constant, which represent the different fla...
MachineRegisterInfo & MRI
This file defines the SmallVector class.
cl::opt< bool > WasmKeepRegisters
This file contains the declaration of the WebAssemblyMCAsmInfo class.
static void removeRegisterOperands(const MachineInstr *MI, MCInst &OutMI)
static std::optional< bool > getWasmGlobalMutable(const GlobalValue *Global, const Function &CurrentFunc, const DiagnosticLocation &DL)
static cl::opt< bool > WasmKeepRegisters("wasm-keep-registers", cl::Hidden, cl::desc("WebAssembly: output stack registers in" " instruction output for test purposes only."), cl::init(false))
static void getFunctionReturns(const MachineInstr *MI, SmallVectorImpl< wasm::ValType > &Returns)
This file declares the class to lower WebAssembly MachineInstrs to their corresponding MCInst records...
This file provides WebAssembly-specific target descriptions.
This file contains the declaration of the WebAssembly-specific type parsing utility functions.
This file declares WebAssembly-specific per-machine-function information.
This file registers the WebAssembly target.
This file contains the declaration of the WebAssembly-specific type parsing utility functions.
This file contains the declaration of the WebAssembly-specific utility functions.
Class for arbitrary precision integers.
LLVM_ABI uint64_t extractBitsAsZExtValue(unsigned numBits, unsigned bitPosition) const
unsigned getNumWords() const
Get the number of words.
ConstantFP - Floating Point Values [float, double].
const APInt & getValue() const
Return the constant as an APInt value reference.
Diagnostic information for unsupported feature in backend.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Instances of this class represent a single low-level machine instruction.
unsigned getNumOperands() const
unsigned getOpcode() const
iterator insert(iterator I, const MCOperand &Op)
void addOperand(const MCOperand Op)
void setOpcode(unsigned Op)
const MCOperand & getOperand(unsigned i) const
Describe properties that are true of each instruction in the target description file.
This holds information about one operand of a machine instruction, indicating the register class for ...
Instances of this class represent operands of the MCInst class.
static MCOperand createExpr(const MCExpr *Val)
static MCOperand createSFPImm(uint32_t Val)
static MCOperand createReg(MCRegister Reg)
static MCOperand createImm(int64_t Val)
static MCOperand createDFPImm(uint64_t Val)
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
const ConstantInt * getCImm() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
unsigned getTargetFlags() const
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
const char * getSymbolName() const
Register getReg() const
getReg - Returns the register number.
const ConstantFP * getFPImm() const
MCSymbol * getMCSymbol() const
@ MO_Immediate
Immediate operand.
@ MO_MCSymbol
MCSymbol reference (for debug/eh info)
@ MO_GlobalAddress
Address of a global value.
@ MO_CImmediate
Immediate >64bit operand.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_Register
Register operand.
@ MO_ExternalSymbol
Name of external global symbol.
@ MO_FPImmediate
Floating-point immediate operand.
int64_t getOffset() const
Return the offset from the symbol in this operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Primary interface to the complete machine description for the target machine.
The instances of the Type class are immutable: once they are created, they are never changed.
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
unsigned getWAReg(Register VReg) const
void lower(const MachineInstr *MI, MCInst &OutMI) const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isCallIndirect(unsigned Opc)
wasm::ValType regClassToValType(unsigned RC)
int32_t getStackOpcode(uint32_t Opcode)
BlockType
Used as immediate MachineOperands for block signatures.
void wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT, ArrayRef< MVT > VTs, bool Mutable)
Sets a Wasm Symbol Type.
@ OPERAND_TYPEINDEX
type signature immediate for call_indirect.
@ OPERAND_SIGNATURE
signature immediate for block/loop.
bool isWasmVarAddressSpace(unsigned AS)
initializer< Ty > init(const Ty &Val)
@ WASM_SYMBOL_TYPE_FUNCTION
This is an optimization pass for GlobalISel generic memory operations.
void computeSignatureVTs(const FunctionType *Ty, const Function *TargetFunc, const Function &ContextFunc, const TargetMachine &TM, SmallVectorImpl< MVT > &Params, SmallVectorImpl< MVT > &Results)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto dyn_cast_or_null(const Y &Val)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ Global
Append to llvm.global_dtors.
void valTypesFromMVTs(ArrayRef< MVT > In, SmallVectorImpl< wasm::ValType > &Out)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
wasm::WasmSignature * signatureFromMVTs(MCContext &Ctx, const SmallVectorImpl< MVT > &Results, const SmallVectorImpl< MVT > &Params)
void computeLegalValueVTs(const WebAssemblyTargetLowering &TLI, LLVMContext &Ctx, const DataLayout &DL, Type *Ty, SmallVectorImpl< MVT > &ValueVTs)