(forest: list[parser.AstNode])
| 1312 | |
| 1313 | |
| 1314 | def analyze_forest(forest: list[parser.AstNode]) -> Analysis: |
| 1315 | instructions: dict[str, Instruction] = {} |
| 1316 | uops: dict[str, Uop] = {} |
| 1317 | families: dict[str, Family] = {} |
| 1318 | pseudos: dict[str, PseudoInstruction] = {} |
| 1319 | labels: dict[str, Label] = {} |
| 1320 | for node in forest: |
| 1321 | match node: |
| 1322 | case parser.InstDef(name): |
| 1323 | if node.kind == "inst": |
| 1324 | desugar_inst(node, instructions, uops) |
| 1325 | else: |
| 1326 | assert node.kind == "op" |
| 1327 | add_op(node, uops) |
| 1328 | case parser.Macro(): |
| 1329 | pass |
| 1330 | case parser.Family(): |
| 1331 | pass |
| 1332 | case parser.Pseudo(): |
| 1333 | pass |
| 1334 | case parser.LabelDef(): |
| 1335 | pass |
| 1336 | case _: |
| 1337 | assert False |
| 1338 | for node in forest: |
| 1339 | if isinstance(node, parser.Macro): |
| 1340 | add_macro(node, instructions, uops) |
| 1341 | for node in forest: |
| 1342 | match node: |
| 1343 | case parser.Family(): |
| 1344 | add_family(node, instructions, families) |
| 1345 | case parser.Pseudo(): |
| 1346 | add_pseudo(node, instructions, pseudos) |
| 1347 | case parser.LabelDef(): |
| 1348 | add_label(node, labels) |
| 1349 | case _: |
| 1350 | pass |
| 1351 | for uop in uops.values(): |
| 1352 | uop.instruction_size = get_instruction_size_for_uop(instructions, uop) |
| 1353 | # Special case BINARY_OP_INPLACE_ADD_UNICODE |
| 1354 | # BINARY_OP_INPLACE_ADD_UNICODE is not a normal family member, |
| 1355 | # as it is the wrong size, but we need it to maintain an |
| 1356 | # historical optimization. |
| 1357 | if "BINARY_OP_INPLACE_ADD_UNICODE" in instructions: |
| 1358 | inst = instructions["BINARY_OP_INPLACE_ADD_UNICODE"] |
| 1359 | inst.family = families["BINARY_OP"] |
| 1360 | families["BINARY_OP"].members.append(inst) |
| 1361 | opmap, first_arg, min_instrumented = assign_opcodes(instructions, families, pseudos) |
| 1362 | return Analysis( |
| 1363 | instructions, uops, families, pseudos, labels, opmap, first_arg, min_instrumented |
| 1364 | ) |
| 1365 | |
| 1366 | |
| 1367 | #Simple heuristic for size to avoid too much stencil duplication |
no test coverage detected
searching dependent graphs…