• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Collabora Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 #include "va_compiler.h"
25 #include "bi_builder.h"
26 
27 /*
28  * Bifrost uses split 64-bit addresses, specified as two consecutive sources.
29  * Valhall uses contiguous 64-bit addresses, specified as a single source with
30  * an aligned register pair. This simple pass inserts moves to lower split
31  * 64-bit sources into a collect, ensuring the register constraints will be
32  * respected by RA. This could be optimized, but this is deferred for now.
33  */
34 static void
lower_split_src(bi_context * ctx,bi_instr * I,unsigned s)35 lower_split_src(bi_context *ctx, bi_instr *I, unsigned s)
36 {
37    /* Skip sources that are already split properly */
38    bi_index offset_fau = I->src[s];
39    offset_fau.offset++;
40 
41    if (I->src[s].type == BI_INDEX_FAU &&
42        I->src[s].offset == 0 &&
43        bi_is_value_equiv(offset_fau, I->src[s + 1])) {
44       return;
45    }
46 
47    /* Allocate temporary before the instruction */
48    bi_builder b = bi_init_builder(ctx, bi_before_instr(I));
49    bi_index vec = bi_temp(ctx);
50    bi_instr *collect = bi_collect_i32_to(&b, vec);
51    collect->nr_srcs = 2;
52 
53    bi_instr *split = bi_split_i32_to(&b, bi_null(), vec);
54    split->nr_dests = 2;
55 
56    /* Emit collect */
57    for (unsigned w = 0; w < 2; ++w) {
58       collect->src[w] = I->src[s + w];
59 
60       split->dest[w] = bi_temp(ctx);
61       I->src[s + w] = split->dest[w];
62    }
63 }
64 
65 void
va_lower_split_64bit(bi_context * ctx)66 va_lower_split_64bit(bi_context *ctx)
67 {
68    bi_foreach_instr_global(ctx, I) {
69       bi_foreach_src(I, s) {
70          if (bi_is_null(I->src[s]) || s >= 4)
71             continue;
72 
73          struct va_src_info info = va_src_info(I->op, s);
74 
75          if (info.size == VA_SIZE_64)
76             lower_split_src(ctx, I, s);
77       }
78    }
79 }
80