49 #define DEBUG_TYPE "asm-printer" 64 LLVM_DEBUG(
errs() <<
"Unknown type for register number: " << RegNo);
72 "Unlowered physical register encountered during assembly printing");
74 unsigned WAReg = MFI->
getWAReg(RegNo);
76 return '$' +
utostr(WAReg);
91 auto Sym = cast<MCSymbolWasm>(It.getValue());
98 for (
const auto &
F : M) {
103 if (
F.isDeclarationForLinker()) {
107 auto *Sym = cast<MCSymbolWasm>(
getSymbol(&
F));
109 if (!Sym->getSignature()) {
111 Sym->setSignature(Signature.get());
121 if (TM.getTargetTriple().isOSBinFormatWasm() &&
122 F.hasFnAttribute(
"wasm-import-module")) {
124 F.getFnAttribute(
"wasm-import-module").getValueAsString();
125 Sym->setImportModule(Name);
128 if (TM.getTargetTriple().isOSBinFormatWasm() &&
129 F.hasFnAttribute(
"wasm-import-name")) {
131 F.getFnAttribute(
"wasm-import-name").getValueAsString();
132 Sym->setImportName(Name);
137 if (
F.hasFnAttribute(
"wasm-export-name")) {
138 auto *Sym = cast<MCSymbolWasm>(
getSymbol(&
F));
139 StringRef Name =
F.getFnAttribute(
"wasm-export-name").getValueAsString();
140 Sym->setExportName(Name);
145 for (
const auto &
G : M.globals()) {
146 if (!
G.hasInitializer() &&
G.hasExternalLinkage()) {
147 if (
G.getValueType()->isSized()) {
148 uint16_t Size = M.getDataLayout().getTypeAllocSize(
G.getValueType());
155 if (
const NamedMDNode *Named = M.getNamedMetadata(
"wasm.custom_sections")) {
156 for (
const Metadata *MD : Named->operands()) {
158 if (!Tuple || Tuple->getNumOperands() != 2)
162 if (!Name || !Contents)
183 for (
size_t I = 0,
E =
Debug->getNumOperands();
I <
E; ++
I) {
184 const auto *
CU = cast<DICompileUnit>(
Debug->getOperand(
I));
187 if (SeenLanguages.
insert(Language).second)
195 for (
size_t I = 0,
E = Ident->getNumOperands();
I <
E; ++
I) {
196 const auto *S = cast<MDString>(Ident->getOperand(
I)->getOperand(0));
197 std::pair<StringRef, StringRef>
Field = S->getString().split(
"version");
200 if (SeenTools.
insert(Name).second)
205 int FieldCount = int(!Languages.
empty()) +
int(!Tools.
empty());
206 if (FieldCount != 0) {
212 for (
auto &Producers : {std::make_pair(
"language", &Languages),
213 std::make_pair(
"processed-by", &Tools)}) {
214 if (Producers.second->empty())
216 OutStreamer->EmitULEB128IntValue(strlen(Producers.first));
218 OutStreamer->EmitULEB128IntValue(Producers.second->size());
219 for (
auto &Producer : *Producers.second) {
220 OutStreamer->EmitULEB128IntValue(Producer.first.size());
222 OutStreamer->EmitULEB128IntValue(Producer.second.size());
231 struct FeatureEntry {
239 std::string MDKey = (
StringRef(
"wasm-feature-") + KV.Key).str();
241 if (Policy ==
nullptr)
248 if (
auto *MD = cast<ConstantAsMetadata>(Policy))
249 if (
auto *
I = cast<ConstantInt>(MD->getValue()))
250 Entry.Prefix =
I->getZExtValue();
261 if (EmittedFeatures.
size() == 0)
271 for (
auto &
F : EmittedFeatures) {
282 "WebAssembly disables constant pools");
296 WasmSym->setSignature(Signature.get());
305 assert(Idx->getNumOperands() == 1);
308 cast<ConstantAsMetadata>(Idx->getOperand(0))->getValue()));
322 case WebAssembly::ARGUMENT_i32:
323 case WebAssembly::ARGUMENT_i32_S:
324 case WebAssembly::ARGUMENT_i64:
325 case WebAssembly::ARGUMENT_i64_S:
326 case WebAssembly::ARGUMENT_f32:
327 case WebAssembly::ARGUMENT_f32_S:
328 case WebAssembly::ARGUMENT_f64:
329 case WebAssembly::ARGUMENT_f64_S:
330 case WebAssembly::ARGUMENT_v16i8:
331 case WebAssembly::ARGUMENT_v16i8_S:
332 case WebAssembly::ARGUMENT_v8i16:
333 case WebAssembly::ARGUMENT_v8i16_S:
334 case WebAssembly::ARGUMENT_v4i32:
335 case WebAssembly::ARGUMENT_v4i32_S:
336 case WebAssembly::ARGUMENT_v2i64:
337 case WebAssembly::ARGUMENT_v2i64_S:
338 case WebAssembly::ARGUMENT_v4f32:
339 case WebAssembly::ARGUMENT_v4f32_S:
340 case WebAssembly::ARGUMENT_v2f64:
341 case WebAssembly::ARGUMENT_v2f64_S:
345 case WebAssembly::FALLTHROUGH_RETURN: {
354 case WebAssembly::COMPILER_FENCE:
358 case WebAssembly::EXTRACT_EXCEPTION_I32:
359 case WebAssembly::EXTRACT_EXCEPTION_I32_S:
363 if (!WasmKeepRegisters)
369 MCInstLowering.
lower(MI, TmpInst);
378 const char *ExtraCode,
416 const char *ExtraCode,
cl::opt< bool > WasmKeepRegisters
reference emplace_back(ArgTypes &&... Args)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant...
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
MachineBasicBlock * getMBB() const
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
This class is used to lower an MachineInstr into an MCInst.
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
MCContext & OutContext
This is the context for the output file that we are streaming.
virtual void emitGlobalType(const MCSymbolWasm *Sym)=0
.globaltype
void push_back(const T &Elt)
This class prints an WebAssembly MCInst to wasm file syntax.
Target specific streamer interface.
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
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.
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeWebAssemblyAsmPrinter()
unsigned const TargetRegisterInfo * TRI
MachineFunction * MF
The current machine function.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end...
void computeSignatureVTs(const FunctionType *Ty, const Function &F, const TargetMachine &TM, SmallVectorImpl< MVT > &Params, SmallVectorImpl< MVT > &Results)
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
constexpr char Language[]
Key for Kernel::Metadata::mLanguage.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
MVT getRegType(unsigned RegNo) const
This file registers the WebAssembly target.
std::unique_ptr< wasm::WasmSignature > signatureFromMVTs(const SmallVectorImpl< MVT > &Results, const SmallVectorImpl< MVT > &Params)
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
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
void EmitTargetFeatures(Module &M)
INLINEASM - Represents an inline asm block.
This file declares the WebAssembly-specific subclass of TargetMachine.
const SubtargetFeatureKV WebAssemblyFeatureKV[WebAssembly::NumSubtargetFeatures]
std::string regToString(const MachineOperand &MO)
StringRef LanguageString(unsigned Language)
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
Used to provide key value pairs for feature and CPU bit flags.
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.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false)
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.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
This file provides WebAssembly-specific target descriptions.
TargetMachine & TM
Target machine description.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
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
This file contains the WebAssembly implementation of the WebAssemblyRegisterInfo class.
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()
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant...
#define LLVM_EXTERNAL_VISIBILITY
std::string utostr(uint64_t X, bool isNeg=false)
void EmitProducerInfo(Module &M)
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.
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 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
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
LLVM_NODISCARD bool empty() const
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.
virtual void emitExportName(const MCSymbolWasm *Sym, StringRef ExportName)=0
.export_name
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 PrintSymbolOperand(const MachineOperand &MO, raw_ostream &OS)
Print the MachineOperand as a symbol.
virtual void emitEventType(const MCSymbolWasm *Sym)=0
.eventtype
unsigned getWAReg(unsigned VReg) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void valTypesFromMVTs(const ArrayRef< MVT > &In, SmallVectorImpl< wasm::ValType > &Out)
void lower(const MachineInstr *MI, MCInst &OutMI) const
static cl::opt< bool, true > Debug("debug", cl::desc("Enable debug output"), cl::Hidden, cl::location(DebugFlag))
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
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()
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
Target & getTheWebAssemblyTarget64()
WebAssemblyTargetStreamer * getTargetStreamer()
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
Wrapper class representing virtual and physical registers.
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.