Skip to content

Commit e0d7de7

Browse files
author
Krzysztof Parzyszek
committed
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
1 parent 862c476 commit e0d7de7

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

llvm/lib/Target/Hexagon/HexagonISelLowering.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,9 @@ namespace {
112112
public:
113113
HexagonCCState(CallingConv::ID CC, bool IsVarArg, MachineFunction &MF,
114114
SmallVectorImpl<CCValAssign> &locs, LLVMContext &C,
115-
const Function *Callee)
116-
: CCState(CC, IsVarArg, MF, locs, C) {
117-
// If a function has zero args and is a vararg function, that's
118-
// disallowed so it must be an undeclared function. Do not assume
119-
// varargs if the callee is undefined.
120-
if (Callee && Callee->isVarArg() &&
121-
Callee->getFunctionType()->getNumParams() != 0)
122-
NumNamedVarArgParams = Callee->getFunctionType()->getNumParams();
123-
}
124-
115+
unsigned NumNamedArgs)
116+
: CCState(CC, IsVarArg, MF, locs, C),
117+
NumNamedVarArgParams(NumNamedArgs) {}
125118
unsigned getNumNamedVarArgParams() const { return NumNamedVarArgParams; }
126119
};
127120

@@ -324,22 +317,21 @@ HexagonTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
324317
bool IsVarArg = CLI.IsVarArg;
325318
bool DoesNotReturn = CLI.DoesNotReturn;
326319

327-
bool IsStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet();
320+
bool IsStructRet = Outs.empty() ? false : Outs[0].Flags.isSRet();
328321
MachineFunction &MF = DAG.getMachineFunction();
329322
MachineFrameInfo &MFI = MF.getFrameInfo();
330323
auto PtrVT = getPointerTy(MF.getDataLayout());
331324

332-
const Function *CalleeF = nullptr;
333-
if (GlobalAddressSDNode *GAN = dyn_cast<GlobalAddressSDNode>(Callee)) {
334-
const GlobalValue *GV = GAN->getGlobal();
335-
Callee = DAG.getTargetGlobalAddress(GV, dl, MVT::i32);
336-
CalleeF = dyn_cast<Function>(GV);
337-
}
325+
unsigned NumParams = CLI.CS.getInstruction()
326+
? CLI.CS.getFunctionType()->getNumParams()
327+
: 0;
328+
if (GlobalAddressSDNode *GAN = dyn_cast<GlobalAddressSDNode>(Callee))
329+
Callee = DAG.getTargetGlobalAddress(GAN->getGlobal(), dl, MVT::i32);
338330

339331
// Analyze operands of the call, assigning locations to each operand.
340332
SmallVector<CCValAssign, 16> ArgLocs;
341333
HexagonCCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext(),
342-
CalleeF);
334+
NumParams);
343335

344336
if (Subtarget.useHVXOps())
345337
CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon_HVX);
@@ -697,7 +689,7 @@ SDValue HexagonTargetLowering::LowerFormalArguments(
697689
// Assign locations to all of the incoming arguments.
698690
SmallVector<CCValAssign, 16> ArgLocs;
699691
HexagonCCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext(),
700-
&MF.getFunction());
692+
MF.getFunction().getFunctionType()->getNumParams());
701693

702694
if (Subtarget.useHVXOps())
703695
CCInfo.AnalyzeFormalArguments(Ins, CC_Hexagon_HVX);

0 commit comments

Comments
 (0)