| 1 |
/* |
| 2 |
* Copyright (C) 2021 Collabora Ltd. |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "bi_builder.h" |
| 7 |
#include "compiler.h" |
| 8 |
#include "va_compiler.h" |
| 9 |
#include "valhall.h" |
| 10 |
#include "compiler.h" |
| 11 |
|
| 12 |
static bi_instr * |
| 13 |
lower(bi_builder *b, bi_instr *I) |
| 14 |
{ |
| 15 |
switch (I->op) { |
| 16 |
case BI_OPCODE_ICMP_I32: |
| 17 |
return bi_icmp_or_u32_to(b, I->dest[0], I->src[0], I->src[1], bi_zero(), |
| 18 |
I->cmpf, I->result_type); |
| 19 |
|
| 20 |
case BI_OPCODE_ICMP_V2I16: |
| 21 |
return bi_icmp_or_v2u16_to(b, I->dest[0], I->src[0], I->src[1], bi_zero(), |
| 22 |
I->cmpf, I->result_type); |
| 23 |
|
| 24 |
case BI_OPCODE_ICMP_V4I8: |
| 25 |
return bi_icmp_or_v4u8_to(b, I->dest[0], I->src[0], I->src[1], bi_zero(), |
| 26 |
I->cmpf, I->result_type); |
| 27 |
|
| 28 |
case BI_OPCODE_ICMP_U32: |
| 29 |
return bi_icmp_or_u32_to(b, I->dest[0], I->src[0], I->src[1], bi_zero(), |
| 30 |
I->cmpf, I->result_type); |
| 31 |
|
| 32 |
case BI_OPCODE_ICMP_V2U16: |
| 33 |
return bi_icmp_or_v2u16_to(b, I->dest[0], I->src[0], I->src[1], bi_zero(), |
| 34 |
I->cmpf, I->result_type); |
| 35 |
|
| 36 |
case BI_OPCODE_ICMP_V4U8: |
| 37 |
return bi_icmp_or_v4u8_to(b, I->dest[0], I->src[0], I->src[1], bi_zero(), |
| 38 |
I->cmpf, I->result_type); |
| 39 |
|
| 40 |
case BI_OPCODE_ICMP_S32: |
| 41 |
return bi_icmp_or_s32_to(b, I->dest[0], I->src[0], I->src[1], bi_zero(), |
| 42 |
I->cmpf, I->result_type); |
| 43 |
|
| 44 |
case BI_OPCODE_ICMP_V2S16: |
| 45 |
return bi_icmp_or_v2s16_to(b, I->dest[0], I->src[0], I->src[1], bi_zero(), |
| 46 |
I->cmpf, I->result_type); |
| 47 |
|
| 48 |
case BI_OPCODE_ICMP_V4S8: |
| 49 |
return bi_icmp_or_v4s8_to(b, I->dest[0], I->src[0], I->src[1], bi_zero(), |
| 50 |
I->cmpf, I->result_type); |
| 51 |
|
| 52 |
case BI_OPCODE_FCMP_F32: |
| 53 |
return bi_fcmp_or_f32_to(b, I->dest[0], I->src[0], I->src[1], bi_zero(), |
| 54 |
I->cmpf, I->result_type); |
| 55 |
|
| 56 |
case BI_OPCODE_FCMP_V2F16: |
| 57 |
return bi_fcmp_or_v2f16_to(b, I->dest[0], I->src[0], I->src[1], bi_zero(), |
| 58 |
I->cmpf, I->result_type); |
| 59 |
|
| 60 |
/* Integer CSEL must have a signedness */ |
| 61 |
case BI_OPCODE_CSEL_I32: |
| 62 |
case BI_OPCODE_CSEL_V2I16: |
| 63 |
assert(I->cmpf == BI_CMPF_EQ || I->cmpf == BI_CMPF_NE); |
| 64 |
|
| 65 |
bi_set_opcode(I, |
| 66 |
(I->op == BI_OPCODE_CSEL_I32) ? BI_OPCODE_CSEL_U32 |
| 67 |
: BI_OPCODE_CSEL_V2U16); |
| 68 |
return NULL; |
| 69 |
|
| 70 |
/* Jump -> conditional branch with condition tied to true. */ |
| 71 |
case BI_OPCODE_JUMP: |
| 72 |
if (I->branch_target) { |
| 73 |
bi_instr *new_I = bi_branchz_i16(b, bi_zero(), I->src[0], BI_CMPF_EQ); |
| 74 |
new_I->branch_target = I->branch_target; |
| 75 |
return I; |
| 76 |
} else { |
| 77 |
return bi_branchzi(b, bi_zero(), I->src[0], BI_CMPF_EQ); |
| 78 |
} |
| 79 |
|
| 80 |
case BI_OPCODE_AXCHG_I64: |
| 81 |
bi_set_opcode(I, BI_OPCODE_ATOM_RETURN_I64); |
| 82 |
I->atom_opc = BI_ATOM_OPC_AXCHG; |
| 83 |
I->sr_count = 2; |
| 84 |
return NULL; |
| 85 |
|
| 86 |
case BI_OPCODE_AXCHG_I32: |
| 87 |
bi_set_opcode(I, BI_OPCODE_ATOM_RETURN_I32); |
| 88 |
I->atom_opc = BI_ATOM_OPC_AXCHG; |
| 89 |
I->sr_count = 1; |
| 90 |
return NULL; |
| 91 |
|
| 92 |
case BI_OPCODE_ACMPXCHG_I64: |
| 93 |
bi_set_opcode(I, BI_OPCODE_ATOM_RETURN_I64); |
| 94 |
I->atom_opc = BI_ATOM_OPC_ACMPXCHG; |
| 95 |
/* Reads 4, this is special cased in bir.c */ |
| 96 |
I->sr_count = 2; |
| 97 |
return NULL; |
| 98 |
|
| 99 |
case BI_OPCODE_ACMPXCHG_I32: |
| 100 |
bi_set_opcode(I, BI_OPCODE_ATOM_RETURN_I32); |
| 101 |
I->atom_opc = BI_ATOM_OPC_ACMPXCHG; |
| 102 |
/* Reads 2, this is special cased in bir.c */ |
| 103 |
I->sr_count = 1; |
| 104 |
return NULL; |
| 105 |
|
| 106 |
case BI_OPCODE_ATOM_RETURN_I32: |
| 107 |
if (bi_is_null(I->dest[0])) |
| 108 |
bi_set_opcode(I, BI_OPCODE_ATOM_I32); |
| 109 |
|
| 110 |
return NULL; |
| 111 |
|
| 112 |
case BI_OPCODE_MUX_I32: |
| 113 |
case BI_OPCODE_MUX_V2I16: |
| 114 |
if (bi_can_replace_with_csel(I)) |
| 115 |
return bi_csel_from_mux(b, I, true); |
| 116 |
|
| 117 |
return NULL; |
| 118 |
|
| 119 |
case BI_OPCODE_FADD_RSCALE_F32: |
| 120 |
return bi_fma_rscale_f32_to(b, I->dest[0], I->src[0], bi_imm_f32(1.0), |
| 121 |
I->src[1], I->src[2], I->special); |
| 122 |
|
| 123 |
default: |
| 124 |
return NULL; |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
void |
| 129 |
va_lower_isel(bi_context *ctx) |
| 130 |
{ |
| 131 |
bi_foreach_instr_global_safe(ctx, I) { |
| 132 |
bi_builder b = bi_init_builder(ctx, bi_before_instr(I)); |
| 133 |
|
| 134 |
if (lower(&b, I)) |
| 135 |
bi_remove_instruction(I); |
| 136 |
} |
| 137 |
} |