[llvm] r357548 - [WebAssembly] Remove unneeded target operand flags

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 2 17:17:30 PDT 2019


Author: sbc
Date: Tue Apr  2 17:17:29 2019
New Revision: 357548

URL: http://llvm.org/viewvc/llvm-project?rev=357548&view=rev
Log:
[WebAssembly] Remove unneeded target operand flags

This change is in preparation for the addition of new target
operand flags for new relocation types.  Have a symbol type as part
of the flag set makes it harder to use and AFAICT these are serving
no purpose.

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

Modified:
    llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.h

Modified: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h?rev=357548&r1=357547&r2=357548&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h (original)
+++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h Tue Apr  2 17:17:29 2019
@@ -90,15 +90,9 @@ namespace WebAssemblyII {
 enum TOF {
   MO_NO_FLAG = 0,
 
-  // Flags to indicate the type of the symbol being referenced
-  MO_SYMBOL_FUNCTION = 0x1,
-  MO_SYMBOL_GLOBAL = 0x2,
-  MO_SYMBOL_EVENT = 0x4,
-  MO_SYMBOL_MASK = 0x7,
-
   // Address of data symbol via a wasm global.  This adds a level of indirection
   // similar to the GOT on native platforms.
-  MO_GOT = 0x8,
+  MO_GOT,
 };
 
 } // end namespace WebAssemblyII

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp?rev=357548&r1=357547&r2=357548&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp Tue Apr  2 17:17:29 2019
@@ -130,7 +130,7 @@ void WebAssemblyFrameLowering::writeSPTo
   const char *ES = "__stack_pointer";
   auto *SPSymbol = MF.createExternalSymbolName(ES);
   BuildMI(MBB, InsertStore, DL, TII->get(WebAssembly::GLOBAL_SET_I32))
-      .addExternalSymbol(SPSymbol, WebAssemblyII::MO_SYMBOL_GLOBAL)
+      .addExternalSymbol(SPSymbol)
       .addReg(SrcReg);
 }
 
@@ -177,7 +177,7 @@ void WebAssemblyFrameLowering::emitProlo
   const char *ES = "__stack_pointer";
   auto *SPSymbol = MF.createExternalSymbolName(ES);
   BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::GLOBAL_GET_I32), SPReg)
-      .addExternalSymbol(SPSymbol, WebAssemblyII::MO_SYMBOL_GLOBAL);
+      .addExternalSymbol(SPSymbol);
 
   bool HasBP = hasBP(MF);
   if (HasBP) {

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp?rev=357548&r1=357547&r2=357548&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp Tue Apr  2 17:17:29 2019
@@ -996,7 +996,7 @@ SDValue WebAssemblyTargetLowering::Lower
   if (GA->getAddressSpace() != 0)
     fail(DL, DAG, "WebAssembly only expects the 0 address space");
 
-  unsigned Flags = 0;
+  unsigned OperandFlags = 0;
   if (isPositionIndependent()) {
     const GlobalValue *GV = GA->getGlobal();
     if (getTargetMachine().shouldAssumeDSOLocal(*GV->getParent(), GV)) {
@@ -1017,13 +1017,13 @@ SDValue WebAssemblyTargetLowering::Lower
 
       return DAG.getNode(ISD::ADD, DL, VT, BaseAddr, SymAddr);
     } else {
-      Flags |= WebAssemblyII::MO_GOT;
+      OperandFlags = WebAssemblyII::MO_GOT;
     }
   }
 
   return DAG.getNode(WebAssemblyISD::Wrapper, DL, VT,
                      DAG.getTargetGlobalAddress(GA->getGlobal(), DL, VT,
-                                                GA->getOffset(), Flags));
+                                                GA->getOffset(), OperandFlags));
 }
 
 SDValue
@@ -1034,15 +1034,8 @@ WebAssemblyTargetLowering::LowerExternal
   EVT VT = Op.getValueType();
   assert(ES->getTargetFlags() == 0 &&
          "Unexpected target flags on generic ExternalSymbolSDNode");
