1 //===- InstCombine.h - InstCombine pass -------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 ///
11 /// This file provides the primary interface to the instcombine pass. This pass
12 /// is suitable for use in the new pass manager. For a pass that works with the
13 /// legacy pass manager, please look for \c createInstructionCombiningPass() in
14 /// Scalar.h.
15 ///
16 //===----------------------------------------------------------------------===//
17 
18 #ifndef LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINE_H
19 #define LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINE_H
20 
21 #include "llvm/IR/Function.h"
22 #include "llvm/IR/PassManager.h"
23 #include "llvm/Transforms/InstCombine/InstCombineWorklist.h"
24 
25 namespace llvm {
26 
27 class InstCombinePass : public PassInfoMixin<InstCombinePass> {
28   InstCombineWorklist Worklist;
29   bool ExpensiveCombines;
30 
31 public:
name()32   static StringRef name() { return "InstCombinePass"; }
33 
34   // Explicitly define constructors for MSVC.
35   InstCombinePass(bool ExpensiveCombines = true)
ExpensiveCombines(ExpensiveCombines)36       : ExpensiveCombines(ExpensiveCombines) {}
InstCombinePass(InstCombinePass && Arg)37   InstCombinePass(InstCombinePass &&Arg)
38       : Worklist(std::move(Arg.Worklist)),
39         ExpensiveCombines(Arg.ExpensiveCombines) {}
40   InstCombinePass &operator=(InstCombinePass &&RHS) {
41     Worklist = std::move(RHS.Worklist);
42     ExpensiveCombines = RHS.ExpensiveCombines;
43     return *this;
44   }
45 
46   PreservedAnalyses run(Function &F, AnalysisManager<Function> &AM);
47 };
48 
49 /// \brief The legacy pass manager's instcombine pass.
50 ///
51 /// This is a basic whole-function wrapper around the instcombine utility. It
52 /// will try to combine all instructions in the function.
53 class InstructionCombiningPass : public FunctionPass {
54   InstCombineWorklist Worklist;
55   const bool ExpensiveCombines;
56 
57 public:
58   static char ID; // Pass identification, replacement for typeid
59 
60   InstructionCombiningPass(bool ExpensiveCombines = true)
FunctionPass(ID)61       : FunctionPass(ID), ExpensiveCombines(ExpensiveCombines) {
62     initializeInstructionCombiningPassPass(*PassRegistry::getPassRegistry());
63   }
64 
65   void getAnalysisUsage(AnalysisUsage &AU) const override;
66   bool runOnFunction(Function &F) override;
67 };
68 }
69 
70 #endif
71