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 <optional>
20
21namespace llvm {
22
23class FunctionPass;
24
25/// A set of parameters to control various transforms performed by GVN pass.
26// Each of the optional boolean parameters can be set to:
27/// true - enabling the transformation.
28/// false - disabling the transformation.
29/// None - relying on a global default.
30/// Intended use is to create a default object, modify parameters with
31/// additional setters and then pass it to GVN.
32struct GVNOptions {
33 std::optional<bool> AllowScalarPRE;
34 std::optional<bool> AllowLoadPRE;
35 std::optional<bool> AllowLoadInLoopPRE;
36 std::optional<bool> AllowLoadPRESplitBackedge;
37 std::optional<bool> AllowMemDep;
38 std::optional<bool> AllowMemorySSA;
39
40 GVNOptions() = default;
41
42 /// Enables or disables PRE of scalars in GVN.
43 GVNOptions &setScalarPRE(bool ScalarPRE) {
44 AllowScalarPRE = ScalarPRE;
45 return *this;
46 }
47
48 /// Enables or disables PRE of loads in GVN.
49 GVNOptions &setLoadPRE(bool LoadPRE) {
50 AllowLoadPRE = LoadPRE;
51 return *this;
52 }
53
54 GVNOptions &setLoadInLoopPRE(bool LoadInLoopPRE) {
55 AllowLoadInLoopPRE = LoadInLoopPRE;
56 return *this;
57 }
58
59 /// Enables or disables PRE of loads in GVN.
60 GVNOptions &setLoadPRESplitBackedge(bool LoadPRESplitBackedge) {
61 AllowLoadPRESplitBackedge = LoadPRESplitBackedge;
62 return *this;
63 }
64
65 /// Enables or disables use of MemDepAnalysis.
66 GVNOptions &setMemDep(bool MemDep) {
67 AllowMemDep = MemDep;
68 return *this;
69 }
70
71 /// Enables or disables use of MemorySSA.
72 GVNOptions &setMemorySSA(bool MemSSA) {
73 AllowMemorySSA = MemSSA;
74 return *this;
75 }
76};
77
78class GVNPass : public OptionalPassInfoMixin<GVNPass> {
79 GVNOptions Options;
80
81public:
82 GVNPass(GVNOptions Options = {}) : Options(Options) {}
83
84 /// Run the pass over the function.
85 LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
86
87 LLVM_ABI void
88 printPipeline(raw_ostream &OS,
89 function_ref<StringRef(StringRef)> MapClassName2PassName);
90};
91
92/// Create a legacy GVN pass.
93LLVM_ABI FunctionPass *createGVNPass(bool ScalarPRE);
95
96} // end namespace llvm
97
98#endif // LLVM_TRANSFORMS_SCALAR_GVN_H
#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
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Run the pass over the function.
Definition GVN.cpp:1195
GVNPass(GVNOptions Options={})
Definition GVN.h:82
LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition GVN.cpp:1236
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI FunctionPass * createGVNPass()
Definition GVN.cpp:4442
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:32
GVNOptions & setLoadPRE(bool LoadPRE)
Enables or disables PRE of loads in GVN.
Definition GVN.h:49
std::optional< bool > AllowLoadPRESplitBackedge
Definition GVN.h:36
std::optional< bool > AllowScalarPRE
Definition GVN.h:33
GVNOptions & setLoadInLoopPRE(bool LoadInLoopPRE)
Definition GVN.h:54
std::optional< bool > AllowLoadInLoopPRE
Definition GVN.h:35
std::optional< bool > AllowMemDep
Definition GVN.h:37
GVNOptions & setMemDep(bool MemDep)
Enables or disables use of MemDepAnalysis.
Definition GVN.h:66
GVNOptions & setScalarPRE(bool ScalarPRE)
Enables or disables PRE of scalars in GVN.
Definition GVN.h:43
std::optional< bool > AllowLoadPRE
Definition GVN.h:34
GVNOptions & setLoadPRESplitBackedge(bool LoadPRESplitBackedge)
Enables or disables PRE of loads in GVN.
Definition GVN.h:60
std::optional< bool > AllowMemorySSA
Definition GVN.h:38
GVNOptions()=default
GVNOptions & setMemorySSA(bool MemSSA)
Enables or disables use of MemorySSA.
Definition GVN.h:72
A CRTP mix-in for passes that can be skipped.