1 //===- InstCombine.h - InstCombine pass -------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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, use \c createInstructionCombiningPass().
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINE_H
18 #define LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINE_H
20 #include "llvm/IR/Function.h"
21 #include "llvm/IR/PassManager.h"
22 #include "llvm/Transforms/InstCombine/InstCombineWorklist.h"
26 class InstCombinePass : public PassInfoMixin<InstCombinePass> {
27 InstCombineWorklist Worklist;
28 bool ExpensiveCombines;
31 static StringRef name() { return "InstCombinePass"; }
33 explicit InstCombinePass(bool ExpensiveCombines = true)
34 : ExpensiveCombines(ExpensiveCombines) {}
36 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
39 /// The legacy pass manager's instcombine pass.
41 /// This is a basic whole-function wrapper around the instcombine utility. It
42 /// will try to combine all instructions in the function.
43 class InstructionCombiningPass : public FunctionPass {
44 InstCombineWorklist Worklist;
45 const bool ExpensiveCombines;
48 static char ID; // Pass identification, replacement for typeid
50 InstructionCombiningPass(bool ExpensiveCombines = true)
51 : FunctionPass(ID), ExpensiveCombines(ExpensiveCombines) {
52 initializeInstructionCombiningPassPass(*PassRegistry::getPassRegistry());
55 void getAnalysisUsage(AnalysisUsage &AU) const override;
56 bool runOnFunction(Function &F) override;
59 //===----------------------------------------------------------------------===//
61 // InstructionCombining - Combine instructions to form fewer, simple
62 // instructions. This pass does not modify the CFG, and has a tendency to make
63 // instructions dead, so a subsequent DCE pass is useful.
65 // This pass combines things like:
71 FunctionPass *createInstructionCombiningPass(bool ExpensiveCombines = true);