replace MAX_OFFSET with IR_MAX_CONTEXT

This commit is contained in:
Anthony Pesch 2017-08-17 20:15:59 -04:00
parent 9c15879c30
commit 357a210c79
3 changed files with 26 additions and 25 deletions

View File

@ -464,12 +464,16 @@ void ir_store_fast(struct ir *ir, struct ir_value *addr, struct ir_value *v) {
struct ir_value *ir_load_context(struct ir *ir, size_t offset,
enum ir_type type) {
CHECK_LE(offset + ir_type_size(type), IR_MAX_CONTEXT);
struct ir_instr *instr = ir_append_instr(ir, OP_LOAD_CONTEXT, type);
ir_set_arg0(ir, instr, ir_alloc_i32(ir, (int32_t)offset));
return instr->result;
}
void ir_store_context(struct ir *ir, size_t offset, struct ir_value *v) {
CHECK_LE(offset + ir_type_size(v->type), IR_MAX_CONTEXT);
struct ir_instr *instr = ir_append_instr(ir, OP_STORE_CONTEXT, VALUE_V);
ir_set_arg0(ir, instr, ir_alloc_i32(ir, (int32_t)offset));
ir_set_arg1(ir, instr, v);

View File

@ -7,6 +7,7 @@
#include "core/list.h"
#define IR_MAX_ARGS 4
#define IR_MAX_CONTEXT 512
enum ir_op {
#define IR_OP(name, flags) OP_##name,

View File

@ -5,8 +5,6 @@
DEFINE_STAT(loads_removed, "context loads eliminated");
DEFINE_STAT(stores_removed, "context stores eliminated");
#define MAX_OFFSET 512
struct lse_entry {
/* cache token when this entry was added */
uint64_t token;
@ -19,7 +17,7 @@ struct lse {
/* current cache token */
uint64_t token;
struct lse_entry available[MAX_OFFSET];
struct lse_entry available[IR_MAX_CONTEXT];
};
static void lse_clear_available(struct lse *lse) {
@ -29,10 +27,9 @@ static void lse_clear_available(struct lse *lse) {
}
static void lse_erase_available(struct lse *lse, int offset, int size) {
CHECK_LT(offset + size, MAX_OFFSET);
int begin = offset;
int end = offset + size - 1;
CHECK_LT(end, IR_MAX_CONTEXT);
/* if the invalidation range intersects with an entry, merge that entry into
the invalidation range */
@ -55,8 +52,26 @@ static void lse_erase_available(struct lse *lse, int offset, int size) {
}
}
static void lse_set_available(struct lse *lse, int offset, struct ir_value *v) {
int size = ir_type_size(v->type);
int begin = offset;
int end = offset + size - 1;
CHECK_LT(end, IR_MAX_CONTEXT);
lse_erase_available(lse, offset, size);
/* add entries for the entire range to aid in invalidation. only the initial
entry where offset == entry.offset is valid for reuse */
for (; begin <= end; begin++) {
struct lse_entry *entry = &lse->available[begin];
entry->token = lse->token;
entry->offset = offset;
entry->value = v;
}
}
static struct ir_value *lse_get_available(struct lse *lse, int offset) {
CHECK_LT(offset, MAX_OFFSET);
CHECK_LT(offset, IR_MAX_CONTEXT);
struct lse_entry *entry = &lse->available[offset];
@ -75,25 +90,6 @@ static struct ir_value *lse_get_available(struct lse *lse, int offset) {
return entry->value;
}
static void lse_set_available(struct lse *lse, int offset, struct ir_value *v) {
int size = ir_type_size(v->type);
CHECK_LT(offset + size, MAX_OFFSET);
int begin = offset;
int end = offset + size - 1;
lse_erase_available(lse, offset, size);
/* add entries for the entire range to aid in invalidation. only the initial
entry where offset == entry.offset is valid for reuse */
for (; begin <= end; begin++) {
struct lse_entry *entry = &lse->available[begin];
entry->token = lse->token;
entry->offset = offset;
entry->value = v;
}
}
static void lse_eliminate_loads(struct lse *lse, struct ir *ir,
struct ir_block *block) {
lse_clear_available(lse);