@@ -5435,36 +5435,12 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
5435
5435
}
5436
5436
}
5437
5437
5438
- void SelectionDAGBuilder::LowerCallTo (ImmutableCallSite CS, SDValue Callee,
5439
- bool isTailCall,
5440
- MachineBasicBlock *LandingPad) {
5441
- const TargetLowering &TLI = DAG.getTargetLoweringInfo ();
5442
- PointerType *PT = cast<PointerType>(CS.getCalledValue ()->getType ());
5443
- FunctionType *FTy = cast<FunctionType>(PT->getElementType ());
5444
- Type *RetTy = FTy->getReturnType ();
5438
+ std::pair<SDValue, SDValue>
5439
+ SelectionDAGBuilder::lowerInvokable (TargetLowering::CallLoweringInfo &CLI,
5440
+ MachineBasicBlock *LandingPad) {
5445
5441
MachineModuleInfo &MMI = DAG.getMachineFunction ().getMMI ();
5446
5442
MCSymbol *BeginLabel = nullptr ;
5447
5443
5448
- TargetLowering::ArgListTy Args;
5449
- TargetLowering::ArgListEntry Entry;
5450
- Args.reserve (CS.arg_size ());
5451
-
5452
- for (ImmutableCallSite::arg_iterator i = CS.arg_begin (), e = CS.arg_end ();
5453
- i != e; ++i) {
5454
- const Value *V = *i;
5455
-
5456
- // Skip empty types
5457
- if (V->getType ()->isEmptyTy ())
5458
- continue ;
5459
-
5460
- SDValue ArgNode = getValue (V);
5461
- Entry.Node = ArgNode; Entry.Ty = V->getType ();
5462
-
5463
- // Skip the first return-type Attribute to get to params.
5464
- Entry.setAttributes (&CS, i - CS.arg_begin () + 1 );
5465
- Args.push_back (Entry);
5466
- }
5467
-
5468
5444
if (LandingPad) {
5469
5445
// Insert a label before the invoke call to mark the try range. This can be
5470
5446
// used to detect deletion of the invoke via the MachineModuleInfo.
@@ -5485,24 +5461,17 @@ void SelectionDAGBuilder::LowerCallTo(ImmutableCallSite CS, SDValue Callee,
5485
5461
// this call might not return.
5486
5462
(void )getRoot ();
5487
5463
DAG.setRoot (DAG.getEHLabel (getCurSDLoc (), getControlRoot (), BeginLabel));
5488
- }
5489
5464
5490
- // Check if target-independent constraints permit a tail call here.
5491
- // Target-dependent constraints are checked within TLI.LowerCallTo.
5492
- if (isTailCall && !isInTailCallPosition (CS, DAG.getTarget ()))
5493
- isTailCall = false ;
5465
+ CLI.setChain (getRoot ());
5466
+ }
5494
5467
5495
- TargetLowering::CallLoweringInfo CLI (DAG);
5496
- CLI.setDebugLoc (getCurSDLoc ()).setChain (getRoot ())
5497
- .setCallee (RetTy, FTy, Callee, std::move (Args), CS).setTailCall (isTailCall);
5468
+ const TargetLowering *TLI = TM.getSubtargetImpl ()->getTargetLowering ();
5469
+ std::pair<SDValue, SDValue> Result = TLI->LowerCallTo (CLI);
5498
5470
5499
- std::pair<SDValue,SDValue> Result = TLI.LowerCallTo (CLI);
5500
- assert ((isTailCall || Result.second .getNode ()) &&
5471
+ assert ((CLI.IsTailCall || Result.second .getNode ()) &&
5501
5472
" Non-null chain expected with non-tail call!" );
5502
5473
assert ((Result.second .getNode () || !Result.first .getNode ()) &&
5503
5474
" Null value expected with tail call!" );
5504
- if (Result.first .getNode ())
5505
- setValue (CS.getInstruction (), Result.first );
5506
5475
5507
5476
if (!Result.second .getNode ()) {
5508
5477
// As a special case, a null chain means that a tail call has been emitted
@@ -5525,6 +5494,50 @@ void SelectionDAGBuilder::LowerCallTo(ImmutableCallSite CS, SDValue Callee,
5525
5494
// Inform MachineModuleInfo of range.
5526
5495
MMI.addInvoke (LandingPad, BeginLabel, EndLabel);
5527
5496
}
5497
+
5498
+ return Result;
5499
+ }
5500
+
5501
+ void SelectionDAGBuilder::LowerCallTo (ImmutableCallSite CS, SDValue Callee,
5502
+ bool isTailCall,
5503
+ MachineBasicBlock *LandingPad) {
5504
+ PointerType *PT = cast<PointerType>(CS.getCalledValue ()->getType ());
5505
+ FunctionType *FTy = cast<FunctionType>(PT->getElementType ());
5506
+ Type *RetTy = FTy->getReturnType ();
5507
+
5508
+ TargetLowering::ArgListTy Args;
5509
+ TargetLowering::ArgListEntry Entry;
5510
+ Args.reserve (CS.arg_size ());
5511
+
5512
+ for (ImmutableCallSite::arg_iterator i = CS.arg_begin (), e = CS.arg_end ();
5513
+ i != e; ++i) {
5514
+ const Value *V = *i;
5515
+
5516
+ // Skip empty types
5517
+ if (V->getType ()->isEmptyTy ())
5518
+ continue ;
5519
+
5520
+ SDValue ArgNode = getValue (V);
5521
+ Entry.Node = ArgNode; Entry.Ty = V->getType ();
5522
+
5523
+ // Skip the first return-type Attribute to get to params.
5524
+ Entry.setAttributes (&CS, i - CS.arg_begin () + 1 );
5525
+ Args.push_back (Entry);
5526
+ }
5527
+
5528
+ // Check if target-independent constraints permit a tail call here.
5529
+ // Target-dependent constraints are checked within TLI->LowerCallTo.
5530
+ if (isTailCall && !isInTailCallPosition (CS, DAG.getTarget ()))
5531
+ isTailCall = false ;
5532
+
5533
+ TargetLowering::CallLoweringInfo CLI (DAG);
5534
+ CLI.setDebugLoc (getCurSDLoc ()).setChain (getRoot ())
5535
+ .setCallee (RetTy, FTy, Callee, std::move (Args), CS)
5536
+ .setTailCall (isTailCall);
5537
+ std::pair<SDValue,SDValue> Result = lowerInvokable (CLI, LandingPad);
5538
+
5539
+ if (Result.first .getNode ())
5540
+ setValue (CS.getInstruction (), Result.first );
5528
5541
}
5529
5542
5530
5543
// / IsOnlyUsedInZeroEqualityComparison - Return true if it only matters that the
@@ -6801,8 +6814,7 @@ SelectionDAGBuilder::LowerCallOperands(const CallInst &CI, unsigned ArgIdx,
6801
6814
.setCallee (CI.getCallingConv (), retTy, Callee, std::move (Args), NumArgs)
6802
6815
.setDiscardResult (!CI.use_empty ());
6803
6816
6804
- const TargetLowering &TLI = DAG.getTargetLoweringInfo ();
6805
- return TLI.LowerCallTo (CLI);
6817
+ return lowerInvokable (CLI, nullptr );
6806
6818
}
6807
6819
6808
6820
// / \brief Add a stack map intrinsic call's live variable operands to a stackmap
@@ -6932,10 +6944,7 @@ void SelectionDAGBuilder::visitPatchpoint(const CallInst &CI) {
6932
6944
std::pair<SDValue, SDValue> Result =
6933
6945
LowerCallOperands (CI, NumMetaOpers, NumCallArgs, Callee, isAnyRegCC);
6934
6946
6935
- // Set the root to the target-lowered call chain.
6936
6947
SDValue Chain = Result.second ;
6937
- DAG.setRoot (Chain);
6938
-
6939
6948
SDNode *CallEnd = Chain.getNode ();
6940
6949
if (hasDef && (CallEnd->getOpcode () == ISD::CopyFromReg))
6941
6950
CallEnd = CallEnd->getOperand (0 ).getNode ();
0 commit comments