[llvm-commits] [llvm] r123974 - in /llvm/trunk: lib/Target/Sparc/SparcISelLowering.cpp test/CodeGen/SPARC/2011-01-21-ByValArgs.ll
Venkatraman Govindaraju
venkatra at cs.wisc.edu
Fri Jan 21 06:00:01 PST 2011
Author: venkatra
Date: Fri Jan 21 08:00:01 2011
New Revision: 123974
URL: http://llvm.org/viewvc/llvm-project?rev=123974&view=rev
Log:
Implement support for byval arguments in Sparc backend.
Added:
llvm/trunk/test/CodeGen/SPARC/2011-01-21-ByValArgs.ll
Modified:
llvm/trunk/lib/Target/Sparc/SparcISelLowering.cpp
Modified: llvm/trunk/lib/Target/Sparc/SparcISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/SparcISelLowering.cpp?rev=123974&r1=123973&r2=123974&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Sparc/SparcISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/Sparc/SparcISelLowering.cpp Fri Jan 21 08:00:01 2011
@@ -313,6 +313,30 @@
// Keep stack frames 8-byte aligned.
ArgsSize = (ArgsSize+7) & ~7;
+ MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo();
+
+ //Create local copies for byval args.
+ SmallVector<SDValue, 8> ByValArgs;
+ for (unsigned i = 0, e = Outs.size(); i != e; ++i) {
+ ISD::ArgFlagsTy Flags = Outs[i].Flags;
+ if (!Flags.isByVal())
+ continue;
+
+ SDValue Arg = OutVals[i];
+ unsigned Size = Flags.getByValSize();
+ unsigned Align = Flags.getByValAlign();
+
+ int FI = MFI->CreateStackObject(Size, Align, false);
+ SDValue FIPtr = DAG.getFrameIndex(FI, getPointerTy());
+ SDValue SizeNode = DAG.getConstant(Size, MVT::i32);
+
+ Chain = DAG.getMemcpy(Chain, dl, FIPtr, Arg, SizeNode, Align,
+ false, //isVolatile,
+ (Size <= 32), //AlwaysInline if size <= 32
+ MachinePointerInfo(), MachinePointerInfo());
+ ByValArgs.push_back(FIPtr);
+ }
+
Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(ArgsSize, true));
SmallVector<std::pair<unsigned, SDValue>, 8> RegsToPass;
@@ -320,12 +344,18 @@
const unsigned StackOffset = 92;
// Walk the register/memloc assignments, inserting copies/loads.
- for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size();
+ for (unsigned i = 0, realArgIdx = 0, byvalArgIdx = 0, e = ArgLocs.size();
i != e;
++i, ++realArgIdx) {
CCValAssign &VA = ArgLocs[i];
SDValue Arg = OutVals[realArgIdx];
+ ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags;
+
+ //Use local copy if it is a byval arg.
+ if (Flags.isByVal())
+ Arg = ByValArgs[byvalArgIdx++];
+
// Promote the value if needed.
switch (VA.getLocInfo()) {
default: llvm_unreachable("Unknown loc info!");
Added: llvm/trunk/test/CodeGen/SPARC/2011-01-21-ByValArgs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/SPARC/2011-01-21-ByValArgs.ll?rev=123974&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/SPARC/2011-01-21-ByValArgs.ll (added)
+++ llvm/trunk/test/CodeGen/SPARC/2011-01-21-ByValArgs.ll Fri Jan 21 08:00:01 2011
@@ -0,0 +1,18 @@
+;RUN: llc -march=sparc < %s | FileCheck %s
+
+%struct.foo_t = type { i32, i32, i32 }
+
+ at s = internal unnamed_addr global %struct.foo_t { i32 10, i32 20, i32 30 }
+
+define i32 @test() nounwind {
+entry:
+;CHECK: test
+;CHECK: st
+;CHECK: st
+;CHECK: st
+;CHECK: bar
+ %0 = tail call i32 @bar(%struct.foo_t* byval @s) nounwind
+ ret i32 %0
+}
+
+declare i32 @bar(%struct.foo_t* byval)
More information about the llvm-commits
mailing list