Skip to content

Commit ac02baa

Browse files
committed
WebAssembly: Update datalayout to match fp128 ABI change
This fix goes along with d1a96e9 and makes the fp128 alignment match clang's long double alignment. Differential Revision: https://reviews.llvm.org/D105749
1 parent fc01faf commit ac02baa

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

clang/lib/Basic/Targets/WebAssembly.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
149149
explicit WebAssembly32TargetInfo(const llvm::Triple &T,
150150
const TargetOptions &Opts)
151151
: WebAssemblyTargetInfo(T, Opts) {
152-
resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128-ni:1");
152+
if (T.isOSEmscripten())
153+
resetDataLayout("e-m:e-p:32:32-i64:64-f128:64-n32:64-S128-ni:1");
154+
else
155+
resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128-ni:1");
153156
}
154157

155158
protected:
@@ -168,7 +171,10 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
168171
SizeType = UnsignedLong;
169172
PtrDiffType = SignedLong;
170173
IntPtrType = SignedLong;
171-
resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128-ni:1");
174+
if (T.isOSEmscripten())
175+
resetDataLayout("e-m:e-p:64:64-i64:64-f128:64-n32:64-S128-ni:1");
176+
else
177+
resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128-ni:1");
172178
}
173179

174180
protected:

llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,17 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine(
120120
const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
121121
const TargetOptions &Options, Optional<Reloc::Model> RM,
122122
Optional<CodeModel::Model> CM, CodeGenOpt::Level OL, bool JIT)
123-
: LLVMTargetMachine(T,
124-
TT.isArch64Bit()
125-
? "e-m:e-p:64:64-i64:64-n32:64-S128-ni:1"
126-
: "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1",
127-
TT, CPU, FS, Options, getEffectiveRelocModel(RM, TT),
128-
getEffectiveCodeModel(CM, CodeModel::Large), OL),
123+
: LLVMTargetMachine(
124+
T,
125+
TT.isArch64Bit()
126+
? (TT.isOSEmscripten()
127+
? "e-m:e-p:64:64-i64:64-f128:64-n32:64-S128-ni:1"
128+
: "e-m:e-p:64:64-i64:64-n32:64-S128-ni:1")
129+
: (TT.isOSEmscripten()
130+
? "e-m:e-p:32:32-i64:64-f128:64-n32:64-S128-ni:1"
131+
: "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1"),
132+
TT, CPU, FS, Options, getEffectiveRelocModel(RM, TT),
133+
getEffectiveCodeModel(CM, CodeModel::Large), OL),
129134
TLOF(new WebAssemblyTargetObjectFile()) {
130135
// WebAssembly type-checks instructions, but a noreturn function with a return
131136
// type that doesn't match the context will cause a check failure. So we lower

llvm/test/CodeGen/WebAssembly/varargs.ll

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
; Test varargs constructs.
44

5-
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
6-
target triple = "wasm32-unknown-unknown"
5+
target triple = "wasm32-unknown-emscripten"
76

87
; Test va_start.
98

@@ -167,21 +166,19 @@ define void @nonlegal_fixed(fp128 %x, ...) nounwind {
167166
; within a vararg buffer.
168167

169168
; CHECK-LABEL: call_fp128_alignment:
170-
; CHECK: global.get $push7=, __stack_pointer
171-
; CHECK-NEXT: i32.const $push8=, 32
172-
; CHECK-NEXT: i32.sub $push12=, $pop7, $pop8
173-
; CHECK-NEXT: local.tee $push11=, $1=, $pop12
174-
; CHECK-NEXT: global.set __stack_pointer, $pop11
175-
; CHECK-NEXT: i32.const $push0=, 24
169+
; CHECK: global.get $push5=, __stack_pointer
170+
; CHECK-NEXT: i32.const $push6=, 32
171+
; CHECK-NEXT: i32.sub $push10=, $pop5, $pop6
172+
; CHECK-NEXT: local.tee $push9=, $1=, $pop10
173+
; CHECK-NEXT: global.set __stack_pointer, $pop9
174+
; CHECK-NEXT: i32.const $push0=, 16
176175
; CHECK-NEXT: i32.add $push1=, $1, $pop0
177176
; CHECK-NEXT: i64.const $push2=, -9223372036854775808
178177
; CHECK-NEXT: i64.store 0($pop1), $pop2
179-
; CHECK-NEXT: i32.const $push3=, 16
180-
; CHECK-NEXT: i32.add $push4=, $1, $pop3
181-
; CHECK-NEXT: i64.const $push5=, 1
182-
; CHECK-NEXT: i64.store 0($pop4), $pop5
183-
; CHECK-NEXT: i32.const $push6=, 7
184-
; CHECK-NEXT: i32.store 0($1), $pop6
178+
; CHECK-NEXT: i64.const $push3=, 1
179+
; CHECK-NEXT: i64.store 8($1), $pop3
180+
; CHECK-NEXT: i32.const $push4=, 7
181+
; CHECK-NEXT: i32.store 0($1), $pop4
185182
; CHECK-NEXT: call callee, $1
186183
define void @call_fp128_alignment(i8* %p) {
187184
entry:

0 commit comments

Comments
 (0)