1 //===- SimplifyCFG.h - Simplify and canonicalize the CFG --------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 /// This file provides the interface for the pass responsible for both
10 /// simplifying and canonicalizing the CFG.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TRANSFORMS_SCALAR_SIMPLIFYCFG_H
15 #define LLVM_TRANSFORMS_SCALAR_SIMPLIFYCFG_H
17 #include "llvm/Transforms/Utils/Local.h"
18 #include "llvm/IR/Function.h"
19 #include "llvm/IR/PassManager.h"
23 /// A pass to simplify and canonicalize the CFG of a function.
25 /// This pass iteratively simplifies the entire CFG of a function. It may change
26 /// or remove control flow to put the CFG into a canonical form expected by
27 /// other passes of the mid-level optimizer. Depending on the specified options,
28 /// it may further optimize control-flow to create non-canonical forms.
29 class SimplifyCFGPass
: public PassInfoMixin
<SimplifyCFGPass
> {
30 SimplifyCFGOptions Options
;
33 /// The default constructor sets the pass options to create canonical IR,
34 /// rather than optimal IR. That is, by default we bypass transformations that
35 /// are likely to improve performance but make analysis for other passes more
38 : SimplifyCFGPass(SimplifyCFGOptions()
39 .forwardSwitchCondToPhi(false)
40 .convertSwitchToLookupTable(false)
41 .needCanonicalLoops(true)
42 .sinkCommonInsts(false)) {}
45 /// Construct a pass with optional optimizations.
46 SimplifyCFGPass(const SimplifyCFGOptions
&PassOptions
);
48 /// Run the pass over the function.
49 PreservedAnalyses
run(Function
&F
, FunctionAnalysisManager
&AM
);