37 cl::desc(
"WebAssembly: output stack registers in" 38 " instruction output for test purposes only."),
47 WebAssemblyMCInstLower::GetGlobalAddressSymbol(
const MachineOperand &MO)
const {
49 if (!isa<Function>(
Global))
52 const auto *FuncTy = cast<FunctionType>(
Global->getValueType());
59 const auto *
const F = dyn_cast<Function>(
Global);
63 bool InvokeDetected =
false;
72 MCSymbol *WebAssemblyMCInstLower::GetExternalSymbolSymbol(
82 if (strcmp(
Name,
"__stack_pointer") == 0 || strcmp(
Name,
"__tls_base") == 0 ||
83 strcmp(
Name,
"__memory_base") == 0 || strcmp(
Name,
"__table_base") == 0 ||
84 strcmp(
Name,
"__tls_size") == 0 || strcmp(
Name,
"__tls_align") == 0) {
86 strcmp(
Name,
"__stack_pointer") == 0 || strcmp(
Name,
"__tls_base") == 0;
89 uint8_t(Subtarget.hasAddr64() && strcmp(
Name,
"__table_base") != 0
98 if (strcmp(
Name,
"__cpp_exception") == 0) {
102 WasmSym->setEventType(
107 WasmSym->setWeak(
true);
108 WasmSym->setExternal(
true);
122 WasmSym->setSignature(Signature.get());
133 switch (TargetFlags) {
155 const auto *WasmSym = cast<MCSymbolWasm>(Sym);
158 if (WasmSym->isFunction())
160 if (WasmSym->isGlobal())
162 if (WasmSym->isEvent())
172 MCOperand WebAssemblyMCInstLower::lowerTypeIndexOperand(
175 auto Signature = std::make_unique<wasm::WasmSignature>(
std::move(Returns),
178 auto *WasmSym = cast<MCSymbolWasm>(Sym);
179 WasmSym->setSignature(Signature.get());
189 if (RC == &WebAssembly::I32RegClass)
191 if (RC == &WebAssembly::I64RegClass)
193 if (RC == &WebAssembly::F32RegClass)
195 if (RC == &WebAssembly::F64RegClass)
197 if (RC == &WebAssembly::V128RegClass)
206 Type *RetTy =
F.getReturnType();
217 unsigned NumVariadicDefs =
MI->getNumExplicitDefs() - Desc.
getNumDefs();
218 for (
unsigned I = 0,
E =
MI->getNumOperands();
I !=
E; ++
I) {
240 unsigned DescIndex =
I - NumVariadicDefs;
248 MI->getParent()->getParent()->getRegInfo();
262 if (
MI->getOpcode() == WebAssembly::RET_CALL_INDIRECT)
268 auto BT = static_cast<WebAssembly::BlockType>(MO.
getImm());
273 MCOp = lowerTypeIndexOperand(
std::move(Returns),
278 assert(static_cast<WebAssembly::HeapType>(MO.
getImm()) !=
300 MCOp = lowerSymbolOperand(MO, GetGlobalAddressSymbol(MO));
306 "WebAssembly uses only symbol flags on ExternalSymbols");
307 MCOp = lowerSymbolOperand(MO, GetExternalSymbolSymbol(MO));
313 "WebAssembly does not use target flags on MCSymbol");
341 if (
MI->isDebugInstr() ||
MI->isLabel() ||
MI->isInlineAsm())
347 assert(StackOpcode != -1 &&
"Failed to stackify instruction");
unsigned getTargetFlags() const
const Function & getFunction() const
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
int getStackOpcode(unsigned short Opcode)
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
MCSymbolWasm * getMCSymbolForFunction(const Function *F, bool EnableEmEH, wasm::WasmSignature *Sig, bool &InvokeDetected)
static MCOperand createExpr(const MCExpr *Val)
void push_back(const T &Elt)
Describe properties that are true of each instruction in the target description file.
cl::opt< bool > EnableEmSjLj
This file declares the class to lower WebAssembly MachineInstrs to their corresponding MCInst records...
float convertToFloat() const
MachineBasicBlock reference.
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 registers the WebAssembly target.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
signature immediate for block/loop.
std::unique_ptr< wasm::WasmSignature > signatureFromMVTs(const SmallVectorImpl< MVT > &Results, const SmallVectorImpl< MVT > &Params)
static MCOperand createReg(unsigned Reg)
const ConstantFP * getFPImm() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Base class for the full range of assembler expressions which are needed for parsing.
Name of external global symbol.
static void removeRegisterOperands(const MachineInstr *MI, MCInst &OutMI)
const char * getSymbolName() const
Type * getType() const
All values are typed, get the type of this value.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
iterator insert(iterator I, const MCOperand &Op)
Analysis containing CSE Info
Instances of this class represent a single low-level machine instruction.
void computeSignatureVTs(const FunctionType *Ty, const Function *TargetFunc, const Function &ContextFunc, const TargetMachine &TM, SmallVectorImpl< MVT > &Params, SmallVectorImpl< MVT > &Results)
unsigned short NumOperands
void getLibcallSignature(const WebAssemblySubtarget &Subtarget, RTLIB::Libcall LC, SmallVectorImpl< wasm::ValType > &Rets, SmallVectorImpl< wasm::ValType > &Params)
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Address of a global value.
initializer< Ty > init(const Ty &Val)
unsigned const MachineRegisterInfo * MRI
The instances of the Type class are immutable: once they are created, they are never changed.
This file provides signature information for runtime libcalls.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const WebAssemblySubtarget & getSubtarget() const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const GlobalValue * getGlobal() const
ConstantFP - Floating Point Values [float, double].
This file provides WebAssembly-specific target descriptions.
double convertToDouble() const
cl::opt< bool > EnableEmException
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
unsigned getNumOperands() const
type signature immediate for call_indirect.
static wasm::ValType getType(const TargetRegisterClass *RC)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void addSignature(std::unique_ptr< wasm::WasmSignature > &&Sig)
const APFloat & getValueAPF() const
void setOpcode(unsigned Op)
MCSymbol * getSymbol(const GlobalValue *GV) const
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
const MCOperand & getOperand(unsigned i) const
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
static MCOperand createFPImm(double Val)
MCSymbol reference (for debug/eh info)
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Representation of each machine instruction.
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
bool isCallIndirect(unsigned Opc)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
int64_t getOffset() const
Return the offset from the symbol in this operand.
This file declares WebAssembly-specific per-machine-function information.
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
bool variadicOpsAreDefs() const
Return true if variadic operands of this instruction are definitions.
unsigned getWAReg(unsigned VReg) const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
heap type immediate for ref.null.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void valTypesFromMVTs(const ArrayRef< MVT > &In, SmallVectorImpl< wasm::ValType > &Out)
void setSignature(wasm::WasmSignature *Sig)
MCSymbol * getMCSymbol() const
void computeLegalValueVTs(const Function &F, const TargetMachine &TM, Type *Ty, SmallVectorImpl< MVT > &ValueVTs)
void addOperand(const MCOperand Op)
Floating-point immediate operand.
void lower(const MachineInstr *MI, MCInst &OutMI) const
const MCOperandInfo * OpInfo
Primary interface to the complete machine description for the target machine.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Register getReg() const
getReg - Returns the register number.
This holds information about one operand of a machine instruction, indicating the register class for ...
unsigned getOpcode() const
Instances of this class represent operands of the MCInst class.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
MCSymbol * createTempSymbol(const Twine &Name) const
static MCOperand createImm(int64_t Val)