TY - JOUR
T1 - The tree-width of C
AU - Krause, Philipp Klaus
AU - Larisch, Lukas
AU - Salfelder, Felix
N1 - KAUST Repository Item: Exported on 2020-10-01
Acknowledgements: This research was supported by Deutsche Forschungsgemeinschaft, Projekt Graphstrukturtheorie im Übersetzerbau, KR 4970/1-1.
PY - 2019/3/1
Y1 - 2019/3/1
N2 - Recently, approaches based on tree-decompositions (TDs) of control-flow graphs (CFGs) have been introduced for many classical problems in compiler construction. Some found practical use in SDCC, a mainstream C compiler for embedded systems. Using TD-based algorithms, SDCC generates faster and often smaller code for its target architectures than other compilers. The width of the TD crucially influences runtime, hence good algorithms computing TDs of small width are essential. The current standard approach to obtain TDs of CFGs is Thorup's heuristic, which was also used in SDCC. Thorup claims that his heuristic will give TDs of width at most 6 for CFGs from C code that contains no goto statements. We present a counterexample resulting in a tree-width of 7. We show how to construct C code without goto statements for which the CFG has tree-width 3, but Thorup's heuristic will yield TDs of arbitrary width. We demonstrate how this flaw adversely affects the compilation of real-world code. We present a constructive proof giving a tight bound on the tree-width of CFGs of C programs. This corrects Thorup and shows the effect that goto has on the tree-width. We empirically evaluate various approaches to finding TDs of CFGs and their impact on compiler runtime and code quality in SDCC. Our research resulted in the replacement of the unconditional use of Thorup's heuristic by a better approach in SDCC 3.7.0, drastically reducing compiler runtime.
AB - Recently, approaches based on tree-decompositions (TDs) of control-flow graphs (CFGs) have been introduced for many classical problems in compiler construction. Some found practical use in SDCC, a mainstream C compiler for embedded systems. Using TD-based algorithms, SDCC generates faster and often smaller code for its target architectures than other compilers. The width of the TD crucially influences runtime, hence good algorithms computing TDs of small width are essential. The current standard approach to obtain TDs of CFGs is Thorup's heuristic, which was also used in SDCC. Thorup claims that his heuristic will give TDs of width at most 6 for CFGs from C code that contains no goto statements. We present a counterexample resulting in a tree-width of 7. We show how to construct C code without goto statements for which the CFG has tree-width 3, but Thorup's heuristic will yield TDs of arbitrary width. We demonstrate how this flaw adversely affects the compilation of real-world code. We present a constructive proof giving a tight bound on the tree-width of CFGs of C programs. This corrects Thorup and shows the effect that goto has on the tree-width. We empirically evaluate various approaches to finding TDs of CFGs and their impact on compiler runtime and code quality in SDCC. Our research resulted in the replacement of the unconditional use of Thorup's heuristic by a better approach in SDCC 3.7.0, drastically reducing compiler runtime.
UR - http://hdl.handle.net/10754/653028
UR - https://www.sciencedirect.com/science/article/pii/S0166218X19300629
UR - http://www.scopus.com/inward/record.url?scp=85062208850&partnerID=8YFLogxK
U2 - 10.1016/j.dam.2019.01.027
DO - 10.1016/j.dam.2019.01.027
M3 - Article
SN - 0166-218X
JO - Discrete Applied Mathematics
JF - Discrete Applied Mathematics
ER -