| 1 |
import py |
| 2 |
import re |
| 3 |
|
| 4 |
from rpython.tool.logparser import extract_category |
| 5 |
from rpython.jit.backend.tool.viewcode import ObjdumpNotFound |
| 6 |
|
| 7 |
from rpython.tool.jitlogparser.parser import (import_log, parse_log_counts, |
| 8 |
mangle_descr) |
| 9 |
from pypy.module.pypyjit.test_pypy_c.test_00_model import BaseTestPyPyC |
| 10 |
|
| 11 |
class TestLogParser(BaseTestPyPyC): |
| 12 |
log_string = 'jit-log-opt,jit-backend' |
| 13 |
|
| 14 |
def test(self): |
| 15 |
def fn_with_bridges(N): |
| 16 |
def is_prime(x): |
| 17 |
for y in range(2, x): |
| 18 |
if x % y == 0: |
| 19 |
return False |
| 20 |
return True |
| 21 |
result = 0 |
| 22 |
for x in range(N): |
| 23 |
if x % 3 == 0: |
| 24 |
result += 5 |
| 25 |
elif x % 5 == 0: |
| 26 |
result += 3 |
| 27 |
elif is_prime(x): |
| 28 |
result += x |
| 29 |
elif x == 99: |
| 30 |
result *= 2 |
| 31 |
return result |
| 32 |
|
| 33 |
N = 10000 |
| 34 |
_log = self.run(fn_with_bridges, [N]) |
| 35 |
log, loops = import_log(_log.logfile) |
| 36 |
parse_log_counts(extract_category(log, 'jit-backend-count'), loops) |
| 37 |
|
| 38 |
is_prime_loops = [] |
| 39 |
fn_with_bridges_loops = [] |
| 40 |
bridges = {} |
| 41 |
|
| 42 |
for loop in loops: |
| 43 |
if hasattr(loop, 'force_asm'): |
| 44 |
try: |
| 45 |
loop.force_asm() |
| 46 |
except ObjdumpNotFound: |
| 47 |
py.test.skip("ObjDump was not found, skipping") |
| 48 |
assert loop.count >= 0 |
| 49 |
if 'is_prime' in loop.comment: |
| 50 |
is_prime_loops.append(loop) |
| 51 |
elif 'fn_with_bridges' in loop.comment: |
| 52 |
fn_with_bridges_loops.append(loop) |
| 53 |
elif 'tuple.contains' in loop.comment: |
| 54 |
pass |
| 55 |
elif ' bridge ' in loop.comment: |
| 56 |
key = mangle_descr(loop.descr) |
| 57 |
assert key not in bridges |
| 58 |
bridges[key] = loop |
| 59 |
|
| 60 |
by_count = lambda l: -l.count |
| 61 |
is_prime_loops.sort(key=by_count) |
| 62 |
fn_with_bridges_loops.sort(key=by_count) |
| 63 |
|
| 64 |
|
| 65 |
mod_bridges = [] |
| 66 |
for op in fn_with_bridges_loops[0].operations: |
| 67 |
if op.descr is not None: |
| 68 |
bridge = bridges.get(mangle_descr(op.descr)) |
| 69 |
if bridge is not None: |
| 70 |
mod_bridges.append(bridge) |
| 71 |
assert len(mod_bridges) in (1, 2, 3) |
| 72 |
|
| 73 |
|
| 74 |
assert N - 2000 < sum(l.count for l in fn_with_bridges_loops) < N + 1500 |
| 75 |
|
| 76 |
|