43 #define DEBUG_TYPE "asm-printer" 56 LLVM_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 F.hasFnAttribute(
"wasm-import-module")) {
99 for (
const auto &
G : M.globals()) {
100 if (!
G.hasInitializer() &&
G.hasExternalLinkage()) {
101 if (
G.getValueType()->isSized()) {
102 uint16_t
Size = M.getDataLayout().getTypeAllocSize(
G.getValueType());
109 if (
const NamedMDNode *Named = M.getNamedMetadata(
"wasm.custom_sections")) {
110 for (
const Metadata *MD : Named->operands()) {
116 if (!Name || !Contents)
132 "WebAssembly disables constant pools");
147 assert(Idx->getNumOperands() == 1);
150 cast<ConstantAsMetadata>(Idx->getOperand(0))->getValue()));
157 if (ResultVTs.
size() == 1)
171 case WebAssembly::ARGUMENT_I32:
172 case WebAssembly::ARGUMENT_I64:
173 case WebAssembly::ARGUMENT_F32:
174 case WebAssembly::ARGUMENT_F64:
175 case WebAssembly::ARGUMENT_v16i8:
176 case WebAssembly::ARGUMENT_v8i16:
177 case WebAssembly::ARGUMENT_v4i32:
178 case WebAssembly::ARGUMENT_v4f32:
182 case WebAssembly::FALLTHROUGH_RETURN_I32:
183 case WebAssembly::FALLTHROUGH_RETURN_I64:
184 case WebAssembly::FALLTHROUGH_RETURN_F32:
185 case WebAssembly::FALLTHROUGH_RETURN_F64:
186 case WebAssembly::FALLTHROUGH_RETURN_v16i8:
187 case WebAssembly::FALLTHROUGH_RETURN_v8i16:
188 case WebAssembly::FALLTHROUGH_RETURN_v4i32:
189 case WebAssembly::FALLTHROUGH_RETURN_v4f32: {
195 OutStreamer->AddComment(
"fallthrough-return: $pop" +
202 case WebAssembly::FALLTHROUGH_RETURN_VOID:
213 MCInstLowering.
Lower(MI, TmpInst);
221 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CV))
222 if (GV->getValueType()->isFunctionTy()) {
230 unsigned OpNo,
unsigned AsmVariant,
231 const char *ExtraCode,
271 const char *ExtraCode,
virtual void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName)=0
.import_module
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
MachineBasicBlock * getMBB() const
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
This class is used to lower an MachineInstr into an MCInst.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Compute iterated dominance frontiers using a linear time algorithm.
const std::vector< MVT > & getLocals() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
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.
unsigned getReg() const
getReg - Returns the register number.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
Target specific streamer interface.
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K)
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.
unsigned const TargetRegisterInfo * TRI
MachineFunction * MF
The current machine function.
const MDOperand & getOperand(unsigned I) const
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end...
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
MVT getRegType(unsigned RegNo) const
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
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.
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Name of external global symbol.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const char * getSymbolName() const
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...
std::string regToString(const MachineOperand &MO)
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...
RegisterAsmPrinter - Helper template for registering a target specific assembly printer, for use in the target machine initialization function.
bool isVRegStackified(unsigned VReg) const
void printOffset(int64_t Offset, raw_ostream &OS) const
This is just convenient handler for printing offsets.
bool isVerbose() const
Return true if assembly output should contain comments.
bool isTypeLegalForClass(const TargetRegisterClass &RC, MVT T) const
Return true if the given TargetRegisterClass has the ValueType T.
Instances of this class represent a single low-level machine instruction.
WebAssembly-specific streamer interface, to implement support WebAssembly-specific assembly directive...
StringRef getString() const
Address of a global value.
Type * getReturnType() const
Returns the type of the ret val.
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...
This represents a section on wasm.
const GlobalValue * getGlobal() 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.
const Triple & getTargetTriple() const
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...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This file declares WebAssembly-specific target streamer classes.
const std::vector< MachineConstantPoolEntry > & getConstants() const
void Lower(const MachineInstr *MI, MCInst &OutMI) const
This file contains the WebAssembly implementation of the WebAssemblyRegisterInfo class.
void LLVMInitializeWebAssemblyAsmPrinter()
MCSymbol * getSymbol(const GlobalValue *GV) const
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)
static SectionKind getMetadata()
std::string utostr(uint64_t X, bool isNeg=false)
const Function & getFunction() const
Return the LLVM function that this machine code represents.
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...
virtual void emitIndirectFunctionType(MCSymbol *Symbol, SmallVectorImpl< MVT > &Params, SmallVectorImpl< MVT > &Results)=0
.functype
const WebAssemblyRegisterInfo * getRegisterInfo() const override
void EmitJumpTableInfo() override
Print assembly representations of the jump tables used by the current function to the current output ...
Representation of each machine instruction.
int64_t getOffset() const
Return the offset from the symbol in this operand.
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
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.
void EmitFunctionBodyStart() override
Targets can override this to emit stuff before the first basic block in the function.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getWAReg(unsigned VReg) const
virtual void emitParam(MCSymbol *Symbol, ArrayRef< MVT > Types)=0
.param
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...
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
This class implements an extremely fast bulk output stream that can only output to a stream...
virtual void emitLocal(ArrayRef< MVT > Types)=0
.local
StringRef - Represent a constant reference to a string, i.e.
const std::vector< MVT > & getParams() const
Target & getTheWebAssemblyTarget32()
bool isOSBinFormatWasm() const
Tests whether the OS uses the Wasm binary format.
unsigned getNumOperands() const
Return number of MDNode operands.
const MachineOperand & getOperand(unsigned i) const
Target & getTheWebAssemblyTarget64()
WebAssemblyTargetStreamer * getTargetStreamer()
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
virtual void emitIndIdx(const MCExpr *Value)=0
.indidx
static unsigned getWARegStackId(unsigned Reg)
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.