1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
10 #include "register_arg_convention.h"
12 unsigned InitVarDscInfo::allocRegArg(var_types type, unsigned numRegs /* = 1 */)
16 unsigned resultArgNum = regArgNum(type);
17 bool isBackFilled = false;
20 // Check for back-filling
21 if (varTypeIsFloating(type) && // We only back-fill the float registers
22 !anyFloatStackArgs && // Is it legal to back-fill? (We haven't put any FP args on the stack yet)
23 (numRegs == 1) && // Is there a possibility we could back-fill?
24 (fltArgSkippedRegMask != RBM_NONE)) // Is there an available back-fill slot?
26 // We will never back-fill something greater than a single register
27 // (TYP_FLOAT, or TYP_STRUCT HFA with a single float). This is because
28 // we don't have any types that require > 2 register alignment, so we
29 // can't create a > 1 register alignment hole to back-fill.
31 // Back-fill the register
32 regMaskTP backFillBitMask = genFindLowestBit(fltArgSkippedRegMask);
33 fltArgSkippedRegMask &= ~backFillBitMask; // Remove the back-filled register(s) from the skipped mask
34 resultArgNum = genMapFloatRegNumToRegArgNum(genRegNumFromMask(backFillBitMask));
35 assert(resultArgNum < MAX_FLOAT_REG_ARG);
38 #endif // _TARGET_ARM_
42 #if defined(_TARGET_AMD64_) && !defined(UNIX_AMD64_ABI)
43 // For System V the reg type counters should be independent.
44 nextReg(TYP_INT, numRegs);
45 nextReg(TYP_FLOAT, numRegs);
47 // We didn't back-fill a register (on ARM), so skip the number of registers that we allocated.
48 nextReg(type, numRegs);
55 bool InitVarDscInfo::enoughAvailRegs(var_types type, unsigned numRegs /* = 1 */)
59 unsigned backFillCount = 0;
62 // Check for back-filling
63 if (varTypeIsFloating(type) && // We only back-fill the float registers
64 !anyFloatStackArgs && // Is it legal to back-fill? (We haven't put any FP args on the stack yet)
65 (numRegs == 1) && // Is there a possibility we could back-fill?
66 (fltArgSkippedRegMask != RBM_NONE)) // Is there an available back-fill slot?
70 #endif // _TARGET_ARM_
72 return regArgNum(type) + numRegs - backFillCount <= maxRegArgNum(type);
75 unsigned InitVarDscInfo::alignReg(var_types type, unsigned requiredRegAlignment)
77 NYI_ARM64("alignReg");
79 assert(requiredRegAlignment > 0);
80 if (requiredRegAlignment == 1)
82 return 0; // Everything is always "1" aligned
85 assert(requiredRegAlignment == 2); // we don't expect anything else right now
87 int alignMask = regArgNum(type) & (requiredRegAlignment - 1);
90 return 0; // We're already aligned
93 unsigned cAlignSkipped = requiredRegAlignment - alignMask;
94 assert(cAlignSkipped == 1); // Alignment is currently only 1 or 2, so misalignment can only be 1.
97 if (varTypeIsFloating(type))
99 fltArgSkippedRegMask |= genMapFloatRegArgNumToRegMask(floatRegArgNum);
101 #endif // _TARGET_ARM_
103 assert(regArgNum(type) + cAlignSkipped <= maxRegArgNum(type)); // if equal, then we aligned the last slot, and the
104 // arg can't be enregistered
105 regArgNum(type) += cAlignSkipped;
107 return cAlignSkipped;
110 bool InitVarDscInfo::canEnreg(var_types type, unsigned numRegs /* = 1 */)
112 if (!isRegParamType(type))
117 if (!enoughAvailRegs(type, numRegs))