From 6f54385b0a4a4d39d73b4de1743cd7ee3ef3e55c Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 24 May 2021 19:47:58 -0400 Subject: [PATCH] agx: Track block offsets For fixing branch offsets. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_compiler.h | 3 +++ src/asahi/compiler/agx_pack.c | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/asahi/compiler/agx_compiler.h b/src/asahi/compiler/agx_compiler.h index a9d818d83c6..02030f09ac6 100644 --- a/src/asahi/compiler/agx_compiler.h +++ b/src/asahi/compiler/agx_compiler.h @@ -303,6 +303,9 @@ typedef struct agx_block { /* Liveness analysis results */ BITSET_WORD *live_in; BITSET_WORD *live_out; + + /* Offset of the block in the emitted binary */ + off_t offset; } agx_block; typedef struct { diff --git a/src/asahi/compiler/agx_pack.c b/src/asahi/compiler/agx_pack.c index c61ff43536a..f75d90dc478 100644 --- a/src/asahi/compiler/agx_pack.c +++ b/src/asahi/compiler/agx_pack.c @@ -552,6 +552,13 @@ agx_pack_instr(struct util_dynarray *emission, agx_instr *I) void agx_pack(agx_context *ctx, struct util_dynarray *emission) { - agx_foreach_instr_global(ctx, ins) - agx_pack_instr(emission, ins); + agx_foreach_block(ctx, block) { + /* Relative to the start of the binary, the block begins at the current + * number of bytes emitted */ + block->offset = emission->size; + + agx_foreach_instr_in_block(block, ins) { + agx_pack_instr(emission, ins); + } + } }