LLVM  14.0.0git
WebAssemblyAsmPrinter.h
Go to the documentation of this file.
1 // WebAssemblyAsmPrinter.h - WebAssembly implementation of AsmPrinter-*- C++ -*-
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H
10 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H
11 
13 #include "WebAssemblySubtarget.h"
15 #include "llvm/MC/MCStreamer.h"
17 
18 namespace llvm {
19 class WebAssemblyTargetStreamer;
20 
22  const WebAssemblySubtarget *Subtarget;
23  const MachineRegisterInfo *MRI;
25  // TODO: Do the uniquing of Signatures here instead of ObjectFileWriter?
26  std::vector<std::unique_ptr<wasm::WasmSignature>> Signatures;
27  std::vector<std::unique_ptr<std::string>> Names;
28  bool signaturesEmitted = false;
29 
30  StringRef storeName(StringRef Name) {
31  std::unique_ptr<std::string> N = std::make_unique<std::string>(Name);
32  Names.push_back(std::move(N));
33  return *Names.back();
34  }
35 
36 public:
38  std::unique_ptr<MCStreamer> Streamer)
39  : AsmPrinter(TM, std::move(Streamer)), Subtarget(nullptr), MRI(nullptr),
40  MFI(nullptr) {}
41 
42  StringRef getPassName() const override {
43  return "WebAssembly Assembly Printer";
44  }
45 
46  const WebAssemblySubtarget &getSubtarget() const { return *Subtarget; }
47  void addSignature(std::unique_ptr<wasm::WasmSignature> &&Sig) {
48  Signatures.push_back(std::move(Sig));
49  }
50 
51  //===------------------------------------------------------------------===//
52  // MachineFunctionPass Implementation.
53  //===------------------------------------------------------------------===//
54 
56  Subtarget = &MF.getSubtarget<WebAssemblySubtarget>();
57  MRI = &MF.getRegInfo();
58  MFI = MF.getInfo<WebAssemblyFunctionInfo>();
60  }
61 
62  //===------------------------------------------------------------------===//
63  // AsmPrinter Implementation.
64  //===------------------------------------------------------------------===//
65 
66  void emitEndOfAsmFile(Module &M) override;
67  void EmitProducerInfo(Module &M);
68  void EmitTargetFeatures(Module &M);
69  void emitGlobalVariable(const GlobalVariable *GV) override;
70  void emitJumpTableInfo() override;
71  void emitConstantPool() override;
72  void emitLinkage(const GlobalValue *, MCSymbol *) const override;
73  void emitFunctionBodyStart() override;
74  void emitInstruction(const MachineInstr *MI) override;
75  bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
76  const char *ExtraCode, raw_ostream &OS) override;
77  bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
78  const char *ExtraCode, raw_ostream &OS) override;
79 
80  MVT getRegType(unsigned RegNo) const;
81  std::string regToString(const MachineOperand &MO);
82  WebAssemblyTargetStreamer *getTargetStreamer();
83  MCSymbolWasm *getMCSymbolForFunction(const Function *F, bool EnableEmEH,
85  bool &InvokeDetected);
86  MCSymbol *getOrCreateWasmSymbol(StringRef Name);
87  void emitExternalDecls(const Module &M);
88 };
89 
90 } // end namespace llvm
91 
92 #endif
AsmPrinter.h
regToString
static yaml::StringValue regToString(Register Reg, const TargetRegisterInfo &TRI)
Definition: SIMachineFunctionInfo.cpp:509
llvm::WebAssemblyAsmPrinter::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition: WebAssemblyAsmPrinter.h:55
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:103
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::WebAssemblyTargetStreamer
WebAssembly-specific streamer interface, to implement support WebAssembly-specific assembly directive...
Definition: WebAssemblyTargetStreamer.h:29
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:52
llvm::Function
Definition: Function.h:61
llvm::WebAssemblyAsmPrinter::getSubtarget
const WebAssemblySubtarget & getSubtarget() const
Definition: WebAssemblyAsmPrinter.h:46
llvm::GlobalVariable
Definition: GlobalVariable.h:40
emitConstantPool
static void emitConstantPool(MCStreamer &Streamer, MCSection *Section, ConstantPool &CP)
Definition: ConstantPools.cpp:79
llvm::WebAssemblyAsmPrinter::getPassName
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: WebAssemblyAsmPrinter.h:42
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::MachineFunction::getRegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Definition: MachineFunction.h:636
TargetMachine.h
llvm::MachineFunction::getInfo
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Definition: MachineFunction.h:724
llvm::WebAssemblyAsmPrinter::addSignature
void addSignature(std::unique_ptr< wasm::WasmSignature > &&Sig)
Definition: WebAssemblyAsmPrinter.h:47
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:626
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::MCSymbolWasm
Definition: MCSymbolWasm.h:16
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:79
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1605
llvm::WebAssemblyFunctionInfo
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
Definition: WebAssemblyMachineFunctionInfo.h:33
llvm::MVT
Machine Value Type.
Definition: MachineValueType.h:31
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::WebAssemblyAsmPrinter
Definition: WebAssemblyAsmPrinter.h:21
WebAssemblyMachineFunctionInfo.h
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::AsmPrinter::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition: AsmPrinter.h:341
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
LLVM_LIBRARY_VISIBILITY
#define LLVM_LIBRARY_VISIBILITY
LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked into a shared library,...
Definition: Compiler.h:131
llvm::WebAssemblySubtarget
Definition: WebAssemblySubtarget.h:35
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
std
Definition: BitVector.h:838
WebAssemblySubtarget.h
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:82
N
#define N
MCStreamer.h
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::wasm::WasmSignature
Definition: Wasm.h:418
llvm::WebAssemblyAsmPrinter::WebAssemblyAsmPrinter
WebAssemblyAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
Definition: WebAssemblyAsmPrinter.h:37