Skip to content

Commit fd4633e

Browse files
committedOct 16, 2014
Reduce code duplication between patchpoint and non-patchpoint lowering. NFC.
This is in preparation for another patch that makes patchpoints invokable. Reviewers: atrick, ributzka Reviewed By: ributzka Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D5657 llvm-svn: 219967
1 parent e5d8eaf commit fd4633e

File tree

2 files changed

+58
-44
lines changed

2 files changed

+58
-44
lines changed
 

Diff for: ‎llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

+53-44
Original file line numberDiff line numberDiff line change
@@ -5435,36 +5435,12 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
54355435
}
54365436
}
54375437

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) {
54455441
MachineModuleInfo &MMI = DAG.getMachineFunction().getMMI();
54465442
MCSymbol *BeginLabel = nullptr;
54475443

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-
54685444
if (LandingPad) {
54695445
// Insert a label before the invoke call to mark the try range. This can be
54705446
// used to detect deletion of the invoke via the MachineModuleInfo.
@@ -5485,24 +5461,17 @@ void SelectionDAGBuilder::LowerCallTo(ImmutableCallSite CS, SDValue Callee,
54855461
// this call might not return.
54865462
(void)getRoot();
54875463
DAG.setRoot(DAG.getEHLabel(getCurSDLoc(), getControlRoot(), BeginLabel));
5488-
}
54895464

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+
}
54945467

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);
54985470

5499-
std::pair<SDValue,SDValue> Result = TLI.LowerCallTo(CLI);
5500-
assert((isTailCall || Result.second.getNode()) &&
5471+
assert((CLI.IsTailCall || Result.second.getNode()) &&
55015472
"Non-null chain expected with non-tail call!");
55025473
assert((Result.second.getNode() || !Result.first.getNode()) &&
55035474
"Null value expected with tail call!");
5504-
if (Result.first.getNode())
5505-
setValue(CS.getInstruction(), Result.first);
55065475

55075476
if (!Result.second.getNode()) {
55085477
// 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,
55255494
// Inform MachineModuleInfo of range.
55265495
MMI.addInvoke(LandingPad, BeginLabel, EndLabel);
55275496
}
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);
55285541
}
55295542

55305543
/// IsOnlyUsedInZeroEqualityComparison - Return true if it only matters that the
@@ -6801,8 +6814,7 @@ SelectionDAGBuilder::LowerCallOperands(const CallInst &CI, unsigned ArgIdx,
68016814
.setCallee(CI.getCallingConv(), retTy, Callee, std::move(Args), NumArgs)
68026815
.setDiscardResult(!CI.use_empty());
68036816

6804-
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
6805-
return TLI.LowerCallTo(CLI);
6817+
return lowerInvokable(CLI, nullptr);
68066818
}
68076819

68086820
/// \brief Add a stack map intrinsic call's live variable operands to a stackmap
@@ -6932,10 +6944,7 @@ void SelectionDAGBuilder::visitPatchpoint(const CallInst &CI) {
69326944
std::pair<SDValue, SDValue> Result =
69336945
LowerCallOperands(CI, NumMetaOpers, NumCallArgs, Callee, isAnyRegCC);
69346946

6935-
// Set the root to the target-lowered call chain.
69366947
SDValue Chain = Result.second;
6937-
DAG.setRoot(Chain);
6938-
69396948
SDNode *CallEnd = Chain.getNode();
69406949
if (hasDef && (CallEnd->getOpcode() == ISD::CopyFromReg))
69416950
CallEnd = CallEnd->getOperand(0).getNode();

Diff for: ‎llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/IR/CallSite.h"
2222
#include "llvm/IR/Constants.h"
2323
#include "llvm/Support/ErrorHandling.h"
24+
#include "llvm/Target/TargetLowering.h"
2425
#include <vector>
2526

2627
namespace llvm {
@@ -644,6 +645,10 @@ class SelectionDAGBuilder {
644645
void UpdateSplitBlock(MachineBasicBlock *First, MachineBasicBlock *Last);
645646

646647
private:
648+
std::pair<SDValue, SDValue> lowerInvokable(
649+
TargetLowering::CallLoweringInfo &CLI,
650+
MachineBasicBlock *LandingPad);
651+
647652
// Terminator instructions.
648653
void visitRet(const ReturnInst &I);
649654
void visitBr(const BranchInst &I);

0 commit comments

Comments
 (0)
Please sign in to comment.