[llvm] r333964 - Simplified WebAssemblyAsmBackend by removing explicit ELF variant.

Derek Schuff via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 4 15:53:36 PDT 2018


Author: dschuff
Date: Mon Jun  4 15:53:36 2018
New Revision: 333964

URL: http://llvm.org/viewvc/llvm-project?rev=333964&view=rev
Log:
Simplified WebAssemblyAsmBackend by removing explicit ELF variant.

The ELF version was broken (does not deal with wasm specific fixups),
and now is slightly less broken. It will be removed in its entirety
in the future which this change makes slightly easier (just remove
the IsELF bool).

Differential Revision: https://reviews.llvm.org/D47745

Patch by Wouter van Oortmerssen

Modified:
    llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyAsmBackend.cpp

Modified: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyAsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyAsmBackend.cpp?rev=333964&r1=333963&r2=333964&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyAsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyAsmBackend.cpp Mon Jun  4 15:53:36 2018
@@ -29,48 +29,14 @@
 using namespace llvm;
 
 namespace {
-class WebAssemblyAsmBackendELF final : public MCAsmBackend {
-  bool Is64Bit;
-
-public:
-  explicit WebAssemblyAsmBackendELF(bool Is64Bit)
-      : MCAsmBackend(support::little), Is64Bit(Is64Bit) {}
-  ~WebAssemblyAsmBackendELF() override {}
-
-  void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
-                  const MCValue &Target, MutableArrayRef<char> Data,
-                  uint64_t Value, bool IsPCRel) const override;
-
-  std::unique_ptr<MCObjectTargetWriter>
-  createObjectTargetWriter() const override;
-
-  // No instruction requires relaxation
-  bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
-                            const MCRelaxableFragment *DF,
-                            const MCAsmLayout &Layout) const override {
-    return false;
-  }
-
-  unsigned getNumFixupKinds() const override {
-    // We currently just use the generic fixups in MCFixup.h and don't have any
-    // target-specific fixups.
-    return 0;
-  }
-
-  bool mayNeedRelaxation(const MCInst &Inst) const override { return false; }
-
-  void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
-                        MCInst &Res) const override {}
-
-  bool writeNopData(raw_ostream &OS, uint64_t Count) const override;
-};
 
 class WebAssemblyAsmBackend final : public MCAsmBackend {
   bool Is64Bit;
+  bool IsELF;
 
-public:
-  explicit WebAssemblyAsmBackend(bool Is64Bit)
-      : MCAsmBackend(support::little), Is64Bit(Is64Bit) {}
+ public:
+  explicit WebAssemblyAsmBackend(bool Is64Bit, bool IsELF)
+      : MCAsmBackend(support::little), Is64Bit(Is64Bit), IsELF(IsELF) {}
   ~WebAssemblyAsmBackend() override {}
 
   unsigned getNumFixupKinds() const override {
@@ -101,43 +67,6 @@ public:
   bool writeNopData(raw_ostream &OS, uint64_t Count) const override;
 };
 
-bool WebAssemblyAsmBackendELF::writeNopData(raw_ostream &OS,
-                                            uint64_t Count) const {
-  for (uint64_t i = 0; i < Count; ++i)
-    OS << char(WebAssembly::Nop);
-
-  return true;
-}
-
-void WebAssemblyAsmBackendELF::applyFixup(const MCAssembler &Asm,
-                                          const MCFixup &Fixup,
-                                          const MCValue &Target,
-                                          MutableArrayRef<char> Data,
-                                          uint64_t Value, bool IsPCRel) const {
-  const MCFixupKindInfo &Info = getFixupKindInfo(Fixup.getKind());
-  assert(Info.Flags == 0 && "WebAssembly does not use MCFixupKindInfo flags");
-
-  unsigned NumBytes = alignTo(Info.TargetSize, 8) / 8;
-  if (Value == 0)
-    return; // Doesn't change encoding.
-
-  // Shift the value into position.
-  Value <<= Info.TargetOffset;
-
-  unsigned Offset = Fixup.getOffset();
-  assert(Offset + NumBytes <= Data.size() && "Invalid fixup offset!");
-
-  // For each byte of the fragment that the fixup touches, mask in the
-  // bits from the fixup value.
-  for (unsigned i = 0; i != NumBytes; ++i)
-    Data[Offset + i] |= uint8_t((Value >> (i * 8)) & 0xff);
-}
-
-std::unique_ptr<MCObjectTargetWriter>
-WebAssemblyAsmBackendELF::createObjectTargetWriter() const {
-  return createWebAssemblyELFObjectWriter(Is64Bit, 0);
-}
-
 const MCFixupKindInfo &
 WebAssemblyAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
   const static MCFixupKindInfo Infos[WebAssembly::NumTargetFixupKinds] = {
@@ -160,9 +89,6 @@ WebAssemblyAsmBackend::getFixupKindInfo(
 
 bool WebAssemblyAsmBackend::writeNopData(raw_ostream &OS,
                                          uint64_t Count) const {
-  if (Count == 0)
-    return true;
-
   for (uint64_t i = 0; i < Count; ++i)
     OS << char(WebAssembly::Nop);
 
@@ -195,12 +121,12 @@ void WebAssemblyAsmBackend::applyFixup(c
 
 std::unique_ptr<MCObjectTargetWriter>
 WebAssemblyAsmBackend::createObjectTargetWriter() const {
-  return createWebAssemblyWasmObjectWriter(Is64Bit);
+  return IsELF ? createWebAssemblyELFObjectWriter(Is64Bit, 0)
+               : createWebAssemblyWasmObjectWriter(Is64Bit);
 }
+
 } // end anonymous namespace
 
 MCAsmBackend *llvm::createWebAssemblyAsmBackend(const Triple &TT) {
-  if (TT.isOSBinFormatELF())
-    return new WebAssemblyAsmBackendELF(TT.isArch64Bit());
-  return new WebAssemblyAsmBackend(TT.isArch64Bit());
+  return new WebAssemblyAsmBackend(TT.isArch64Bit(), TT.isOSBinFormatELF());
 }




More information about the llvm-commits mailing list