From a0f5c85846872d6a96a2df062788d14d2370edaa Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Thu, 15 Feb 2018 17:20:07 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@325269 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/Hexagon/HexagonISelLowering.cpp | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/lib/Target/Hexagon/HexagonISelLowering.cpp b/lib/Target/Hexagon/HexagonISelLowering.cpp index e20c2875cb6..034034d82d5 100644 --- a/lib/Target/Hexagon/HexagonISelLowering.cpp +++ b/lib/Target/Hexagon/HexagonISelLowering.cpp @@ -112,16 +112,9 @@ namespace { public: HexagonCCState(CallingConv::ID CC, bool IsVarArg, MachineFunction &MF, SmallVectorImpl &locs, LLVMContext &C, - const Function *Callee) - : CCState(CC, IsVarArg, MF, locs, C) { - // If a function has zero args and is a vararg function, that's - // 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 NumNamedArgs) + : CCState(CC, IsVarArg, MF, locs, C), + NumNamedVarArgParams(NumNamedArgs) {} unsigned getNumNamedVarArgParams() const { return NumNamedVarArgParams; } }; @@ -324,22 +317,21 @@ HexagonTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, bool IsVarArg = CLI.IsVarArg; 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(); MachineFrameInfo &MFI = MF.getFrameInfo(); auto PtrVT = getPointerTy(MF.getDataLayout()); - const Function *CalleeF = nullptr; - if (GlobalAddressSDNode *GAN = dyn_cast(Callee)) { - const GlobalValue *GV = GAN->getGlobal(); - Callee = DAG.getTargetGlobalAddress(GV, dl, MVT::i32); - CalleeF = dyn_cast(GV); - } + unsigned NumParams = CLI.CS.getInstruction() + ? CLI.CS.getFunctionType()->getNumParams() + : 0; + if (GlobalAddressSDNode *GAN = dyn_cast(Callee)) + Callee = DAG.getTargetGlobalAddress(GAN->getGlobal(), dl, MVT::i32); // Analyze operands of the call, assigning locations to each operand. SmallVector ArgLocs; HexagonCCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext(), - CalleeF); + NumParams); if (Subtarget.useHVXOps()) CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon_HVX); @@ -697,7 +689,7 @@ SDValue HexagonTargetLowering::LowerFormalArguments( // Assign locations to all of the incoming arguments. SmallVector ArgLocs; HexagonCCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext(), - &MF.getFunction()); + MF.getFunction().getFunctionType()->getNumParams()); if (Subtarget.useHVXOps()) CCInfo.AnalyzeFormalArguments(Ins, CC_Hexagon_HVX); -- 2.11.0