1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/xlat/livevar.c Tue Apr 07 10:55:03 2009 +0000
1.5 + * $Id: livevar.h 931 2008-10-31 02:57:59Z nkeynes $
1.7 + * Live variable analysis
1.9 + * Copyright (c) 2009 Nathan Keynes.
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.22 +#include "xlat/xir.h"
1.23 +#include "xlat/xiropt.h"
1.26 +gboolean live_range_calculate( xir_op_t start, xir_op_t end,
1.27 + struct live_range *live_ranges, unsigned int live_ranges_size )
1.29 + struct live_range *current[MAX_REGISTERS];
1.30 + struct live_range *range_next = live_ranges;
1.31 + struct live_range *range_end = live_ranges + live_ranges_size;
1.32 + xir_offset_t position = 0;
1.33 + xir_offset_t last_exc = 0;
1.36 + memset( current, 0, sizeof(current) );
1.38 + while( it != end ) {
1.42 + if( it->exc != NULL ) {
1.43 + // Track when the last possible exception was
1.44 + last_exc = position;
1.47 + if( XOP_READS_REG1(it) ) { // Update live-range for op0
1.48 + reg0 = XOP_REG1(it);
1.49 + if( current[reg0] == NULL ) {
1.50 + current[reg0] = range_next++;
1.51 + if( current[reg0] == range_end )
1.53 + current[reg0]->start = it;
1.54 + current[reg0]->offset = position;
1.55 + current[reg0]->writeback = FALSE; // register is already coherent
1.57 + current[reg0]->end = it;
1.58 + current[reg0]->length = position - current[reg0]->offset;
1.61 + if( XOP_READS_REG2(it) ) {
1.62 + reg1 = XOP_REG2(it);
1.63 + if( current[reg1] == NULL ) {
1.64 + current[reg1] = range_next++;
1.65 + if( current[reg1] == range_end )
1.67 + current[reg1]->start = it;
1.68 + current[reg1]->offset = position;
1.70 + current[reg1]->end = it;
1.71 + current[reg1]->length = position - current[reg1]->offset;
1.72 + } // op1 is Use-only
1.74 + if( XOP_WRITES_REG1(it) ) {
1.77 + if( XOP_WRITES_REG2(it) ) {
1.78 + int reg = XOP_REG2(it);
1.79 + if( last_exc < current[reg].end ) {
1.80 + // Value is dead and doesn't need to be spilled.
1.81 + current[reg].writeback = FALSE;
1.83 + // Kill last range for op1 if we're not using it. Otherwise
1.84 + // this is just a continuation.
1.85 + current[reg] = range_next++;
1.86 + if( current[reg] == range_end )
1.88 + current[reg]->start = it;
1.89 + current[reg]->offset = position;
1.90 + current[reg]->end = it;
1.91 + current[reg]->length = 0;
1.92 + current[reg]->writeback = TRUE;
1.100 \ No newline at end of file