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

[Hexagon] Fix lowering of formal arguments after r324737

Lowering of formal arguments needs to be aware of vararg functions.

llvm-svn: 325255
This commit is contained in:
Krzysztof Parzyszek 2018-02-15 15:47:53 +00:00
parent 987657b803
commit 5ef76c0c23
2 changed files with 28 additions and 18 deletions

View File

@ -107,14 +107,20 @@ static cl::opt<int> MaxStoresPerMemsetOptSizeCL("max-store-memset-Os",
namespace { namespace {
class HexagonCCState : public CCState { class HexagonCCState : public CCState {
unsigned NumNamedVarArgParams; unsigned NumNamedVarArgParams = 0;
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,
int NumNamedVarArgParams) const Function *Callee)
: CCState(CC, IsVarArg, MF, locs, C), : CCState(CC, IsVarArg, MF, locs, C) {
NumNamedVarArgParams(NumNamedVarArgParams) {} // 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 getNumNamedVarArgParams() const { return NumNamedVarArgParams; } unsigned getNumNamedVarArgParams() const { return NumNamedVarArgParams; }
}; };
@ -323,25 +329,17 @@ HexagonTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
MachineFrameInfo &MFI = MF.getFrameInfo(); MachineFrameInfo &MFI = MF.getFrameInfo();
auto PtrVT = getPointerTy(MF.getDataLayout()); auto PtrVT = getPointerTy(MF.getDataLayout());
// Check for varargs. const Function *CalleeF = nullptr;
unsigned NumNamedVarArgParams = 0;
if (GlobalAddressSDNode *GAN = dyn_cast<GlobalAddressSDNode>(Callee)) { if (GlobalAddressSDNode *GAN = dyn_cast<GlobalAddressSDNode>(Callee)) {
const GlobalValue *GV = GAN->getGlobal(); const GlobalValue *GV = GAN->getGlobal();
Callee = DAG.getTargetGlobalAddress(GV, dl, MVT::i32); Callee = DAG.getTargetGlobalAddress(GV, dl, MVT::i32);
if (const Function* F = dyn_cast<Function>(GV)) { CalleeF = dyn_cast<Function>(GV);
// 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 (F->isVarArg() && F->getFunctionType()->getNumParams() != 0)
NumNamedVarArgParams = F->getFunctionType()->getNumParams();
}
} }
// 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, DAG.getMachineFunction(), HexagonCCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext(),
ArgLocs, *DAG.getContext(), NumNamedVarArgParams); CalleeF);
if (Subtarget.useHVXOps()) if (Subtarget.useHVXOps())
CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon_HVX); CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon_HVX);
@ -698,8 +696,8 @@ 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;
CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs, HexagonCCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext(),
*DAG.getContext()); &MF.getFunction());
if (Subtarget.useHVXOps()) if (Subtarget.useHVXOps())
CCInfo.AnalyzeFormalArguments(Ins, CC_Hexagon_HVX); CCInfo.AnalyzeFormalArguments(Ins, CC_Hexagon_HVX);

View File

@ -0,0 +1,12 @@
; RUN: llc -march=hexagon < %s | FileCheck %s
; Make sure that the first formal argument is not loaded from memory.
; CHECK-NOT: memw
define i32 @fred(i32 %a0, ...) #0 {
b1:
%v2 = add i32 %a0, 1
ret i32 %v2
}
attributes #0 = { nounwind }