LLVM 24.0.0git
GVN.h
Go to the documentation of this file.
1//===- GVN.h - Eliminate redundant values and loads -------------*- 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/// This file provides the interface for LLVM's Global Value Numbering pass
10/// which eliminates fully redundant instructions. It also does somewhat Ad-Hoc
11/// PRE and dead load elimination.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_TRANSFORMS_SCALAR_GVN_H
16#define LLVM_TRANSFORMS_SCALAR_GVN_H
17
18#include "llvm/IR/PassManager.h"
19#include <memory>
20#include <optional>
21
22namespace llvm {
23
24class FunctionPass;
25class GVNPassImpl;
26
27/// A set of parameters to control various transforms performed by GVN pass.
28// Each of the optional boolean parameters can be set to:
29/// true - enabling the transformation.
30/// false - disabling the transformation.
31/// None - relying on a global default.
32/// Intended use is to create a default object, modify parameters with
33/// additional setters and then pass it to GVN.
34struct GVNOptions {
35 std::optional<bool> AllowScalarPRE;
36 std::optional<bool> AllowLoadPRE;
37 std::optional<bool> AllowLoadInLoopPRE;
38 std::optional<bool> AllowLoadPRESplitBackedge;
39 std::optional<bool> AllowMemDep;
40 std::optional<bool> AllowMemorySSA;
41
42 GVNOptions() = default;
43
44 /// Enables or disables PRE of scalars in GVN.
45 GVNOptions &setScalarPRE(bool ScalarPRE) {
46 AllowScalarPRE = ScalarPRE;
47 return *this;
48 }
49
50 /// Enables or disables PRE of loads in GVN.
51 GVNOptions &setLoadPRE(bool LoadPRE) {
52 AllowLoadPRE = LoadPRE;
53 return *this;
54 }
55
56 GVNOptions &setLoadInLoopPRE(bool LoadInLoopPRE) {
57 AllowLoadInLoopPRE = LoadInLoopPRE;
58 return *this;
59 }
60
61 /// Enables or disables PRE of loads in GVN.
62 GVNOptions &setLoadPRESplitBackedge(bool LoadPRESplitBackedge) {
63 AllowLoadPRESplitBackedge = LoadPRESplitBackedge;
64 return *this;
65 }
66
67 /// Enables or disables use of MemDepAnalysis.
68 GVNOptions &setMemDep(bool MemDep) {
69 AllowMemDep = MemDep;
70 return *this;
71 }
72
73 /// Enables or disables use of MemorySSA.
74 GVNOptions &setMemorySSA(bool MemSSA) {
75 AllowMemorySSA = MemSSA;
76 return *this;
77 }
78};
79
80class GVNPass : public OptionalPassInfoMixin<GVNPass> {
81 std::unique_ptr<GVNPassImpl> Impl;
82
83public:
86
87 LLVM_ABI GVNPass(GVNPass &&) noexcept;
88 LLVM_ABI GVNPass &operator=(GVNPass &&) noexcept;
89
90 GVNPass(const GVNPass &) = delete;
91 GVNPass &operator=(const GVNPass &) = delete;
92
93 /// Run the pass over the function.
95
96 LLVM_ABI void
98 function_ref<StringRef(StringRef)> MapClassName2PassName);
99};
100
101/// Create a legacy GVN pass.
102LLVM_ABI FunctionPass *createGVNPass(bool ScalarPRE);
104
105} // end namespace llvm
106
107#endif // LLVM_TRANSFORMS_SCALAR_GVN_H
aarch64 promote const
#define LLVM_ABI
Definition Compiler.h:215
This header defines various interfaces for pass management in LLVM.
static LVOptions Options
Definition LVOptions.cpp:25
#define F(x, y, z)
Definition MD5.cpp:54
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
The core GVN pass object.
Definition GVN.cpp:242
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Run the pass over the function.
Definition GVN.cpp:1168
LLVM_ABI GVNPass(GVNOptions Options={})
Definition GVN.cpp:1159
LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition GVN.cpp:1207
LLVM_ABI ~GVNPass()
LLVM_ABI GVNPass(GVNPass &&) noexcept
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
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:53
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI FunctionPass * createGVNPass(bool ScalarPRE)
Create a legacy GVN pass.
Definition GVN.cpp:4428
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
A set of parameters to control various transforms performed by GVN pass.
Definition GVN.h:34
GVNOptions & setLoadPRE(bool LoadPRE)
Enables or disables PRE of loads in GVN.
Definition GVN.h:51
std::optional< bool > AllowLoadPRESplitBackedge
Definition GVN.h:38
std::optional< bool > AllowScalarPRE
Definition GVN.h:35
GVNOptions & setLoadInLoopPRE(bool LoadInLoopPRE)
Definition GVN.h:56
std::optional< bool > AllowLoadInLoopPRE
Definition GVN.h:37
std::optional< bool > AllowMemDep
Definition GVN.h:39
GVNOptions & setMemDep(bool MemDep)
Enables or disables use of MemDepAnalysis.
Definition GVN.h:68
GVNOptions & setScalarPRE(bool ScalarPRE)
Enables or disables PRE of scalars in GVN.
Definition GVN.h:45
std::optional< bool > AllowLoadPRE
Definition GVN.h:36
GVNOptions & setLoadPRESplitBackedge(bool LoadPRESplitBackedge)
Enables or disables PRE of loads in GVN.
Definition GVN.h:62
std::optional< bool > AllowMemorySSA
Definition GVN.h:40
GVNOptions()=default
GVNOptions & setMemorySSA(bool MemSSA)
Enables or disables use of MemorySSA.
Definition GVN.h:74
A CRTP mix-in for passes that can be skipped.