Mercurial > hg > CbC > CbC_llvm
comparison llvm/utils/pipeline.py @ 252:1f2b6ac9f198 llvm-original
LLVM16-1
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 18 Aug 2023 09:04:13 +0900 |
parents | c4bab56944e8 |
children |
comparison
equal
deleted
inserted
replaced
237:c80f45b162ad | 252:1f2b6ac9f198 |
---|---|
4 | 4 |
5 def fromStr(pipeStr): | 5 def fromStr(pipeStr): |
6 """Create pipeline object from string representation.""" | 6 """Create pipeline object from string representation.""" |
7 stack = [] | 7 stack = [] |
8 curr = [] | 8 curr = [] |
9 tok = '' | 9 tok = "" |
10 kind = '' | 10 kind = "" |
11 for c in pipeStr: | 11 for c in pipeStr: |
12 if c == ',': | 12 if c == ",": |
13 if tok != '': | 13 if tok != "": |
14 curr.append([None, tok]) | 14 curr.append([None, tok]) |
15 tok = '' | 15 tok = "" |
16 elif c == '(': | 16 elif c == "(": |
17 stack.append([kind, curr]) | 17 stack.append([kind, curr]) |
18 kind = tok | 18 kind = tok |
19 curr = [] | 19 curr = [] |
20 tok = '' | 20 tok = "" |
21 elif c == ')': | 21 elif c == ")": |
22 if tok != '': | 22 if tok != "": |
23 curr.append([None, tok]) | 23 curr.append([None, tok]) |
24 tok = '' | 24 tok = "" |
25 oldKind = kind | 25 oldKind = kind |
26 oldCurr = curr | 26 oldCurr = curr |
27 [kind, curr] = stack.pop() | 27 [kind, curr] = stack.pop() |
28 curr.append([oldKind, oldCurr]) | 28 curr.append([oldKind, oldCurr]) |
29 else: | 29 else: |
30 tok += c | 30 tok += c |
31 if tok != '': | 31 if tok != "": |
32 curr.append([None, tok]) | 32 curr.append([None, tok]) |
33 return curr | 33 return curr |
34 | 34 |
35 | 35 |
36 def toStr(pipeObj): | 36 def toStr(pipeObj): |
37 """Create string representation of pipeline object.""" | 37 """Create string representation of pipeline object.""" |
38 res = '' | 38 res = "" |
39 lastIdx = len(pipeObj) - 1 | 39 lastIdx = len(pipeObj) - 1 |
40 for i, c in enumerate(pipeObj): | 40 for i, c in enumerate(pipeObj): |
41 if c[0]: | 41 if c[0]: |
42 res += c[0] + '(' | 42 res += c[0] + "(" |
43 res += toStr(c[1]) | 43 res += toStr(c[1]) |
44 res += ')' | 44 res += ")" |
45 else: | 45 else: |
46 res += c[1] | 46 res += c[1] |
47 if i != lastIdx: | 47 if i != lastIdx: |
48 res += ',' | 48 res += "," |
49 return res | 49 return res |
50 | 50 |
51 | 51 |
52 def count(pipeObj): | 52 def count(pipeObj): |
53 """Count number of passes (pass-managers excluded) in pipeline object.""" | 53 """Count number of passes (pass-managers excluded) in pipeline object.""" |
60 return cnt | 60 return cnt |
61 | 61 |
62 | 62 |
63 def split(pipeObj, splitIndex): | 63 def split(pipeObj, splitIndex): |
64 """Create two new pipeline objects by splitting pipeObj in two directly after pass with index splitIndex.""" | 64 """Create two new pipeline objects by splitting pipeObj in two directly after pass with index splitIndex.""" |
65 | |
65 def splitInt(src, splitIndex, dstA, dstB, idx): | 66 def splitInt(src, splitIndex, dstA, dstB, idx): |
66 for s in src: | 67 for s in src: |
67 if s[0]: | 68 if s[0]: |
68 dstA2 = [] | 69 dstA2 = [] |
69 dstB2 = [] | 70 dstB2 = [] |
84 return [listA, listB] | 85 return [listA, listB] |
85 | 86 |
86 | 87 |
87 def remove(pipeObj, removeIndex): | 88 def remove(pipeObj, removeIndex): |
88 """Create new pipeline object by removing pass with index removeIndex from pipeObj.""" | 89 """Create new pipeline object by removing pass with index removeIndex from pipeObj.""" |
90 | |
89 def removeInt(src, removeIndex, dst, idx): | 91 def removeInt(src, removeIndex, dst, idx): |
90 for s in src: | 92 for s in src: |
91 if s[0]: | 93 if s[0]: |
92 dst2 = [] | 94 dst2 = [] |
93 idx = removeInt(s[1], removeIndex, dst2, idx) | 95 idx = removeInt(s[1], removeIndex, dst2, idx) |
103 return dst | 105 return dst |
104 | 106 |
105 | 107 |
106 def copy(srcPipeObj): | 108 def copy(srcPipeObj): |
107 """Create copy of pipeline object srcPipeObj.""" | 109 """Create copy of pipeline object srcPipeObj.""" |
110 | |
108 def copyInt(dst, src): | 111 def copyInt(dst, src): |
109 for s in src: | 112 for s in src: |
110 if s[0]: | 113 if s[0]: |
111 dst2 = [] | 114 dst2 = [] |
112 copyInt(dst2, s[1]) | 115 copyInt(dst2, s[1]) |
119 return dstPipeObj | 122 return dstPipeObj |
120 | 123 |
121 | 124 |
122 def prune(srcPipeObj): | 125 def prune(srcPipeObj): |
123 """Create new pipeline object by removing empty pass-managers (those with count = 0) from srcPipeObj.""" | 126 """Create new pipeline object by removing empty pass-managers (those with count = 0) from srcPipeObj.""" |
127 | |
124 def pruneInt(dst, src): | 128 def pruneInt(dst, src): |
125 for s in src: | 129 for s in src: |
126 if s[0]: | 130 if s[0]: |
127 if count(s[1]): | 131 if count(s[1]): |
128 dst2 = [] | 132 dst2 = [] |
139 if __name__ == "__main__": | 143 if __name__ == "__main__": |
140 import unittest | 144 import unittest |
141 | 145 |
142 class Test(unittest.TestCase): | 146 class Test(unittest.TestCase): |
143 def test_0(self): | 147 def test_0(self): |
144 pipeStr = 'a,b,A(c,B(d,e),f),g' | 148 pipeStr = "a,b,A(c,B(d,e),f),g" |
145 pipeObj = fromStr(pipeStr) | 149 pipeObj = fromStr(pipeStr) |
146 | 150 |
147 self.assertEqual(7, count(pipeObj)) | 151 self.assertEqual(7, count(pipeObj)) |
148 | 152 |
149 self.assertEqual(pipeObj, pipeObj) | 153 self.assertEqual(pipeObj, pipeObj) |
153 self.assertEqual(pipeStr, toStr(pipeObj)) | 157 self.assertEqual(pipeStr, toStr(pipeObj)) |
154 self.assertEqual(pipeStr, toStr(prune(pipeObj))) | 158 self.assertEqual(pipeStr, toStr(prune(pipeObj))) |
155 self.assertEqual(pipeStr, toStr(copy(pipeObj))) | 159 self.assertEqual(pipeStr, toStr(copy(pipeObj))) |
156 | 160 |
157 [pipeObjA, pipeObjB] = split(pipeObj, 3) | 161 [pipeObjA, pipeObjB] = split(pipeObj, 3) |
158 self.assertEqual('a,b,A(c,B(d))', toStr(pipeObjA)) | 162 self.assertEqual("a,b,A(c,B(d))", toStr(pipeObjA)) |
159 self.assertEqual('A(B(e),f),g', toStr(pipeObjB)) | 163 self.assertEqual("A(B(e),f),g", toStr(pipeObjB)) |
160 | 164 |
161 self.assertEqual('b,A(c,B(d,e),f),g', toStr(remove(pipeObj, 0))) | 165 self.assertEqual("b,A(c,B(d,e),f),g", toStr(remove(pipeObj, 0))) |
162 self.assertEqual('a,b,A(c,B(d,e),f)', toStr(remove(pipeObj, 6))) | 166 self.assertEqual("a,b,A(c,B(d,e),f)", toStr(remove(pipeObj, 6))) |
163 | 167 |
164 pipeObjC = remove(pipeObj, 4) | 168 pipeObjC = remove(pipeObj, 4) |
165 self.assertEqual('a,b,A(c,B(d),f),g', toStr(pipeObjC)) | 169 self.assertEqual("a,b,A(c,B(d),f),g", toStr(pipeObjC)) |
166 pipeObjC = remove(pipeObjC, 3) | 170 pipeObjC = remove(pipeObjC, 3) |
167 self.assertEqual('a,b,A(c,B(),f),g', toStr(pipeObjC)) | 171 self.assertEqual("a,b,A(c,B(),f),g", toStr(pipeObjC)) |
168 pipeObjC = prune(pipeObjC) | 172 pipeObjC = prune(pipeObjC) |
169 self.assertEqual('a,b,A(c,f),g', toStr(pipeObjC)) | 173 self.assertEqual("a,b,A(c,f),g", toStr(pipeObjC)) |
170 | 174 |
171 unittest.main() | 175 unittest.main() |
172 exit(0) | 176 exit(0) |