1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (C) 2021 Collabora Ltd. 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21bf215546Sopenharmony_ci * SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci * Authors (Collabora): 24bf215546Sopenharmony_ci * Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> 25bf215546Sopenharmony_ci */ 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#ifndef __VALHALL_COMPILER_H 28bf215546Sopenharmony_ci#define __VALHALL_COMPILER_H 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include "compiler.h" 31bf215546Sopenharmony_ci#include "valhall.h" 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci#ifdef __cplusplus 34bf215546Sopenharmony_ciextern "C" { 35bf215546Sopenharmony_ci#endif 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_cibool va_validate_fau(bi_instr *I); 38bf215546Sopenharmony_civoid va_validate(FILE *fp, bi_context *ctx); 39bf215546Sopenharmony_civoid va_repair_fau(bi_builder *b, bi_instr *I); 40bf215546Sopenharmony_civoid va_fuse_add_imm(bi_instr *I); 41bf215546Sopenharmony_civoid va_lower_constants(bi_context *ctx, bi_instr *I); 42bf215546Sopenharmony_civoid va_lower_isel(bi_instr *I); 43bf215546Sopenharmony_civoid va_assign_slots(bi_context *ctx); 44bf215546Sopenharmony_civoid va_insert_flow_control_nops(bi_context *ctx); 45bf215546Sopenharmony_civoid va_merge_flow(bi_context *ctx); 46bf215546Sopenharmony_civoid va_mark_last(bi_context *ctx); 47bf215546Sopenharmony_ciuint64_t va_pack_instr(const bi_instr *I); 48bf215546Sopenharmony_ci 49bf215546Sopenharmony_cistatic inline unsigned 50bf215546Sopenharmony_civa_fau_page(enum bir_fau value) 51bf215546Sopenharmony_ci{ 52bf215546Sopenharmony_ci /* Uniform slots of FAU have a 7-bit index. The top 2-bits are the page; the 53bf215546Sopenharmony_ci * bottom 5-bits are specified in the source. 54bf215546Sopenharmony_ci */ 55bf215546Sopenharmony_ci if (value & BIR_FAU_UNIFORM) { 56bf215546Sopenharmony_ci unsigned slot = value & ~BIR_FAU_UNIFORM; 57bf215546Sopenharmony_ci unsigned page = slot >> 5; 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_ci assert(page <= 3); 60bf215546Sopenharmony_ci return page; 61bf215546Sopenharmony_ci } 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_ci /* Special indices are also paginated */ 64bf215546Sopenharmony_ci switch (value) { 65bf215546Sopenharmony_ci case BIR_FAU_TLS_PTR: 66bf215546Sopenharmony_ci case BIR_FAU_WLS_PTR: 67bf215546Sopenharmony_ci return 1; 68bf215546Sopenharmony_ci case BIR_FAU_LANE_ID: 69bf215546Sopenharmony_ci case BIR_FAU_CORE_ID: 70bf215546Sopenharmony_ci case BIR_FAU_PROGRAM_COUNTER: 71bf215546Sopenharmony_ci return 3; 72bf215546Sopenharmony_ci default: 73bf215546Sopenharmony_ci return 0; 74bf215546Sopenharmony_ci } 75bf215546Sopenharmony_ci} 76bf215546Sopenharmony_ci 77bf215546Sopenharmony_cistatic inline unsigned 78bf215546Sopenharmony_civa_select_fau_page(const bi_instr *I) 79bf215546Sopenharmony_ci{ 80bf215546Sopenharmony_ci bi_foreach_src(I, s) { 81bf215546Sopenharmony_ci if (I->src[s].type == BI_INDEX_FAU) 82bf215546Sopenharmony_ci return va_fau_page((enum bir_fau) I->src[s].value); 83bf215546Sopenharmony_ci } 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ci return 0; 86bf215546Sopenharmony_ci} 87bf215546Sopenharmony_ci 88bf215546Sopenharmony_ci/** Cycle model for Valhall. Results need to be normalized */ 89bf215546Sopenharmony_cistruct va_stats { 90bf215546Sopenharmony_ci /** Counts per pipe */ 91bf215546Sopenharmony_ci unsigned fma, cvt, sfu, v, ls, t; 92bf215546Sopenharmony_ci}; 93bf215546Sopenharmony_ci 94bf215546Sopenharmony_civoid 95bf215546Sopenharmony_civa_count_instr_stats(bi_instr *I, struct va_stats *stats); 96bf215546Sopenharmony_ci 97bf215546Sopenharmony_ci#ifdef __cplusplus 98bf215546Sopenharmony_ci} /* extern C */ 99bf215546Sopenharmony_ci#endif 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_ci#endif 102