LLVM 24.0.0git
MFPropsModifier.h
Go to the documentation of this file.
1//===- MFPropsModifier.h - Machine function properties ---------*- 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//
9// An RAII helper for checking and updating machine function properties.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CODEGEN_MFPROPSMODIFIER_H
14#define LLVM_CODEGEN_MFPROPSMODIFIER_H
15
16#include "llvm/ADT/STLExtras.h"
20#include <utility>
21
22namespace llvm {
23
24/// An RAII based helper class to modify MachineFunctionProperties when running
25/// pass. Define a MFPropsModifier in PassT::run to set
26/// MachineFunctionProperties properly.
27template <typename PassT> class MFPropsModifier {
28public:
29 MFPropsModifier(const PassT &P_, MachineFunction &MF_) : P(P_), MF(MF_) {
30 auto &MFProps = MF.getProperties();
31#ifndef NDEBUG
32 if constexpr (has_get_required_properties_v<PassT>) {
33 auto &MFProps = MF.getProperties();
34 auto RequiredProperties = P.getRequiredProperties();
35 if (!MFProps.verifyRequiredProperties(RequiredProperties)) {
36 errs() << "MachineFunctionProperties required by " << PassT::name()
37 << " pass are not met by function " << MF.getName() << ".\n"
38 << "Required properties: ";
39 RequiredProperties.print(errs());
40 errs() << "\nCurrent properties: ";
41 MFProps.print(errs());
42 errs() << '\n';
43 reportFatalUsageError("MachineFunctionProperties check failed");
44 }
45 }
46#endif // NDEBUG
47 if constexpr (has_get_cleared_properties_v<PassT>)
48 MFProps.reset(P.getClearedProperties());
49 }
50
52 if constexpr (has_get_set_properties_v<PassT>) {
53 auto &MFProps = MF.getProperties();
54 MFProps.set(P.getSetProperties());
55 }
56 }
57
58private:
59 const PassT &P;
61
62 template <typename T>
63 using has_get_required_properties_t =
64 decltype(std::declval<T &>().getRequiredProperties());
65
66 template <typename T>
67 using has_get_set_properties_t =
68 decltype(std::declval<T &>().getSetProperties());
69
70 template <typename T>
71 using has_get_cleared_properties_t =
72 decltype(std::declval<T &>().getClearedProperties());
73
74 template <typename T>
75 static constexpr bool has_get_required_properties_v =
77
78 template <typename T>
79 static constexpr bool has_get_set_properties_v =
81
82 template <typename T>
83 static constexpr bool has_get_cleared_properties_v =
85};
86
87// Additional deduction guide to suppress warning.
88template <typename PassT>
90
91} // namespace llvm
92
93#endif // LLVM_CODEGEN_MFPROPSMODIFIER_H
#define P_
#define P(N)
This file contains some templates that are useful if you are working with the STL at all.
An RAII based helper class to modify MachineFunctionProperties when running pass.
MFPropsModifier(const PassT &P_, MachineFunction &MF_)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
MFPropsModifier(PassT &P, MachineFunction &MF) -> MFPropsModifier< PassT >
typename detail::detector< void, Op, Args... >::value_t is_detected
Detects if a given trait holds for some set of arguments 'Args'.
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:177