1 //===- InstCombine.h - InstCombine pass -------------------------*- 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 //===----------------------------------------------------------------------===//
10 /// This file provides the primary interface to the instcombine pass. This pass
11 /// is suitable for use in the new pass manager. For a pass that works with the
12 /// legacy pass manager, use \c createInstructionCombiningPass().
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINE_H
17 #define LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINE_H
19 #include "llvm/IR/Function.h"
20 #include "llvm/IR/PassManager.h"
21 #include "llvm/Transforms/InstCombine/InstCombineWorklist.h"
25 class InstCombinePass
: public PassInfoMixin
<InstCombinePass
> {
26 InstCombineWorklist Worklist
;
27 bool ExpensiveCombines
;
30 static StringRef
name() { return "InstCombinePass"; }
32 explicit InstCombinePass(bool ExpensiveCombines
= true)
33 : ExpensiveCombines(ExpensiveCombines
) {}
35 PreservedAnalyses
run(Function
&F
, FunctionAnalysisManager
&AM
);
38 /// The legacy pass manager's instcombine pass.
40 /// This is a basic whole-function wrapper around the instcombine utility. It
41 /// will try to combine all instructions in the function.
42 class InstructionCombiningPass
: public FunctionPass
{
43 InstCombineWorklist Worklist
;
44 const bool ExpensiveCombines
;
47 static char ID
; // Pass identification, replacement for typeid
49 InstructionCombiningPass(bool ExpensiveCombines
= true)
50 : FunctionPass(ID
), ExpensiveCombines(ExpensiveCombines
) {
51 initializeInstructionCombiningPassPass(*PassRegistry::getPassRegistry());
54 void getAnalysisUsage(AnalysisUsage
&AU
) const override
;
55 bool runOnFunction(Function
&F
) override
;
58 //===----------------------------------------------------------------------===//
60 // InstructionCombining - Combine instructions to form fewer, simple
61 // instructions. This pass does not modify the CFG, and has a tendency to make
62 // instructions dead, so a subsequent DCE pass is useful.
64 // This pass combines things like:
70 FunctionPass
*createInstructionCombiningPass(bool ExpensiveCombines
= true);