43 #define DEBUG_TYPE "asm-printer"
56 DEBUG(
errs() <<
"Unknown type for register number: " << RegNo);
62 unsigned RegNo = MO.
getReg();
64 "Unlowered physical register encountered during assembly printing");
66 unsigned WAReg = MFI->
getWAReg(RegNo);
68 return '$' +
utostr(WAReg);
81 for (
const auto &
F : M) {
83 if (
F.isDeclarationForLinker() && !
F.isIntrinsic()) {
91 for (
const auto &
G : M.globals()) {
92 if (!
G.hasInitializer() &&
G.hasExternalLinkage()) {
93 uint16_t
Size = M.getDataLayout().getTypeAllocSize(
G.getValueType());
103 "WebAssembly disables constant pools");
117 if (
MDNode *Idx =
F.getMetadata(
"wasm.index")) {
118 assert(Idx->getNumOperands() == 1);
121 cast<ConstantAsMetadata>(Idx->getOperand(0))->getValue()));
128 if (ResultVTs.
size() == 1)
135 for (
unsigned Idx = 0, IdxE = MRI->
getNumVirtRegs(); Idx != IdxE; ++Idx) {
137 unsigned WAReg = MFI->
getWAReg(VReg);
142 if (WAReg < MFI->getParams().size())
162 DEBUG(
dbgs() <<
"EmitInstruction: " << *MI <<
'\n');
165 case WebAssembly::ARGUMENT_I32:
166 case WebAssembly::ARGUMENT_I64:
167 case WebAssembly::ARGUMENT_F32:
168 case WebAssembly::ARGUMENT_F64:
169 case WebAssembly::ARGUMENT_v16i8:
170 case WebAssembly::ARGUMENT_v8i16:
171 case WebAssembly::ARGUMENT_v4i32:
172 case WebAssembly::ARGUMENT_v4f32:
176 case WebAssembly::FALLTHROUGH_RETURN_I32:
177 case WebAssembly::FALLTHROUGH_RETURN_I64:
178 case WebAssembly::FALLTHROUGH_RETURN_F32:
179 case WebAssembly::FALLTHROUGH_RETURN_F64:
180 case WebAssembly::FALLTHROUGH_RETURN_v16i8:
181 case WebAssembly::FALLTHROUGH_RETURN_v8i16:
182 case WebAssembly::FALLTHROUGH_RETURN_v4i32:
183 case WebAssembly::FALLTHROUGH_RETURN_v4f32: {
189 OutStreamer->AddComment(
"fallthrough-return: $pop" +
196 case WebAssembly::FALLTHROUGH_RETURN_VOID:
207 MCInstLowering.
Lower(MI, TmpInst);
215 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CV))
216 if (GV->getValueType()->isFunctionTy()) {
224 unsigned OpNo,
unsigned AsmVariant,
225 const char *ExtraCode,
265 const char *ExtraCode,
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
const GlobalValue * getGlobal() const
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
MCSymbol * getSymbol(const GlobalValue *GV) const
This class is used to lower an MachineInstr into an MCInst.
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
MachineBasicBlock * getMBB() const
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
A Module instance is used to store all the information related to an LLVM module. ...
MCContext & OutContext
This is the context for the output file that we are streaming.
This class prints an WebAssembly MCInst to wasm file syntax.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
Target specific streamer interface.
const MachineFunction * MF
The current machine function.
virtual void emitGlobalImport(StringRef name)=0
.import_global
This file declares the class to lower WebAssembly MachineInstrs to their corresponding MCInst records...
void EmitInstruction(const MachineInstr *MI) override
Targets should implement this to emit instructions.
Function Alias Analysis Results
MachineBasicBlock reference.
const char * getSymbolName() const
bool isVRegStackified(unsigned VReg) const
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end...
const Triple & getTargetTriple() const
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
void ComputeLegalValueVTs(const Function &F, const TargetMachine &TM, Type *Ty, SmallVectorImpl< MVT > &ValueVTs)
Base class for the full range of assembler expressions which are needed for parsing.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
Name of external global symbol.
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant...
unsigned getWAReg(unsigned Reg) const
std::string regToString(const MachineOperand &MO)
MVT getRegType(unsigned RegNo) const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
static std::string utostr(uint64_t X, bool isNeg=false)
virtual void emitEndFunc()=0
.endfunc
Instances of this class represent a single low-level machine instruction.
WebAssembly-specific streamer interface, to implement support WebAssembly-specific assembly directive...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Address of a global value.
MCSymbol * CurrentFnSym
The symbol for the current function.
const MCAsmInfo * MAI
Target Asm Printer information.
virtual void emitResult(MCSymbol *Symbol, ArrayRef< MVT > Types)=0
.result
void ComputeSignatureVTs(const Function &F, const TargetMachine &TM, SmallVectorImpl< MVT > &Params, SmallVectorImpl< MVT > &Results)
This is an important base class in LLVM.
void EmitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
const MachineOperand & getOperand(unsigned i) const
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant...
This file provides WebAssembly-specific target descriptions.
TargetMachine & TM
Target machine description.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
void printOffset(int64_t Offset, raw_ostream &OS) const
This is just convenient handler for printing offsets.
int64_t getOffset() const
Return the offset from the symbol in this operand.
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
const MCExpr * lowerConstant(const Constant *CV) override
Lower the specified LLVM Constant to an MCExpr.
static const unsigned UnusedReg
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
This file declares WebAssembly-specific target streamer classes.
This file contains the WebAssembly implementation of the WebAssemblyRegisterInfo class.
void LLVMInitializeWebAssemblyAsmPrinter()
virtual const MCExpr * lowerConstant(const Constant *CV)
Lower the specified LLVM Constant to an MCExpr.
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...
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
virtual void EmitFunctionBodyStart()
Targets can override this to emit stuff before the first basic block in the function.
void EmitConstantPool() override
Print to the current output stream assembly representations of the constants in the constant pool MCP...
void Lower(const MachineInstr *MI, MCInst &OutMI) const
virtual void emitIndirectFunctionType(MCSymbol *Symbol, SmallVectorImpl< MVT > &Params, SmallVectorImpl< MVT > &Results)=0
.functype
void EmitFunctionBodyEnd() override
Targets can override this to emit stuff after the last basic block in the function.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
const WebAssemblyRegisterInfo * getRegisterInfo() const override
llvm_unreachable("Unknown RegBank!")
const std::vector< MVT > & getParams() const
void EmitJumpTableInfo() override
Print assembly representations of the jump tables used by the current function to the current output ...
Representation of each machine instruction.
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
This file declares WebAssembly-specific per-machine-function information.
const std::vector< MVT > & getLocals() const
void EmitFunctionBodyStart() override
Targets can override this to emit stuff before the first basic block in the function.
virtual void emitParam(MCSymbol *Symbol, ArrayRef< MVT > Types)=0
.param
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
bool isTypeLegalForClass(const TargetRegisterClass &RC, MVT T) const
Return true if the given TargetRegisterClass has the ValueType T.
RegisterAsmPrinter - Helper template for registering a target specific assembly printer, for use in the target machine initialization function.
This class implements an extremely fast bulk output stream that can only output to a stream...
virtual void emitLocal(ArrayRef< MVT > Types)=0
.local
const std::vector< MachineConstantPoolEntry > & getConstants() const
virtual void print(raw_ostream &O, const Module *M) const
print - Print out the internal state of the pass.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
Target & getTheWebAssemblyTarget32()
bool isVerbose() const
Return true if assembly output should contain comments.
Target & getTheWebAssemblyTarget64()
WebAssemblyTargetStreamer * getTargetStreamer()
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
virtual void emitIndIdx(const MCExpr *Value)=0
.indidx
static unsigned getWARegStackId(unsigned Reg)