aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2019-03-26 19:46:15 +0000
committerSam Clegg <sbc@chromium.org>2019-03-26 19:46:15 +0000
commit492f752969ff3a37138372e8e973317dc63ef2d3 (patch)
treedb63368f472fbb77026751650cc85ecc6c114f07 /llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
parent6f4c45e9fc70473e2e176608657c02beb122973b (diff)
downloadllvm-492f752969ff3a37138372e8e973317dc63ef2d3.zip
llvm-492f752969ff3a37138372e8e973317dc63ef2d3.tar.gz
llvm-492f752969ff3a37138372e8e973317dc63ef2d3.tar.bz2
[WebAssembly] Initial implementation of PIC code generation
This change implements lowering of references global symbols in PIC mode. This change implements lowering of global references in PIC mode using a new @GOT reference type. @GOT references can be used with function or data symbol names combined with the get_global instruction. In this case the linker will insert the wasm global that stores the address of the symbol (either in memory for data symbols or in the wasm table for function symbols). For now I'm continuing to use the R_WASM_GLOBAL_INDEX_LEB relocation type for this type of reference which means that this relocation type can refer to either a global or a function or data symbol. We could choose to introduce specific relocation types for GOT entries in the future. See the current dynamic linking proposal: https://github.com/WebAssembly/tool-conventions/blob/master/DynamicLinking.md Differential Revision: https://reviews.llvm.org/D54647 llvm-svn: 357022
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp')
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
index 15df3d4..1705748 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
@@ -151,7 +151,7 @@ private:
return MVT::INVALID_SIMPLE_VALUE_TYPE;
}
bool computeAddress(const Value *Obj, Address &Addr);
- void materializeLoadStoreOperands(Address &Addr);
+ bool materializeLoadStoreOperands(Address &Addr);
void addLoadStoreOperands(const Address &Addr, const MachineInstrBuilder &MIB,
MachineMemOperand *MMO);
unsigned maskI1Value(unsigned Reg, const Value *V);
@@ -374,10 +374,13 @@ bool WebAssemblyFastISel::computeAddress(const Value *Obj, Address &Addr) {
return Addr.getReg() != 0;
}
-void WebAssemblyFastISel::materializeLoadStoreOperands(Address &Addr) {
+bool WebAssemblyFastISel::materializeLoadStoreOperands(Address &Addr) {
if (Addr.isRegBase()) {
unsigned Reg = Addr.getReg();
if (Reg == 0) {
+ const GlobalValue *GV = Addr.getGlobalValue();
+ if (GV && TLI.isPositionIndependent())
+ return false;
Reg = createResultReg(Subtarget->hasAddr64() ? &WebAssembly::I64RegClass
: &WebAssembly::I32RegClass);
unsigned Opc = Subtarget->hasAddr64() ? WebAssembly::CONST_I64
@@ -387,6 +390,7 @@ void WebAssemblyFastISel::materializeLoadStoreOperands(Address &Addr) {
Addr.setReg(Reg);
}
}
+ return true;
}
void WebAssemblyFastISel::addLoadStoreOperands(const Address &Addr,
@@ -604,7 +608,9 @@ unsigned WebAssemblyFastISel::fastMaterializeAlloca(const AllocaInst *AI) {
}
unsigned WebAssemblyFastISel::fastMaterializeConstant(const Constant *C) {
- if (const auto *GV = dyn_cast<GlobalValue>(C)) {
+ if (const GlobalValue *GV = dyn_cast<GlobalValue>(C)) {
+ if (TLI.isPositionIndependent())
+ return 0;
unsigned ResultReg =
createResultReg(Subtarget->hasAddr64() ? &WebAssembly::I64RegClass
: &WebAssembly::I32RegClass);
@@ -1181,7 +1187,8 @@ bool WebAssemblyFastISel::selectLoad(const Instruction *I) {
return false;
}
- materializeLoadStoreOperands(Addr);
+ if (!materializeLoadStoreOperands(Addr))
+ return false;
unsigned ResultReg = createResultReg(RC);
auto MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc),
@@ -1233,7 +1240,8 @@ bool WebAssemblyFastISel::selectStore(const Instruction *I) {
return false;
}
- materializeLoadStoreOperands(Addr);
+ if (!materializeLoadStoreOperands(Addr))
+ return false;
unsigned ValueReg = getRegForValue(Store->getValueOperand());
if (ValueReg == 0)