LLVM  9.0.0svn
InstCombine.h
Go to the documentation of this file.
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"
22 
23 namespace llvm {
24 
25 class InstCombinePass : public PassInfoMixin<InstCombinePass> {
26  InstCombineWorklist Worklist;
27  bool ExpensiveCombines;
28 
29 public:
30  static StringRef name() { return "InstCombinePass"; }
31 
32  explicit InstCombinePass(bool ExpensiveCombines = true)
33  : ExpensiveCombines(ExpensiveCombines) {}
34 
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.
43  InstCombineWorklist Worklist;
44  const bool ExpensiveCombines;
45 
46 public:
47  static char ID; // Pass identification, replacement for typeid
48 
49  InstructionCombiningPass(bool ExpensiveCombines = true)
50  : FunctionPass(ID), ExpensiveCombines(ExpensiveCombines) {
52  }
53 
54  void getAnalysisUsage(AnalysisUsage &AU) const override;
55  bool runOnFunction(Function &F) override;
56 };
57 
58 //===----------------------------------------------------------------------===//
59 //
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.
63 //
64 // This pass combines things like:
65 // %Y = add int 1, %X
66 // %Z = add int 1, %Y
67 // into:
68 // %Z = add int 2, %X
69 //
70 FunctionPass *createInstructionCombiningPass(bool ExpensiveCombines = true);
71 }
72 
73 #endif
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
Definition: AllocatorList.h:23
F(f)
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:372
FunctionPass * createInstructionCombiningPass(bool ExpensiveCombines=true)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
static bool runOnFunction(Function &F, bool PostInlining)
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:284
The legacy pass manager&#39;s instcombine pass.
Definition: InstCombine.h:42
InstructionCombiningPass(bool ExpensiveCombines=true)
Definition: InstCombine.h:49
InstCombineWorklist - This is the worklist management logic for InstCombine.
InstCombinePass(bool ExpensiveCombines=true)
Definition: InstCombine.h:32
static StringRef name()
Definition: InstCombine.h:30
void initializeInstructionCombiningPassPass(PassRegistry &)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
A container for analyses that lazily runs them and caches their results.
This header defines various interfaces for pass management in LLVM.