[WebAssembly] Remove unneeded target operand flags
authorSam Clegg <sbc@chromium.org>
Wed, 3 Apr 2019 00:17:29 +0000 (00:17 +0000)
committerSam Clegg <sbc@chromium.org>
Wed, 3 Apr 2019 00:17:29 +0000 (00:17 +0000)
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

llvm-svn: 357548

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

index 7d12dd7..69c477b 100644 (file)
@@ -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
index 0f4e1ab..a1c567f 100644 (file)
@@ -130,7 +130,7 @@ void WebAssemblyFrameLowering::writeSPToGlobal(
   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::emitPrologue(MachineFunction &MF,
   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) {
index dc9afb7..b5e9d9e 100644 (file)
@@ -996,7 +996,7 @@ SDValue WebAssemblyTargetLowering::LowerGlobalAddress(SDValue Op,
   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::LowerGlobalAddress(SDValue Op,
 
       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::LowerExternalSymbol(SDValue Op,
   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::LowerIntrinsic(SDValue Op,
     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
                        {
index 3f5aba0..ee69811 100644 (file)
@@ -199,7 +199,7 @@ unsigned WebAssemblyInstrInfo::insertBranch(
       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]);
index f365aa7..49258de 100644 (file)
@@ -307,7 +307,7 @@ bool WebAssemblyLateEHPrepare::addExceptionExtraction(MachineFunction &MF) {
     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);
 
index 9ca9779..fd09b74 100644 (file)
@@ -120,26 +120,27 @@ MCSymbol *WebAssemblyMCInstLower::GetExternalSymbolSymbol(
   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 MachineInstr *MI,
       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;
     }
 
index 125ba1d..2c375a0 100644 (file)
@@ -32,8 +32,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyMCInstLower {
 
   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)