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);
83 auto Sym = cast<MCSymbolWasm>(It.getValue());
90 for (
const auto &
F : M) {
92 if (
F.isDeclarationForLinker() && !
F.isIntrinsic()) {
98 if (!Sym->getSignature()) {
100 Sym->setSignature(Signature.get());
110 if (TM.getTargetTriple().isOSBinFormatWasm() &&
111 F.hasFnAttribute(
"wasm-import-module")) {
113 F.getFnAttribute(
"wasm-import-module").getValueAsString();
114 Sym->setImportModule(Name);
117 if (TM.getTargetTriple().isOSBinFormatWasm() &&
118 F.hasFnAttribute(
"wasm-import-name")) {
120 F.getFnAttribute(
"wasm-import-name").getValueAsString();
121 Sym->setImportName(Name);
127 for (
const auto &
G : M.globals()) {
128 if (!
G.hasInitializer() &&
G.hasExternalLinkage()) {
129 if (
G.getValueType()->isSized()) {
130 uint16_t
Size = M.getDataLayout().getTypeAllocSize(
G.getValueType());
137 if (
const NamedMDNode *Named = M.getNamedMetadata(
"wasm.custom_sections")) {
138 for (
const Metadata *MD : Named->operands()) {
144 if (!Name || !Contents)
160 "WebAssembly disables constant pools");
174 WasmSym->setSignature(Signature.get());
183 assert(Idx->getNumOperands() == 1);
186 cast<ConstantAsMetadata>(Idx->getOperand(0))->getValue()));
200 case WebAssembly::ARGUMENT_i32:
201 case WebAssembly::ARGUMENT_i32_S:
202 case WebAssembly::ARGUMENT_i64:
203 case WebAssembly::ARGUMENT_i64_S:
204 case WebAssembly::ARGUMENT_f32:
205 case WebAssembly::ARGUMENT_f32_S:
206 case WebAssembly::ARGUMENT_f64:
207 case WebAssembly::ARGUMENT_f64_S:
208 case WebAssembly::ARGUMENT_v16i8:
209 case WebAssembly::ARGUMENT_v16i8_S:
210 case WebAssembly::ARGUMENT_v8i16:
211 case WebAssembly::ARGUMENT_v8i16_S:
212 case WebAssembly::ARGUMENT_v4i32:
213 case WebAssembly::ARGUMENT_v4i32_S:
214 case WebAssembly::ARGUMENT_v2i64:
215 case WebAssembly::ARGUMENT_v2i64_S:
216 case WebAssembly::ARGUMENT_v4f32:
217 case WebAssembly::ARGUMENT_v4f32_S:
218 case WebAssembly::ARGUMENT_v2f64:
219 case WebAssembly::ARGUMENT_v2f64_S:
223 case WebAssembly::FALLTHROUGH_RETURN_I32:
224 case WebAssembly::FALLTHROUGH_RETURN_I32_S:
225 case WebAssembly::FALLTHROUGH_RETURN_I64:
226 case WebAssembly::FALLTHROUGH_RETURN_I64_S:
227 case WebAssembly::FALLTHROUGH_RETURN_F32:
228 case WebAssembly::FALLTHROUGH_RETURN_F32_S:
229 case WebAssembly::FALLTHROUGH_RETURN_F64:
230 case WebAssembly::FALLTHROUGH_RETURN_F64_S:
231 case WebAssembly::FALLTHROUGH_RETURN_v16i8:
232 case WebAssembly::FALLTHROUGH_RETURN_v16i8_S:
233 case WebAssembly::FALLTHROUGH_RETURN_v8i16:
234 case WebAssembly::FALLTHROUGH_RETURN_v8i16_S:
235 case WebAssembly::FALLTHROUGH_RETURN_v4i32:
236 case WebAssembly::FALLTHROUGH_RETURN_v4i32_S:
237 case WebAssembly::FALLTHROUGH_RETURN_v2i64:
238 case WebAssembly::FALLTHROUGH_RETURN_v2i64_S:
239 case WebAssembly::FALLTHROUGH_RETURN_v4f32:
240 case WebAssembly::FALLTHROUGH_RETURN_v4f32_S:
241 case WebAssembly::FALLTHROUGH_RETURN_v2f64:
242 case WebAssembly::FALLTHROUGH_RETURN_v2f64_S: {
246 OutStreamer->AddComment(
"fallthrough-return-value");
251 case WebAssembly::FALLTHROUGH_RETURN_VOID:
252 case WebAssembly::FALLTHROUGH_RETURN_VOID_S:
256 OutStreamer->AddComment(
"fallthrough-return-void");
263 MCInstLowering.
Lower(MI, TmpInst);
271 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CV))
272 if (GV->getValueType()->isFunctionTy()) {
280 unsigned OpNo,
unsigned AsmVariant,
281 const char *ExtraCode,
324 const char *ExtraCode,
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.
This class represents lattice values for constants.
const std::vector< MVT > & getLocals() const
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.
virtual void emitGlobalType(const MCSymbolWasm *Sym)=0
.globaltype
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
virtual void emitImportModule(const MCSymbolWasm *Sym, StringRef ImportModule)=0
.import_module
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
amdgpu Simplify well known AMD library false Value Value const Twine & Name
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
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
INLINEASM - Represents an inline asm block.
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)
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.
const SymbolTable & getSymbols() const
getSymbols - Get a reference for the symbol table for clients that want to, for example, iterate over all symbols.
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.
MCSymbol * CurrentFnSym
The symbol for the current function.
const MCAsmInfo * MAI
Target Asm Printer information.
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.
std::unique_ptr< wasm::WasmSignature > SignatureFromMVTs(const SmallVectorImpl< MVT > &Results, const SmallVectorImpl< MVT > &Params)
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.
void addSignature(std::unique_ptr< wasm::WasmSignature > &&Sig)
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.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
void ComputeSignatureVTs(const FunctionType *Ty, const Function &F, const TargetMachine &TM, SmallVectorImpl< MVT > &Params, SmallVectorImpl< MVT > &Results)
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...
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.
virtual void emitFunctionType(const MCSymbolWasm *Sym)=0
.functype
void ValTypesFromMVTs(const ArrayRef< MVT > &In, SmallVectorImpl< wasm::ValType > &Out)
virtual void emitImportName(const MCSymbolWasm *Sym, StringRef ImportName)=0
.import_name
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)
virtual void emitEventType(const MCSymbolWasm *Sym)=0
.eventtype
unsigned getWAReg(unsigned VReg) const
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...
virtual void emitLocal(ArrayRef< wasm::ValType > Types)=0
.local
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
Target & getTheWebAssemblyTarget32()
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
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.