diff --git a/llvm/lib/Target/M68k/M68kCallingConv.h b/llvm/lib/Target/M68k/M68kCallingConv.h --- a/llvm/lib/Target/M68k/M68kCallingConv.h +++ b/llvm/lib/Target/M68k/M68kCallingConv.h @@ -24,14 +24,13 @@ namespace llvm { /// Custom state to propagate llvm type info to register CC assigner -class M68kCCState : public CCState { -public: - const llvm::Function &F; +struct M68kCCState : public CCState { + ArrayRef ArgTypeList; - M68kCCState(const llvm::Function &F, CallingConv::ID CC, bool IsVarArg, + M68kCCState(ArrayRef ArgTypes, CallingConv::ID CC, bool IsVarArg, MachineFunction &MF, SmallVectorImpl &Locs, LLVMContext &C) - : CCState(CC, IsVarArg, MF, Locs, C), F(F) {} + : CCState(CC, IsVarArg, MF, Locs, C), ArgTypeList(ArgTypes) {} }; /// NOTE this function is used to select registers for formal arguments and call @@ -39,7 +38,7 @@ inline bool CC_M68k_Any_AssignToReg(unsigned &ValNo, MVT &ValVT, MVT &LocVT, CCValAssign::LocInfo &LocInfo, ISD::ArgFlagsTy &ArgFlags, CCState &State) { - M68kCCState CCInfo = static_cast(State); + const M68kCCState &CCInfo = static_cast(State); static const MCPhysReg DataRegList[] = {M68k::D0, M68k::D1, M68k::A0, M68k::A1}; @@ -52,14 +51,15 @@ M68k::D1, }; - auto I = CCInfo.F.arg_begin(); + const auto &ArgTypes = CCInfo.ArgTypeList; + auto I = ArgTypes.begin(), End = ArgTypes.end(); int No = ValNo; - while (No > 0) { - No -= I->getType()->isIntegerTy(64) ? 2 : 1; - I++; + while (No > 0 && I != End) { + No -= (*I)->isIntegerTy(64) ? 2 : 1; + ++I; } - bool IsPtr = I != CCInfo.F.arg_end() && I->getType()->isPointerTy(); + bool IsPtr = I != End && (*I)->isPointerTy(); unsigned Reg = IsPtr ? State.AllocateReg(AddrRegList) : State.AllocateReg(DataRegList); diff --git a/llvm/lib/Target/M68k/M68kISelLowering.cpp b/llvm/lib/Target/M68k/M68kISelLowering.cpp --- a/llvm/lib/Target/M68k/M68kISelLowering.cpp +++ b/llvm/lib/Target/M68k/M68kISelLowering.cpp @@ -519,9 +519,10 @@ // Analyze operands of the call, assigning locations to each operand. SmallVector ArgLocs; - // It is empty for LibCall - const Function *CalleeFunc = CLI.CB ? CLI.CB->getCalledFunction() : nullptr; - M68kCCState CCInfo(*CalleeFunc, CallConv, IsVarArg, MF, ArgLocs, + SmallVector ArgTypes; + for (const auto &Arg : CLI.getArgs()) + ArgTypes.emplace_back(Arg.Ty); + M68kCCState CCInfo(ArgTypes, CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext()); CCInfo.AnalyzeCallOperands(Outs, CC_M68k); @@ -876,8 +877,10 @@ // Assign locations to all of the incoming arguments. SmallVector ArgLocs; - M68kCCState CCInfo(MF.getFunction(), CCID, IsVarArg, MF, ArgLocs, - *DAG.getContext()); + SmallVector ArgTypes; + for (const Argument &Arg : MF.getFunction().args()) + ArgTypes.emplace_back(Arg.getType()); + M68kCCState CCInfo(ArgTypes, CCID, IsVarArg, MF, ArgLocs, *DAG.getContext()); CCInfo.AnalyzeFormalArguments(Ins, CC_M68k);