forked from OSchip/llvm-project
[WebAssembly] Remove ELF file support.
This support was partial and temporary. Now that we have wasm object file support its no longer needed. Differential Revision: https://reviews.llvm.org/D48744 llvm-svn: 337222
This commit is contained in:
parent
c71adc8040
commit
cf2a9e28b1
|
@ -312,11 +312,6 @@ enum {
|
||||||
EM_RISCV = 243, // RISC-V
|
EM_RISCV = 243, // RISC-V
|
||||||
EM_LANAI = 244, // Lanai 32-bit processor
|
EM_LANAI = 244, // Lanai 32-bit processor
|
||||||
EM_BPF = 247, // Linux kernel bpf virtual machine
|
EM_BPF = 247, // Linux kernel bpf virtual machine
|
||||||
|
|
||||||
// A request has been made to the maintainer of the official registry for
|
|
||||||
// such numbers for an official value for WebAssembly. As soon as one is
|
|
||||||
// allocated, this enum will be updated to use it.
|
|
||||||
EM_WEBASSEMBLY = 0x4157, // WebAssembly architecture
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Object file classes.
|
// Object file classes.
|
||||||
|
@ -644,11 +639,6 @@ enum {
|
||||||
#include "ELFRelocs/Sparc.def"
|
#include "ELFRelocs/Sparc.def"
|
||||||
};
|
};
|
||||||
|
|
||||||
// ELF Relocation types for WebAssembly
|
|
||||||
enum {
|
|
||||||
#include "ELFRelocs/WebAssembly.def"
|
|
||||||
};
|
|
||||||
|
|
||||||
// AMDGPU specific e_flags.
|
// AMDGPU specific e_flags.
|
||||||
enum : unsigned {
|
enum : unsigned {
|
||||||
// Processor selection mask for EF_AMDGPU_MACH_* values.
|
// Processor selection mask for EF_AMDGPU_MACH_* values.
|
||||||
|
@ -1175,9 +1165,6 @@ enum {
|
||||||
PT_MIPS_RTPROC = 0x70000001, // Runtime procedure table.
|
PT_MIPS_RTPROC = 0x70000001, // Runtime procedure table.
|
||||||
PT_MIPS_OPTIONS = 0x70000002, // Options segment.
|
PT_MIPS_OPTIONS = 0x70000002, // Options segment.
|
||||||
PT_MIPS_ABIFLAGS = 0x70000003, // Abiflags segment.
|
PT_MIPS_ABIFLAGS = 0x70000003, // Abiflags segment.
|
||||||
|
|
||||||
// WebAssembly program header types.
|
|
||||||
PT_WEBASSEMBLY_FUNCTIONS = PT_LOPROC + 0, // Function definitions.
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Segment flag bits.
|
// Segment flag bits.
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
|
|
||||||
#ifndef ELF_RELOC
|
|
||||||
#error "ELF_RELOC must be defined"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ELF_RELOC(R_WEBASSEMBLY_NONE, 0)
|
|
||||||
ELF_RELOC(R_WEBASSEMBLY_DATA, 1)
|
|
||||||
ELF_RELOC(R_WEBASSEMBLY_FUNCTION, 2)
|
|
|
@ -1026,8 +1026,6 @@ StringRef ELFObjectFile<ELFT>::getFileFormatName() const {
|
||||||
case ELF::EM_SPARC:
|
case ELF::EM_SPARC:
|
||||||
case ELF::EM_SPARC32PLUS:
|
case ELF::EM_SPARC32PLUS:
|
||||||
return "ELF32-sparc";
|
return "ELF32-sparc";
|
||||||
case ELF::EM_WEBASSEMBLY:
|
|
||||||
return "ELF32-wasm";
|
|
||||||
case ELF::EM_AMDGPU:
|
case ELF::EM_AMDGPU:
|
||||||
return "ELF32-amdgpu";
|
return "ELF32-amdgpu";
|
||||||
default:
|
default:
|
||||||
|
@ -1051,8 +1049,6 @@ StringRef ELFObjectFile<ELFT>::getFileFormatName() const {
|
||||||
return "ELF64-sparc";
|
return "ELF64-sparc";
|
||||||
case ELF::EM_MIPS:
|
case ELF::EM_MIPS:
|
||||||
return "ELF64-mips";
|
return "ELF64-mips";
|
||||||
case ELF::EM_WEBASSEMBLY:
|
|
||||||
return "ELF64-wasm";
|
|
||||||
case ELF::EM_AMDGPU:
|
case ELF::EM_AMDGPU:
|
||||||
return "ELF64-amdgpu";
|
return "ELF64-amdgpu";
|
||||||
case ELF::EM_BPF:
|
case ELF::EM_BPF:
|
||||||
|
@ -1114,12 +1110,6 @@ template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const {
|
||||||
return IsLittleEndian ? Triple::sparcel : Triple::sparc;
|
return IsLittleEndian ? Triple::sparcel : Triple::sparc;
|
||||||
case ELF::EM_SPARCV9:
|
case ELF::EM_SPARCV9:
|
||||||
return Triple::sparcv9;
|
return Triple::sparcv9;
|
||||||
case ELF::EM_WEBASSEMBLY:
|
|
||||||
switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) {
|
|
||||||
case ELF::ELFCLASS32: return Triple::wasm32;
|
|
||||||
case ELF::ELFCLASS64: return Triple::wasm64;
|
|
||||||
default: return Triple::UnknownArch;
|
|
||||||
}
|
|
||||||
|
|
||||||
case ELF::EM_AMDGPU: {
|
case ELF::EM_AMDGPU: {
|
||||||
if (!IsLittleEndian)
|
if (!IsLittleEndian)
|
||||||
|
|
|
@ -59,7 +59,6 @@ module LLVM_BinaryFormat {
|
||||||
textual header "BinaryFormat/ELFRelocs/Sparc.def"
|
textual header "BinaryFormat/ELFRelocs/Sparc.def"
|
||||||
textual header "BinaryFormat/ELFRelocs/SystemZ.def"
|
textual header "BinaryFormat/ELFRelocs/SystemZ.def"
|
||||||
textual header "BinaryFormat/ELFRelocs/x86_64.def"
|
textual header "BinaryFormat/ELFRelocs/x86_64.def"
|
||||||
textual header "BinaryFormat/ELFRelocs/WebAssembly.def"
|
|
||||||
textual header "BinaryFormat/WasmRelocs.def"
|
textual header "BinaryFormat/WasmRelocs.def"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -696,8 +696,7 @@ AsmParser::AsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
|
||||||
case MCObjectFileInfo::IsWasm:
|
case MCObjectFileInfo::IsWasm:
|
||||||
// TODO: WASM will need its own MCAsmParserExtension implementation, but
|
// TODO: WASM will need its own MCAsmParserExtension implementation, but
|
||||||
// for now we can re-use the ELF one, since the directives can be the
|
// for now we can re-use the ELF one, since the directives can be the
|
||||||
// same for now, and this makes the -triple=wasm32-unknown-unknown-wasm
|
// same for now.
|
||||||
// path work.
|
|
||||||
PlatformParser.reset(createELFAsmParser());
|
PlatformParser.reset(createELFAsmParser());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,13 +125,6 @@ StringRef llvm::object::getELFRelocationTypeName(uint32_t Machine,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ELF::EM_WEBASSEMBLY:
|
|
||||||
switch (Type) {
|
|
||||||
#include "llvm/BinaryFormat/ELFRelocs/WebAssembly.def"
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ELF::EM_AMDGPU:
|
case ELF::EM_AMDGPU:
|
||||||
switch (Type) {
|
switch (Type) {
|
||||||
#include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
|
#include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
|
||||||
|
@ -188,8 +181,6 @@ uint32_t llvm::object::getELFRelrRelocationType(uint32_t Machine) {
|
||||||
case ELF::EM_SPARC32PLUS:
|
case ELF::EM_SPARC32PLUS:
|
||||||
case ELF::EM_SPARCV9:
|
case ELF::EM_SPARCV9:
|
||||||
return ELF::R_SPARC_RELATIVE;
|
return ELF::R_SPARC_RELATIVE;
|
||||||
case ELF::EM_WEBASSEMBLY:
|
|
||||||
break;
|
|
||||||
case ELF::EM_AMDGPU:
|
case ELF::EM_AMDGPU:
|
||||||
break;
|
break;
|
||||||
case ELF::EM_BPF:
|
case ELF::EM_BPF:
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
add_llvm_library(LLVMWebAssemblyDesc
|
add_llvm_library(LLVMWebAssemblyDesc
|
||||||
WebAssemblyAsmBackend.cpp
|
WebAssemblyAsmBackend.cpp
|
||||||
WebAssemblyELFObjectWriter.cpp
|
|
||||||
WebAssemblyMCAsmInfo.cpp
|
WebAssemblyMCAsmInfo.cpp
|
||||||
WebAssemblyMCCodeEmitter.cpp
|
WebAssemblyMCCodeEmitter.cpp
|
||||||
WebAssemblyMCTargetDesc.cpp
|
WebAssemblyMCTargetDesc.cpp
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#include "llvm/MC/MCAsmBackend.h"
|
#include "llvm/MC/MCAsmBackend.h"
|
||||||
#include "llvm/MC/MCAssembler.h"
|
#include "llvm/MC/MCAssembler.h"
|
||||||
#include "llvm/MC/MCDirectives.h"
|
#include "llvm/MC/MCDirectives.h"
|
||||||
#include "llvm/MC/MCELFObjectWriter.h"
|
|
||||||
#include "llvm/MC/MCExpr.h"
|
#include "llvm/MC/MCExpr.h"
|
||||||
#include "llvm/MC/MCFixupKindInfo.h"
|
#include "llvm/MC/MCFixupKindInfo.h"
|
||||||
#include "llvm/MC/MCObjectWriter.h"
|
#include "llvm/MC/MCObjectWriter.h"
|
||||||
|
@ -26,17 +25,17 @@
|
||||||
#include "llvm/MC/MCWasmObjectWriter.h"
|
#include "llvm/MC/MCWasmObjectWriter.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class WebAssemblyAsmBackend final : public MCAsmBackend {
|
class WebAssemblyAsmBackend final : public MCAsmBackend {
|
||||||
bool Is64Bit;
|
bool Is64Bit;
|
||||||
bool IsELF;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit WebAssemblyAsmBackend(bool Is64Bit, bool IsELF)
|
explicit WebAssemblyAsmBackend(bool Is64Bit)
|
||||||
: MCAsmBackend(support::little), Is64Bit(Is64Bit), IsELF(IsELF) {}
|
: MCAsmBackend(support::little), Is64Bit(Is64Bit) {}
|
||||||
~WebAssemblyAsmBackend() override {}
|
~WebAssemblyAsmBackend() override {}
|
||||||
|
|
||||||
unsigned getNumFixupKinds() const override {
|
unsigned getNumFixupKinds() const override {
|
||||||
|
@ -126,12 +125,11 @@ void WebAssemblyAsmBackend::applyFixup(const MCAssembler &Asm,
|
||||||
|
|
||||||
std::unique_ptr<MCObjectTargetWriter>
|
std::unique_ptr<MCObjectTargetWriter>
|
||||||
WebAssemblyAsmBackend::createObjectTargetWriter() const {
|
WebAssemblyAsmBackend::createObjectTargetWriter() const {
|
||||||
return IsELF ? createWebAssemblyELFObjectWriter(Is64Bit, 0)
|
return createWebAssemblyWasmObjectWriter(Is64Bit);
|
||||||
: createWebAssemblyWasmObjectWriter(Is64Bit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
MCAsmBackend *llvm::createWebAssemblyAsmBackend(const Triple &TT) {
|
MCAsmBackend *llvm::createWebAssemblyAsmBackend(const Triple &TT) {
|
||||||
return new WebAssemblyAsmBackend(TT.isArch64Bit(), TT.isOSBinFormatELF());
|
return new WebAssemblyAsmBackend(TT.isArch64Bit());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,65 +0,0 @@
|
||||||
//===-- WebAssemblyELFObjectWriter.cpp - WebAssembly ELF Writer -----------===//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file is distributed under the University of Illinois Open Source
|
|
||||||
// License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
///
|
|
||||||
/// \file
|
|
||||||
/// This file handles ELF-specific object emission, converting LLVM's
|
|
||||||
/// internal fixups into the appropriate relocations.
|
|
||||||
///
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
|
|
||||||
#include "llvm/MC/MCELFObjectWriter.h"
|
|
||||||
#include "llvm/MC/MCFixup.h"
|
|
||||||
#include "llvm/MC/MCObjectWriter.h"
|
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
|
||||||
using namespace llvm;
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
class WebAssemblyELFObjectWriter final : public MCELFObjectTargetWriter {
|
|
||||||
public:
|
|
||||||
WebAssemblyELFObjectWriter(bool Is64Bit, uint8_t OSABI);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
|
|
||||||
const MCFixup &Fixup, bool IsPCRel) const override;
|
|
||||||
};
|
|
||||||
} // end anonymous namespace
|
|
||||||
|
|
||||||
WebAssemblyELFObjectWriter::WebAssemblyELFObjectWriter(bool Is64Bit,
|
|
||||||
uint8_t OSABI)
|
|
||||||
: MCELFObjectTargetWriter(Is64Bit, OSABI, ELF::EM_WEBASSEMBLY,
|
|
||||||
/*HasRelocationAddend=*/false) {}
|
|
||||||
|
|
||||||
unsigned WebAssemblyELFObjectWriter::getRelocType(MCContext &Ctx,
|
|
||||||
const MCValue &Target,
|
|
||||||
const MCFixup &Fixup,
|
|
||||||
bool IsPCRel) const {
|
|
||||||
// WebAssembly functions are not allocated in the address space. To resolve a
|
|
||||||
// pointer to a function, we must use a special relocation type.
|
|
||||||
if (const MCSymbolRefExpr *SyExp =
|
|
||||||
dyn_cast<MCSymbolRefExpr>(Fixup.getValue()))
|
|
||||||
if (SyExp->getKind() == MCSymbolRefExpr::VK_WebAssembly_FUNCTION)
|
|
||||||
return ELF::R_WEBASSEMBLY_FUNCTION;
|
|
||||||
|
|
||||||
switch (Fixup.getKind()) {
|
|
||||||
case FK_Data_4:
|
|
||||||
assert(!is64Bit() && "4-byte relocations only supported on wasm32");
|
|
||||||
return ELF::R_WEBASSEMBLY_DATA;
|
|
||||||
case FK_Data_8:
|
|
||||||
assert(is64Bit() && "8-byte relocations only supported on wasm64");
|
|
||||||
return ELF::R_WEBASSEMBLY_DATA;
|
|
||||||
default:
|
|
||||||
llvm_unreachable("unimplemented fixup kind");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<MCObjectTargetWriter>
|
|
||||||
llvm::createWebAssemblyELFObjectWriter(bool Is64Bit, uint8_t OSABI) {
|
|
||||||
return llvm::make_unique<WebAssemblyELFObjectWriter>(Is64Bit, OSABI);
|
|
||||||
}
|
|
|
@ -15,40 +15,11 @@
|
||||||
|
|
||||||
#include "WebAssemblyMCAsmInfo.h"
|
#include "WebAssemblyMCAsmInfo.h"
|
||||||
#include "llvm/ADT/Triple.h"
|
#include "llvm/ADT/Triple.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
#define DEBUG_TYPE "wasm-mc-asm-info"
|
#define DEBUG_TYPE "wasm-mc-asm-info"
|
||||||
|
|
||||||
WebAssemblyMCAsmInfoELF::~WebAssemblyMCAsmInfoELF() {}
|
|
||||||
|
|
||||||
WebAssemblyMCAsmInfoELF::WebAssemblyMCAsmInfoELF(const Triple &T) {
|
|
||||||
CodePointerSize = CalleeSaveStackSlotSize = T.isArch64Bit() ? 8 : 4;
|
|
||||||
|
|
||||||
// TODO: What should MaxInstLength be?
|
|
||||||
|
|
||||||
UseDataRegionDirectives = true;
|
|
||||||
|
|
||||||
// Use .skip instead of .zero because .zero is confusing when used with two
|
|
||||||
// arguments (it doesn't actually zero things out).
|
|
||||||
ZeroDirective = "\t.skip\t";
|
|
||||||
|
|
||||||
Data8bitsDirective = "\t.int8\t";
|
|
||||||
Data16bitsDirective = "\t.int16\t";
|
|
||||||
Data32bitsDirective = "\t.int32\t";
|
|
||||||
Data64bitsDirective = "\t.int64\t";
|
|
||||||
|
|
||||||
AlignmentIsInBytes = false;
|
|
||||||
COMMDirectiveAlignmentIsInBytes = false;
|
|
||||||
LCOMMDirectiveAlignmentType = LCOMM::Log2Alignment;
|
|
||||||
|
|
||||||
SupportsDebugInformation = true;
|
|
||||||
|
|
||||||
// TODO: UseIntegratedAssembler?
|
|
||||||
|
|
||||||
// WebAssembly's stack is never executable.
|
|
||||||
UsesNonexecutableStackSection = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
WebAssemblyMCAsmInfo::~WebAssemblyMCAsmInfo() {}
|
WebAssemblyMCAsmInfo::~WebAssemblyMCAsmInfo() {}
|
||||||
|
|
||||||
WebAssemblyMCAsmInfo::WebAssemblyMCAsmInfo(const Triple &T) {
|
WebAssemblyMCAsmInfo::WebAssemblyMCAsmInfo(const Triple &T) {
|
||||||
|
|
|
@ -15,19 +15,12 @@
|
||||||
#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCASMINFO_H
|
#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCASMINFO_H
|
||||||
#define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCASMINFO_H
|
#define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCASMINFO_H
|
||||||
|
|
||||||
#include "llvm/MC/MCAsmInfoELF.h"
|
|
||||||
#include "llvm/MC/MCAsmInfoWasm.h"
|
#include "llvm/MC/MCAsmInfoWasm.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
class Triple;
|
class Triple;
|
||||||
|
|
||||||
class WebAssemblyMCAsmInfoELF final : public MCAsmInfoELF {
|
|
||||||
public:
|
|
||||||
explicit WebAssemblyMCAsmInfoELF(const Triple &T);
|
|
||||||
~WebAssemblyMCAsmInfoELF() override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class WebAssemblyMCAsmInfo final : public MCAsmInfoWasm {
|
class WebAssemblyMCAsmInfo final : public MCAsmInfoWasm {
|
||||||
public:
|
public:
|
||||||
explicit WebAssemblyMCAsmInfo(const Triple &T);
|
explicit WebAssemblyMCAsmInfo(const Triple &T);
|
||||||
|
|
|
@ -36,8 +36,6 @@ using namespace llvm;
|
||||||
|
|
||||||
static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
|
static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
|
||||||
const Triple &TT) {
|
const Triple &TT) {
|
||||||
if (TT.isOSBinFormatELF())
|
|
||||||
return new WebAssemblyMCAsmInfoELF(TT);
|
|
||||||
return new WebAssemblyMCAsmInfo(TT);
|
return new WebAssemblyMCAsmInfo(TT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,10 +80,6 @@ static MCSubtargetInfo *createMCSubtargetInfo(const Triple &TT, StringRef CPU,
|
||||||
|
|
||||||
static MCTargetStreamer *
|
static MCTargetStreamer *
|
||||||
createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
|
createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
|
||||||
const Triple &TT = STI.getTargetTriple();
|
|
||||||
if (TT.isOSBinFormatELF())
|
|
||||||
return new WebAssemblyTargetELFStreamer(S);
|
|
||||||
|
|
||||||
return new WebAssemblyTargetWasmStreamer(S);
|
return new WebAssemblyTargetWasmStreamer(S);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,6 @@ MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII);
|
||||||
|
|
||||||
MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT);
|
MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT);
|
||||||
|
|
||||||
std::unique_ptr<MCObjectTargetWriter>
|
|
||||||
createWebAssemblyELFObjectWriter(bool Is64Bit, uint8_t OSABI);
|
|
||||||
|
|
||||||
std::unique_ptr<MCObjectTargetWriter>
|
std::unique_ptr<MCObjectTargetWriter>
|
||||||
createWebAssemblyWasmObjectWriter(bool Is64Bit);
|
createWebAssemblyWasmObjectWriter(bool Is64Bit);
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,8 @@
|
||||||
#include "InstPrinter/WebAssemblyInstPrinter.h"
|
#include "InstPrinter/WebAssemblyInstPrinter.h"
|
||||||
#include "WebAssemblyMCTargetDesc.h"
|
#include "WebAssemblyMCTargetDesc.h"
|
||||||
#include "llvm/MC/MCContext.h"
|
#include "llvm/MC/MCContext.h"
|
||||||
#include "llvm/MC/MCSectionELF.h"
|
|
||||||
#include "llvm/MC/MCSectionWasm.h"
|
#include "llvm/MC/MCSectionWasm.h"
|
||||||
#include "llvm/MC/MCSubtargetInfo.h"
|
#include "llvm/MC/MCSubtargetInfo.h"
|
||||||
#include "llvm/MC/MCSymbolELF.h"
|
|
||||||
#include "llvm/MC/MCSymbolWasm.h"
|
#include "llvm/MC/MCSymbolWasm.h"
|
||||||
#include "llvm/Support/Casting.h"
|
#include "llvm/Support/Casting.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
|
@ -38,9 +36,6 @@ WebAssemblyTargetAsmStreamer::WebAssemblyTargetAsmStreamer(
|
||||||
MCStreamer &S, formatted_raw_ostream &OS)
|
MCStreamer &S, formatted_raw_ostream &OS)
|
||||||
: WebAssemblyTargetStreamer(S), OS(OS) {}
|
: WebAssemblyTargetStreamer(S), OS(OS) {}
|
||||||
|
|
||||||
WebAssemblyTargetELFStreamer::WebAssemblyTargetELFStreamer(MCStreamer &S)
|
|
||||||
: WebAssemblyTargetStreamer(S) {}
|
|
||||||
|
|
||||||
WebAssemblyTargetWasmStreamer::WebAssemblyTargetWasmStreamer(MCStreamer &S)
|
WebAssemblyTargetWasmStreamer::WebAssemblyTargetWasmStreamer(MCStreamer &S)
|
||||||
: WebAssemblyTargetStreamer(S) {}
|
: WebAssemblyTargetStreamer(S) {}
|
||||||
|
|
||||||
|
@ -116,44 +111,6 @@ void WebAssemblyTargetAsmStreamer::emitIndIdx(const MCExpr *Value) {
|
||||||
OS << "\t.indidx \t" << *Value << '\n';
|
OS << "\t.indidx \t" << *Value << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebAssemblyTargetELFStreamer::emitParam(MCSymbol *Symbol,
|
|
||||||
ArrayRef<MVT> Types) {
|
|
||||||
// Nothing to emit; params are declared as part of the function signature.
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebAssemblyTargetELFStreamer::emitResult(MCSymbol *Symbol,
|
|
||||||
ArrayRef<MVT> Types) {
|
|
||||||
// Nothing to emit; results are declared as part of the function signature.
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebAssemblyTargetELFStreamer::emitLocal(ArrayRef<MVT> Types) {
|
|
||||||
Streamer.EmitULEB128IntValue(Types.size());
|
|
||||||
for (MVT Type : Types)
|
|
||||||
emitValueType(WebAssembly::toValType(Type));
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebAssemblyTargetELFStreamer::emitEndFunc() {
|
|
||||||
Streamer.EmitIntValue(WebAssembly::End, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebAssemblyTargetELFStreamer::emitIndIdx(const MCExpr *Value) {
|
|
||||||
llvm_unreachable(".indidx encoding not yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebAssemblyTargetELFStreamer::emitIndirectFunctionType(
|
|
||||||
MCSymbol *Symbol, SmallVectorImpl<MVT> &Params, SmallVectorImpl<MVT> &Results) {
|
|
||||||
// Nothing to emit here. TODO: Re-design how linking works and re-evaluate
|
|
||||||
// whether it's necessary for .o files to declare indirect function types.
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebAssemblyTargetELFStreamer::emitGlobalImport(StringRef name) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebAssemblyTargetELFStreamer::emitImportModule(MCSymbolWasm *Sym,
|
|
||||||
StringRef ModuleName) {
|
|
||||||
llvm_unreachable(".import_module encoding not yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebAssemblyTargetWasmStreamer::emitParam(MCSymbol *Symbol,
|
void WebAssemblyTargetWasmStreamer::emitParam(MCSymbol *Symbol,
|
||||||
ArrayRef<MVT> Types) {
|
ArrayRef<MVT> Types) {
|
||||||
SmallVector<wasm::ValType, 4> Params;
|
SmallVector<wasm::ValType, 4> Params;
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
class MCELFStreamer;
|
|
||||||
class MCWasmStreamer;
|
class MCWasmStreamer;
|
||||||
class MCSymbolWasm;
|
class MCSymbolWasm;
|
||||||
|
|
||||||
|
@ -74,23 +73,6 @@ public:
|
||||||
void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override;
|
void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// This part is for ELF object output
|
|
||||||
class WebAssemblyTargetELFStreamer final : public WebAssemblyTargetStreamer {
|
|
||||||
public:
|
|
||||||
explicit WebAssemblyTargetELFStreamer(MCStreamer &S);
|
|
||||||
|
|
||||||
void emitParam(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
|
|
||||||
void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
|
|
||||||
void emitLocal(ArrayRef<MVT> Types) override;
|
|
||||||
void emitEndFunc() override;
|
|
||||||
void emitIndirectFunctionType(MCSymbol *Symbol,
|
|
||||||
SmallVectorImpl<MVT> &Params,
|
|
||||||
SmallVectorImpl<MVT> &Results) override;
|
|
||||||
void emitIndIdx(const MCExpr *Value) override;
|
|
||||||
void emitGlobalImport(StringRef name) override;
|
|
||||||
void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// This part is for Wasm object output
|
/// This part is for Wasm object output
|
||||||
class WebAssemblyTargetWasmStreamer final : public WebAssemblyTargetStreamer {
|
class WebAssemblyTargetWasmStreamer final : public WebAssemblyTargetStreamer {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
#include "llvm/MC/MCSectionWasm.h"
|
#include "llvm/MC/MCSectionWasm.h"
|
||||||
#include "llvm/MC/MCStreamer.h"
|
#include "llvm/MC/MCStreamer.h"
|
||||||
#include "llvm/MC/MCSymbol.h"
|
#include "llvm/MC/MCSymbol.h"
|
||||||
#include "llvm/MC/MCSymbolELF.h"
|
|
||||||
#include "llvm/MC/MCSymbolWasm.h"
|
#include "llvm/MC/MCSymbolWasm.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/TargetRegistry.h"
|
#include "llvm/Support/TargetRegistry.h"
|
||||||
|
@ -101,8 +100,6 @@ void WebAssemblyAsmPrinter::EmitEndOfAsmFile(Module &M) {
|
||||||
if (!G.hasInitializer() && G.hasExternalLinkage()) {
|
if (!G.hasInitializer() && G.hasExternalLinkage()) {
|
||||||
if (G.getValueType()->isSized()) {
|
if (G.getValueType()->isSized()) {
|
||||||
uint16_t Size = M.getDataLayout().getTypeAllocSize(G.getValueType());
|
uint16_t Size = M.getDataLayout().getTypeAllocSize(G.getValueType());
|
||||||
if (TM.getTargetTriple().isOSBinFormatELF())
|
|
||||||
getTargetStreamer()->emitGlobalImport(G.getGlobalIdentifier());
|
|
||||||
OutStreamer->emitELFSize(getSymbol(&G),
|
OutStreamer->emitELFSize(getSymbol(&G),
|
||||||
MCConstantExpr::create(Size, OutContext));
|
MCConstantExpr::create(Size, OutContext));
|
||||||
}
|
}
|
||||||
|
@ -162,34 +159,11 @@ void WebAssemblyAsmPrinter::EmitFunctionBodyStart() {
|
||||||
else
|
else
|
||||||
getTargetStreamer()->emitResult(CurrentFnSym, ArrayRef<MVT>());
|
getTargetStreamer()->emitResult(CurrentFnSym, ArrayRef<MVT>());
|
||||||
|
|
||||||
if (TM.getTargetTriple().isOSBinFormatELF()) {
|
|
||||||
assert(MFI->getLocals().empty());
|
|
||||||
for (unsigned Idx = 0, IdxE = MRI->getNumVirtRegs(); Idx != IdxE; ++Idx) {
|
|
||||||
unsigned VReg = TargetRegisterInfo::index2VirtReg(Idx);
|
|
||||||
unsigned WAReg = MFI->getWAReg(VReg);
|
|
||||||
// Don't declare unused registers.
|
|
||||||
if (WAReg == WebAssemblyFunctionInfo::UnusedReg)
|
|
||||||
continue;
|
|
||||||
// Don't redeclare parameters.
|
|
||||||
if (WAReg < MFI->getParams().size())
|
|
||||||
continue;
|
|
||||||
// Don't declare stackified registers.
|
|
||||||
if (int(WAReg) < 0)
|
|
||||||
continue;
|
|
||||||
MFI->addLocal(getRegType(VReg));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getTargetStreamer()->emitLocal(MFI->getLocals());
|
getTargetStreamer()->emitLocal(MFI->getLocals());
|
||||||
|
|
||||||
AsmPrinter::EmitFunctionBodyStart();
|
AsmPrinter::EmitFunctionBodyStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebAssemblyAsmPrinter::EmitFunctionBodyEnd() {
|
|
||||||
if (TM.getTargetTriple().isOSBinFormatELF())
|
|
||||||
getTargetStreamer()->emitEndFunc();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebAssemblyAsmPrinter::EmitInstruction(const MachineInstr *MI) {
|
void WebAssemblyAsmPrinter::EmitInstruction(const MachineInstr *MI) {
|
||||||
LLVM_DEBUG(dbgs() << "EmitInstruction: " << *MI << '\n');
|
LLVM_DEBUG(dbgs() << "EmitInstruction: " << *MI << '\n');
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,6 @@ public:
|
||||||
void EmitJumpTableInfo() override;
|
void EmitJumpTableInfo() override;
|
||||||
void EmitConstantPool() override;
|
void EmitConstantPool() override;
|
||||||
void EmitFunctionBodyStart() override;
|
void EmitFunctionBodyStart() override;
|
||||||
void EmitFunctionBodyEnd() override;
|
|
||||||
void EmitInstruction(const MachineInstr *MI) override;
|
void EmitInstruction(const MachineInstr *MI) override;
|
||||||
const MCExpr *lowerConstant(const Constant *CV) override;
|
const MCExpr *lowerConstant(const Constant *CV) override;
|
||||||
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
||||||
|
|
|
@ -358,9 +358,7 @@ static void PlaceMarkers(MachineFunction &MF, const MachineLoopInfo &MLI,
|
||||||
FixEndsAtEndOfFunction(MF, MFI, BlockTops, LoopTops);
|
FixEndsAtEndOfFunction(MF, MFI, BlockTops, LoopTops);
|
||||||
|
|
||||||
// Add an end instruction at the end of the function body.
|
// Add an end instruction at the end of the function body.
|
||||||
if (!MF.getSubtarget<WebAssemblySubtarget>()
|
AppendEndToFunction(MF, TII);
|
||||||
.getTargetTriple().isOSBinFormatELF())
|
|
||||||
AppendEndToFunction(MF, TII);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebAssemblyCFGStackify::runOnMachineFunction(MachineFunction &MF) {
|
bool WebAssemblyCFGStackify::runOnMachineFunction(MachineFunction &MF) {
|
||||||
|
|
|
@ -189,11 +189,6 @@ bool WebAssemblyExplicitLocals::runOnMachineFunction(MachineFunction &MF) {
|
||||||
if (DisableWebAssemblyExplicitLocals)
|
if (DisableWebAssemblyExplicitLocals)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Disable this pass if we aren't doing direct wasm object emission.
|
|
||||||
if (MF.getSubtarget<WebAssemblySubtarget>()
|
|
||||||
.getTargetTriple().isOSBinFormatELF())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
MachineRegisterInfo &MRI = MF.getRegInfo();
|
MachineRegisterInfo &MRI = MF.getRegInfo();
|
||||||
WebAssemblyFunctionInfo &MFI = *MF.getInfo<WebAssemblyFunctionInfo>();
|
WebAssemblyFunctionInfo &MFI = *MF.getInfo<WebAssemblyFunctionInfo>();
|
||||||
|
|
|
@ -106,29 +106,9 @@ static void writeSPToMemory(unsigned SrcReg, MachineFunction &MF,
|
||||||
|
|
||||||
const char *ES = "__stack_pointer";
|
const char *ES = "__stack_pointer";
|
||||||
auto *SPSymbol = MF.createExternalSymbolName(ES);
|
auto *SPSymbol = MF.createExternalSymbolName(ES);
|
||||||
if (MF.getSubtarget<WebAssemblySubtarget>()
|
BuildMI(MBB, InsertStore, DL, TII->get(WebAssembly::SET_GLOBAL_I32))
|
||||||
.getTargetTriple().isOSBinFormatELF()) {
|
.addExternalSymbol(SPSymbol)
|
||||||
MachineRegisterInfo &MRI = MF.getRegInfo();
|
.addReg(SrcReg);
|
||||||
const TargetRegisterClass *PtrRC =
|
|
||||||
MRI.getTargetRegisterInfo()->getPointerRegClass(MF);
|
|
||||||
unsigned Zero = MRI.createVirtualRegister(PtrRC);
|
|
||||||
|
|
||||||
BuildMI(MBB, InsertAddr, DL, TII->get(WebAssembly::CONST_I32), Zero)
|
|
||||||
.addImm(0);
|
|
||||||
MachineMemOperand *MMO = MF.getMachineMemOperand(
|
|
||||||
MachinePointerInfo(MF.getPSVManager().getExternalSymbolCallEntry(ES)),
|
|
||||||
MachineMemOperand::MOStore, 4, 4);
|
|
||||||
BuildMI(MBB, InsertStore, DL, TII->get(WebAssembly::STORE_I32))
|
|
||||||
.addImm(2) // p2align
|
|
||||||
.addExternalSymbol(SPSymbol)
|
|
||||||
.addReg(Zero)
|
|
||||||
.addReg(SrcReg)
|
|
||||||
.addMemOperand(MMO);
|
|
||||||
} else {
|
|
||||||
BuildMI(MBB, InsertStore, DL, TII->get(WebAssembly::SET_GLOBAL_I32))
|
|
||||||
.addExternalSymbol(SPSymbol)
|
|
||||||
.addReg(SrcReg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MachineBasicBlock::iterator
|
MachineBasicBlock::iterator
|
||||||
|
@ -172,25 +152,8 @@ void WebAssemblyFrameLowering::emitPrologue(MachineFunction &MF,
|
||||||
|
|
||||||
const char *ES = "__stack_pointer";
|
const char *ES = "__stack_pointer";
|
||||||
auto *SPSymbol = MF.createExternalSymbolName(ES);
|
auto *SPSymbol = MF.createExternalSymbolName(ES);
|
||||||
if (MF.getSubtarget<WebAssemblySubtarget>()
|
BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::GET_GLOBAL_I32), SPReg)
|
||||||
.getTargetTriple().isOSBinFormatELF()) {
|
.addExternalSymbol(SPSymbol);
|
||||||
unsigned Zero = MRI.createVirtualRegister(PtrRC);
|
|
||||||
|
|
||||||
BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::CONST_I32), Zero)
|
|
||||||
.addImm(0);
|
|
||||||
MachineMemOperand *LoadMMO = MF.getMachineMemOperand(
|
|
||||||
MachinePointerInfo(MF.getPSVManager().getExternalSymbolCallEntry(ES)),
|
|
||||||
MachineMemOperand::MOLoad, 4, 4);
|
|
||||||
// Load the SP value.
|
|
||||||
BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::LOAD_I32), SPReg)
|
|
||||||
.addImm(2) // p2align
|
|
||||||
.addExternalSymbol(SPSymbol)
|
|
||||||
.addReg(Zero) // addr
|
|
||||||
.addMemOperand(LoadMMO);
|
|
||||||
} else {
|
|
||||||
BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::GET_GLOBAL_I32), SPReg)
|
|
||||||
.addExternalSymbol(SPSymbol);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HasBP = hasBP(MF);
|
bool HasBP = hasBP(MF);
|
||||||
if (HasBP) {
|
if (HasBP) {
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#include "llvm/MC/MCContext.h"
|
#include "llvm/MC/MCContext.h"
|
||||||
#include "llvm/MC/MCExpr.h"
|
#include "llvm/MC/MCExpr.h"
|
||||||
#include "llvm/MC/MCInst.h"
|
#include "llvm/MC/MCInst.h"
|
||||||
#include "llvm/MC/MCSymbolELF.h"
|
|
||||||
#include "llvm/MC/MCSymbolWasm.h"
|
#include "llvm/MC/MCSymbolWasm.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
@ -34,11 +33,7 @@ using namespace llvm;
|
||||||
MCSymbol *
|
MCSymbol *
|
||||||
WebAssemblyMCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const {
|
WebAssemblyMCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const {
|
||||||
const GlobalValue *Global = MO.getGlobal();
|
const GlobalValue *Global = MO.getGlobal();
|
||||||
MCSymbol *Sym = Printer.getSymbol(Global);
|
MCSymbolWasm *WasmSym = cast<MCSymbolWasm>(Printer.getSymbol(Global));
|
||||||
if (isa<MCSymbolELF>(Sym))
|
|
||||||
return Sym;
|
|
||||||
|
|
||||||
MCSymbolWasm *WasmSym = cast<MCSymbolWasm>(Sym);
|
|
||||||
|
|
||||||
if (const auto *FuncTy = dyn_cast<FunctionType>(Global->getValueType())) {
|
if (const auto *FuncTy = dyn_cast<FunctionType>(Global->getValueType())) {
|
||||||
const MachineFunction &MF = *MO.getParent()->getParent()->getParent();
|
const MachineFunction &MF = *MO.getParent()->getParent()->getParent();
|
||||||
|
@ -83,11 +78,8 @@ WebAssemblyMCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const {
|
||||||
MCSymbol *WebAssemblyMCInstLower::GetExternalSymbolSymbol(
|
MCSymbol *WebAssemblyMCInstLower::GetExternalSymbolSymbol(
|
||||||
const MachineOperand &MO) const {
|
const MachineOperand &MO) const {
|
||||||
const char *Name = MO.getSymbolName();
|
const char *Name = MO.getSymbolName();
|
||||||
MCSymbol *Sym = Printer.GetExternalSymbolSymbol(Name);
|
MCSymbolWasm *WasmSym =
|
||||||
if (isa<MCSymbolELF>(Sym))
|
cast<MCSymbolWasm>(Printer.GetExternalSymbolSymbol(Name));
|
||||||
return Sym;
|
|
||||||
|
|
||||||
MCSymbolWasm *WasmSym = cast<MCSymbolWasm>(Sym);
|
|
||||||
const WebAssemblySubtarget &Subtarget = Printer.getSubtarget();
|
const WebAssemblySubtarget &Subtarget = Printer.getSubtarget();
|
||||||
|
|
||||||
// __stack_pointer is a global variable; all other external symbols used by
|
// __stack_pointer is a global variable; all other external symbols used by
|
||||||
|
@ -177,35 +169,32 @@ void WebAssemblyMCInstLower::Lower(const MachineInstr *MI,
|
||||||
const MCOperandInfo &Info = Desc.OpInfo[i];
|
const MCOperandInfo &Info = Desc.OpInfo[i];
|
||||||
if (Info.OperandType == WebAssembly::OPERAND_TYPEINDEX) {
|
if (Info.OperandType == WebAssembly::OPERAND_TYPEINDEX) {
|
||||||
MCSymbol *Sym = Printer.createTempSymbol("typeindex");
|
MCSymbol *Sym = Printer.createTempSymbol("typeindex");
|
||||||
if (!isa<MCSymbolELF>(Sym)) {
|
|
||||||
SmallVector<wasm::ValType, 4> Returns;
|
|
||||||
SmallVector<wasm::ValType, 4> Params;
|
|
||||||
|
|
||||||
const MachineRegisterInfo &MRI =
|
SmallVector<wasm::ValType, 4> Returns;
|
||||||
MI->getParent()->getParent()->getRegInfo();
|
SmallVector<wasm::ValType, 4> Params;
|
||||||
for (const MachineOperand &MO : MI->defs())
|
|
||||||
Returns.push_back(getType(MRI.getRegClass(MO.getReg())));
|
|
||||||
for (const MachineOperand &MO : MI->explicit_uses())
|
|
||||||
if (MO.isReg())
|
|
||||||
Params.push_back(getType(MRI.getRegClass(MO.getReg())));
|
|
||||||
|
|
||||||
// call_indirect instructions have a callee operand at the end which
|
const MachineRegisterInfo &MRI =
|
||||||
// doesn't count as a param.
|
MI->getParent()->getParent()->getRegInfo();
|
||||||
if (WebAssembly::isCallIndirect(*MI))
|
for (const MachineOperand &MO : MI->defs())
|
||||||
Params.pop_back();
|
Returns.push_back(getType(MRI.getRegClass(MO.getReg())));
|
||||||
|
for (const MachineOperand &MO : MI->explicit_uses())
|
||||||
|
if (MO.isReg())
|
||||||
|
Params.push_back(getType(MRI.getRegClass(MO.getReg())));
|
||||||
|
|
||||||
MCSymbolWasm *WasmSym = cast<MCSymbolWasm>(Sym);
|
// call_indirect instructions have a callee operand at the end which
|
||||||
WasmSym->setReturns(std::move(Returns));
|
// doesn't count as a param.
|
||||||
WasmSym->setParams(std::move(Params));
|
if (WebAssembly::isCallIndirect(*MI))
|
||||||
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
|
Params.pop_back();
|
||||||
|
|
||||||
const MCExpr *Expr =
|
MCSymbolWasm *WasmSym = cast<MCSymbolWasm>(Sym);
|
||||||
MCSymbolRefExpr::create(WasmSym,
|
WasmSym->setReturns(std::move(Returns));
|
||||||
MCSymbolRefExpr::VK_WebAssembly_TYPEINDEX,
|
WasmSym->setParams(std::move(Params));
|
||||||
Ctx);
|
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
|
||||||
MCOp = MCOperand::createExpr(Expr);
|
|
||||||
break;
|
const MCExpr *Expr = MCSymbolRefExpr::create(
|
||||||
}
|
WasmSym, MCSymbolRefExpr::VK_WebAssembly_TYPEINDEX, Ctx);
|
||||||
|
MCOp = MCOperand::createExpr(Expr);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MCOp = MCOperand::createImm(MO.getImm());
|
MCOp = MCOperand::createImm(MO.getImm());
|
||||||
|
|
|
@ -83,18 +83,13 @@ static bool MaybeRewriteToFallthrough(MachineInstr &MI, MachineBasicBlock &MBB,
|
||||||
return false;
|
return false;
|
||||||
if (&MBB != &MF.back())
|
if (&MBB != &MF.back())
|
||||||
return false;
|
return false;
|
||||||
if (MF.getSubtarget<WebAssemblySubtarget>()
|
|
||||||
.getTargetTriple().isOSBinFormatELF()) {
|
MachineBasicBlock::iterator End = MBB.end();
|
||||||
if (&MI != &MBB.back())
|
--End;
|
||||||
return false;
|
assert(End->getOpcode() == WebAssembly::END_FUNCTION);
|
||||||
} else {
|
--End;
|
||||||
MachineBasicBlock::iterator End = MBB.end();
|
if (&MI != &*End)
|
||||||
--End;
|
return false;
|
||||||
assert(End->getOpcode() == WebAssembly::END_FUNCTION);
|
|
||||||
--End;
|
|
||||||
if (&MI != &*End)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FallthroughOpc != WebAssembly::FALLTHROUGH_RETURN_VOID) {
|
if (FallthroughOpc != WebAssembly::FALLTHROUGH_RETURN_VOID) {
|
||||||
// If the operand isn't stackified, insert a COPY to read the operand and
|
// If the operand isn't stackified, insert a COPY to read the operand and
|
||||||
|
|
|
@ -749,14 +749,6 @@ bool WebAssemblyRegStackify::runOnMachineFunction(MachineFunction &MF) {
|
||||||
MachineDominatorTree &MDT = getAnalysis<MachineDominatorTree>();
|
MachineDominatorTree &MDT = getAnalysis<MachineDominatorTree>();
|
||||||
LiveIntervals &LIS = getAnalysis<LiveIntervals>();
|
LiveIntervals &LIS = getAnalysis<LiveIntervals>();
|
||||||
|
|
||||||
// Disable the TEE optimization if we aren't doing direct wasm object
|
|
||||||
// emission, because lowering TEE to TEE_LOCAL is done in the ExplicitLocals
|
|
||||||
// pass, which is also disabled.
|
|
||||||
bool UseTee = true;
|
|
||||||
if (MF.getSubtarget<WebAssemblySubtarget>()
|
|
||||||
.getTargetTriple().isOSBinFormatELF())
|
|
||||||
UseTee = false;
|
|
||||||
|
|
||||||
// Walk the instructions from the bottom up. Currently we don't look past
|
// Walk the instructions from the bottom up. Currently we don't look past
|
||||||
// block boundaries, and the blocks aren't ordered so the block visitation
|
// block boundaries, and the blocks aren't ordered so the block visitation
|
||||||
// order isn't significant, but we may want to change this in the future.
|
// order isn't significant, but we may want to change this in the future.
|
||||||
|
@ -822,7 +814,7 @@ bool WebAssemblyRegStackify::runOnMachineFunction(MachineFunction &MF) {
|
||||||
Insert =
|
Insert =
|
||||||
RematerializeCheapDef(Reg, Op, *Def, MBB, Insert->getIterator(),
|
RematerializeCheapDef(Reg, Op, *Def, MBB, Insert->getIterator(),
|
||||||
LIS, MFI, MRI, TII, TRI);
|
LIS, MFI, MRI, TII, TRI);
|
||||||
} else if (UseTee && CanMove &&
|
} else if (CanMove &&
|
||||||
OneUseDominatesOtherUses(Reg, Op, MBB, MRI, MDT, LIS, MFI)) {
|
OneUseDominatesOtherUses(Reg, Op, MBB, MRI, MDT, LIS, MFI)) {
|
||||||
Insert = MoveAndTeeForMultiUse(Reg, Op, Def, MBB, Insert, LIS, MFI,
|
Insert = MoveAndTeeForMultiUse(Reg, Op, Def, MBB, Insert, LIS, MFI,
|
||||||
MRI, TII);
|
MRI, TII);
|
||||||
|
|
|
@ -97,11 +97,7 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine(
|
||||||
: "e-m:e-p:32:32-i64:64-n32:64-S128",
|
: "e-m:e-p:32:32-i64:64-n32:64-S128",
|
||||||
TT, CPU, FS, Options, getEffectiveRelocModel(RM),
|
TT, CPU, FS, Options, getEffectiveRelocModel(RM),
|
||||||
CM ? *CM : CodeModel::Large, OL),
|
CM ? *CM : CodeModel::Large, OL),
|
||||||
TLOF(TT.isOSBinFormatELF() ?
|
TLOF(new WebAssemblyTargetObjectFile()) {
|
||||||
static_cast<TargetLoweringObjectFile*>(
|
|
||||||
new WebAssemblyTargetObjectFileELF()) :
|
|
||||||
static_cast<TargetLoweringObjectFile*>(
|
|
||||||
new WebAssemblyTargetObjectFile())) {
|
|
||||||
// WebAssembly type-checks instructions, but a noreturn function with a return
|
// WebAssembly type-checks instructions, but a noreturn function with a return
|
||||||
// type that doesn't match the context will cause a check failure. So we lower
|
// type that doesn't match the context will cause a check failure. So we lower
|
||||||
// LLVM 'unreachable' to ISD::TRAP and then lower that to WebAssembly's
|
// LLVM 'unreachable' to ISD::TRAP and then lower that to WebAssembly's
|
||||||
|
@ -110,11 +106,9 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine(
|
||||||
|
|
||||||
// WebAssembly treats each function as an independent unit. Force
|
// WebAssembly treats each function as an independent unit. Force
|
||||||
// -ffunction-sections, effectively, so that we can emit them independently.
|
// -ffunction-sections, effectively, so that we can emit them independently.
|
||||||
if (!TT.isOSBinFormatELF()) {
|
this->Options.FunctionSections = true;
|
||||||
this->Options.FunctionSections = true;
|
this->Options.DataSections = true;
|
||||||
this->Options.DataSections = true;
|
this->Options.UniqueSectionNames = true;
|
||||||
this->Options.UniqueSectionNames = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
initAsmInfo();
|
initAsmInfo();
|
||||||
|
|
||||||
|
|
|
@ -15,13 +15,8 @@
|
||||||
|
|
||||||
#include "WebAssemblyTargetObjectFile.h"
|
#include "WebAssemblyTargetObjectFile.h"
|
||||||
#include "WebAssemblyTargetMachine.h"
|
#include "WebAssemblyTargetMachine.h"
|
||||||
using namespace llvm;
|
|
||||||
|
|
||||||
void WebAssemblyTargetObjectFileELF::Initialize(MCContext &Ctx,
|
using namespace llvm;
|
||||||
const TargetMachine &TM) {
|
|
||||||
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
|
|
||||||
InitializeELF(TM.Options.UseInitArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebAssemblyTargetObjectFile::Initialize(MCContext &Ctx,
|
void WebAssemblyTargetObjectFile::Initialize(MCContext &Ctx,
|
||||||
const TargetMachine &TM) {
|
const TargetMachine &TM) {
|
||||||
|
|
|
@ -20,12 +20,6 @@
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
class WebAssemblyTargetObjectFileELF final
|
|
||||||
: public TargetLoweringObjectFileELF {
|
|
||||||
public:
|
|
||||||
void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class WebAssemblyTargetObjectFile final : public TargetLoweringObjectFileWasm {
|
class WebAssemblyTargetObjectFile final : public TargetLoweringObjectFileWasm {
|
||||||
public:
|
public:
|
||||||
void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
|
void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# RUN: llvm-mc -triple=wasm32-unknown-unknown-elf < %s | FileCheck %s
|
|
||||||
# RUN: llvm-mc -triple=wasm32-unknown-unknown < %s | FileCheck %s
|
# RUN: llvm-mc -triple=wasm32-unknown-unknown < %s | FileCheck %s
|
||||||
|
|
||||||
.text
|
.text
|
||||||
|
|
|
@ -1062,7 +1062,6 @@ static const EnumEntry<unsigned> ElfMachineType[] = {
|
||||||
ENUM_ENT(EM_56800EX, "EM_56800EX"),
|
ENUM_ENT(EM_56800EX, "EM_56800EX"),
|
||||||
ENUM_ENT(EM_AMDGPU, "EM_AMDGPU"),
|
ENUM_ENT(EM_AMDGPU, "EM_AMDGPU"),
|
||||||
ENUM_ENT(EM_RISCV, "RISC-V"),
|
ENUM_ENT(EM_RISCV, "RISC-V"),
|
||||||
ENUM_ENT(EM_WEBASSEMBLY, "EM_WEBASSEMBLY"),
|
|
||||||
ENUM_ENT(EM_LANAI, "EM_LANAI"),
|
ENUM_ENT(EM_LANAI, "EM_LANAI"),
|
||||||
ENUM_ENT(EM_BPF, "EM_BPF"),
|
ENUM_ENT(EM_BPF, "EM_BPF"),
|
||||||
};
|
};
|
||||||
|
|
|
@ -1049,11 +1049,6 @@ TEST(TripleTest, FileFormat) {
|
||||||
EXPECT_EQ(Triple::Wasm,
|
EXPECT_EQ(Triple::Wasm,
|
||||||
Triple("wasm64-unknown-unknown-wasm").getObjectFormat());
|
Triple("wasm64-unknown-unknown-wasm").getObjectFormat());
|
||||||
|
|
||||||
EXPECT_EQ(Triple::ELF,
|
|
||||||
Triple("wasm32-unknown-unknown-elf").getObjectFormat());
|
|
||||||
EXPECT_EQ(Triple::ELF,
|
|
||||||
Triple("wasm64-unknown-unknown-elf").getObjectFormat());
|
|
||||||
|
|
||||||
Triple MSVCNormalized(Triple::normalize("i686-pc-windows-msvc-elf"));
|
Triple MSVCNormalized(Triple::normalize("i686-pc-windows-msvc-elf"));
|
||||||
EXPECT_EQ(Triple::ELF, MSVCNormalized.getObjectFormat());
|
EXPECT_EQ(Triple::ELF, MSVCNormalized.getObjectFormat());
|
||||||
|
|
||||||
|
|
|
@ -72,8 +72,8 @@ TEST(Disassembler, WebAssemblyTest) {
|
||||||
uint8_t *BytesP = Bytes;
|
uint8_t *BytesP = Bytes;
|
||||||
const char OutStringSize = 100;
|
const char OutStringSize = 100;
|
||||||
char OutString[OutStringSize];
|
char OutString[OutStringSize];
|
||||||
LLVMDisasmContextRef DCR = LLVMCreateDisasm(
|
LLVMDisasmContextRef DCR = LLVMCreateDisasm("wasm32-unknown-unknown", nullptr,
|
||||||
"wasm32-unknown-unknown-elf", nullptr, 0, nullptr, symbolLookupCallback);
|
0, nullptr, symbolLookupCallback);
|
||||||
if (!DCR)
|
if (!DCR)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue