Index: include/llvm/CodeGen/GlobalISel/CallLowering.h =================================================================== --- include/llvm/CodeGen/GlobalISel/CallLowering.h +++ include/llvm/CodeGen/GlobalISel/CallLowering.h @@ -49,7 +49,10 @@ ArgInfo(unsigned Reg, Type *Ty, ISD::ArgFlagsTy Flags = ISD::ArgFlagsTy{}, bool IsFixed = true) - : Reg(Reg), Ty(Ty), Flags(Flags), IsFixed(IsFixed) {} + : Reg(Reg), Ty(Ty), Flags(Flags), IsFixed(IsFixed) { + if (IsFixed) + Flags.setFixed(); + } }; /// Argument handling is mostly uniform between the four places that Index: include/llvm/CodeGen/TargetCallingConv.h =================================================================== --- include/llvm/CodeGen/TargetCallingConv.h +++ include/llvm/CodeGen/TargetCallingConv.h @@ -26,6 +26,7 @@ struct ArgFlagsTy { private: + unsigned IsFixed : 1; ///< Is 'fixed' (not vararg) unsigned IsZExt : 1; ///< Zero extended unsigned IsSExt : 1; ///< Sign extended unsigned IsInReg : 1; ///< Passed in register @@ -51,8 +52,8 @@ public: ArgFlagsTy() - : IsZExt(0), IsSExt(0), IsInReg(0), IsSRet(0), IsByVal(0), IsNest(0), - IsReturned(0), IsSplit(0), IsInAlloca(0), IsSplitEnd(0), + : IsFixed(0), IsZExt(0), IsSExt(0), IsInReg(0), IsSRet(0), IsByVal(0), + IsNest(0), IsReturned(0), IsSplit(0), IsInAlloca(0), IsSplitEnd(0), IsSwiftSelf(0), IsSwiftError(0), IsHva(0), IsHvaStart(0), IsSecArgPass(0), ByValAlign(0), OrigAlign(0), IsInConsecutiveRegsLast(0), IsInConsecutiveRegs(0), @@ -60,6 +61,9 @@ static_assert(sizeof(*this) == 2 * sizeof(unsigned), "flags are too big"); } + bool isFixed() const { return IsFixed; } + void setFixed() { IsFixed = 1; } + bool isZExt() const { return IsZExt; } void setZExt() { IsZExt = 1; } Index: include/llvm/Target/TargetCallingConv.td =================================================================== --- include/llvm/Target/TargetCallingConv.td +++ include/llvm/Target/TargetCallingConv.td @@ -37,6 +37,16 @@ string Predicate = predicate; } +/// CCIfFixed - If the current argument is 'fixed' (not a vararg), apply +/// Action A. +class CCIfFixed : CCIf<"ArgFlags.isFixed()", A> { +} + +/// CCIfNotFixed - If the current argument is not 'fixed' (i.e. it's a vararg), +/// apply Action A. +class CCIfNotFixed : CCIf<"!ArgFlags.isFixed()", A> { +} + /// CCIfByVal - If the current argument has ByVal parameter attribute, apply /// Action A. class CCIfByVal : CCIf<"ArgFlags.isByVal()", A> { Index: lib/CodeGen/SelectionDAG/FastISel.cpp =================================================================== --- lib/CodeGen/SelectionDAG/FastISel.cpp +++ lib/CodeGen/SelectionDAG/FastISel.cpp @@ -959,6 +959,7 @@ MyFlags.VT = RegisterVT; MyFlags.ArgVT = VT; MyFlags.Used = CLI.IsReturnValueUsed; + MyFlags.Flags.setFixed(); if (CLI.RetSExt) MyFlags.Flags.setSExt(); if (CLI.RetZExt) @@ -971,6 +972,7 @@ // Handle all of the outgoing arguments. CLI.clearOuts(); + unsigned i = 0; for (auto &Arg : CLI.getArgs()) { Type *FinalType = Arg.Ty; if (Arg.IsByVal) @@ -979,6 +981,8 @@ FinalType, CLI.CallConv, CLI.IsVarArg); ISD::ArgFlagsTy Flags; + if (i < CLI.NumFixedArgs) + Flags.setFixed(); if (Arg.IsZExt) Flags.setZExt(); if (Arg.IsSExt) @@ -1023,6 +1027,7 @@ CLI.OutVals.push_back(Arg.Val); CLI.OutFlags.push_back(Flags); + i++; } if (!fastLowerCall(CLI)) Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -1535,6 +1535,7 @@ // 'inreg' on function refers to return value ISD::ArgFlagsTy Flags = ISD::ArgFlagsTy(); + Flags.setFixed(); if (RetInReg) Flags.setInReg(); @@ -8127,6 +8128,7 @@ MyFlags.VT = RegisterVT; MyFlags.ArgVT = VT; MyFlags.Used = CLI.IsReturnValueUsed; + MyFlags.Flags.setFixed(); if (CLI.RetSExt) MyFlags.Flags.setSExt(); if (CLI.RetZExt) @@ -8177,6 +8179,8 @@ // specify the alignment it wants. unsigned OriginalAlignment = getABIAlignmentForCallingConv(ArgTy, DL); + if (i < CLI.NumFixedArgs) + Flags.setFixed(); if (Args[i].IsZExt) Flags.setZExt(); if (Args[i].IsSExt) @@ -8660,6 +8664,8 @@ unsigned OriginalAlignment = TLI->getABIAlignmentForCallingConv(ArgTy, DL); + if (ArgNo < F.getFunctionType()->getNumParams()) + Flags.setFixed(); if (Arg.hasAttribute(Attribute::ZExt)) Flags.setZExt(); if (Arg.hasAttribute(Attribute::SExt)) Index: lib/Target/Hexagon/HexagonISelLowering.cpp =================================================================== --- lib/Target/Hexagon/HexagonISelLowering.cpp +++ lib/Target/Hexagon/HexagonISelLowering.cpp @@ -103,30 +103,6 @@ cl::Hidden, cl::ZeroOrMore, cl::init(4), cl::desc("Max #stores to inline memset")); - -namespace { - - class HexagonCCState : public CCState { - unsigned NumNamedVarArgParams; - - public: - HexagonCCState(CallingConv::ID CC, bool isVarArg, MachineFunction &MF, - SmallVectorImpl &locs, LLVMContext &C, - int NumNamedVarArgParams) - : CCState(CC, isVarArg, MF, locs, C), - NumNamedVarArgParams(NumNamedVarArgParams) {} - - unsigned getNumNamedVarArgParams() const { return NumNamedVarArgParams; } - }; - - enum StridedLoadKind { - Even = 0, - Odd, - NoPattern - }; - -} // end anonymous namespace - // Implement calling convention for Hexagon. static const MVT LegalV64[] = { MVT::v64i8, MVT::v32i16, MVT::v16i32 }; @@ -178,9 +154,7 @@ CC_Hexagon_VarArg (unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State) { - HexagonCCState &HState = static_cast(State); - - if (ValNo < HState.getNumNamedVarArgParams()) { + if (ArgFlags.isFixed()) { // Deal with named arguments. return CC_Hexagon(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State); } @@ -709,8 +683,8 @@ // Analyze operands of the call, assigning locations to each operand. SmallVector ArgLocs; - HexagonCCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs, - *DAG.getContext(), NumNamedVarArgParams); + CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs, + *DAG.getContext()); if (IsVarArg) CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon_VarArg); Index: lib/Target/Lanai/LanaiISelLowering.cpp =================================================================== --- lib/Target/Lanai/LanaiISelLowering.cpp +++ lib/Target/Lanai/LanaiISelLowering.cpp @@ -368,14 +368,13 @@ #include "LanaiGenCallingConv.inc" -static unsigned NumFixedArgs; static bool CC_Lanai32_VarArg(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State) { // Handle fixed arguments with default CC. // Note: Both the default and fast CC handle VarArg the same and hence the // calling convention of the function is not considered here. - if (ValNo < NumFixedArgs) { + if (ArgFlags.isFixed()) { return CC_Lanai32(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State); } @@ -609,20 +608,12 @@ GlobalAddressSDNode *G = dyn_cast(Callee); MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo(); - NumFixedArgs = 0; - if (IsVarArg && G) { - const Function *CalleeFn = dyn_cast(G->getGlobal()); - if (CalleeFn) - NumFixedArgs = CalleeFn->getFunctionType()->getNumParams(); - } - if (NumFixedArgs) + if (IsVarArg && G) CCInfo.AnalyzeCallOperands(Outs, CC_Lanai32_VarArg); - else { - if (CallConv == CallingConv::Fast) - CCInfo.AnalyzeCallOperands(Outs, CC_Lanai32_Fast); - else - CCInfo.AnalyzeCallOperands(Outs, CC_Lanai32); - } + else if (CallConv == CallingConv::Fast) + CCInfo.AnalyzeCallOperands(Outs, CC_Lanai32_Fast); + else + CCInfo.AnalyzeCallOperands(Outs, CC_Lanai32); // Get a count of how many bytes are to be pushed on the stack. unsigned NumBytes = CCInfo.getNextStackOffset(); Index: lib/Target/Mips/MipsCCState.h =================================================================== --- lib/Target/Mips/MipsCCState.h +++ lib/Target/Mips/MipsCCState.h @@ -72,10 +72,6 @@ /// vector. SmallVector OriginalRetWasFloatVector; - /// Records whether the value was a fixed argument. - /// See ISD::OutputArg::IsFixed, - SmallVector CallOperandIsFixed; - // Used to handle MIPS16-specific calling convention tweaks. // FIXME: This should probably be a fully fledged calling convention. SpecialCallingConvType SpecialCallingConv; @@ -96,12 +92,12 @@ OriginalArgWasF128.clear(); OriginalArgWasFloat.clear(); OriginalArgWasFloatVector.clear(); - CallOperandIsFixed.clear(); } // The AnalyzeCallOperands in the base class is not usable since we must - // provide a means of accessing ArgListEntry::IsFixed. Delete them from this - // class. This doesn't stop them being used via the base class though. + // provide a means of accessing type information about the original + // arguments. Delete them from this class. This doesn't stop them being used + // via the base class though. void AnalyzeCallOperands(const SmallVectorImpl &Outs, CCAssignFn Fn) = delete; void AnalyzeCallOperands(const SmallVectorImpl &Outs, @@ -159,7 +155,6 @@ bool WasOriginalRetVectorFloat(unsigned ValNo) const { return OriginalRetWasFloatVector[ValNo]; } - bool IsCallOperandFixed(unsigned ValNo) { return CallOperandIsFixed[ValNo]; } SpecialCallingConvType getSpecialCallingConv() { return SpecialCallingConv; } }; } Index: lib/Target/Mips/MipsCCState.cpp =================================================================== --- lib/Target/Mips/MipsCCState.cpp +++ lib/Target/Mips/MipsCCState.cpp @@ -139,7 +139,6 @@ OriginalArgWasF128.push_back(originalTypeIsF128(FuncArg.Ty, Func)); OriginalArgWasFloat.push_back(FuncArg.Ty->isFloatingPointTy()); OriginalArgWasFloatVector.push_back(FuncArg.Ty->isVectorTy()); - CallOperandIsFixed.push_back(Outs[i].IsFixed); } } Index: lib/Target/Mips/MipsCallingConv.td =================================================================== --- lib/Target/Mips/MipsCallingConv.td +++ lib/Target/Mips/MipsCallingConv.td @@ -31,12 +31,6 @@ class CCIfOrigArgWasF128 : CCIf<"static_cast(&State)->WasOriginalArgF128(ValNo)", A>; -/// Match if this specific argument is a vararg. -/// This is slightly different fro CCIfIsVarArg which matches if any argument is -/// a vararg. -class CCIfArgIsVarArg - : CCIf<"!static_cast(&State)->IsCallOperandFixed(ValNo)", A>; - /// Match if the return was a floating point vector. class CCIfOrigArgWasNotVectorFloat : CCIf<"!static_cast(&State)" @@ -351,7 +345,7 @@ ]>; def CC_Mips : CallingConv<[ - CCIfVarArg>>, + CCIfVarArg>>, CCDelegateTo ]>; Index: lib/Target/RISCV/RISCVISelLowering.cpp =================================================================== --- lib/Target/RISCV/RISCVISelLowering.cpp +++ lib/Target/RISCV/RISCVISelLowering.cpp @@ -480,7 +480,7 @@ // Implements the RISC-V calling convention. Returns true upon failure. static bool CC_RISCV(const DataLayout &DL, unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, - CCState &State, bool IsFixed, bool IsRet, Type *OrigTy) { + CCState &State, bool IsRet, Type *OrigTy) { unsigned XLen = DL.getLargestLegalIntTypeSizeInBits(); assert(XLen == 32 || XLen == 64); MVT XLenVT = XLen == 32 ? MVT::i32 : MVT::i64; @@ -500,7 +500,7 @@ // original type is larger than 2*XLEN, so the register alignment rule does // not apply. unsigned TwoXLenInBytes = (2 * XLen) / 8; - if (!IsFixed && ArgFlags.getOrigAlign() == TwoXLenInBytes && + if (!ArgFlags.isFixed() && ArgFlags.getOrigAlign() == TwoXLenInBytes && DL.getTypeAllocSize(OrigTy) == TwoXLenInBytes) { unsigned RegIdx = State.getFirstUnallocated(ArgGPRs); // Skip 'odd' register if necessary. @@ -592,7 +592,7 @@ ArgTy = FType->getParamType(Ins[i].getOrigArgIndex()); if (CC_RISCV(MF.getDataLayout(), i, ArgVT, ArgVT, CCValAssign::Full, - ArgFlags, CCInfo, /*IsRet=*/true, IsRet, ArgTy)) { + ArgFlags, CCInfo, IsRet, ArgTy)) { DEBUG(dbgs() << "InputArg #" << i << " has unhandled type " << EVT(ArgVT).getEVTString() << '\n'); llvm_unreachable(nullptr); @@ -612,7 +612,7 @@ Type *OrigTy = CLI ? CLI->getArgs()[Outs[i].OrigArgIndex].Ty : nullptr; if (CC_RISCV(MF.getDataLayout(), i, ArgVT, ArgVT, CCValAssign::Full, - ArgFlags, CCInfo, Outs[i].IsFixed, IsRet, OrigTy)) { + ArgFlags, CCInfo, IsRet, OrigTy)) { DEBUG(dbgs() << "OutputArg #" << i << " has unhandled type " << EVT(ArgVT).getEVTString() << "\n"); llvm_unreachable(nullptr); @@ -990,7 +990,7 @@ MVT VT = Outs[i].VT; ISD::ArgFlagsTy ArgFlags = Outs[i].Flags; if (CC_RISCV(MF.getDataLayout(), i, VT, VT, CCValAssign::Full, ArgFlags, - CCInfo, /*IsFixed=*/true, /*IsRet=*/true, nullptr)) + CCInfo, /*IsRet=*/true, nullptr)) return false; } return true; Index: lib/Target/SystemZ/SystemZCallingConv.h =================================================================== --- lib/Target/SystemZ/SystemZCallingConv.h +++ lib/Target/SystemZ/SystemZCallingConv.h @@ -25,10 +25,6 @@ class SystemZCCState : public CCState { private: - /// Records whether the value was a fixed argument. - /// See ISD::OutputArg::IsFixed. - SmallVector ArgIsFixed; - /// Records whether the value was widened from a short vector type. SmallVector ArgIsShortVector; @@ -44,10 +40,6 @@ void AnalyzeFormalArguments(const SmallVectorImpl &Ins, CCAssignFn Fn) { - // Formal arguments are always fixed. - ArgIsFixed.clear(); - for (unsigned i = 0; i < Ins.size(); ++i) - ArgIsFixed.push_back(true); // Record whether the call operand was a short vector. ArgIsShortVector.clear(); for (unsigned i = 0; i < Ins.size(); ++i) @@ -58,10 +50,6 @@ void AnalyzeCallOperands(const SmallVectorImpl &Outs, CCAssignFn Fn) { - // Record whether the call operand was a fixed argument. - ArgIsFixed.clear(); - for (unsigned i = 0; i < Outs.size(); ++i) - ArgIsFixed.push_back(Outs[i].IsFixed); // Record whether the call operand was a short vector. ArgIsShortVector.clear(); for (unsigned i = 0; i < Outs.size(); ++i) @@ -71,12 +59,12 @@ } // This version of AnalyzeCallOperands in the base class is not usable - // since we must provide a means of accessing ISD::OutputArg::IsFixed. + // since we must provide a means of accessing type information about the + // original argument. void AnalyzeCallOperands(const SmallVectorImpl &Outs, SmallVectorImpl &Flags, CCAssignFn Fn) = delete; - bool IsFixed(unsigned ValNo) { return ArgIsFixed[ValNo]; } bool IsShortVector(unsigned ValNo) { return ArgIsShortVector[ValNo]; } }; Index: lib/Target/SystemZ/SystemZCallingConv.td =================================================================== --- lib/Target/SystemZ/SystemZCallingConv.td +++ lib/Target/SystemZ/SystemZCallingConv.td @@ -17,10 +17,6 @@ "(State.getMachineFunction().getSubtarget()).", F), A>; -// Match if this specific argument is a fixed (i.e. named) argument. -class CCIfFixed - : CCIf<"static_cast(&State)->IsFixed(ValNo)", A>; - // Match if this specific argument was widened from a short vector type. class CCIfShortVector : CCIf<"static_cast(&State)->IsShortVector(ValNo)", A>;