1111#include < string.h>
1212
1313LUAU_FASTFLAGVARIABLE (DebugCodegenChaosA64)
14- LUAU_FASTFLAGVARIABLE(LuauCodeGenRegAutoSpillA64)
1514
1615namespace Luau
1716{
@@ -147,19 +146,11 @@ RegisterA64 IrRegAllocA64::allocReg(KindA64 kind, uint32_t index)
147146
148147 if (set.free == 0 )
149148 {
150- if (FFlag::LuauCodeGenRegAutoSpillA64)
149+ // Try to find and spill a register that is not used in the current instruction and has the furthest next use
150+ if (uint32_t furthestUseTarget = findInstructionWithFurthestNextUse (set); furthestUseTarget != kInvalidInstIdx )
151151 {
152- // Try to find and spill a register that is not used in the current instruction and has the furthest next use
153- if (uint32_t furthestUseTarget = findInstructionWithFurthestNextUse (set); furthestUseTarget != kInvalidInstIdx )
154- {
155- spill (set, index, furthestUseTarget);
156- CODEGEN_ASSERT (set.free != 0 );
157- }
158- else
159- {
160- error = true ;
161- return RegisterA64{kind, 0 };
162- }
152+ spill (set, index, furthestUseTarget);
153+ CODEGEN_ASSERT (set.free != 0 );
163154 }
164155 else
165156 {
@@ -185,19 +176,11 @@ RegisterA64 IrRegAllocA64::allocTemp(KindA64 kind)
185176
186177 if (set.free == 0 )
187178 {
188- if (FFlag::LuauCodeGenRegAutoSpillA64)
179+ // Try to find and spill a register that is not used in the current instruction and has the furthest next use
180+ if (uint32_t furthestUseTarget = findInstructionWithFurthestNextUse (set); furthestUseTarget != kInvalidInstIdx )
189181 {
190- // Try to find and spill a register that is not used in the current instruction and has the furthest next use
191- if (uint32_t furthestUseTarget = findInstructionWithFurthestNextUse (set); furthestUseTarget != kInvalidInstIdx )
192- {
193- spill (set, currInstIdx, furthestUseTarget);
194- CODEGEN_ASSERT (set.free != 0 );
195- }
196- else
197- {
198- error = true ;
199- return RegisterA64{kind, 0 };
200- }
182+ spill (set, currInstIdx, furthestUseTarget);
183+ CODEGEN_ASSERT (set.free != 0 );
201184 }
202185 else
203186 {
@@ -351,79 +334,16 @@ size_t IrRegAllocA64::spill(uint32_t index, std::initializer_list<RegisterA64> l
351334
352335 while (regs)
353336 {
354- if (FFlag::LuauCodeGenRegAutoSpillA64)
355- {
356- int reg = 31 - countlz (regs);
357-
358- uint32_t targetInstIdx = set.defs [reg];
359-
360- CODEGEN_ASSERT (targetInstIdx != kInvalidInstIdx );
361- CODEGEN_ASSERT (function.instructions [targetInstIdx].regA64 .index == reg);
362-
363- spill (set, index, targetInstIdx);
364-
365- regs &= ~(1u << reg);
366- }
367- else
368- {
369- int reg = 31 - countlz (regs);
370-
371- uint32_t inst = set.defs [reg];
372- CODEGEN_ASSERT (inst != kInvalidInstIdx );
373-
374- IrInst& def = function.instructions [inst];
375- CODEGEN_ASSERT (def.regA64 .index == reg);
376- CODEGEN_ASSERT (!def.reusedReg );
377- CODEGEN_ASSERT (!def.spilled );
378- CODEGEN_ASSERT (!def.needsReload );
379-
380- if (def.lastUse == index)
381- {
382- // instead of spilling the register to never reload it, we assume the register is not needed anymore
383- }
384- else if (getReloadAddress (function, def, /* limitToCurrentBlock*/ true ).base != xzr)
385- {
386- // instead of spilling the register to stack, we can reload it from VM stack/constants
387- // we still need to record the spill for restore(start) to work
388- Spill s = {inst, def.regA64 , -1 };
389- spills.push_back (s);
390-
391- def.needsReload = true ;
392-
393- if (stats)
394- stats->spillsToRestore ++;
395- }
396- else
397- {
398- int slot = allocSpill (freeSpillSlots, def.regA64 .kind );
399- if (slot < 0 )
400- {
401- slot = kInvalidSpill ;
402- error = true ;
403- }
404-
405- build.str (def.regA64 , mem (sp, sSpillArea .data + slot * 8 ));
406-
407- Spill s = {inst, def.regA64 , int8_t (slot)};
408- spills.push_back (s);
409-
410- def.spilled = true ;
411-
412- if (stats)
413- {
414- stats->spillsToSlot ++;
415-
416- if (slot != kInvalidSpill && unsigned (slot + 1 ) > stats->maxSpillSlotsUsed )
417- stats->maxSpillSlotsUsed = slot + 1 ;
418- }
419- }
420-
421- def.regA64 = noreg;
422-
423- regs &= ~(1u << reg);
424- set.free |= 1u << reg;
425- set.defs [reg] = kInvalidInstIdx ;
426- }
337+ int reg = 31 - countlz (regs);
338+
339+ uint32_t targetInstIdx = set.defs [reg];
340+
341+ CODEGEN_ASSERT (targetInstIdx != kInvalidInstIdx );
342+ CODEGEN_ASSERT (function.instructions [targetInstIdx].regA64 .index == reg);
343+
344+ spill (set, index, targetInstIdx);
345+
346+ regs &= ~(1u << reg);
427347 }
428348
429349 CODEGEN_ASSERT (set.free == set.base );
@@ -485,8 +405,6 @@ void IrRegAllocA64::restoreReg(IrInst& inst)
485405
486406void IrRegAllocA64::spill (Set& set, uint32_t index, uint32_t targetInstIdx)
487407{
488- CODEGEN_ASSERT (FFlag::LuauCodeGenRegAutoSpillA64);
489-
490408 IrInst& def = function.instructions [targetInstIdx];
491409 int reg = def.regA64 .index ;
492410
@@ -543,8 +461,6 @@ void IrRegAllocA64::spill(Set& set, uint32_t index, uint32_t targetInstIdx)
543461
544462uint32_t IrRegAllocA64::findInstructionWithFurthestNextUse (Set& set) const
545463{
546- CODEGEN_ASSERT (FFlag::LuauCodeGenRegAutoSpillA64);
547-
548464 if (currInstIdx == kInvalidInstIdx )
549465 return kInvalidInstIdx ;
550466
0 commit comments