Skip to content

Commit 1242d93

Browse files
[Wasm] Revert all relative pointer workarounds
1 parent 2b3a974 commit 1242d93

File tree

7 files changed

+8
-82
lines changed

7 files changed

+8
-82
lines changed

include/swift/Basic/RelativePointer.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,6 @@ static inline uintptr_t applyRelativeOffset(BasePtrTy *basePtr, Offset offset) {
146146
std::is_signed<Offset>::value,
147147
"offset type should be signed integer");
148148

149-
#ifdef __wasm__
150-
// WebAssembly: hack: disable relative pointers
151-
return (uintptr_t)(intptr_t)offset;
152-
#endif
153-
154149
auto base = reinterpret_cast<uintptr_t>(basePtr);
155150
// We want to do wrapping arithmetic, but with a sign-extended
156151
// offset. To do this in C, we need to do signed promotion to get
@@ -169,13 +164,6 @@ static inline Offset measureRelativeOffset(A *referent, B *base) {
169164
static_assert(std::is_integral<Offset>::value &&
170165
std::is_signed<Offset>::value,
171166
"offset type should be signed integer");
172-
#ifdef __wasm__
173-
// WebAssembly: hack: disable relative pointers
174-
auto offset = (Offset)(uintptr_t)referent;
175-
assert((intptr_t)offset == (intptr_t)(uintptr_t)referent
176-
&& "pointer too large to fit in offset type");
177-
return offset;
178-
#endif
179167

180168
auto distance = (uintptr_t)referent - (uintptr_t)base;
181169
// Truncate as unsigned, then wrap around to signed.

lib/IRGen/ConstantBuilder.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ class ConstantAggregateBuilderBase
9191

9292
void addRelativeAddress(llvm::Constant *target) {
9393
assert(!isa<llvm::ConstantPointerNull>(target));
94-
if (IGM().TargetInfo.OutputObjectFormat == llvm::Triple::Wasm) {
95-
// WebAssembly: hack: doesn't support PCrel data relocations
96-
add(llvm::ConstantExpr::getPtrToInt(target, IGM().RelativeAddressTy, false));
97-
return;
98-
}
9994
addRelativeOffset(IGM().RelativeAddressTy, target);
10095
}
10196

@@ -104,21 +99,6 @@ class ConstantAggregateBuilderBase
10499
/// a "GOT-equivalent", i.e. a pointer to an external object; if so,
105100
/// set the low bit of the offset to indicate that this is true.
106101
void addRelativeAddress(ConstantReference reference) {
107-
if (IGM().TargetInfo.OutputObjectFormat == llvm::Triple::Wasm) {
108-
// WebAssembly: hack: doesn't support PCrel data relocations
109-
// also, we should set the lowest bit, but I don't know how to do that
110-
// there's no GOT on WebAssembly anyways though
111-
112-
113-
llvm::Constant *offset = llvm::ConstantExpr::getPtrToInt(reference.getValue(), IGM().RelativeAddressTy, false);
114-
// borrowed from addTaggedRelativeOffset
115-
unsigned tag = unsigned(reference.isIndirect());
116-
if (tag) {
117-
offset = llvm::ConstantExpr::getAdd(offset, llvm::ConstantInt::get(IGM().RelativeAddressTy, tag));
118-
}
119-
add(offset);
120-
return;
121-
}
122102
addTaggedRelativeOffset(IGM().RelativeAddressTy,
123103
reference.getValue(),
124104
unsigned(reference.isIndirect()));
@@ -128,11 +108,6 @@ class ConstantAggregateBuilderBase
128108
/// The target must be a "GOT-equivalent", i.e. a pointer to an
129109
/// external object.
130110
void addIndirectRelativeAddress(ConstantReference reference) {
131-
if (IGM().TargetInfo.OutputObjectFormat == llvm::Triple::Wasm) {
132-
// WebAssembly: hack: doesn't support PCrel data relocations
133-
add(llvm::ConstantExpr::getPtrToInt(reference.getValue(), IGM().RelativeAddressTy, false));
134-
return;
135-
}
136111
assert(reference.isIndirect());
137112
addRelativeOffset(IGM().RelativeAddressTy,
138113
reference.getValue());

lib/IRGen/GenDecl.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3738,11 +3738,6 @@ IRGenModule::emitDirectRelativeReference(llvm::Constant *target,
37383738
// Convert the target to an integer.
37393739
auto targetAddr = llvm::ConstantExpr::getPtrToInt(target, SizeTy);
37403740

3741-
// WebAssembly hack: WebAssembly doesn't support PC-relative references
3742-
if (TargetInfo.OutputObjectFormat == llvm::Triple::Wasm) {
3743-
return targetAddr;
3744-
}
3745-
37463741
SmallVector<llvm::Constant*, 4> indices;
37473742
indices.push_back(llvm::ConstantInt::get(Int32Ty, 0));
37483743
for (unsigned baseIndex : baseIndices) {

lib/IRGen/GenMeta.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5493,18 +5493,7 @@ GenericRequirementsMetadata irgen::addGenericRequirements(
54935493
unsigned tag = unsigned(descriptorRef.isIndirect());
54945494
if (protocol->isObjC())
54955495
tag |= 0x02;
5496-
// WebAssembly: hack: Wasm doesn't support PC-relative offsets.
5497-
// also doesn't handle tag yet
5498-
if (IGM.TargetInfo.OutputObjectFormat == llvm::Triple::Wasm) {
5499-
llvm::Constant *offset = llvm::ConstantExpr::getPtrToInt(descriptorRef.getValue(), IGM.RelativeAddressTy, false);
5500-
// borrowed from addTaggedRelativeOffset
5501-
if (tag) {
5502-
offset = llvm::ConstantExpr::getAdd(offset, llvm::ConstantInt::get(IGM.RelativeAddressTy, tag));
5503-
}
5504-
B.add(offset);
5505-
return;
5506-
}
5507-
5496+
55085497
B.addTaggedRelativeOffset(IGM.RelativeAddressTy,
55095498
descriptorRef.getValue(),
55105499
tag);

lib/IRGen/IRGenFunction.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,6 @@ IRGenFunction::emitLoadOfRelativePointer(Address addr, bool isFar,
330330
value = Builder.CreateSExt(value, IGM.IntPtrTy);
331331
}
332332

333-
// FIXME: add absolute pointer mode for IRGen
334-
if (IGM.TargetInfo.OutputObjectFormat == llvm::Triple::Wasm) {
335-
auto *uncastPointer = Builder.CreateIntToPtr(value, IGM.Int8PtrTy);
336-
auto uncastPointerAddress = Address(uncastPointer, IGM.getPointerAlignment());
337-
auto pointer = Builder.CreateBitCast(uncastPointerAddress, expectedType);
338-
return pointer.getAddress();
339-
}
340333
auto *addrInt = Builder.CreatePtrToInt(addr.getAddress(), IGM.IntPtrTy);
341334
auto *uncastPointerInt = Builder.CreateAdd(addrInt, value);
342335
auto *uncastPointer = Builder.CreateIntToPtr(uncastPointerInt, IGM.Int8PtrTy);

lib/IRGen/MetadataRequest.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2775,18 +2775,14 @@ emitMetadataAccessByMangledName(IRGenFunction &IGF, CanType type,
27752775
IGM.SizeTy);
27762776

27772777
llvm::Value *stringAddr;
2778-
if (IGM.TargetInfo.OutputObjectFormat == llvm::Triple::Wasm) {
2779-
stringAddr = subIGF.Builder.CreateIntToPtr(stringAddrOffset, IGM.Int8PtrTy);
2780-
} else {
2781-
auto stringAddrBase = subIGF.Builder.CreatePtrToInt(cache, IGM.SizeTy);
2782-
if (IGM.getModule()->getDataLayout().isBigEndian()) {
2783-
stringAddrBase = subIGF.Builder.CreateAdd(stringAddrBase,
2784-
llvm::ConstantInt::get(IGM.SizeTy, 4));
2785-
}
2786-
stringAddr = subIGF.Builder.CreateAdd(stringAddrBase,
2787-
stringAddrOffset);
2788-
stringAddr = subIGF.Builder.CreateIntToPtr(stringAddr, IGM.Int8PtrTy);
2778+
auto stringAddrBase = subIGF.Builder.CreatePtrToInt(cache, IGM.SizeTy);
2779+
if (IGM.getModule()->getDataLayout().isBigEndian()) {
2780+
stringAddrBase = subIGF.Builder.CreateAdd(stringAddrBase,
2781+
llvm::ConstantInt::get(IGM.SizeTy, 4));
27892782
}
2783+
stringAddr = subIGF.Builder.CreateAdd(stringAddrBase,
2784+
stringAddrOffset);
2785+
stringAddr = subIGF.Builder.CreateIntToPtr(stringAddr, IGM.Int8PtrTy);
27902786

27912787
llvm::CallInst *call;
27922788
if (request.isStaticallyAbstract()) {

stdlib/public/core/KeyPath.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2700,19 +2700,9 @@ internal protocol KeyPathPatternVisitor {
27002700

27012701
internal func _resolveRelativeAddress(_ base: UnsafeRawPointer,
27022702
_ offset: Int32) -> UnsafeRawPointer {
2703-
#if arch(wasm32)
2704-
// FIXME: If offset is 0, it means the pointer is null.
2705-
// For real relative pointer, it always calculates valid non-null address
2706-
// because the base address is always valid.
2707-
// But hacked absolute pointer can be null pointer.
2708-
// The return type doesn't allow nil, so return given base temporarily.
2709-
if offset == 0 { return base }
2710-
return UnsafeRawPointer(bitPattern: Int(offset)).unsafelyUnwrapped
2711-
#else
27122703
// Sign-extend the offset to pointer width and add with wrap on overflow.
27132704
return UnsafeRawPointer(bitPattern: Int(bitPattern: base) &+ Int(offset))
27142705
.unsafelyUnwrapped
2715-
#endif
27162706
}
27172707
internal func _resolveRelativeIndirectableAddress(_ base: UnsafeRawPointer,
27182708
_ offset: Int32)

0 commit comments

Comments
 (0)