1 //===- InstCombine.h - InstCombine pass -------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 ///
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().
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINE_H
17 #define LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINE_H
18 
19 #include "llvm/IR/Function.h"
20 #include "llvm/IR/PassManager.h"
21 
22 #define DEBUG_TYPE "instcombine"
23 #include "llvm/Transforms/Utils/InstructionWorklist.h"
24 
25 namespace llvm {
26 
27 class InstCombinePass : public PassInfoMixin<InstCombinePass> {
28   InstructionWorklist Worklist;
29   const unsigned MaxIterations;
30 
31 public:
32   explicit InstCombinePass();
33   explicit InstCombinePass(unsigned MaxIterations);
34 
35   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
36 };
37 
38 /// The legacy pass manager's instcombine pass.
39 ///
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   InstructionWorklist Worklist;
44   const unsigned MaxIterations;
45 
46 public:
47   static char ID; // Pass identification, replacement for typeid
48 
49   explicit InstructionCombiningPass();
50   explicit InstructionCombiningPass(unsigned MaxIterations);
51 
52   void getAnalysisUsage(AnalysisUsage &AU) const override;
53   bool runOnFunction(Function &F) override;
54 };
55 
56 //===----------------------------------------------------------------------===//
57 //
58 // InstructionCombining - Combine instructions to form fewer, simple
59 // instructions. This pass does not modify the CFG, and has a tendency to make
60 // instructions dead, so a subsequent DCE pass is useful.
61 //
62 // This pass combines things like:
63 //    %Y = add int 1, %X
64 //    %Z = add int 1, %Y
65 // into:
66 //    %Z = add int 2, %X
67 //
68 FunctionPass *createInstructionCombiningPass();
69 FunctionPass *createInstructionCombiningPass(unsigned MaxIterations);
70 }
71 
72 #undef DEBUG_TYPE
73 
74 #endif
75