1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 03:23:01 +02:00

Recommit [Hexagon] Make the vararg handling a bit more robust

Use the FunctionType of the callee when it's available. It may not be
available for synthetic calls to functions specified by external symbols.

llvm-svn: 325269
This commit is contained in:
Krzysztof Parzyszek 2018-02-15 17:20:07 +00:00
parent ee44ad2475
commit 2f577c23eb

View File

@ -112,16 +112,9 @@ namespace {
public: public:
HexagonCCState(CallingConv::ID CC, bool IsVarArg, MachineFunction &MF, HexagonCCState(CallingConv::ID CC, bool IsVarArg, MachineFunction &MF,
SmallVectorImpl<CCValAssign> &locs, LLVMContext &C, SmallVectorImpl<CCValAssign> &locs, LLVMContext &C,
const Function *Callee) unsigned NumNamedArgs)
: CCState(CC, IsVarArg, MF, locs, C) { : CCState(CC, IsVarArg, MF, locs, C),
// If a function has zero args and is a vararg function, that's NumNamedVarArgParams(NumNamedArgs) {}
// disallowed so it must be an undeclared function. Do not assume
// varargs if the callee is undefined.
if (Callee && Callee->isVarArg() &&
Callee->getFunctionType()->getNumParams() != 0)
NumNamedVarArgParams = Callee->getFunctionType()->getNumParams();
}
unsigned getNumNamedVarArgParams() const { return NumNamedVarArgParams; } unsigned getNumNamedVarArgParams() const { return NumNamedVarArgParams; }
}; };
@ -324,22 +317,21 @@ HexagonTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
bool IsVarArg = CLI.IsVarArg; bool IsVarArg = CLI.IsVarArg;
bool DoesNotReturn = CLI.DoesNotReturn; bool DoesNotReturn = CLI.DoesNotReturn;
bool IsStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); bool IsStructRet = Outs.empty() ? false : Outs[0].Flags.isSRet();
MachineFunction &MF = DAG.getMachineFunction(); MachineFunction &MF = DAG.getMachineFunction();
MachineFrameInfo &MFI = MF.getFrameInfo(); MachineFrameInfo &MFI = MF.getFrameInfo();
auto PtrVT = getPointerTy(MF.getDataLayout()); auto PtrVT = getPointerTy(MF.getDataLayout());
const Function *CalleeF = nullptr; unsigned NumParams = CLI.CS.getInstruction()
if (GlobalAddressSDNode *GAN = dyn_cast<GlobalAddressSDNode>(Callee)) { ? CLI.CS.getFunctionType()->getNumParams()
const GlobalValue *GV = GAN->getGlobal(); : 0;
Callee = DAG.getTargetGlobalAddress(GV, dl, MVT::i32); if (GlobalAddressSDNode *GAN = dyn_cast<GlobalAddressSDNode>(Callee))
CalleeF = dyn_cast<Function>(GV); Callee = DAG.getTargetGlobalAddress(GAN->getGlobal(), dl, MVT::i32);
}
// Analyze operands of the call, assigning locations to each operand. // Analyze operands of the call, assigning locations to each operand.
SmallVector<CCValAssign, 16> ArgLocs; SmallVector<CCValAssign, 16> ArgLocs;
HexagonCCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext(), HexagonCCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext(),
CalleeF); NumParams);
if (Subtarget.useHVXOps()) if (Subtarget.useHVXOps())
CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon_HVX); CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon_HVX);
@ -697,7 +689,7 @@ SDValue HexagonTargetLowering::LowerFormalArguments(
// Assign locations to all of the incoming arguments. // Assign locations to all of the incoming arguments.
SmallVector<CCValAssign, 16> ArgLocs; SmallVector<CCValAssign, 16> ArgLocs;
HexagonCCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext(), HexagonCCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext(),
&MF.getFunction()); MF.getFunction().getFunctionType()->getNumParams());
if (Subtarget.useHVXOps()) if (Subtarget.useHVXOps())
CCInfo.AnalyzeFormalArguments(Ins, CC_Hexagon_HVX); CCInfo.AnalyzeFormalArguments(Ins, CC_Hexagon_HVX);