@@ -473,9 +473,11 @@ SDValue SBFTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
473
473
SmallVector<std::pair<unsigned , SDValue>, MaxArgs> RegsToPass;
474
474
475
475
// Walk arg assignments
476
- bool HasStackArgs = false ;
477
- unsigned e, i, ae = ArgLocs.size ();
478
- for (i = 0 , e = ae; i != e; ++i) {
476
+ unsigned i;
477
+ SmallVector<SDValue, 8 > MemOpChain;
478
+ SBFFunctionInfo * SBFFuncInfo = MF.getInfo <SBFFunctionInfo>();
479
+
480
+ for (i = 0 ; i < ArgLocs.size (); i++) {
479
481
CCValAssign &VA = ArgLocs[i];
480
482
SDValue Arg = OutVals[i];
481
483
@@ -496,37 +498,13 @@ SDValue SBFTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
496
498
break ;
497
499
}
498
500
499
- if (VA.isMemLoc ()) {
500
- HasStackArgs = true ;
501
- break ;
502
- }
503
-
504
501
// Push arguments into RegsToPass vector
505
502
if (VA.isRegLoc ())
506
503
RegsToPass.push_back (std::make_pair (VA.getLocReg (), Arg));
507
- else
508
- llvm_unreachable (" call arg pass bug" );
509
- }
510
-
511
- SDValue InGlue;
512
-
513
- if (HasStackArgs) {
514
- SBFFunctionInfo * SBFFuncInfo = MF.getInfo <SBFFunctionInfo>();
515
- // Stack arguments have to be walked in reverse order by inserting
516
- // chained stores, this ensures their order is not changed by the scheduler
517
- // and that the push instruction sequence generated is correct, otherwise they
518
- // can be freely intermixed.
519
- for (ae = i, i = ArgLocs.size (); i != ae; --i) {
520
- unsigned Loc = i - 1 ;
521
- CCValAssign &VA = ArgLocs[Loc];
522
- SDValue Arg = OutVals[Loc];
504
+ else if (VA.isMemLoc ()) {
505
+ CCValAssign &VA = ArgLocs[i];
506
+ SDValue Arg = OutVals[i];
523
507
524
- assert (VA.isMemLoc ());
525
-
526
- EVT PtrVT = DAG.getTargetLoweringInfo ().getPointerTy (DAG.getDataLayout ());
527
- SDValue DstAddr;
528
- MachinePointerInfo DstInfo;
529
- int FrameIndex;
530
508
int64_t Offset = static_cast <int64_t >(VA.getLocMemOffset ());
531
509
uint64_t Size = VA.getLocVT ().getFixedSizeInBits () / 8 ;
532
510
if (Subtarget->getHasDynamicFrames ()) {
@@ -536,14 +514,22 @@ SDValue SBFTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
536
514
Offset += Size;
537
515
}
538
516
539
- FrameIndex = MF.getFrameInfo ().CreateFixedObject (
517
+ int FrameIndex = MF.getFrameInfo ().CreateFixedObject (
540
518
Size, Offset, false );
541
519
SBFFuncInfo->storeFrameIndexArgument (FrameIndex);
542
- DstAddr = DAG.getFrameIndex (FrameIndex, PtrVT);
543
- DstInfo = MachinePointerInfo::getFixedStack (MF, FrameIndex, Offset);
544
- Chain = DAG.getStore (Chain, CLI.DL , Arg, DstAddr, DstInfo);
545
- }
520
+ SDValue DstAddr = DAG.getFrameIndex (FrameIndex, PtrVT);
521
+ MachinePointerInfo DstInfo = MachinePointerInfo::getFixedStack (MF, FrameIndex, Offset);
522
+ SDValue Store = DAG.getStore (Chain, CLI.DL , Arg, DstAddr, DstInfo);
523
+ MemOpChain. push_back (Store);
546
524
525
+ } else
526
+ llvm_unreachable (" call arg pass bug" );
527
+ }
528
+
529
+ SDValue InGlue;
530
+
531
+ if (!MemOpChain.empty ()) {
532
+ Chain = DAG.getNode (ISD::TokenFactor, CLI.DL , MVT::Other, MemOpChain);
547
533
if (!Subtarget->getHasDynamicFrames ()) {
548
534
// Pass the current stack frame pointer via SBF::R5, gluing the
549
535
// instruction to instructions passing the first 4 arguments in
@@ -554,7 +540,6 @@ SDValue SBFTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
554
540
Chain = DAG.getCopyToReg (Chain, CLI.DL , SBF::R5, FramePtr, InGlue);
555
541
InGlue = Chain.getValue (1 );
556
542
}
557
-
558
543
}
559
544
560
545
// Build a sequence of copy-to-reg nodes chained together with token chain and
@@ -586,7 +571,7 @@ SDValue SBFTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
586
571
for (auto &Reg : RegsToPass)
587
572
Ops.push_back (DAG.getRegister (Reg.first , Reg.second .getValueType ()));
588
573
589
- if (HasStackArgs && !Subtarget->getHasDynamicFrames ()) {
574
+ if (!MemOpChain. empty () && !Subtarget->getHasDynamicFrames ()) {
590
575
Ops.push_back (DAG.getRegister (SBF::R5, MVT::i64 ));
591
576
}
592
577
0 commit comments