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 * Authors (Collabora): 24 * Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> 25 */ 26 27#ifndef __VALHALL_COMPILER_H 28#define __VALHALL_COMPILER_H 29 30#include "compiler.h" 31#include "valhall.h" 32 33#ifdef __cplusplus 34extern "C" { 35#endif 36 37bool va_validate_fau(bi_instr *I); 38void va_validate(FILE *fp, bi_context *ctx); 39void va_repair_fau(bi_builder *b, bi_instr *I); 40void va_fuse_add_imm(bi_instr *I); 41void va_lower_constants(bi_context *ctx, bi_instr *I); 42void va_lower_isel(bi_instr *I); 43void va_assign_slots(bi_context *ctx); 44void va_insert_flow_control_nops(bi_context *ctx); 45void va_merge_flow(bi_context *ctx); 46void va_mark_last(bi_context *ctx); 47uint64_t va_pack_instr(const bi_instr *I); 48 49static inline unsigned 50va_fau_page(enum bir_fau value) 51{ 52 /* Uniform slots of FAU have a 7-bit index. The top 2-bits are the page; the 53 * bottom 5-bits are specified in the source. 54 */ 55 if (value & BIR_FAU_UNIFORM) { 56 unsigned slot = value & ~BIR_FAU_UNIFORM; 57 unsigned page = slot >> 5; 58 59 assert(page <= 3); 60 return page; 61 } 62 63 /* Special indices are also paginated */ 64 switch (value) { 65 case BIR_FAU_TLS_PTR: 66 case BIR_FAU_WLS_PTR: 67 return 1; 68 case BIR_FAU_LANE_ID: 69 case BIR_FAU_CORE_ID: 70 case BIR_FAU_PROGRAM_COUNTER: 71 return 3; 72 default: 73 return 0; 74 } 75} 76 77static inline unsigned 78va_select_fau_page(const bi_instr *I) 79{ 80 bi_foreach_src(I, s) { 81 if (I->src[s].type == BI_INDEX_FAU) 82 return va_fau_page((enum bir_fau) I->src[s].value); 83 } 84 85 return 0; 86} 87 88/** Cycle model for Valhall. Results need to be normalized */ 89struct va_stats { 90 /** Counts per pipe */ 91 unsigned fma, cvt, sfu, v, ls, t; 92}; 93 94void 95va_count_instr_stats(bi_instr *I, struct va_stats *stats); 96 97#ifdef __cplusplus 98} /* extern C */ 99#endif 100 101#endif 102