xref: /llvm-project/llvm/docs/BugpointRedesign.md (revision 72f996e4d90c9a10065386bdf79d2f100fd2bf2c)
1ddc64eb9SDiego Trevino Ferrer# Bugpoint Redesign
2ddc64eb9SDiego Trevino FerrerAuthor: Diego Treviño (diegotf@google.com)
3ddc64eb9SDiego Trevino Ferrer
4ddc64eb9SDiego Trevino FerrerDate: 2019-06-05
5ddc64eb9SDiego Trevino Ferrer
6ddc64eb9SDiego Trevino FerrerStatus: Draft
7ddc64eb9SDiego Trevino Ferrer
8ddc64eb9SDiego Trevino Ferrer
9ddc64eb9SDiego Trevino Ferrer## Introduction
10ddc64eb9SDiego Trevino FerrerAs use of bugpoint has grown several areas of improvement have been identified
11ddc64eb9SDiego Trevino Ferrerthrough years of use: confusing to use, slow, it doesn’t always produce high
12ddc64eb9SDiego Trevino Ferrerquality test cases, etc. This document proposes a new approach with a narrower
13ddc64eb9SDiego Trevino Ferrerfocus: minimization of IR test cases.
14ddc64eb9SDiego Trevino Ferrer
15ddc64eb9SDiego Trevino Ferrer
16ddc64eb9SDiego Trevino Ferrer## Proposed New Design
17ddc64eb9SDiego Trevino Ferrer
18ddc64eb9SDiego Trevino Ferrer
19ddc64eb9SDiego Trevino Ferrer### Narrow focus: test-case reduction
20ddc64eb9SDiego Trevino FerrerThe main focus will be a code reduction strategy to obtain much smaller test
21ddc64eb9SDiego Trevino Ferrercases that still have the same property as the original one. This will be done
22ddc64eb9SDiego Trevino Ferrervia classic delta debugging and by adding some IR-specific reductions (e.g.
23ddc64eb9SDiego Trevino Ferrerreplacing globals, removing unused instructions, etc), similar to what
24ddc64eb9SDiego Trevino Ferreralready exists, but with more in-depth minimization.
25ddc64eb9SDiego Trevino Ferrer
26ddc64eb9SDiego Trevino Ferrer
27ddc64eb9SDiego Trevino FerrerGranted, if the community differs on this proposal, the legacy code could still
28ddc64eb9SDiego Trevino Ferrerbe present in the tool, but with the caveat of still being documented and
29ddc64eb9SDiego Trevino Ferrerdesigned towards delta reduction.
30ddc64eb9SDiego Trevino Ferrer
31ddc64eb9SDiego Trevino Ferrer
32ddc64eb9SDiego Trevino Ferrer### Command-Line Options
33ddc64eb9SDiego Trevino FerrerWe are proposing to reduce the plethora of bugpoint’s options to just two: an
34ddc64eb9SDiego Trevino Ferrerinteresting-ness test and the arguments for said test, similar to other delta
35ddc64eb9SDiego Trevino Ferrerreduction tools such as CReduce, Delta, and Lithium; the tool should feel less
36ddc64eb9SDiego Trevino Ferrer cluttered, and there should also be no uncertainty about how to operate it.
37ddc64eb9SDiego Trevino Ferrer
38ddc64eb9SDiego Trevino Ferrer
39ddc64eb9SDiego Trevino FerrerThe interesting-ness test that’s going to be run to reduce the code is given
40ddc64eb9SDiego Trevino Ferrerby name:
41ddc64eb9SDiego Trevino Ferrer        `--test=<test_name>`
42ddc64eb9SDiego Trevino FerrerIf a `--test`  option is not given, the program exits; this option is similar
43ddc64eb9SDiego Trevino Ferrerto bugpoint’s current `-compile-custom` option, which lets the user run a
44ddc64eb9SDiego Trevino Ferrercustom script.
45ddc64eb9SDiego Trevino Ferrer
46ddc64eb9SDiego Trevino Ferrer
47ddc64eb9SDiego Trevino FerrerThe interesting-ness test would be defined as a script that returns 0 when the
48ddc64eb9SDiego Trevino FerrerIR achieves a user-defined behaviour (e.g. failure to compile on clang) and a
49ddc64eb9SDiego Trevino Ferrernonzero value when otherwise. Leaving the user the freedom to determine what is
50ddc64eb9SDiego Trevino Ferrerand isn’t interesting to the tool, and thus, streamlining the process of
51ddc64eb9SDiego Trevino Ferrerreducing a test-case.
52ddc64eb9SDiego Trevino Ferrer
53ddc64eb9SDiego Trevino Ferrer
54ddc64eb9SDiego Trevino FerrerIf the test accepts any arguments (excluding the input ll/bc file), they are
55ddc64eb9SDiego Trevino Ferrergiven via the following flag:
56ddc64eb9SDiego Trevino Ferrer        `--test_args=<test_arguments>`
57ddc64eb9SDiego Trevino FerrerIf unspecified, the test is run as given. It’s worth noting that the input file
58ddc64eb9SDiego Trevino Ferrerwould be passed as a parameter to the test, similar how `-compile-custom`
59ddc64eb9SDiego Trevino Ferrercurrently operates.
60ddc64eb9SDiego Trevino Ferrer
61ddc64eb9SDiego Trevino Ferrer
62ddc64eb9SDiego Trevino Ferrer### Implementation
63ddc64eb9SDiego Trevino FerrerThe tool would behave similar to CReduce’s functionality in that it would have a
64ddc64eb9SDiego Trevino Ferrerlist of passes that try to minimize the given test-case. We should be able to
65ddc64eb9SDiego Trevino Ferrermodularize the tool’s behavior, as well as making it easier to maintain and
66ddc64eb9SDiego Trevino Ferrerexpand.
67ddc64eb9SDiego Trevino Ferrer
68ddc64eb9SDiego Trevino Ferrer
69ddc64eb9SDiego Trevino FerrerThe first version of this redesign would try to:
70ddc64eb9SDiego Trevino Ferrer
71ddc64eb9SDiego Trevino Ferrer
72ddc64eb9SDiego Trevino Ferrer* Discard functions, instructions and metadata that don’t influence the
73ddc64eb9SDiego Trevino Ferrer  interesting-ness test
74ddc64eb9SDiego Trevino Ferrer* Remove unused parameters from functions
75ddc64eb9SDiego Trevino Ferrer* Eliminate unvisited conditional paths
76ddc64eb9SDiego Trevino Ferrer* Rename variables to more regular ones (such as “a”, “b”, “c”, etc.)
77ddc64eb9SDiego Trevino Ferrer
78ddc64eb9SDiego Trevino Ferrer
79ddc64eb9SDiego Trevino FerrerOnce these passes are implemented, more meaningful reductions (such as type
80ddc64eb9SDiego Trevino Ferrerreduction) would be added to the tool, to even further reduce IR.
81ddc64eb9SDiego Trevino Ferrer
82ddc64eb9SDiego Trevino Ferrer
83ddc64eb9SDiego Trevino Ferrer## Background on historical bugpoint issues
84ddc64eb9SDiego Trevino Ferrer
85ddc64eb9SDiego Trevino Ferrer
86ddc64eb9SDiego Trevino Ferrer### Root Cause Analysis
87ddc64eb9SDiego Trevino FerrerPresently, bugpoint takes a long time to find the source problem in a given IR
88ddc64eb9SDiego Trevino Ferrerfile, mainly due to the fact that it tries to debug the input by running
89ddc64eb9SDiego Trevino Ferrervarious strategies to classify the bug, which in turn run multiple optimizer
90ddc64eb9SDiego Trevino Ferrerand compilation passes over the input, taking up a lot of time. Furthermore,
91ddc64eb9SDiego Trevino Ferrerwhen the IR crashes, it tries to reduce it by performing some sub-optimal
92ddc64eb9SDiego Trevino Ferrerpasses (e.g. a lot of unreachable blocks), and sometimes even fails to minimize
93ddc64eb9SDiego Trevino Ferrerat all.
94ddc64eb9SDiego Trevino Ferrer
95ddc64eb9SDiego Trevino Ferrer
96ddc64eb9SDiego Trevino Ferrer### "Quirky" Interface
97ddc64eb9SDiego Trevino FerrerBugpoint’s current interface overwhelms and confuses the user, the help screen
98*72f996e4SDiego Trevino Ferreralone ends up confusing rather providing guidance. And, not only are there
99*72f996e4SDiego Trevino Ferrernumerous features and options, but some of them also work in unexpected ways
100*72f996e4SDiego Trevino Ferrerand most of the time the user ends up using a custom script. Pruning and
101*72f996e4SDiego Trevino Ferrersimplifying the interface will be worth considering in order to make the tool
102*72f996e4SDiego Trevino Ferrermore useful in the general case and easier to maintain.
103