src/lima/pp_lir/instr_combine.c
//Tries to move constants from old to new, creating a map used for updating
//indvidual instructions
Tries to move constants from old to new, creating a map used for updating
indvidual instructions
Tries to move constants from old to new creating a map used for updating indvidual instructions
static bool try_create_const_map(lima_pp_lir_scheduled_instr_t* new,
								 lima_pp_lir_scheduled_instr_t* old,
								 unsigned* const_map)
{
	unsigned const0_inserted = 0, const1_inserted = 0;
	unsigned i, j;
	for (i = 0; i < 8; i++)
		const_map[i] = 8;
	bool const0_fit = true;
	for (i = 0; i < old->const0_size; i++)
	{
		bool found = false;
		for (j = 0; j < new->const0_size; j++)
			if (new->const0[j] == old->const0[i])
			{
				const_map[i] = j;
				found = true;
				break;
			}
		if (found)
			continue;
		if (new->const0_size + const0_inserted == 4)
		{
			const0_fit = false;
			break;
		}
		const_map[i] = new->const0_size + const0_inserted;
		const0_inserted++;
	}
	if (!const0_fit)
	{
		const0_inserted = 0;
		for (i = 0; i < old->const0_size; i++)
		{
			bool found = false;
			for (j = 0; j < new->const1_size; j++)
				if (new->const1[j] == old->const0[i])
				{
					const_map[i] = j + 4;
					found = true;
					break;
				}
			if (found)
				continue;
			if (new->const1_size + const1_inserted == 4)
				return false;
			const_map[i] = new->const1_size + const1_inserted + 4;
			const1_inserted++;
		}
	}
	const0_fit = true;
	unsigned old_const0_inserted = const0_inserted;
	for (i = 0; i < old->const1_size; i++)
	{
		bool found = false;
		for (j = 0; j < new->const0_size; j++)
			if (new->const0[j] == old->const1[i])
			{
				const_map[i + 4] = j;
				found = true;
				break;
			}
		if (found)
			continue;
		if (new->const0_size + const0_inserted == 4)
		{
			const0_fit = false;
			break;
		}
		const_map[i + 4] = new->const0_size + const0_inserted;
		const0_inserted++;
	}
	if (!const0_fit)
	{
		const0_inserted = old_const0_inserted;
		for (i = 0; i < old->const1_size; i++)
		{
			bool found = false;
			for (j = 0; j < new->const1_size; j++)
				if (new->const1[j] == old->const1[i])
				{
					const_map[i + 4] = j + 4;
					found = true;
					break;
				}
			if (found)
				continue;
			if (new->const1_size + const1_inserted == 4)
				return false;
			const_map[i + 4] = new->const1_size + const1_inserted + 4;
			const1_inserted++;
		}
	}
	for (i = 0; i < old->const0_size; i++)
		assert(const_map[i] < 8);
	for (i = 0; i < old->const1_size; i++)
		assert(const_map[i + 4] < 8);
	return true;
}
static bool try_create_const_map ( lima_pp_lir_scheduled_instr_t * new , lima_pp_lir_scheduled_instr_t * old , unsigned * const_map ) { unsigned const0_inserted = 0 , const1_inserted = 0 ; unsigned i , j ; for ( i = 0 ; i < 8 ; i ++ ) const_map [ i ] = 8 ; bool const0_fit = true ; for ( i = 0 ; i < old -> const0_size ; i ++ ) { bool found = false ; for ( j = 0 ; j < new -> const0_size ; j ++ ) if ( new -> const0 [ j ] == old -> const0 [ i ] ) { const_map [ i ] = j ; found = true ; break ; } if ( found ) continue ; if ( new -> const0_size + const0_inserted == 4 ) { const0_fit = false ; break ; } const_map [ i ] = new -> const0_size + const0_inserted ; const0_inserted ++ ; } if ( ! const0_fit ) { const0_inserted = 0 ; for ( i = 0 ; i < old -> const0_size ; i ++ ) { bool found = false ; for ( j = 0 ; j < new -> const1_size ; j ++ ) if ( new -> const1 [ j ] == old -> const0 [ i ] ) { const_map [ i ] = j + 4 ; found = true ; break ; } if ( found ) continue ; if ( new -> const1_size + const1_inserted == 4 ) return false ; const_map [ i ] = new -> const1_size + const1_inserted + 4 ; const1_inserted ++ ; } } const0_fit = true ; unsigned old_const0_inserted = const0_inserted ; for ( i = 0 ; i < old -> const1_size ; i ++ ) { bool found = false ; for ( j = 0 ; j < new -> const0_size ; j ++ ) if ( new -> const0 [ j ] == old -> const1 [ i ] ) { const_map [ i + 4 ] = j ; found = true ; break ; } if ( found ) continue ; if ( new -> const0_size + const0_inserted == 4 ) { const0_fit = false ; break ; } const_map [ i + 4 ] = new -> const0_size + const0_inserted ; const0_inserted ++ ; } if ( ! const0_fit ) { const0_inserted = old_const0_inserted ; for ( i = 0 ; i < old -> const1_size ; i ++ ) { bool found = false ; for ( j = 0 ; j < new -> const1_size ; j ++ ) if ( new -> const1 [ j ] == old -> const1 [ i ] ) { const_map [ i + 4 ] = j + 4 ; found = true ; break ; } if ( found ) continue ; if ( new -> const1_size + const1_inserted == 4 ) return false ; const_map [ i + 4 ] = new -> const1_size + const1_inserted + 4 ; const1_inserted ++ ; } } for ( i = 0 ; i < old -> const0_size ; i ++ ) assert ( const_map [ i ] < 8 ) ; for ( i = 0 ; i < old -> const1_size ; i ++ ) assert ( const_map [ i + 4 ] < 8 ) ; return true ; }
Tries to move constants from old to new, creating a map used for updating
indvidual instructions
Tries to move constants from old to new creating a map used for updating indvidual instructions
//First, try to find a home for const0 //Inserting into const0 didn't work, try const1 //Same thing for const1 //Inserting into const0 didn't work, try const1