Skip to content

Commit

Permalink
[WebAssembly] Remove unneeded target operand flags
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sbc100 committed Apr 3, 2019
1 parent 4c1581e commit ef4c66c
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 50 deletions.
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down
23 changes: 7 additions & 16 deletions llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
Expand Up @@ -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)) {
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp
Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
Expand Up @@ -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);

Expand Down
40 changes: 19 additions & 21 deletions llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.h
Expand Up @@ -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)
Expand Down

0 comments on commit ef4c66c

Please sign in to comment.