summary refs log tree commit diff
path: root/simpl.c
blob: 384a8da63be7a9cf6024bd495af54019a6eb306e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "all.h"

static void
elimext(Ins *i, int ext, Fn *fn)
{
	Tmp *t;
	Use *u;

	assert(rtype(i->to) == RTmp);
	t = &fn->tmp[i->to.val];
	for (u=t->use; u<&t->use[t->nuse]; u++)
		if (u->type == UIns
		&& u->u.ins->op == ext
		&& (u->u.ins->cls == i->cls || i->cls == Kl)) {
			u->u.ins->op = Ocopy;
			elimext(u->u.ins, ext, fn);
		}
}

/* requires & preserves uses */
void
simpl(Fn *fn)
{
	Blk *b;
	Ins *i;
	int ext;

	for (b=fn->start; b; b=b->link)
		for (i=b->ins; i<&b->ins[b->nins]; i++)
			switch (i->op) {
			case Oloadsb:
			case Oloadub:
			case Oloadsh:
			case Oloaduh:
				ext = Oextsb + (i->op - Oloadsb);
				goto Elimext;
			case Oextsb:
			case Oextub:
			case Oextsh:
			case Oextuh:
				ext = i->op;
			Elimext:
				elimext(i, ext, fn);
				break;
			}
}