[flang] Support OPEN(..., FORM="BINARY") (#124657)
[llvm-project.git] / lld / test / MachO / bp-section-orderer-stress.s
blob0bfd99eb3dd867db7f965f6f5b913dc63d04a656
1 # REQUIRES: aarch64
3 # Generate a large test case and check that the output is deterministic.
5 # RUN: %python %s %t.s %t.proftext
7 # RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %t.s -o %t.o
8 # RUN: llvm-profdata merge %t.proftext -o %t.profdata
10 # RUN: %no-fatal-warnings-lld -arch arm64 -lSystem -e _main --icf=all -o - %t.o --irpgo-profile-sort=%t.profdata --compression-sort-startup-functions --compression-sort=both | llvm-nm --numeric-sort --format=just-symbols - > %t.order1.txt
11 # RUN: %no-fatal-warnings-lld -arch arm64 -lSystem -e _main --icf=all -o - %t.o --irpgo-profile-sort=%t.profdata --compression-sort-startup-functions --compression-sort=both | llvm-nm --numeric-sort --format=just-symbols - > %t.order2.txt
12 # RUN: diff %t.order1.txt %t.order2.txt
14 # RUN: %lld -arch arm64 -lSystem -e _main --icf=all -o - %t.o --irpgo-profile=%t.profdata --bp-startup-sort=function --bp-compression-sort-startup-functions --bp-compression-sort=both | llvm-nm --numeric-sort --format=just-symbols - > %t.order1.txt
15 # RUN: %lld -arch arm64 -lSystem -e _main --icf=all -o - %t.o --irpgo-profile=%t.profdata --bp-startup-sort=function --bp-compression-sort-startup-functions --bp-compression-sort=both | llvm-nm --numeric-sort --format=just-symbols - > %t.order2.txt
16 # RUN: diff %t.order1.txt %t.order2.txt
17 import random
18 import sys
20 assembly_filepath = sys.argv[1]
21 proftext_filepath = sys.argv[2]
23 random.seed(1234)
24 num_functions = 1000
25 num_data = 100
26 num_traces = 10
28 function_names = [f"f{n}" for n in range(num_functions)]
29 data_names = [f"d{n}" for n in range(num_data)]
30 profiled_functions = function_names[: int(num_functions / 2)]
32 function_contents = [
33 f"""
34 {name}:
35 add w0, w0, #{i % 4096}
36 add w1, w1, #{i % 10}
37 add w2, w0, #{i % 20}
38 adrp x3, {name}@PAGE
39 ret
40 """
41 for i, name in enumerate(function_names)
44 data_contents = [
45 f"""
46 {name}:
47 .ascii "s{i % 2}-{i % 3}-{i % 5}"
48 .xword {name}
49 """
50 for i, name in enumerate(data_names)
53 trace_contents = [
54 f"""
55 # Weight
57 {", ".join(random.sample(profiled_functions, len(profiled_functions)))}
58 """
59 for i in range(num_traces)
62 profile_contents = [
63 f"""
64 {name}
65 # Func Hash:
66 {i}
67 # Num Counters:
69 # Counter Values:
71 """
72 for i, name in enumerate(profiled_functions)
75 with open(assembly_filepath, "w") as f:
76 f.write(
77 f"""
78 .text
79 .globl _main
81 _main:
82 ret
84 {"".join(function_contents)}
86 .data
87 {"".join(data_contents)}
89 .subsections_via_symbols
90 """
93 with open(proftext_filepath, "w") as f:
94 f.write(
95 f"""
96 :ir
97 :temporal_prof_traces
99 # Num Traces
100 {num_traces}
101 # Trace Stream Size:
102 {num_traces}
104 {"".join(trace_contents)}
106 {"".join(profile_contents)}