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#include "llvm/Pass.h"
22
23#define DEBUG_TYPE "instcombine"
24#include "llvm/Transforms/Utils/InstructionWorklist.h"
25
26namespace llvm {
27
28static constexpr unsigned InstCombineDefaultMaxIterations = 1;
29
30struct InstCombineOptions {
31 bool UseLoopInfo = false;
32 // Verify that a fix point has been reached after MaxIterations.
33 bool VerifyFixpoint = false;
34 unsigned MaxIterations = InstCombineDefaultMaxIterations;
35
36 InstCombineOptions() = default;
37
38 InstCombineOptions &setUseLoopInfo(bool Value) {
39 UseLoopInfo = Value;
40 return *this;
41 }
42
43 InstCombineOptions &setVerifyFixpoint(bool Value) {
44 VerifyFixpoint = Value;
45 return *this;
46 }
47
48 InstCombineOptions &setMaxIterations(unsigned Value) {
49 MaxIterations = Value;
50 return *this;
51 }
52};
53
54class InstCombinePass : public PassInfoMixin<InstCombinePass> {
55private:
56 InstructionWorklist Worklist;
57 InstCombineOptions Options;
58
59public:
60 explicit InstCombinePass(InstCombineOptions Opts = {});
61 void printPipeline(raw_ostream &OS,
62 function_ref<StringRef(StringRef)> MapClassName2PassName);
63
64 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
65};
66
67/// The legacy pass manager's instcombine pass.
68///
69/// This is a basic whole-function wrapper around the instcombine utility. It
70/// will try to combine all instructions in the function.
71class InstructionCombiningPass : public FunctionPass {
72 InstructionWorklist Worklist;
73
74public:
75 static char ID; // Pass identification, replacement for typeid
76
77 explicit InstructionCombiningPass();
78
79 void getAnalysisUsage(AnalysisUsage &AU) const override;
80 bool runOnFunction(Function &F) override;
81};
82
83//===----------------------------------------------------------------------===//
84//
85// InstructionCombining - Combine instructions to form fewer, simple
86// instructions. This pass does not modify the CFG, and has a tendency to make
87// instructions dead, so a subsequent DCE pass is useful.
88//
89// This pass combines things like:
90// %Y = add int 1, %X
91// %Z = add int 1, %Y
92// into:
93// %Z = add int 2, %X
94//
95FunctionPass *createInstructionCombiningPass();
96}
97
98#undef DEBUG_TYPE
99
100#endif
101

source code of llvm/include/llvm/Transforms/InstCombine/InstCombine.h