LLVM 17.0.0git
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"
21#include "llvm/Pass.h"
22
23#define DEBUG_TYPE "instcombine"
25
26namespace llvm {
27
28static constexpr unsigned InstCombineDefaultMaxIterations = 1000;
29
31 bool UseLoopInfo = false;
33
34 InstCombineOptions() = default;
35
38 return *this;
39 }
40
43 return *this;
44 }
45};
46
47class InstCombinePass : public PassInfoMixin<InstCombinePass> {
48private:
49 InstructionWorklist Worklist;
50 InstCombineOptions Options;
51
52public:
53 explicit InstCombinePass(InstCombineOptions Opts = {});
55 function_ref<StringRef(StringRef)> MapClassName2PassName);
56
58};
59
60/// The legacy pass manager's instcombine pass.
61///
62/// This is a basic whole-function wrapper around the instcombine utility. It
63/// will try to combine all instructions in the function.
65 InstructionWorklist Worklist;
66 const unsigned MaxIterations;
67
68public:
69 static char ID; // Pass identification, replacement for typeid
70
71 explicit InstructionCombiningPass();
72 explicit InstructionCombiningPass(unsigned MaxIterations);
73
74 void getAnalysisUsage(AnalysisUsage &AU) const override;
75 bool runOnFunction(Function &F) override;
76};
77
78//===----------------------------------------------------------------------===//
79//
80// InstructionCombining - Combine instructions to form fewer, simple
81// instructions. This pass does not modify the CFG, and has a tendency to make
82// instructions dead, so a subsequent DCE pass is useful.
83//
84// This pass combines things like:
85// %Y = add int 1, %X
86// %Z = add int 1, %Y
87// into:
88// %Z = add int 2, %X
89//
91FunctionPass *createInstructionCombiningPass(unsigned MaxIterations);
92}
93
94#undef DEBUG_TYPE
95
96#endif
#define F(x, y, z)
Definition: MD5.cpp:55
This header defines various interfaces for pass management in LLVM.
raw_pwrite_stream & OS
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:620
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:311
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
The legacy pass manager's instcombine pass.
Definition: InstCombine.h:64
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
InstructionWorklist - This is the worklist management logic for InstCombine and other simplification ...
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
LLVM Value Representation.
Definition: Value.h:74
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
FunctionPass * createInstructionCombiningPass()
static constexpr unsigned InstCombineDefaultMaxIterations
Definition: InstCombine.h:28
InstCombineOptions & setMaxIterations(unsigned Value)
Definition: InstCombine.h:41
InstCombineOptions & setUseLoopInfo(bool Value)
Definition: InstCombine.h:36
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:371