-
Notifications
You must be signed in to change notification settings - Fork 1
/
interference.py
86 lines (77 loc) · 2.17 KB
/
interference.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from x86AST import *
def addEdge(u, v, graph):
if u in graph:
graph[u][0].add(v)
else:
graph[u] = (set([v]), False)
#guarantees node exists in graph
def addNode(reg, graph):
if reg and not reg in graph:
graph[reg] = (set(), False)
def interfereNegPop(instr, liveSet, graph):
addNode(instr.reg, graph)
t = instr.reg
for v in liveSet:
if v != t:
addEdge(t, v, graph)
addEdge(v, t, graph)
def interfereMov(instr, liveSet, graph):
s = instr.reg1
t = instr.reg2
addNode(s, graph)
addNode(t, graph)
for v in liveSet:
if v != t and v != s:
addEdge(t, v, graph)
addEdge(v, t, graph)
def interfereTwoArg(instr, liveSet, graph):
s = instr.reg1
t = instr.reg2
addNode(s, graph)
addNode(t, graph)
for v in liveSet:
if v != t:
addEdge(t, v, graph)
addEdge(v, t, graph)
def interfereCall(instr, liveSet, graph):
t = instr.reg
for v in liveSet:
addEdge("%eax", v, graph)
addEdge("%ecx", v, graph)
addEdge("%edx", v, graph)
addEdge(v, "%eax", graph)
addEdge(v, "%ecx", graph)
addEdge(v, "%edx", graph)
if instr.star and v != t:
addEdge(t, v, graph)
addEdge(v, t, graph)
def interfereIfStmt(instr, liveSet, graph):
interfere(instr.thenAssign, instr.liveThen, graph)
interfere(instr.elseAssign, instr.liveElse, graph)
def interfereModWhile(instr, liveSet, graph):
interfere(instr.testAssign, instr.liveTest, graph)
interfere(instr.bodyAssign, instr.liveBody, graph)
def interfere(asm, liveness, graph):
interferePass = lambda i,l,g: None
for index, instr in enumerate(asm):
{
Pushl: interferePass,
Popl: interfereNegPop,
Negl: interfereNegPop,
Movl: interfereMov,
Addl: interfereTwoArg,
Subl: interfereTwoArg,
Orl: interfereTwoArg,
Andl: interfereTwoArg,
Xorl: interfereTwoArg,
Cmpl: interfereTwoArg,
Cmovel: interfereTwoArg,
Call: interfereCall,
Leave: interferePass,
Ret: interferePass,
Newline: interferePass,
Label: interferePass,
IfStmt: interfereIfStmt,
ModWhile: interfereModWhile
}[instr.__class__](instr, liveness[index+1], graph)
return graph