-  // Set the TargetFlags to MO_SYMBOL_FUNCTION which indicates that this is a
-  // "function" symbol rather than a data symbol. We do this unconditionally
-  // even though we don't know anything about the symbol other than its name,
-  // because all external symbols used in target-independent SelectionDAG code
-  // are for functions.
-  return DAG.getNode(
-      WebAssemblyISD::Wrapper, DL, VT,
-      DAG.getTargetExternalSymbol(ES->getSymbol(), VT,
-                                  WebAssemblyII::MO_SYMBOL_FUNCTION));
+  return DAG.getNode(WebAssemblyISD::Wrapper, DL, VT,
+                     DAG.getTargetExternalSymbol(ES->getSymbol(), VT));
 }
 
 SDValue WebAssemblyTargetLowering::LowerJumpTable(SDValue Op,
@@ -1136,10 +1129,8 @@ SDValue WebAssemblyTargetLowering::Lower
     const TargetLowering &TLI = DAG.getTargetLoweringInfo();
     MVT PtrVT = TLI.getPointerTy(DAG.getDataLayout());
     const char *SymName = MF.createExternalSymbolName("__cpp_exception");
-    SDValue SymNode =
-        DAG.getNode(WebAssemblyISD::Wrapper, DL, PtrVT,
-                    DAG.getTargetExternalSymbol(
-                        SymName, PtrVT, WebAssemblyII::MO_SYMBOL_EVENT));
+    SDValue SymNode = DAG.getNode(WebAssemblyISD::Wrapper, DL, PtrVT,
+                                  DAG.getTargetExternalSymbol(SymName, PtrVT));
     return DAG.getNode(WebAssemblyISD::THROW, DL,
                        MVT::Other, // outchain type
                        {

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp?rev=357548&r1=357547&r2=357548&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp Tue Apr  2 17:17:29 2019
@@ -199,7 +199,7 @@ unsigned WebAssemblyInstrInfo::insertBra
       const char *CPPExnSymbol = MF.createExternalSymbolName("__cpp_exception");
       BuildMI(&MBB, DL, get(WebAssembly::BR_ON_EXN))
           .addMBB(TBB)
-          .addExternalSymbol(CPPExnSymbol, WebAssemblyII::MO_SYMBOL_EVENT)
+          .addExternalSymbol(CPPExnSymbol)
           .add(Cond[1]);
     } else
       BuildMI(&MBB, DL, get(WebAssembly::BR_IF)).addMBB(TBB).add(Cond[1]);

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp?rev=357548&r1=357547&r2=357548&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp Tue Apr  2 17:17:29 2019
@@ -307,7 +307,7 @@ bool WebAssemblyLateEHPrepare::addExcept
     const char *CPPExnSymbol = MF.createExternalSymbolName("__cpp_exception");
     BuildMI(EHPad, DL, TII.get(WebAssembly::BR_ON_EXN))
         .addMBB(ThenMBB)
-        .addExternalSymbol(CPPExnSymbol, WebAssemblyII::MO_SYMBOL_EVENT)
+        .addExternalSymbol(CPPExnSymbol)
         .addReg(ExnReg);
     BuildMI(EHPad, DL, TII.get(WebAssembly::BR)).addMBB(ElseMBB);
 

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp?rev=357548&r1=357547&r2=357548&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp Tue Apr  2 17:17:29 2019
@@ -120,26 +120,27 @@ MCSymbol *WebAssemblyMCInstLower::GetExt
   return WasmSym;
 }
 
-MCOperand WebAssemblyMCInstLower::lowerSymbolOperand(
-    MCSymbol *Sym, int64_t Offset, bool IsFunc, unsigned TargetFlags) const {
-  MCSymbolRefExpr::VariantKind Kind = MCSymbolRefExpr::VK_None;
-  if (TargetFlags & WebAssemblyII::MO_GOT)
-    Kind = MCSymbolRefExpr::VK_GOT;
+MCOperand WebAssemblyMCInstLower::lowerSymbolOperand(const MachineOperand &MO,
+                                                     MCSymbol *Sym) const {
+  bool isGOT = MO.getTargetFlags() == WebAssemblyII::MO_GOT;
+  MCSymbolRefExpr::VariantKind Kind =
+      isGOT ? MCSymbolRefExpr::VK_GOT : MCSymbolRefExpr::VK_None;
   const MCExpr *Expr = MCSymbolRefExpr::create(Sym, Kind, Ctx);
 
-  if (Offset != 0) {
-    if (TargetFlags & WebAssemblyII::MO_GOT)
+  if (MO.getOffset() != 0) {
+    const auto *WasmSym = cast<MCSymbolWasm>(Sym);
+    if (isGOT)
       report_fatal_error("GOT symbol references do not support offsets");
-    unsigned Type = TargetFlags & WebAssemblyII::MO_SYMBOL_MASK;
-    assert((Type == WebAssemblyII::MO_SYMBOL_FUNCTION) == IsFunc);
-    if (Type == WebAssemblyII::MO_SYMBOL_FUNCTION || IsFunc)
+
+    if (WasmSym->isFunction())
       report_fatal_error("Function addresses with offsets not supported");
-    if (Type == WebAssemblyII::MO_SYMBOL_GLOBAL)
+    if (WasmSym->isGlobal())
       report_fatal_error("Global indexes with offsets not supported");
-    if (Type == WebAssemblyII::MO_SYMBOL_EVENT)
+    if (WasmSym->isEvent())
       report_fatal_error("Event indexes with offsets not supported");
-    Expr =
-        MCBinaryExpr::createAdd(Expr, MCConstantExpr::create(Offset, Ctx), Ctx);
+
+    Expr = MCBinaryExpr::createAdd(
+        Expr, MCConstantExpr::create(MO.getOffset(), Ctx), Ctx);
   }
 
   return MCOperand::createExpr(Expr);
@@ -236,24 +237,21 @@ void WebAssemblyMCInstLower::lower(const
       break;
     }
     case MachineOperand::MO_GlobalAddress:
-      MCOp = lowerSymbolOperand(GetGlobalAddressSymbol(MO), MO.getOffset(),
-                                MO.getGlobal()->getValueType()->isFunctionTy(),
-                                MO.getTargetFlags());
+      MCOp = lowerSymbolOperand(MO, GetGlobalAddressSymbol(MO));
       break;
     case MachineOperand::MO_ExternalSymbol:
       // The target flag indicates whether this is a symbol for a
       // variable or a function.
-      assert((MO.getTargetFlags() & ~WebAssemblyII::MO_SYMBOL_MASK) == 0 &&
+      assert(MO.getTargetFlags() == 0 &&
              "WebAssembly uses only symbol flags on ExternalSymbols");
-      MCOp = lowerSymbolOperand(
-          GetExternalSymbolSymbol(MO), /*Offset=*/0, false, MO.getTargetFlags());
+      MCOp = lowerSymbolOperand(MO, GetExternalSymbolSymbol(MO));
       break;
     case MachineOperand::MO_MCSymbol:
       // This is currently used only for LSDA symbols (GCC_except_table),
       // because global addresses or other external symbols are handled above.
       assert(MO.getTargetFlags() == 0 &&
              "WebAssembly does not use target flags on MCSymbol");
-      MCOp = lowerSymbolOperand(MO.getMCSymbol(), /*Offset=*/0, false, MO.getTargetFlags());
+      MCOp = lowerSymbolOperand(MO, MO.getMCSymbol());
       break;
     }
 

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.h?rev=357548&r1=357547&r2=357548&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.h (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.h Tue Apr  2 17:17:29 2019
@@ -32,8 +32,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssembl
 
   MCSymbol *GetGlobalAddressSymbol(const MachineOperand &MO) const;
   MCSymbol *GetExternalSymbolSymbol(const MachineOperand &MO) const;
-  MCOperand lowerSymbolOperand(MCSymbol *Sym, int64_t Offset, bool IsFunc,
-                               unsigned flags) const;
+  MCOperand lowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const;
 
 public:
   WebAssemblyMCInstLower(MCContext &ctx, WebAssemblyAsmPrinter &printer)




More information about the llvm-commits mailing list