Debian Codegraph @

rpython/jit/backend/llsupport/jump.py

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