[pkg-d-commits] [ldc] 08/12: Attempt to fix PPC64-LE, MIPS64 and ARM/AArch64 ABIs

Matthias Klumpp mak at moszumanska.debian.org
Sun Apr 23 22:35:57 UTC 2017


This is an automated email from the git hooks/post-receive script.

mak pushed a commit to annotated tag v0.17.3
in repository ldc.

commit 641e775c5222718b4d78c52385a923dedb1e7700
Author: Martin <noone at nowhere.com>
Date:   Tue Nov 29 22:07:48 2016 +0100

    Attempt to fix PPC64-LE, MIPS64 and ARM/AArch64 ABIs
    
    Most importantly, make sure sret is enforced for all non-POD structs as
    done for all other ABIs, and don't treat extern(D) any different from the
    C ABI wrt. return values anymore.
    
    Also reduce code duplication via common TargetABI patterns.
---
 gen/abi-aarch64.cpp | 10 +++-------
 gen/abi-arm.cpp     |  7 ++-----
 gen/abi-mips64.cpp  | 10 +++++++++-
 gen/abi-ppc64le.cpp | 38 ++++++++------------------------------
 4 files changed, 22 insertions(+), 43 deletions(-)

diff --git a/gen/abi-aarch64.cpp b/gen/abi-aarch64.cpp
index 5a63613..d94cd7c 100644
--- a/gen/abi-aarch64.cpp
+++ b/gen/abi-aarch64.cpp
@@ -28,12 +28,10 @@ struct AArch64TargetABI : TargetABI {
 
     Type *rt = tf->next->toBasetype();
 
-    // FIXME
-    if (tf->linkage == LINKd)
-      return rt->ty == Tsarray || rt->ty == Tstruct;
+    if (!isPOD(rt))
+      return true;
 
-    return rt->ty == Tsarray ||
-      (rt->ty == Tstruct && rt->size() > 16 && !isHFA((TypeStruct *)rt));
+    return passByVal(rt);
   }
 
   bool passByVal(Type *t) override {
@@ -60,8 +58,6 @@ struct AArch64TargetABI : TargetABI {
     for (auto arg : fty.args) {
       if (!arg->byref)
         rewriteArgument(fty, *arg);
-      else if (passByVal(arg->type))
-        arg->attrs.remove(LLAttribute::ByVal);
     }
 
     // extern(D): reverse parameter order for non variadics, for DMD-compliance
diff --git a/gen/abi-arm.cpp b/gen/abi-arm.cpp
index c302f4b..431b3b5 100644
--- a/gen/abi-arm.cpp
+++ b/gen/abi-arm.cpp
@@ -32,11 +32,8 @@ struct ArmTargetABI : TargetABI {
       return false;
     Type *rt = tf->next->toBasetype();
 
-    // For extern(D), always return structs by arg because of problem with
-    // non-POD structs (failure in std.algorithm.move when struct has a ctor).
-    // TODO: figure out what the problem is
-    if (tf->linkage == LINKd)
-      return rt->ty == Tsarray || rt->ty == Tstruct;
+    if (!isPOD(rt))
+      return true;
 
     return rt->ty == Tsarray ||
            (rt->ty == Tstruct && rt->size() > 4 &&
diff --git a/gen/abi-mips64.cpp b/gen/abi-mips64.cpp
index 7f013f0..439a82f 100644
--- a/gen/abi-mips64.cpp
+++ b/gen/abi-mips64.cpp
@@ -30,11 +30,15 @@ struct MIPS64TargetABI : TargetABI {
       return false;
     }
 
+    Type *rt = tf->next->toBasetype();
+
+    if (!isPOD(rt))
+      return true;
+
     // Return structs and static arrays on the stack. The latter is needed
     // because otherwise LLVM tries to actually return the array in a number
     // of physical registers, which leads, depending on the target, to
     // either horrendous codegen or backend crashes.
-    Type *rt = tf->next->toBasetype();
     return (rt->ty == Tstruct || rt->ty == Tsarray);
   }
 
@@ -44,6 +48,10 @@ struct MIPS64TargetABI : TargetABI {
   }
 
   void rewriteFunctionType(TypeFunction *tf, IrFuncTy &fty) override {
+    if (!fty.ret->byref) {
+      rewriteArgument(fty, *fty.ret);
+    }
+
     for (auto arg : fty.args) {
       if (!arg->byref) {
         rewriteArgument(fty, *arg);
diff --git a/gen/abi-ppc64le.cpp b/gen/abi-ppc64le.cpp
index 7220b03..bbcc7c4 100644
--- a/gen/abi-ppc64le.cpp
+++ b/gen/abi-ppc64le.cpp
@@ -35,18 +35,10 @@ struct PPC64LETargetABI : TargetABI {
 
     Type *rt = tf->next->toBasetype();
 
-    // FIXME: The return value of this function translates
-    // to RETstack or RETregs in function retStyle(), which
-    // directly influences if NRVO is possible or not
-    // (false -> RETregs -> nrvo_can = false). Depending on
-    // NRVO, the postblit constructor is called or not.
-    // Thus using the rules of the C ABI here (as mandated by
-    // the D specification) leads to crashes.
-    if (tf->linkage == LINKd)
-      return rt->ty == Tsarray || rt->ty == Tstruct;
+    if (!isPOD(rt))
+      return true;
 
-    return rt->ty == Tsarray || (rt->ty == Tstruct && rt->size() > 16 &&
-                                 !isHFA((TypeStruct *)rt, nullptr, 8));
+    return passByVal(rt);
   }
 
   bool passByVal(Type *t) override {
@@ -56,28 +48,13 @@ struct PPC64LETargetABI : TargetABI {
   }
 
   void rewriteFunctionType(TypeFunction *tf, IrFuncTy &fty) override {
-    // RETURN VALUE
+    // return value
     Type *retTy = fty.ret->type->toBasetype();
     if (!fty.ret->byref) {
-      if (retTy->ty == Tstruct || retTy->ty == Tsarray) {
-        if (retTy->ty == Tstruct &&
-            isHFA((TypeStruct *)retTy, &fty.ret->ltype, 8)) {
-          fty.ret->rewrite = &hfaToArray;
-          fty.ret->ltype = hfaToArray.type(fty.ret->type, fty.ret->ltype);
-        } else if (canRewriteAsInt(retTy, true)) {
-          fty.ret->rewrite = &integerRewrite;
-          fty.ret->ltype = integerRewrite.type(fty.ret->type, fty.ret->ltype);
-        } else {
-          fty.ret->rewrite = &compositeToArray64;
-          fty.ret->ltype =
-              compositeToArray64.type(fty.ret->type, fty.ret->ltype);
-        }
-      } else if (retTy->isintegral())
-        fty.ret->attrs.add(retTy->isunsigned() ? LLAttribute::ZExt
-                                               : LLAttribute::SExt);
+      rewriteArgument(fty, *fty.ret);
     }
 
-    // EXPLICIT PARAMETERS
+    // explicit parameters
     for (auto arg : fty.args) {
       if (!arg->byref) {
         rewriteArgument(fty, *arg);
@@ -103,8 +80,9 @@ struct PPC64LETargetABI : TargetABI {
         arg.rewrite = &compositeToArray64;
         arg.ltype = compositeToArray64.type(arg.type, arg.ltype);
       }
-    } else if (ty->isintegral())
+    } else if (ty->isintegral()) {
       arg.attrs.add(ty->isunsigned() ? LLAttribute::ZExt : LLAttribute::SExt);
+    }
   }
 };
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git



More information about the pkg-d-commits mailing list