llvm.org GIT mirror llvm / 1a00946
initial support for variable number of arguments git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29567 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 13 years ago
3 changed file(s) with 50 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
7878 unsigned CallConv = cast(Op.getOperand(1))->getValue();
7979 assert(CallConv == CallingConv::C && "unknown calling convention");
8080 bool isVarArg = cast(Op.getOperand(2))->getValue() != 0;
81 assert(isVarArg == false && "VarArg not supported");
8281 bool isTailCall = cast(Op.getOperand(3))->getValue() != 0;
8382 assert(isTailCall == false && "tail call not supported");
8483 SDOperand Callee = Op.getOperand(4);
8887 // only the link register.
8988 unsigned NumBytes = 4;
9089
91 assert(NumOps <= 4); //no args on the stack
90 // Add up all the space actually used.
91 for (unsigned i = 4; i < NumOps; ++i)
92 NumBytes += MVT::getSizeInBits(Op.getOperand(5+2*i).getValueType())/8;
9293
9394 // Adjust the stack pointer for the new arguments...
9495 // These operations are automatically eliminated by the prolog/epilog pass
9596 Chain = DAG.getCALLSEQ_START(Chain,
9697 DAG.getConstant(NumBytes, MVT::i32));
9798
98 static const unsigned regs[] = {
99 SDOperand StackPtr = DAG.getRegister(ARM::R13, MVT::i32);
100
101 static const unsigned int num_regs = 4;
102 static const unsigned regs[num_regs] = {
99103 ARM::R0, ARM::R1, ARM::R2, ARM::R3
100104 };
101105
102106 std::vector > RegsToPass;
107 std::vector MemOpChains;
103108
104109 for (unsigned i = 0; i != NumOps; ++i) {
105110 SDOperand Arg = Op.getOperand(5+2*i);
106 RegsToPass.push_back(std::make_pair(regs[i], Arg));
107 }
111 assert(Arg.getValueType() == MVT::i32);
112 if (i < num_regs)
113 RegsToPass.push_back(std::make_pair(regs[i], Arg));
114 else {
115 unsigned ArgOffset = (i - num_regs) * 4;
116 SDOperand PtrOff = DAG.getConstant(ArgOffset, StackPtr.getValueType());
117 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
118 MemOpChains.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
119 Arg, PtrOff, DAG.getSrcValue(NULL)));
120 }
121 }
122 if (!MemOpChains.empty())
123 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, MemOpChains);
108124
109125 // Build a sequence of copy-to-reg nodes chained together with token chain
110126 // and flag operands which copy the outgoing args into the appropriate regs.
123123 //hack
124124 assert(NumBytes == 0);
125125
126 //sub sp, sp, #4
127 BuildMI(MBB, MBBI, ARM::subri, 2, ARM::R13).addReg(ARM::R13).addImm(4);
128 //str lr, [sp]
129 BuildMI(MBB, MBBI, ARM::str, 1, ARM::R14).addReg(ARM::R13);
126 if (MFI->hasCalls()) {
127 // We reserve argument space for call sites in the function immediately on
128 // entry to the current function. This eliminates the need for add/sub
129 // brackets around call sites.
130 NumBytes += MFI->getMaxCallFrameSize();
131 }
132
133 MFI->setStackSize(NumBytes);
134
135 //sub sp, sp, #NumBytes
136 BuildMI(MBB, MBBI, ARM::subri, 2, ARM::R13).addReg(ARM::R13).addImm(NumBytes);
137 //add ip, sp, #NumBytes - 4
138 BuildMI(MBB, MBBI, ARM::addri, 2, ARM::R12).addReg(ARM::R13).addImm(NumBytes - 4);
139 //str lr, [ip]
140 BuildMI(MBB, MBBI, ARM::str, 1, ARM::R14).addReg(ARM::R12);
130141 }
131142
132143 void ARMRegisterInfo::emitEpilogue(MachineFunction &MF,
137148
138149 MachineFrameInfo *MFI = MF.getFrameInfo();
139150 int NumBytes = (int) MFI->getStackSize();
140 //hack
141 assert(NumBytes == 0);
142151
143152 //ldr lr, [sp]
144153 BuildMI(MBB, MBBI, ARM::ldr, 2, ARM::R14).addImm(0).addReg(ARM::R13);
145 //add sp, sp, #4
146 BuildMI(MBB, MBBI, ARM::addri, 2, ARM::R13).addReg(ARM::R13).addImm(4);
154 //add sp, sp, #NumBytes
155 BuildMI(MBB, MBBI, ARM::addri, 2, ARM::R13).addReg(ARM::R13).addImm(NumBytes);
147156 }
148157
149158 unsigned ARMRegisterInfo::getRARegister() const {
0 ; RUN: llvm-as < %s | llc -march=arm
1 %str = internal constant [43 x sbyte] c"Hello World %d %d %d %d %d %d %d %d %d %d\0A\00" ; <[43 x sbyte]*> [#uses=1]
2
3 implementation ; Functions:
4
5 int %main() {
6 entry:
7 %tmp = call int (sbyte*, ...)* %printf( sbyte* getelementptr ([43 x sbyte]* %str, int 0, uint 0), int 1, int 2, int 3, int 4, int 5, int 6, int 7, int 8, int 9, int 10 ) ; [#uses=0]
8 ret int 0
9 }
10
11 declare int %printf(sbyte*, ...)