From: Alexey Samsonov <vonosmas@gmail.com> Date: Mon, 29 Sep 2014 21:21:48 +0000 (+0000) Subject: Introduce CGFunctionInfo::getNumRequiredArgs(). NFC. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7a37fa654e87f38315c1e4c6daebe29454caf3a7;p=clang Introduce CGFunctionInfo::getNumRequiredArgs(). NFC. Save the callers from necessity to special-case on variadic functions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@218625 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/CodeGen/CGFunctionInfo.h b/include/clang/CodeGen/CGFunctionInfo.h index bc4d25cb88..8aea6c3708 100644 --- a/include/clang/CodeGen/CGFunctionInfo.h +++ b/include/clang/CodeGen/CGFunctionInfo.h @@ -406,6 +406,9 @@ public: bool isVariadic() const { return Required.allowsOptionalArgs(); } RequiredArgs getRequiredArgs() const { return Required; } + unsigned getNumRequiredArgs() const { + return isVariadic() ? getRequiredArgs().getNumRequiredArgs() : arg_size(); + } bool isInstanceMethod() const { return InstanceMethod; } diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index e4da4e1411..b016e788b4 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -1053,12 +1053,8 @@ CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI) { } // Add in all of the required arguments. - CGFunctionInfo::const_arg_iterator it = FI.arg_begin(), ie; - if (FI.isVariadic()) { - ie = it + FI.getRequiredArgs().getNumRequiredArgs(); - } else { - ie = FI.arg_end(); - } + CGFunctionInfo::const_arg_iterator it = FI.arg_begin(), + ie = it + FI.getNumRequiredArgs(); for (; it != ie; ++it) { const ABIArgInfo &argAI = it->info; diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index 17552a5069..58d66b7bb1 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/lib/CodeGen/TargetInfo.cpp @@ -2568,23 +2568,17 @@ void X86_64ABIInfo::computeInfo(CGFunctionInfo &FI) const { if (FI.getReturnInfo().isIndirect()) --freeIntRegs; - bool isVariadic = FI.isVariadic(); - unsigned numRequiredArgs = 0; - if (isVariadic) - numRequiredArgs = FI.getRequiredArgs().getNumRequiredArgs(); - + unsigned NumRequiredArgs = FI.getNumRequiredArgs(); // AMD64-ABI 3.2.3p3: Once arguments are classified, the registers // get assigned (in left-to-right order) for passing as follows... + unsigned ArgNo = 0; for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end(); - it != ie; ++it) { - bool isNamedArg = true; - if (isVariadic) - isNamedArg = (it - FI.arg_begin()) < - static_cast<signed>(numRequiredArgs); + it != ie; ++it, ++ArgNo) { + bool IsNamedArg = ArgNo < NumRequiredArgs; unsigned neededInt, neededSSE; it->info = classifyArgumentType(it->type, freeIntRegs, neededInt, - neededSSE, isNamedArg); + neededSSE, IsNamedArg); // AMD64-ABI 3.2.3p3: If there are no registers available for any // eightbyte of an argument, the whole argument is passed on the @@ -3554,20 +3548,18 @@ private: // Find the number of named arguments. Variadic arguments get special // treatment with the Darwin ABI. - unsigned NumRequiredArgs = (FI.isVariadic() ? - FI.getRequiredArgs().getNumRequiredArgs() : - FI.arg_size()); + unsigned NumRequiredArgs = FI.getNumRequiredArgs(); if (!getCXXABI().classifyReturnType(FI)) FI.getReturnInfo() = classifyReturnType(FI.getReturnType()); + unsigned ArgNo = 0; for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end(); - it != ie; ++it) { + it != ie; ++it, ++ArgNo) { unsigned PreAllocation = AllocatedVFP, PreGPR = AllocatedGPR; bool IsHA = false, IsSmallAggr = false; const unsigned NumVFPs = 8; const unsigned NumGPRs = 8; - bool IsNamedArg = ((it - FI.arg_begin()) < - static_cast<signed>(NumRequiredArgs)); + bool IsNamedArg = ArgNo < NumRequiredArgs; it->info = classifyArgumentType(it->type, AllocatedVFP, IsHA, AllocatedGPR, IsSmallAggr, IsNamedArg);