Debian Codegraph @

rpython/jit/backend/aarch64/jump.py

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