1283625Sdim//===- SimplifyCFG.h - Simplify and canonicalize the CFG --------*- C++ -*-===// 2283625Sdim// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6283625Sdim// 7283625Sdim//===----------------------------------------------------------------------===// 8283625Sdim/// \file 9283625Sdim/// This file provides the interface for the pass responsible for both 10283625Sdim/// simplifying and canonicalizing the CFG. 11283625Sdim/// 12283625Sdim//===----------------------------------------------------------------------===// 13283625Sdim 14283625Sdim#ifndef LLVM_TRANSFORMS_SCALAR_SIMPLIFYCFG_H 15283625Sdim#define LLVM_TRANSFORMS_SCALAR_SIMPLIFYCFG_H 16283625Sdim 17341825Sdim#include "llvm/Transforms/Utils/Local.h" 18283625Sdim#include "llvm/IR/Function.h" 19283625Sdim#include "llvm/IR/PassManager.h" 20283625Sdim 21283625Sdimnamespace llvm { 22283625Sdim 23327952Sdim/// A pass to simplify and canonicalize the CFG of a function. 24283625Sdim/// 25327952Sdim/// This pass iteratively simplifies the entire CFG of a function. It may change 26327952Sdim/// or remove control flow to put the CFG into a canonical form expected by 27327952Sdim/// other passes of the mid-level optimizer. Depending on the specified options, 28327952Sdim/// it may further optimize control-flow to create non-canonical forms. 29309124Sdimclass SimplifyCFGPass : public PassInfoMixin<SimplifyCFGPass> { 30327952Sdim SimplifyCFGOptions Options; 31283625Sdim 32283625Sdimpublic: 33327952Sdim /// The default constructor sets the pass options to create canonical IR, 34327952Sdim /// rather than optimal IR. That is, by default we bypass transformations that 35327952Sdim /// are likely to improve performance but make analysis for other passes more 36327952Sdim /// difficult. 37327952Sdim SimplifyCFGPass() 38327952Sdim : SimplifyCFGPass(SimplifyCFGOptions() 39327952Sdim .forwardSwitchCondToPhi(false) 40327952Sdim .convertSwitchToLookupTable(false) 41327952Sdim .needCanonicalLoops(true) 42327952Sdim .sinkCommonInsts(false)) {} 43283625Sdim 44283625Sdim 45327952Sdim /// Construct a pass with optional optimizations. 46327952Sdim SimplifyCFGPass(const SimplifyCFGOptions &PassOptions); 47327952Sdim 48341825Sdim /// Run the pass over the function. 49314564Sdim PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); 50283625Sdim}; 51283625Sdim 52285181Sdim} 53283625Sdim 54283625Sdim#endif 55