summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/WebAssembly
diff options
context:
space:
mode:
authorDan Gohman <dan433584@gmail.com>2015-12-06 19:33:32 +0000
committerDan Gohman <dan433584@gmail.com>2015-12-06 19:33:32 +0000
commita4b710a74f737c4d9ec4d55ecce0f93d2a6229a2 (patch)
tree311df54fd19037773dba601fecc8a808653fc87f /llvm/lib/Target/WebAssembly
parent6ddce716cb8d0cd45f1604aae4f226a8c9f99f87 (diff)
downloadbcm5719-llvm-a4b710a74f737c4d9ec4d55ecce0f93d2a6229a2.tar.gz
bcm5719-llvm-a4b710a74f737c4d9ec4d55ecce0f93d2a6229a2.zip
[WebAssembly] Enable folding of offsets into global variable addresses.
llvm-svn: 254882
Diffstat (limited to 'llvm/lib/Target/WebAssembly')
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp10
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp9
2 files changed, 11 insertions, 8 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
index 6e1283b4d33..85fb753ed0e 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -196,9 +196,8 @@ FastISel *WebAssemblyTargetLowering::createFastISel(
bool WebAssemblyTargetLowering::isOffsetFoldingLegal(
const GlobalAddressSDNode * /*GA*/) const {
- // The WebAssembly target doesn't support folding offsets into global
- // addresses.
- return false;
+ // All offsets can be folded.
+ return true;
}
MVT WebAssemblyTargetLowering::getScalarShiftAmountTy(const DataLayout & /*DL*/,
@@ -528,13 +527,12 @@ SDValue WebAssemblyTargetLowering::LowerGlobalAddress(SDValue Op,
SDLoc DL(Op);
const auto *GA = cast<GlobalAddressSDNode>(Op);
EVT VT = Op.getValueType();
- assert(GA->getOffset() == 0 &&
- "offsets on global addresses are forbidden by isOffsetFoldingLegal");
assert(GA->getTargetFlags() == 0 && "WebAssembly doesn't set target flags");
if (GA->getAddressSpace() != 0)
fail(DL, DAG, "WebAssembly only expects the 0 address space");
return DAG.getNode(WebAssemblyISD::Wrapper, DL, VT,
- DAG.getTargetGlobalAddress(GA->getGlobal(), DL, VT));
+ DAG.getTargetGlobalAddress(GA->getGlobal(), DL, VT,
+ GA->getOffset()));
}
SDValue
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
index dd9358035a8..2d2adeb93d2 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
@@ -39,11 +39,16 @@ MCSymbol *WebAssemblyMCInstLower::GetExternalSymbolSymbol(
MCOperand WebAssemblyMCInstLower::LowerSymbolOperand(const MachineOperand &MO,
MCSymbol *Sym) const {
+ assert(MO.getTargetFlags() == 0 && "WebAssembly does not use target flags");
const MCExpr *Expr = MCSymbolRefExpr::create(Sym, Ctx);
- if (!MO.isJTI() && MO.getOffset())
- llvm_unreachable("unknown symbol op");
+ int64_t Offset = MO.getOffset();
+ if (Offset != 0) {
+ assert(!MO.isJTI() && "Unexpected offset with jump table index");
+ Expr =
+ MCBinaryExpr::createAdd(Expr, MCConstantExpr::create(Offset, Ctx), Ctx);
+ }
return MCOperand::createExpr(Expr);
}
OpenPOWER on IntegriCloud