105 lines · plain
1# REQUIRES: aarch642 3## Generate a large test case and check that the output is deterministic.4 5# RUN: %python %s %t.s %t.proftext6 7# RUN: llvm-mc -filetype=obj -triple=aarch64 %t.s -o %t.o8# RUN: llvm-profdata merge %t.proftext -o %t.profdata9 10# RUN: ld.lld --icf=all -o %t1.o %t.o --irpgo-profile=%t.profdata --bp-startup-sort=function --bp-compression-sort-startup-functions --bp-compression-sort=both11# RUN: ld.lld --icf=all -o %t2.o %t.o --irpgo-profile=%t.profdata --bp-startup-sort=function --bp-compression-sort-startup-functions --bp-compression-sort=both12# RUN: cmp %t1.o %t2.o13 14import random15import sys16 17assembly_filepath = sys.argv[1]18proftext_filepath = sys.argv[2]19 20random.seed(1234)21num_functions = 100022num_data = 10023num_traces = 1024 25function_names = [f"f{n}" for n in range(num_functions)]26data_names = [f"d{n}" for n in range(num_data)]27profiled_functions = function_names[: int(num_functions / 2)]28 29function_contents = [30 f"""31{name}:32 add w0, w0, #{i % 4096}33 add w1, w1, #{i % 10}34 add w2, w0, #{i % 20}35 adrp x3, {name}36 ret37"""38 for i, name in enumerate(function_names)39]40 41data_contents = [42 f"""43{name}:44 .ascii "s{i % 2}-{i % 3}-{i % 5}"45 .xword {name}46"""47 for i, name in enumerate(data_names)48]49 50trace_contents = [51 f"""52# Weight53154{", ".join(random.sample(profiled_functions, len(profiled_functions)))}55"""56 for i in range(num_traces)57]58 59profile_contents = [60 f"""61{name}62# Func Hash:63{i}64# Num Counters:65166# Counter Values:67168"""69 for i, name in enumerate(profiled_functions)70]71 72with open(assembly_filepath, "w") as f:73 f.write(74 f"""75.text76.globl _start77 78_start:79 ret80 81{"".join(function_contents)}82 83.data84{"".join(data_contents)}85 86"""87 )88 89with open(proftext_filepath, "w") as f:90 f.write(91 f"""92:ir93:temporal_prof_traces94 95# Num Traces96{num_traces}97# Trace Stream Size:98{num_traces}99 100{"".join(trace_contents)}101 102{"".join(profile_contents)}103"""104 )105