Debian Codegraph @

rpython/jit/backend/arm/jump.py

raw symbols SCIP
1 # ../x86/jump.py
2 # XXX combine with ../x86/jump.py and move to llsupport
3
4
5 def remap_frame_layout(assembler, src_locations, dst_locations, tmpreg):
6 pending_dests = len(dst_locations)
7 srccount = {} # maps dst_locations to how many times the same
8 # location appears in src_locations
9 for dst in dst_locations:
10 key = dst.as_key()
11 assert key not in srccount, "duplicate value in dst_locations!"
12 srccount[key] = 0
13 for i in range(len(dst_locations)):
14 src = src_locations[i]
15 if src.is_imm():
16 continue
17 key = src.as_key()
18 if key in srccount:
19 if key == dst_locations[i].as_key():
20 # ignore a move "x = x"
21 # setting any "large enough" negative value is ok, but
22 # be careful of overflows, don't use -sys.maxint
23 srccount[key] = -len(dst_locations) - 1
24 pending_dests -= 1
25 else:
26 srccount[key] += 1
27
28 while pending_dests > 0:
29 progress = False
30 for i in range(len(dst_locations)):
31 dst = dst_locations[i]
32 key = dst.as_key()
33 if srccount[key] == 0:
34 srccount[key] = -1 # means "it's done"
35 pending_dests -= 1
36 src = src_locations[i]
37 if not src.is_imm():
38 key = src.as_key()
39 if key in srccount:
40 srccount[key] -= 1
41 _move(assembler, src, dst, tmpreg)
42 progress = True
43 if not progress:
44 # we are left with only pure disjoint cycles
45 sources = {} # maps dst_locations to src_locations
46 for i in range(len(dst_locations)):
47 src = src_locations[i]
48 dst = dst_locations[i]
49 sources[dst.as_key()] = src
50 #
51 for i in range(len(dst_locations)):
52 dst = dst_locations[i]
53 originalkey = dst.as_key()
54 if srccount[originalkey] >= 0:
55 assembler.regalloc_push(dst)
56 while True:
57 key = dst.as_key()
58 assert srccount[key] == 1
59 # ^^^ because we are in a simple cycle
60 srccount[key] = -1
61 pending_dests -= 1
62 src = sources[key]
63 if src.as_key() == originalkey:
64 break
65 _move(assembler, src, dst, tmpreg)
66 dst = src
67 assembler.regalloc_pop(dst)
68 assert pending_dests == 0
69
70
71 def _move(assembler, src, dst, tmpreg):
72 if dst.is_stack() and src.is_stack():
73 assembler.regalloc_mov(src, tmpreg)
74 src = tmpreg
75 assembler.regalloc_mov(src, dst)
76
77
78 def remap_frame_layout_mixed(assembler,
79 src_locations1, dst_locations1, tmpreg1,
80 src_locations2, dst_locations2, tmpreg2):
81 # find and push the xmm stack locations from src_locations2 that
82 # are going to be overwritten by dst_locations1
83 from rpython.jit.backend.arm.arch import WORD
84 extrapushes = []
85 dst_keys = {}
86 for loc in dst_locations1:
87 dst_keys[loc.as_key()] = None
88 src_locations2red = []
89 dst_locations2red = []
90 for i in range(len(src_locations2)):
91 loc = src_locations2[i]
92 dstloc = dst_locations2[i]
93 if loc.is_stack():
94 key = loc.as_key()
95 if (key in dst_keys or (loc.width > WORD and
96 (key + 1) in dst_keys)):
97 assembler.regalloc_push(loc)
98 extrapushes.append(dstloc)
99 continue
100 src_locations2red.append(loc)
101 dst_locations2red.append(dstloc)
102 src_locations2 = src_locations2red
103 dst_locations2 = dst_locations2red
104 #
105 # remap the integer and pointer registers and stack locations
106 remap_frame_layout(assembler, src_locations1, dst_locations1, tmpreg1)
107 #
108 # remap the vfp registers and stack locations
109 remap_frame_layout(assembler, src_locations2, dst_locations2, tmpreg2)
110 #
111 # finally, pop the extra xmm stack locations
112 while len(extrapushes) > 0:
113 loc = extrapushes.pop()
114 assembler.regalloc_pop(loc)