[clang] ac02baa - WebAssembly: Update datalayout to match fp128 ABI change

Derek Schuff via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 9 16:52:14 PDT 2021


Author: Derek Schuff
Date: 2021-07-09T16:51:36-07:00
New Revision: ac02baab48c2ff512e40140e2fe6845d2b6a636f

URL: https://github.com/llvm/llvm-project/commit/ac02baab48c2ff512e40140e2fe6845d2b6a636f
DIFF: https://github.com/llvm/llvm-project/commit/ac02baab48c2ff512e40140e2fe6845d2b6a636f.diff

LOG: WebAssembly: Update datalayout to match fp128 ABI change

This fix goes along with d1a96e906cc03a95cfd41a1f22bdda92651250c7
and makes the fp128 alignment match clang's long double alignment.

Differential Revision: https://reviews.llvm.org/D105749

Added: 
    

Modified: 
    clang/lib/Basic/Targets/WebAssembly.h
    llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
    llvm/test/CodeGen/WebAssembly/varargs.ll

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Targets/WebAssembly.h b/clang/lib/Basic/Targets/WebAssembly.h
index c3e5d7e572c3..a43e770eb1e8 100644
--- a/clang/lib/Basic/Targets/WebAssembly.h
+++ b/clang/lib/Basic/Targets/WebAssembly.h
@@ -149,7 +149,10 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
   explicit WebAssembly32TargetInfo(const llvm::Triple &T,
                                    const TargetOptions &Opts)
       : WebAssemblyTargetInfo(T, Opts) {
-    resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128-ni:1");
+    if (T.isOSEmscripten())
+      resetDataLayout("e-m:e-p:32:32-i64:64-f128:64-n32:64-S128-ni:1");
+    else
+      resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128-ni:1");
   }
 
 protected:
@@ -168,7 +171,10 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
     SizeType = UnsignedLong;
     PtrDiffType = SignedLong;
     IntPtrType = SignedLong;
-    resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128-ni:1");
+    if (T.isOSEmscripten())
+      resetDataLayout("e-m:e-p:64:64-i64:64-f128:64-n32:64-S128-ni:1");
+    else
+      resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128-ni:1");
   }
 
 protected:

diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
index a0c7c778767c..6a37903da4f5 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -120,12 +120,17 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine(
     const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
     const TargetOptions &Options, Optional<Reloc::Model> RM,
     Optional<CodeModel::Model> CM, CodeGenOpt::Level OL, bool JIT)
-    : LLVMTargetMachine(T,
-                        TT.isArch64Bit()
-                            ? "e-m:e-p:64:64-i64:64-n32:64-S128-ni:1"
-                            : "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1",
-                        TT, CPU, FS, Options, getEffectiveRelocModel(RM, TT),
-                        getEffectiveCodeModel(CM, CodeModel::Large), OL),
+    : LLVMTargetMachine(
+          T,
+          TT.isArch64Bit()
+              ? (TT.isOSEmscripten()
+                     ? "e-m:e-p:64:64-i64:64-f128:64-n32:64-S128-ni:1"
+                     : "e-m:e-p:64:64-i64:64-n32:64-S128-ni:1")
+              : (TT.isOSEmscripten()
+                     ? "e-m:e-p:32:32-i64:64-f128:64-n32:64-S128-ni:1"
+                     : "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1"),
+          TT, CPU, FS, Options, getEffectiveRelocModel(RM, TT),
+          getEffectiveCodeModel(CM, CodeModel::Large), OL),
       TLOF(new WebAssemblyTargetObjectFile()) {
   // WebAssembly type-checks instructions, but a noreturn function with a return
   // type that doesn't match the context will cause a check failure. So we lower

diff  --git a/llvm/test/CodeGen/WebAssembly/varargs.ll b/llvm/test/CodeGen/WebAssembly/varargs.ll
index c36912854c0c..7a9f0b08c1f4 100644
--- a/llvm/test/CodeGen/WebAssembly/varargs.ll
+++ b/llvm/test/CodeGen/WebAssembly/varargs.ll
@@ -2,8 +2,7 @@
 
 ; Test varargs constructs.
 
-target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
-target triple = "wasm32-unknown-unknown"
+target triple = "wasm32-unknown-emscripten"
 
 ; Test va_start.
 
@@ -167,21 +166,19 @@ define void @nonlegal_fixed(fp128 %x, ...) nounwind {
 ; within a vararg buffer.
 
 ; CHECK-LABEL: call_fp128_alignment:
-; CHECK:      global.get      $push7=, __stack_pointer
-; CHECK-NEXT: i32.const       $push8=, 32
-; CHECK-NEXT: i32.sub         $push12=, $pop7, $pop8
-; CHECK-NEXT: local.tee       $push11=, $1=, $pop12
-; CHECK-NEXT: global.set      __stack_pointer, $pop11
-; CHECK-NEXT: i32.const       $push0=, 24
+; CHECK:      global.get      $push5=, __stack_pointer
+; CHECK-NEXT: i32.const       $push6=, 32
+; CHECK-NEXT: i32.sub         $push10=, $pop5, $pop6
+; CHECK-NEXT: local.tee       $push9=, $1=, $pop10
+; CHECK-NEXT: global.set      __stack_pointer, $pop9
+; CHECK-NEXT: i32.const       $push0=, 16
 ; CHECK-NEXT: i32.add         $push1=, $1, $pop0
 ; CHECK-NEXT: i64.const       $push2=, -9223372036854775808
 ; CHECK-NEXT: i64.store       0($pop1), $pop2
-; CHECK-NEXT: i32.const       $push3=, 16
-; CHECK-NEXT: i32.add         $push4=, $1, $pop3
-; CHECK-NEXT: i64.const       $push5=, 1
-; CHECK-NEXT: i64.store       0($pop4), $pop5
-; CHECK-NEXT: i32.const       $push6=, 7
-; CHECK-NEXT: i32.store       0($1), $pop6
+; CHECK-NEXT: i64.const       $push3=, 1
+; CHECK-NEXT: i64.store       8($1), $pop3
+; CHECK-NEXT: i32.const       $push4=, 7
+; CHECK-NEXT: i32.store       0($1), $pop4
 ; CHECK-NEXT: call            callee, $1
 define void @call_fp128_alignment(i8* %p) {
 entry:


        


More information about the cfe-commits mailing list