xref: /llvm-project/llvm/docs/CommandGuide/llvm-reduce.rst (revision 792253ae0ef3acf9e55f92de25e0bd47a8531d1a)
1ae2d8defSaabhinavgllvm-reduce - LLVM automatic testcase reducer.
2ae2d8defSaabhinavg==============================================
3ae2d8defSaabhinavg
4ae2d8defSaabhinavg.. program:: llvm-reduce
5ae2d8defSaabhinavg
6ae2d8defSaabhinavgSYNOPSIS
7ae2d8defSaabhinavg--------
8ae2d8defSaabhinavg
9ae2d8defSaabhinavg:program:`llvm-reduce` [*options*] [*input...*]
10ae2d8defSaabhinavg
11ae2d8defSaabhinavgDESCRIPTION
12ae2d8defSaabhinavg-----------
13ae2d8defSaabhinavg
14ae2d8defSaabhinavgThe :program:`llvm-reduce` tool project that can be used for reducing the size of LLVM test cases.
15ae2d8defSaabhinavgIt works by removing redundant or unnecessary code from LLVM test cases while still preserving
16ae2d8defSaabhinavgtheir ability to detect bugs.
17ae2d8defSaabhinavg
18ae2d8defSaabhinavgIf ``input`` is "``-``", :program:`llvm-reduce` reads from standard
19ae2d8defSaabhinavginput. Otherwise, it will read from the specified ``filenames``.
20ae2d8defSaabhinavg
21ae2d8defSaabhinavgLLVM-Reduce is a useful tool for reducing the size and
22ae2d8defSaabhinavgcomplexity of LLVM test cases, making it easier to identify and debug issues in
23ae2d8defSaabhinavgthe LLVM compiler infrastructure.
24ae2d8defSaabhinavg
25ae2d8defSaabhinavgGENERIC OPTIONS
26ae2d8defSaabhinavg---------------
27ae2d8defSaabhinavg
28ae2d8defSaabhinavg
29ae2d8defSaabhinavg.. option:: --help
30ae2d8defSaabhinavg
31ae2d8defSaabhinavg Display available options (--help-hidden for more).
32ae2d8defSaabhinavg
33ae2d8defSaabhinavg.. option:: --abort-on-invalid-reduction
34ae2d8defSaabhinavg
35ae2d8defSaabhinavg Abort if any reduction results in invalid IR
36ae2d8defSaabhinavg
37ae2d8defSaabhinavg.. option::--delta-passes=<string>
38ae2d8defSaabhinavg
39ae2d8defSaabhinavg Delta passes to run, separated by commas. By default, run all delta passes.
40ae2d8defSaabhinavg
41ae2d8defSaabhinavg
42ae2d8defSaabhinavg.. option:: --in-place
43ae2d8defSaabhinavg
44ae2d8defSaabhinavg WARNING: This option will replace your input file with the reduced version!
45ae2d8defSaabhinavg
46ae2d8defSaabhinavg.. option:: --ir-passes=<string>
47ae2d8defSaabhinavg
48ae2d8defSaabhinavg A textual description of the pass pipeline, same as what's passed to `opt -passes`.
49ae2d8defSaabhinavg
50ae2d8defSaabhinavg.. option:: -j <uint>
51ae2d8defSaabhinavg
52ae2d8defSaabhinavg Maximum number of threads to use to process chunks. Set to 1 to disable parallelism.
53ae2d8defSaabhinavg
54ae2d8defSaabhinavg.. option::  --max-pass-iterations=<int>
55ae2d8defSaabhinavg
56ae2d8defSaabhinavg  Maximum number of times to run the full set of delta passes (default=5).
57ae2d8defSaabhinavg
58ae2d8defSaabhinavg.. option:: --mtriple=<string>
59ae2d8defSaabhinavg
60ae2d8defSaabhinavg Set the target triple.
61ae2d8defSaabhinavg
62ae2d8defSaabhinavg.. option:: --preserve-debug-environment
63ae2d8defSaabhinavg
64ae2d8defSaabhinavg Don't disable features used for crash debugging (crash reports, llvm-symbolizer and core dumps)
65ae2d8defSaabhinavg
66ae2d8defSaabhinavg.. option:: --print-delta-passes
67ae2d8defSaabhinavg
68ae2d8defSaabhinavg Print list of delta passes, passable to --delta-passes as a comma separated liste.
69ae2d8defSaabhinavg
70ae2d8defSaabhinavg.. option:: --skip-delta-passes=<string>
71ae2d8defSaabhinavg
72ae2d8defSaabhinavg Delta passes to not run, separated by commas. By default, run all delta passes.
73ae2d8defSaabhinavg
74ae2d8defSaabhinavg.. option:: --starting-granularity-level=<uint>
75ae2d8defSaabhinavg
76ae2d8defSaabhinavg  Number of times to divide chunks prior to first test.
77ae2d8defSaabhinavg
78ae2d8defSaabhinavg  Note : Granularity refers to the level of detail at which the reduction process operates.
79ae2d8defSaabhinavg  A lower granularity means that the reduction process operates at a more coarse-grained level,
80ae2d8defSaabhinavg  while a higher granularity means that it operates at a more fine-grained level.
81ae2d8defSaabhinavg
82ae2d8defSaabhinavg.. option::  --test=<string>
83ae2d8defSaabhinavg
84ae2d8defSaabhinavg Name of the interesting-ness test to be run.
85ae2d8defSaabhinavg
86ae2d8defSaabhinavg.. option:: --test-arg=<string>
87ae2d8defSaabhinavg
88ae2d8defSaabhinavg Arguments passed onto the interesting-ness test.
89ae2d8defSaabhinavg
90ae2d8defSaabhinavg.. option:: --verbose
91ae2d8defSaabhinavg
92ae2d8defSaabhinavg Print extra debugging information.
93ae2d8defSaabhinavg
94ae2d8defSaabhinavg.. option::  --write-tmp-files-as-bitcode
95ae2d8defSaabhinavg
96ae2d8defSaabhinavg Always write temporary files as bitcode instead of textual IR.
97ae2d8defSaabhinavg
98ae2d8defSaabhinavg.. option:: -x={ir|mir}
99ae2d8defSaabhinavg
100ae2d8defSaabhinavg Input language as ir or mir.
101ae2d8defSaabhinavg
102ae2d8defSaabhinavgEXIT STATUS
103ae2d8defSaabhinavg------------
104ae2d8defSaabhinavg
105ae2d8defSaabhinavg:program:`llvm-reduce` returns 0 under normal operation. It returns a non-zero
106ae2d8defSaabhinavgexit code if there were any errors.
107ae2d8defSaabhinavg
108*792253aeSFrancesco PetrogalliEXAMPLE
109*792253aeSFrancesco Petrogalli-------
110ae2d8defSaabhinavg
111*792253aeSFrancesco Petrogalli:program:`llvm-reduce` can be used to simplify a test that causes a
112*792253aeSFrancesco Petrogallicompiler crash.
113*792253aeSFrancesco Petrogalli
114*792253aeSFrancesco PetrogalliFor example, let's assume that `opt` is crashing on the IR file
115*792253aeSFrancesco Petrogalli`test.ll` with error message `Assertion failed at line 1234 of
116*792253aeSFrancesco PetrogalliWhateverFile.cpp`, when running at `-O2`.
117*792253aeSFrancesco Petrogalli
118*792253aeSFrancesco PetrogalliThe test case of `test.ll` can be reduced by invoking the following
119*792253aeSFrancesco Petrogallicommand:
120*792253aeSFrancesco Petrogalli
121*792253aeSFrancesco Petrogalli.. code-block:: bash
122*792253aeSFrancesco Petrogalli
123*792253aeSFrancesco Petrogalli   $(LLVM_BUILD_FOLDER)/bin/llvm-reduce --test=script.sh <path to>/test.ll
124*792253aeSFrancesco Petrogalli
125*792253aeSFrancesco PetrogalliThe shell script passed to the option `test` consists of the
126*792253aeSFrancesco Petrogallifollowing:
127*792253aeSFrancesco Petrogalli
128*792253aeSFrancesco Petrogalli.. code-block:: bash
129*792253aeSFrancesco Petrogalli
130*792253aeSFrancesco Petrogalli   $(LLVM_BUILD_FOLDER)/bin/opt -O2 -disable-output $1 \
131*792253aeSFrancesco Petrogalli     |& grep "Assertion failed at line 1234 of WhateverFile.cpp"
132*792253aeSFrancesco Petrogalli
133*792253aeSFrancesco Petrogalli(In this script, `grep` exits with 0 if it finds the string and that
134*792253aeSFrancesco Petrogallibecomes the whole script's status.)
135*792253aeSFrancesco Petrogalli
136*792253aeSFrancesco PetrogalliThis example can be generalized to other tools that process IR files,
137*792253aeSFrancesco Petrogallifor example `llc`.
138