
Currently wasm adds an extra level of options that work backwards from the standard options, and overwrites them. The ExceptionModel field in TM->Options is the standard user configuration option for the exception model to use. MCAsmInfo's ExceptionsType is a constant for the default to use for the triple if not explicitly set in the TargetOptions ExceptionModel. This was adding 2 custom flags, changing the MCAsmInfo default, and overwriting the ExceptionModel from the custom flags. These comments about compiling bitcode with clang are describing a toolchain bug or user error. TargetOptions is bad, and we should move to eliminating it. It is module state not captured in the IR. Ideally the exception model should either come implied from the triple, or a module flag and not depend on this side state. Currently it is the responsibility of the toolchain and/or user to ensure the same command line flags are used at each phase of the compilation. It is not the backend's responsibilty to try to second guess these options. -wasm-enable-eh and -wasm-enable-sjlj should also be removed in favor of the standard exception control. I'm a bit confused by how all of these fields are supposed to interact, but there are a few uses in the backend that are directly looking at these flags instead of the already parsed ExceptionModel which need to be cleaned up. Additionally, this was enforcing some rules about the combinations of flags at a random point in the IR pass pipeline configuration. This is a module property that should be handled at TargetMachine construction time at the latest. This required adding flags to a few mir and clang tests which never got this far to avoid hitting the errors.
86 lines
3.1 KiB
C++
86 lines
3.1 KiB
C++
// WebAssemblyAsmPrinter.h - WebAssembly implementation of AsmPrinter-*- C++ -*-
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H
|
|
#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H
|
|
|
|
#include "WebAssemblyMachineFunctionInfo.h"
|
|
#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 {
|
|
public:
|
|
static char ID;
|
|
|
|
private:
|
|
const WebAssemblySubtarget *Subtarget;
|
|
const MachineRegisterInfo *MRI;
|
|
WebAssemblyFunctionInfo *MFI;
|
|
bool signaturesEmitted = false;
|
|
|
|
public:
|
|
explicit WebAssemblyAsmPrinter(TargetMachine &TM,
|
|
std::unique_ptr<MCStreamer> Streamer)
|
|
: AsmPrinter(TM, std::move(Streamer), ID), Subtarget(nullptr),
|
|
MRI(nullptr), MFI(nullptr) {}
|
|
|
|
StringRef getPassName() const override {
|
|
return "WebAssembly Assembly Printer";
|
|
}
|
|
|
|
const WebAssemblySubtarget &getSubtarget() const { return *Subtarget; }
|
|
|
|
//===------------------------------------------------------------------===//
|
|
// MachineFunctionPass Implementation.
|
|
//===------------------------------------------------------------------===//
|
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override {
|
|
Subtarget = &MF.getSubtarget<WebAssemblySubtarget>();
|
|
MRI = &MF.getRegInfo();
|
|
MFI = MF.getInfo<WebAssemblyFunctionInfo>();
|
|
return AsmPrinter::runOnMachineFunction(MF);
|
|
}
|
|
|
|
//===------------------------------------------------------------------===//
|
|
// AsmPrinter Implementation.
|
|
//===------------------------------------------------------------------===//
|
|
|
|
void emitEndOfAsmFile(Module &M) override;
|
|
void EmitProducerInfo(Module &M);
|
|
void EmitTargetFeatures(Module &M);
|
|
void EmitFunctionAttributes(Module &M);
|
|
void emitSymbolType(const MCSymbolWasm *Sym);
|
|
void emitGlobalVariable(const GlobalVariable *GV) override;
|
|
void emitJumpTableInfo() override;
|
|
void emitConstantPool() override;
|
|
void emitFunctionBodyStart() override;
|
|
void emitInstruction(const MachineInstr *MI) override;
|
|
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
|
const char *ExtraCode, raw_ostream &OS) override;
|
|
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
|
|
const char *ExtraCode, raw_ostream &OS) override;
|
|
|
|
MVT getRegType(unsigned RegNo) const;
|
|
std::string regToString(const MachineOperand &MO);
|
|
WebAssemblyTargetStreamer *getTargetStreamer();
|
|
MCSymbolWasm *getMCSymbolForFunction(const Function *F,
|
|
wasm::WasmSignature *Sig,
|
|
bool &InvokeDetected);
|
|
MCSymbol *getOrCreateWasmSymbol(StringRef Name);
|
|
void emitDecls(const Module &M);
|
|
};
|
|
|
|
} // end namespace llvm
|
|
|
|
#endif
|