llvm.org GIT mirror llvm / 876eaf1
According to ARM EABI, 8-bytes function arguments must be 8-bytes aligned. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34241 91177308-0d34-0410-b5e6-96231b3b80d8 Lauro Ramos Venancio 13 years ago
3 changed file(s) with 63 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
337337 }
338338
339339 static void
340 HowToPassArgument(MVT::ValueType ObjectVT,
341 unsigned NumGPRs, unsigned &ObjSize, unsigned &ObjGPRs) {
342 ObjSize = 0;
343 ObjGPRs = 0;
344
340 HowToPassArgument(MVT::ValueType ObjectVT, unsigned NumGPRs,
341 unsigned StackOffset, unsigned &NeededGPRs,
342 unsigned &NeededStackSize, unsigned &GPRPad,
343 unsigned &StackPad, unsigned Flags) {
344 NeededStackSize = 0;
345 NeededGPRs = 0;
346 StackPad = 0;
347 GPRPad = 0;
348 unsigned align = (Flags >> 27);
349 GPRPad = NumGPRs % ((align + 3)/4);
350 StackPad = StackOffset % align;
351 unsigned firstGPR = NumGPRs + GPRPad;
345352 switch (ObjectVT) {
346353 default: assert(0 && "Unhandled argument type!");
347354 case MVT::i32:
348355 case MVT::f32:
349 if (NumGPRs < 4)
350 ObjGPRs = 1;
356 if (firstGPR < 4)
357 NeededGPRs = 1;
351358 else
352 ObjSize = 4;
359 NeededStackSize = 4;
353360 break;
354361 case MVT::i64:
355362 case MVT::f64:
356 if (NumGPRs < 3)
357 ObjGPRs = 2;
358 else if (NumGPRs == 3) {
359 ObjGPRs = 1;
360 ObjSize = 4;
363 if (firstGPR < 3)
364 NeededGPRs = 2;
365 else if (firstGPR == 3) {
366 NeededGPRs = 1;
367 NeededStackSize = 4;
361368 } else
362 ObjSize = 8;
369 NeededStackSize = 8;
363370 }
364371 }
365372
382389
383390 // Add up all the space actually used.
384391 for (unsigned i = 0; i < NumOps; ++i) {
385 unsigned ObjSize = 0;
386 unsigned ObjGPRs = 0;
392 unsigned ObjSize;
393 unsigned ObjGPRs;
394 unsigned StackPad;
395 unsigned GPRPad;
387396 MVT::ValueType ObjectVT = Op.getOperand(5+2*i).getValueType();
388 HowToPassArgument(ObjectVT, NumGPRs, ObjSize, ObjGPRs);
389 NumBytes += ObjSize;
390 NumGPRs += ObjGPRs;
397 unsigned Flags = Op.getConstantOperandVal(5+2*i+1);
398 HowToPassArgument(ObjectVT, NumGPRs, NumBytes, ObjGPRs, ObjSize,
399 GPRPad, StackPad, Flags);
400 NumBytes += ObjSize + StackPad;
401 NumGPRs += ObjGPRs + GPRPad;
391402 }
392403
393404 // Adjust the stack pointer for the new arguments...
406417 std::vector MemOpChains;
407418 for (unsigned i = 0; i != NumOps; ++i) {
408419 SDOperand Arg = Op.getOperand(5+2*i);
420 unsigned Flags = Op.getConstantOperandVal(5+2*i+1);
409421 MVT::ValueType ArgVT = Arg.getValueType();
410422
411 unsigned ObjSize = 0;
412 unsigned ObjGPRs = 0;
413 HowToPassArgument(ArgVT, NumGPRs, ObjSize, ObjGPRs);
423 unsigned ObjSize;
424 unsigned ObjGPRs;
425 unsigned GPRPad;
426 unsigned StackPad;
427 HowToPassArgument(ArgVT, NumGPRs, ArgOffset, ObjGPRs,
428 ObjSize, GPRPad, StackPad, Flags);
429 NumGPRs += GPRPad;
430 ArgOffset += StackPad;
414431 if (ObjGPRs > 0) {
415432 switch (ArgVT) {
416433 default: assert(0 && "Unexpected ValueType for argument!");
417434 case MVT::i32:
418435 RegsToPass.push_back(std::make_pair(GPRArgRegs[NumGPRs], Arg));
419436 break;
420 case MVT::f32:
437 case MVT::f32:
421438 RegsToPass.push_back(std::make_pair(GPRArgRegs[NumGPRs],
422439 DAG.getNode(ISD::BIT_CONVERT, MVT::i32, Arg)));
423440 break;
435452 MemOpChains.push_back(DAG.getStore(Chain, Hi, PtrOff, NULL, 0));
436453 }
437454 break;
438 }
455 }
439456 case MVT::f64: {
440457 SDOperand Cvt = DAG.getNode(ARMISD::FMRRD,
441458 DAG.getVTList(MVT::i32, MVT::i32),
714731 }
715732
716733 static SDOperand LowerFORMAL_ARGUMENT(SDOperand Op, SelectionDAG &DAG,
717 unsigned *vRegs, unsigned ArgNo,
734 unsigned *vRegs, unsigned ArgNo,
718735 unsigned &NumGPRs, unsigned &ArgOffset) {
719736 MachineFunction &MF = DAG.getMachineFunction();
720737 MVT::ValueType ObjectVT = Op.getValue(ArgNo).getValueType();
726743 ARM::R0, ARM::R1, ARM::R2, ARM::R3
727744 };
728745
729 unsigned ObjSize = 0;
730 unsigned ObjGPRs = 0;
731 HowToPassArgument(ObjectVT, NumGPRs, ObjSize, ObjGPRs);
746 unsigned ObjSize;
747 unsigned ObjGPRs;
748 unsigned GPRPad;
749 unsigned StackPad;
750 unsigned Flags = Op.getConstantOperandVal(ArgNo + 3);
751 HowToPassArgument(ObjectVT, NumGPRs, ArgOffset, ObjGPRs,
752 ObjSize, GPRPad, StackPad, Flags);
753 NumGPRs += GPRPad;
754 ArgOffset += StackPad;
732755
733756 SDOperand ArgValue;
734757 if (ObjGPRs == 1) {
3838 std::string("e-p:32:32-d:32:32-l:32:32-s:16:32-b:8:32-B:8:32-A:32") :
3939 std::string("e-p:32:32-d:32:32-l:32:32")) :
4040 (Subtarget.isThumb() ?
41 std::string("e-p:32:32-d:32:64-l:32:64-s:16:32-b:8:32-B:8:32-A:32") :
42 std::string("e-p:32:32-d:32:64-l:32:64"))),
41 std::string("e-p:32:32-d:32:64-l:64:64-s:16:32-b:8:32-B:8:32-A:32") :
42 std::string("e-p:32:32-d:32:64-l:64:64"))),
4343 InstrInfo(Subtarget),
4444 FrameInfo(Subtarget) {}
4545
0 ; RUN: llvm-as < %s | llc -march=arm &&
1 ; RUN: llvm-as < %s | llc -mtriple=arm-linux | grep "mov r0, r2" | wc -l | grep 1 &&
2 ; RUN: llvm-as < %s | llc -mtriple=arm-apple-darwin | grep "mov r0, r1" | wc -l | grep 1
3
4 define i32 @f(i32 %a, i64 %b) {
5 %tmp = call i32 @g(i64 %b)
6 ret i32 %tmp
7 }
8
9 declare i32 @g(i64)