[PATCH] D13554: [X86] Enable soft float ABI for x86

Michael Kuperstein via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 8 07:43:17 PDT 2015


mkuper created this revision.
mkuper added reviewers: rafael, rnk.
mkuper added a subscriber: cfe-commits.

The Intel MCU psABI is a new soft-float ABI, based on the IA32 psABI. 
The document describing the ABI can be found here: https://github.com/hjl-tools/x86-psABI/wiki/iamcu-psABI-0.7.pdf 

Perhaps the biggest difference between the IA32 and MCU ABIs is that the MCU ABI is soft-float. 
This patch makes the x86-32 ABI code respect "-mfloat-abi soft" and generate float inreg arguments.

This is the first patch in a series - there will be separate patches to add the "-miamcu" driver option, as well as more ABI adjustments to actually make it work.

(I'll clean up the one-letter variable names in a separate commit.)

http://reviews.llvm.org/D13554

Files:
  lib/CodeGen/TargetInfo.cpp
  test/CodeGen/x86-soft-float.c

Index: lib/CodeGen/TargetInfo.cpp
===================================================================
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -798,6 +798,7 @@
   bool IsDarwinVectorABI;
   bool IsSmallStructInRegABI;
   bool IsWin32StructABI;
+  bool IsSoftFloatABI;
   unsigned DefaultNumRegisterParameters;
 
   static bool isRegisterSize(unsigned Size) {
@@ -846,16 +847,17 @@
                     QualType Ty) const override;
 
   X86_32ABIInfo(CodeGen::CodeGenTypes &CGT, bool d, bool p, bool w,
-                unsigned r)
+                unsigned r, bool s)
     : ABIInfo(CGT), IsDarwinVectorABI(d), IsSmallStructInRegABI(p),
-      IsWin32StructABI(w), DefaultNumRegisterParameters(r) {}
+      IsWin32StructABI(w), DefaultNumRegisterParameters(r),
+      IsSoftFloatABI(s) {}
 };
 
 class X86_32TargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   X86_32TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT,
-      bool d, bool p, bool w, unsigned r)
-    :TargetCodeGenInfo(new X86_32ABIInfo(CGT, d, p, w, r)) {}
+      bool d, bool p, bool w, unsigned r, bool s)
+    :TargetCodeGenInfo(new X86_32ABIInfo(CGT, d, p, w, r, s)) {}
 
   static bool isStructReturnInRegABI(
       const llvm::Triple &Triple, const CodeGenOptions &Opts);
@@ -1206,10 +1208,12 @@
 bool X86_32ABIInfo::shouldUseInReg(QualType Ty, CCState &State,
                                    bool &NeedsPadding) const {
   NeedsPadding = false;
-  Class C = classify(Ty);
-  if (C == Float)
-    return false;
-
+  if (!IsSoftFloatABI) {
+    Class C = classify(Ty);  
+    if (C == Float)
+      return false;
+  }
+  
   unsigned Size = getContext().getTypeSize(Ty);
   unsigned SizeInRegs = (Size + 31) / 32;
 
@@ -1877,7 +1881,7 @@
 public:
   WinX86_32TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT,
         bool d, bool p, bool w, unsigned RegParms)
-    : X86_32TargetCodeGenInfo(CGT, d, p, w, RegParms) {}
+    : X86_32TargetCodeGenInfo(CGT, d, p, w, RegParms, false) {}
 
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
                            CodeGen::CodeGenModule &CGM) const override;
@@ -7389,7 +7393,8 @@
     } else {
       return *(TheTargetCodeGenInfo = new X86_32TargetCodeGenInfo(
                    Types, IsDarwinVectorABI, IsSmallStructInRegABI,
-                   IsWin32FloatStructABI, CodeGenOpts.NumRegisterParameters));
+                   IsWin32FloatStructABI, CodeGenOpts.NumRegisterParameters,
+                   CodeGenOpts.FloatABI == "soft"));
     }
   }
 
Index: test/CodeGen/x86-soft-float.c
===================================================================
--- test/CodeGen/x86-soft-float.c
+++ test/CodeGen/x86-soft-float.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple i386-unknown-unknown -mregparm 3 -emit-llvm %s -o - | FileCheck %s -check-prefix=HARD
+// RUN: %clang_cc1 -triple i386-unknown-unknown -mregparm 3 -mfloat-abi soft -emit-llvm %s -o - | FileCheck %s -check-prefix=SOFT
+
+// HARD: define void @f1(float %a)
+// SOFT: define void @f1(float inreg %a)
+void f1(float a) {}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13554.36853.patch
Type: text/x-patch
Size: 3124 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151008/aea64a0f/attachment-0001.bin>


More information about the cfe-commits mailing list