2017-02-24 23:18:00 +00:00
|
|
|
// WebAssemblyAsmPrinter.h - WebAssembly implementation of AsmPrinter-*- C++ -*-
|
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-02-24 23:18:00 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H
|
|
|
|
#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H
|
|
|
|
|
2017-10-24 21:29:15 +00:00
|
|
|
#include "WebAssemblyMachineFunctionInfo.h"
|
2017-02-24 23:18:00 +00:00
|
|
|
#include "WebAssemblySubtarget.h"
|
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class WebAssemblyTargetStreamer;
|
|
|
|
|
|
|
|
class LLVM_LIBRARY_VISIBILITY WebAssemblyAsmPrinter final : public AsmPrinter {
|
|
|
|
const WebAssemblySubtarget *Subtarget;
|
|
|
|
const MachineRegisterInfo *MRI;
|
|
|
|
WebAssemblyFunctionInfo *MFI;
|
2018-10-03 22:22:48 +00:00
|
|
|
// TODO: Do the uniquing of Signatures here instead of ObjectFileWriter?
|
|
|
|
std::vector<std::unique_ptr<wasm::WasmSignature>> Signatures;
|
2020-04-06 20:46:11 -07:00
|
|
|
std::vector<std::unique_ptr<std::string>> Names;
|
|
|
|
|
2020-04-07 14:02:20 -07:00
|
|
|
StringRef storeName(StringRef Name) {
|
2020-04-06 20:46:11 -07:00
|
|
|
std::unique_ptr<std::string> N = std::make_unique<std::string>(Name);
|
|
|
|
Names.push_back(std::move(N));
|
2020-04-07 14:02:20 -07:00
|
|
|
return *Names.back();
|
2020-04-06 20:46:11 -07:00
|
|
|
}
|
2017-02-24 23:18:00 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit WebAssemblyAsmPrinter(TargetMachine &TM,
|
|
|
|
std::unique_ptr<MCStreamer> Streamer)
|
2018-09-05 01:27:38 +00:00
|
|
|
: AsmPrinter(TM, std::move(Streamer)), Subtarget(nullptr), MRI(nullptr),
|
|
|
|
MFI(nullptr) {}
|
2017-02-24 23:18:00 +00:00
|
|
|
|
|
|
|
StringRef getPassName() const override {
|
|
|
|
return "WebAssembly Assembly Printer";
|
|
|
|
}
|
|
|
|
|
|
|
|
const WebAssemblySubtarget &getSubtarget() const { return *Subtarget; }
|
2018-10-03 22:22:48 +00:00
|
|
|
void addSignature(std::unique_ptr<wasm::WasmSignature> &&Sig) {
|
|
|
|
Signatures.push_back(std::move(Sig));
|
|
|
|
}
|
2017-02-24 23:18:00 +00:00
|
|
|
|
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
// MachineFunctionPass Implementation.
|
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override {
|
|
|
|
Subtarget = &MF.getSubtarget<WebAssemblySubtarget>();
|
|
|
|
MRI = &MF.getRegInfo();
|
|
|
|
MFI = MF.getInfo<WebAssemblyFunctionInfo>();
|
|
|
|
return AsmPrinter::runOnMachineFunction(MF);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
// AsmPrinter Implementation.
|
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
|
2020-02-13 13:10:49 -08:00
|
|
|
void emitEndOfAsmFile(Module &M) override;
|
2019-01-18 02:47:48 +00:00
|
|
|
void EmitProducerInfo(Module &M);
|
[WebAssembly] Merge used feature sets, update atomics linkage policy
Summary:
It does not currently make sense to use WebAssembly features in some functions
but not others, so this CL adds an IR pass that takes the union of all used
feature sets and applies it to each function in the module. This allows us to
prevent atomics from being lowered away if some function has opted in to using
them. When atomics is not enabled anywhere, we detect whether there exists any
atomic operations or thread local storage that would be stripped and disallow
linking with objects that contain atomics if and only if atomics or tls are
stripped. When atomics is enabled, mark it as used but do not require it of
other objects in the link. These changes allow libraries that do not use atomics
to be built once and linked into both single-threaded and multithreaded
binaries.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59625
llvm-svn: 357226
2019-03-29 00:14:01 +00:00
|
|
|
void EmitTargetFeatures(Module &M);
|
2020-02-13 16:36:27 -08:00
|
|
|
void emitJumpTableInfo() override;
|
|
|
|
void emitConstantPool() override;
|
2020-02-13 13:10:49 -08:00
|
|
|
void emitFunctionBodyStart() override;
|
2020-02-13 21:58:16 -08:00
|
|
|
void emitInstruction(const MachineInstr *MI) override;
|
2017-02-24 23:18:00 +00:00
|
|
|
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
[AsmPrinter] refactor to remove remove AsmVariant. NFC
Summary:
The InlineAsm::AsmDialect is only required for X86; no architecture
makes use of it and as such it gets passed around between arch-specific
and general code while being unused for all architectures but X86.
Since the AsmDialect is queried from a MachineInstr, which we also pass
around, remove the additional AsmDialect parameter and query for it deep
in the X86AsmPrinter only when needed/as late as possible.
This refactor should help later planned refactors to AsmPrinter, as this
difference in the X86AsmPrinter makes it harder to make AsmPrinter more
generic.
Reviewers: craig.topper
Subscribers: jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, javed.absar, sbc100, jgravelle-google, eraman, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, llvm-commits, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60488
llvm-svn: 358101
2019-04-10 16:38:43 +00:00
|
|
|
const char *ExtraCode, raw_ostream &OS) override;
|
2017-02-24 23:18:00 +00:00
|
|
|
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
|
[AsmPrinter] refactor to remove remove AsmVariant. NFC
Summary:
The InlineAsm::AsmDialect is only required for X86; no architecture
makes use of it and as such it gets passed around between arch-specific
and general code while being unused for all architectures but X86.
Since the AsmDialect is queried from a MachineInstr, which we also pass
around, remove the additional AsmDialect parameter and query for it deep
in the X86AsmPrinter only when needed/as late as possible.
This refactor should help later planned refactors to AsmPrinter, as this
difference in the X86AsmPrinter makes it harder to make AsmPrinter more
generic.
Reviewers: craig.topper
Subscribers: jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, javed.absar, sbc100, jgravelle-google, eraman, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, llvm-commits, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60488
llvm-svn: 358101
2019-04-10 16:38:43 +00:00
|
|
|
const char *ExtraCode, raw_ostream &OS) override;
|
2017-02-24 23:18:00 +00:00
|
|
|
|
|
|
|
MVT getRegType(unsigned RegNo) const;
|
|
|
|
std::string regToString(const MachineOperand &MO);
|
|
|
|
WebAssemblyTargetStreamer *getTargetStreamer();
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|