
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.
133 lines
4.7 KiB
C++
133 lines
4.7 KiB
C++
//===-- WebAssemblyMCTargetDesc.cpp - WebAssembly Target Descriptions -----===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file
|
|
/// This file provides WebAssembly-specific target descriptions.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
|
|
#include "MCTargetDesc/WebAssemblyInstPrinter.h"
|
|
#include "MCTargetDesc/WebAssemblyMCAsmInfo.h"
|
|
#include "MCTargetDesc/WebAssemblyTargetStreamer.h"
|
|
#include "TargetInfo/WebAssemblyTargetInfo.h"
|
|
#include "llvm/MC/MCInstrInfo.h"
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
|
#include "llvm/MC/TargetRegistry.h"
|
|
#include "llvm/Support/Compiler.h"
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
using namespace llvm;
|
|
|
|
#define DEBUG_TYPE "wasm-mc-target-desc"
|
|
|
|
#define GET_INSTRINFO_MC_DESC
|
|
#define ENABLE_INSTR_PREDICATE_VERIFIER
|
|
#include "WebAssemblyGenInstrInfo.inc"
|
|
|
|
#define GET_SUBTARGETINFO_MC_DESC
|
|
#include "WebAssemblyGenSubtargetInfo.inc"
|
|
|
|
#define GET_REGINFO_MC_DESC
|
|
#include "WebAssemblyGenRegisterInfo.inc"
|
|
|
|
static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
|
|
const Triple &TT,
|
|
const MCTargetOptions &Options) {
|
|
return new WebAssemblyMCAsmInfo(TT, Options);
|
|
}
|
|
|
|
static MCInstrInfo *createMCInstrInfo() {
|
|
auto *X = new MCInstrInfo();
|
|
InitWebAssemblyMCInstrInfo(X);
|
|
return X;
|
|
}
|
|
|
|
static MCRegisterInfo *createMCRegisterInfo(const Triple & /*T*/) {
|
|
auto *X = new MCRegisterInfo();
|
|
InitWebAssemblyMCRegisterInfo(X, 0);
|
|
return X;
|
|
}
|
|
|
|
static MCInstPrinter *createMCInstPrinter(const Triple & /*T*/,
|
|
unsigned SyntaxVariant,
|
|
const MCAsmInfo &MAI,
|
|
const MCInstrInfo &MII,
|
|
const MCRegisterInfo &MRI) {
|
|
assert(SyntaxVariant == 0 && "WebAssembly only has one syntax variant");
|
|
return new WebAssemblyInstPrinter(MAI, MII, MRI);
|
|
}
|
|
|
|
static MCCodeEmitter *createCodeEmitter(const MCInstrInfo &MCII,
|
|
MCContext &Ctx) {
|
|
return createWebAssemblyMCCodeEmitter(MCII, Ctx);
|
|
}
|
|
|
|
static MCAsmBackend *createAsmBackend(const Target & /*T*/,
|
|
const MCSubtargetInfo &STI,
|
|
const MCRegisterInfo & /*MRI*/,
|
|
const MCTargetOptions & /*Options*/) {
|
|
return createWebAssemblyAsmBackend(STI.getTargetTriple());
|
|
}
|
|
|
|
static MCSubtargetInfo *createMCSubtargetInfo(const Triple &TT, StringRef CPU,
|
|
StringRef FS) {
|
|
return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
|
|
}
|
|
|
|
static MCTargetStreamer *
|
|
createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
|
|
return new WebAssemblyTargetWasmStreamer(S);
|
|
}
|
|
|
|
static MCTargetStreamer *
|
|
createAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS,
|
|
MCInstPrinter * /*InstPrint*/) {
|
|
return new WebAssemblyTargetAsmStreamer(S, OS);
|
|
}
|
|
|
|
static MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) {
|
|
return new WebAssemblyTargetNullStreamer(S);
|
|
}
|
|
|
|
// Force static initialization.
|
|
extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
|
|
LLVMInitializeWebAssemblyTargetMC() {
|
|
for (Target *T :
|
|
{&getTheWebAssemblyTarget32(), &getTheWebAssemblyTarget64()}) {
|
|
// Register the MC asm info.
|
|
RegisterMCAsmInfoFn X(*T, createMCAsmInfo);
|
|
|
|
// Register the MC instruction info.
|
|
TargetRegistry::RegisterMCInstrInfo(*T, createMCInstrInfo);
|
|
|
|
// Register the MC register info.
|
|
TargetRegistry::RegisterMCRegInfo(*T, createMCRegisterInfo);
|
|
|
|
// Register the MCInstPrinter.
|
|
TargetRegistry::RegisterMCInstPrinter(*T, createMCInstPrinter);
|
|
|
|
// Register the MC code emitter.
|
|
TargetRegistry::RegisterMCCodeEmitter(*T, createCodeEmitter);
|
|
|
|
// Register the ASM Backend.
|
|
TargetRegistry::RegisterMCAsmBackend(*T, createAsmBackend);
|
|
|
|
// Register the MC subtarget info.
|
|
TargetRegistry::RegisterMCSubtargetInfo(*T, createMCSubtargetInfo);
|
|
|
|
// Register the object target streamer.
|
|
TargetRegistry::RegisterObjectTargetStreamer(*T,
|
|
createObjectTargetStreamer);
|
|
// Register the asm target streamer.
|
|
TargetRegistry::RegisterAsmTargetStreamer(*T, createAsmTargetStreamer);
|
|
// Register the null target streamer.
|
|
TargetRegistry::RegisterNullTargetStreamer(*T, createNullTargetStreamer);
|
|
}
|
|
}
|