From 1655be290cf871f22b1da1fc700ad9e1deab2a01 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Sun, 12 Jan 2014 04:13:17 +0000 Subject: The SPARCv9 ABI returns a float in %f0. This is different from the argument passing convention which puts the first float argument in %f1. With this patch, all returned floats are treated as if the 'inreg' flag were set. This means multiple float return values get packed in %f0, %f1, %f2, ... Note that when returning a struct in registers, clang will set the 'inreg' flag on the return value, so that behavior is unchanged. This also happens when returning a float _Complex. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199028 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/Sparc/SparcCallingConv.td | 11 ++++++++++- lib/Target/Sparc/SparcISelLowering.cpp | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/Target/Sparc/SparcCallingConv.td b/lib/Target/Sparc/SparcCallingConv.td index acd4ec21de..dfaaabf344 100644 --- a/lib/Target/Sparc/SparcCallingConv.td +++ b/lib/Target/Sparc/SparcCallingConv.td @@ -103,7 +103,7 @@ def RetCC_Sparc32 : CallingConv<[ // Function return values are passed exactly like function arguments, except a // struct up to 32 bytes in size can be returned in registers. -// Function arguments AND return values. +// Function arguments AND most return values. def CC_Sparc64 : CallingConv<[ // The frontend uses the inreg flag to indicate i32 and float arguments from // structs. These arguments are not promoted to 64 bits, but they can still @@ -118,6 +118,15 @@ def CC_Sparc64 : CallingConv<[ CCCustom<"CC_Sparc64_Full"> ]>; +def RetCC_Sparc64 : CallingConv<[ + // A single f32 return value always goes in %f0. The ABI doesn't specify what + // happens to multiple f32 return values outside a struct. + CCIfType<[f32], CCCustom<"CC_Sparc64_Half">>, + + // Otherwise, return values are passed exactly like arguments. + CCDelegateTo +]>; + // Callee-saved registers are handled by the register window mechanism. def CSR : CalleeSavedRegs<(add)> { let OtherPreserved = (add (sequence "I%u", 0, 7), diff --git a/lib/Target/Sparc/SparcISelLowering.cpp b/lib/Target/Sparc/SparcISelLowering.cpp index 2fce971edf..fce2c0d5b0 100644 --- a/lib/Target/Sparc/SparcISelLowering.cpp +++ b/lib/Target/Sparc/SparcISelLowering.cpp @@ -254,7 +254,7 @@ SparcTargetLowering::LowerReturn_64(SDValue Chain, DAG.getTarget(), RVLocs, *DAG.getContext()); // Analyze return values. - CCInfo.AnalyzeReturn(Outs, CC_Sparc64); + CCInfo.AnalyzeReturn(Outs, RetCC_Sparc64); SDValue Flag; SmallVector RetOps(1, Chain); @@ -1258,7 +1258,7 @@ SparcTargetLowering::LowerCall_64(TargetLowering::CallLoweringInfo &CLI, if (CLI.Ins.size() == 1 && CLI.Ins[0].VT == MVT::f32 && CLI.CS == 0) CLI.Ins[0].Flags.setInReg(); - RVInfo.AnalyzeCallResult(CLI.Ins, CC_Sparc64); + RVInfo.AnalyzeCallResult(CLI.Ins, RetCC_Sparc64); // Copy all of the result registers out of their specified physreg. for (unsigned i = 0; i != RVLocs.size(); ++i) { -- cgit v1.2.3