LLVM: lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

32

33using namespace llvm;

34

35

36

39 cl::desc("WebAssembly: output stack registers in"

40 " instruction output for test purposes only."),

42

44

46WebAssemblyMCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const {

48 if (!isa(Global)) {

49 auto *WasmSym = cast(Printer.getSymbol(Global));

50

51

52

54 !WasmSym->getType()) {

58 Type *GlobalVT = Global->getValueType();

61

63 }

64 return WasmSym;

65 }

66

67 const auto *FuncTy = cast(Global->getValueType());

71

74 const auto *const F = dyn_cast(Global);

77

78 bool InvokeDetected = false;

81 Signature, InvokeDetected);

84 return WasmSym;

85}

86

87MCSymbol *WebAssemblyMCInstLower::GetExternalSymbolSymbol(

90}

91

96

97 switch (TargetFlags) {

99 break;

102 break;

105 break;

108 break;

111 break;

114 break;

115 default:

117 }

118

120

122 const auto *WasmSym = cast(Sym);

125 if (WasmSym->isFunction())

127 if (WasmSym->isGlobal())

129 if (WasmSym->isTag())

131 if (WasmSym->isTable())

133

136 }

137

139}

140

141MCOperand WebAssemblyMCInstLower::lowerTypeIndexOperand(

145 Signature->Returns = std::move(Returns);

146 Signature->Params = std::move(Params);

148 auto *WasmSym = cast(Sym);

149 WasmSym->setSignature(Signature);

154}

155

158 const Function &F = MI->getMF()->getFunction();

164}

165

167 MCInst &OutMI) const {

169

171 unsigned NumVariadicDefs = MI->getNumExplicitDefs() - Desc.getNumDefs();

172 for (unsigned I = 0, E = MI->getNumOperands(); I != E; ++I) {

174

177 default:

182 llvm_unreachable("MachineBasicBlock operand should have been rewritten");

184

186 continue;

191 break;

192 }

194 unsigned DescIndex = I - NumVariadicDefs;

195 if (DescIndex < Desc.NumOperands) {

200

202 MI->getParent()->getParent()->getRegInfo();

205 MRI.getRegClass(MO.getReg())->getID()));

209 MRI.getRegClass(MO.getReg())->getID()));

210

211

212

215

216

217

218 if (MI->getOpcode() == WebAssembly::RET_CALL_INDIRECT)

220

221 MCOp = lowerTypeIndexOperand(std::move(Returns), std::move(Params));

222 break;

223 }

229

230

231

232

233

234

235

236

237

238

239

242 else

244 MCOp = lowerTypeIndexOperand(std::move(Returns),

246 break;

247 }

248 }

249 }

251 break;

252 }

256 Imm->getValueAPF().bitcastToAPInt().getZExtValue();

257 if (Imm->getType()->isFloatTy())

259 else if (Imm->getType()->isDoubleTy())

261 else

263 break;

264 }

266 MCOp = lowerSymbolOperand(MO, GetGlobalAddressSymbol(MO));

267 break;

269 MCOp = lowerSymbolOperand(MO, GetExternalSymbolSymbol(MO));

270 break;

273 "WebAssembly does not use target flags on MCSymbol");

274 MCOp = lowerSymbolOperand(MO, MO.getMCSymbol());

275 break;

276 }

277

279 }

280

283 else if (Desc.variadicOpsAreDefs())

285}

286

288

289

290

291

292

293

294

295

296

297

298

299

300

301 if (MI->isDebugInstr() || MI->isLabel() || MI->isInlineAsm())

302 return;

303

304

305 auto RegOpcode = OutMI.getOpcode();

307 assert(StackOpcode != -1 && "Failed to stackify instruction");

309

310

313 if (MO.isReg()) {

314 OutMI.erase(&MO);

315 }

316 }

317}

unsigned const MachineRegisterInfo * MRI

Analysis containing CSE Info

This file contains the declarations for the subclasses of Constant, which represent the different fla...

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

cl::opt< bool > WasmKeepRegisters

static void removeRegisterOperands(const MachineInstr *MI, MCInst &OutMI)

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 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.

MCSymbol * getSymbol(const GlobalValue *GV) const

MCSymbol * createTempSymbol(const Twine &Name) const

ConstantFP - Floating Point Values [float, double].

static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)

static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)

wasm::WasmSignature * createWasmSignature()

Allocates and returns a new WasmSignature instance (with empty parameter and return type lists).

Base class for the full range of assembler expressions which are needed for parsing.

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)

void setSignature(wasm::WasmSignature *Sig)

MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...

const MachineFunction * getParent() const

Return the MachineFunction containing this basic block.

Function & getFunction()

Return the LLVM function that this machine code represents.

const TargetMachine & getTarget() const

getTarget - Return the target machine this machine code is compiled with

Representation of each machine instruction.

const MachineBasicBlock * getParent() const

MachineOperand class - Representation of each machine instruction operand.

const GlobalValue * getGlobal() const

bool isReg() const

isReg - Tests if this is a MO_Register operand.

MachineInstr * getParent()

getParent - Return the instruction that this operand belongs to.

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_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,...

virtual void print(raw_ostream &OS, const Module *M) const

print - Print out the internal state of the pass.

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.

MCSymbol * getOrCreateWasmSymbol(StringRef Name)

MCSymbolWasm * getMCSymbolForFunction(const Function *F, bool EnableEmEH, wasm::WasmSignature *Sig, bool &InvokeDetected)

This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...

unsigned getWAReg(unsigned 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)

void wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT, ArrayRef< MVT > VTs)

Sets a Wasm Symbol Type.

cl::opt< bool > WasmEnableEmEH

BlockType

Used as immediate MachineOperands for block signatures.

@ OPERAND_TYPEINDEX

type signature immediate for call_indirect.

@ OPERAND_SIGNATURE

signature immediate for block/loop.

cl::opt< bool > WasmEnableEmSjLj

int getStackOpcode(unsigned short Opcode)

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)

void report_fatal_error(Error Err, bool gen_crash_diag=true)

Report a serious error, calling any installed error handler.

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)

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)

Description of the encoding of one expression Op.

SmallVector< ValType, 1 > Returns