kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

6_5_33_regalloc_spill.c (1479B)


      1 /* Regalloc spill stress.
      2  *
      3  * Each `xN + 0` arg is a binop that leaves a register-resident rvalue on
      4  * the cg value stack until cg_call materializes it. With 12 simultaneously
      5  * accumulating arg values and a 10-INT scratch pool on aarch64, several
      6  * code paths the spill driver must handle get exercised:
      7  *
      8  *   - alloc_reg_or_spill returning REG_NONE on pool exhaustion and
      9  *     picking the deepest unpinned RES_REG via pick_victim, then routing
     10  *     it through spill_reg / take_spill_slot.
     11  *   - ensure_reg reloading SPILLED args inside cg_call's arg-pop loop,
     12  *     consuming pool slots as it goes.
     13  *   - The avs-in-flight fallback: once cg_call has popped enough RES_REG
     14  *     args into avs[] to drain the pool, alloc_reg_or_spill finds no
     15  *     stack victim (later args are SPILLED, earlier args are off-stack
     16  *     in avs[]) and falls back to spilling an OPK_REG avs entry through
     17  *     spill_avs_victim, rewriting it to OPK_LOCAL so the backend's call
     18  *     lowering loads from the spill slot.
     19  *
     20  * 1+2+...+12 = 78. */
     21 
     22 int sum12(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j,
     23           int k, int l) {
     24   return a + b + c + d + e + f + g + h + i + j + k + l;
     25 }
     26 
     27 int test_main(void) {
     28   int x1 = 1, x2 = 2, x3 = 3, x4 = 4, x5 = 5, x6 = 6;
     29   int x7 = 7, x8 = 8, x9 = 9, x10 = 10, x11 = 11, x12 = 12;
     30   return sum12(x1 + 0, x2 + 0, x3 + 0, x4 + 0, x5 + 0, x6 + 0, x7 + 0, x8 + 0,
     31                x9 + 0, x10 + 0, x11 + 0, x12 + 0);
     32 }