Debian Codegraph @

rpython/jit/backend/ppc/jump.py

raw symbols SCIP
1 # ../x86/jump.py
2 # XXX combine with ../x86/jump.py and move to llsupport
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.regalloc_push(dst, 0)
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.regalloc_pop(dst, 0)
67 assert pending_dests == 0
68
69 def _move(assembler, src, dst, tmpreg):
70 if dst.is_stack() and src.is_stack():
71 assembler.regalloc_mov(src, tmpreg)
72 src = tmpreg
73 assembler.regalloc_mov(src, dst)
74
75 def remap_frame_layout_mixed(assembler,
76 src_locations1, dst_locations1, tmpreg1,
77 src_locations2, dst_locations2, tmpreg2):
78 # find and push the fp stack locations from src_locations2 that
79 # are going to be overwritten by dst_locations1
80 from rpython.jit.backend.ppc.arch import WORD
81 extrapushes = []
82 dst_keys = {}
83 for loc in dst_locations1:
84 dst_keys[loc.as_key()] = None
85 src_locations2red = []
86 dst_locations2red = []
87 for i in range(len(src_locations2)):
88 loc = src_locations2[i]
89 dstloc = dst_locations2[i]
90 if loc.is_stack():
91 key = loc.as_key()
92 if (key in dst_keys or (loc.width > WORD and
93 (key + 1) in dst_keys)):
94 # don't call regalloc_push with already_pushed==0 here
95 # because it can conflict with the regalloc_push() above
96 assembler.regalloc_push(loc, len(extrapushes) + 1)
97 extrapushes.append(dstloc)
98 continue
99 src_locations2red.append(loc)
100 dst_locations2red.append(dstloc)
101 src_locations2 = src_locations2red
102 dst_locations2 = dst_locations2red
103 #
104 # remap the integer and pointer registers and stack locations
105 remap_frame_layout(assembler, src_locations1, dst_locations1, tmpreg1)
106 #
107 # remap the fp registers and stack locations
108 remap_frame_layout(assembler, src_locations2, dst_locations2, tmpreg2)
109 #
110 # finally, pop the extra fp stack locations
111 while len(extrapushes) > 0:
112 loc = extrapushes.pop()
113 assembler.regalloc_pop(loc, len(extrapushes) + 1)